在 Azure 中部署容器實例

查克尼思·賓
查克尼思·賓
2024年7月2日
已更新 2024年11月19日
分享:
This article was translated from English: Does it need improvement?
Translated
View the article in English

使用Azure 上的 Terraform來部署 IronSecureDoc Docker 容器,並使其可通過公共 IP 地址和 FQDN 訪問。

先決條件

步驟一:複製 GitHub 儲存庫範本

我們已經為您準備好了 GitHub 存儲庫範本,可以讓您立即克隆並開始使用,請點擊這裡

https://github.com/iron-software/IronSecureDoc-Terraform/

步驟2:修改所有資源名稱

修改variables.tf中的所有資源名稱

  • resource_group_name:資源群組的名稱。
  • resource_group_location: 資源組的位置。您可以從 REGIONS.md 中找到區域,使用第二列填寫此變量。
  • container_group_name:容器群組的名稱。
  • container_name:容器名稱。
  • image_tag:要部署的映像標籤可以是latest或任何數字。
  • 其他變量不需要更改。

建立secret.tfvars以包含所有敏感資料,並填寫以下變數

Azure 容器註冊處

dns_name_label = var.dns_name_label 之後,main.tf 附加如下內容:

image_registry_credential {
  server   = var.registry_server
  username = var.registry_username
  password = var.registry_password
}

variables.tf 添加:

variable "registry_server" {
  type        = string
  sensitive   = false
  description = "The server for the container registry. Required if the image is stored in a private registry."
}

variable "registry_username" {
  type        = string
  sensitive   = true
  description = "Username for the container registry. Required if the image is stored in a private registry."  
}

variable "registry_password" {
  type        = string
  sensitive   = true
  description = "Password for the container registry. Required if the image is stored in a private registry."
  default     = "latest"
}

secret.tfvars 添加:

registry_server     = "<registry-name>.azurecr.io"
registry_username   = "YOUR-REGISTRY-USERNAME"
registry_password   = "YOUR-REGISTRY-PASSWORD"
license_key         = "YOUR-LICENSE-KEY"

Docker Hub

secret.tfvars 添加:

license_key         = "YOUR-LICENSE-KEY"

步驟 3:初始化 Terraform

執行 terraform init 以初始化 Terraform 部署。 此命令下載所需的 Azure 提供者來管理您的 Azure 資源。

terraform init -upgrade

步驟 4:創建 Terraform 執行計劃

運行terraform plan以建立執行計畫。

terraform plan -var-file="secret.tfvars" -out main.tfplan

步驟 5:應用 Terraform 執行計劃

運行terraform apply以將執行計劃應用到您的雲端基礎架構。

terraform apply main.tfplan

步驟 6:驗證結果

  1. 當您應用執行計劃時,Terraform 會輸出公共 IP 地址。 要再次顯示 IP 地址,請執行 terraform output。
  terraform output -raw container_ipv4_address

或顯示完整域名 (FQDN)。

  terraform output -raw container_fqdn
  1. 使用 Postman 或 curl 進行驗證。 結果應返回pong
  curl http://<container_ipv4_address>:8080/v1/document-services/ping

或使用FQDN

  curl http://<container_fqdn>:8080/v1/document-services/ping

步驟 7:銷毀資源

  • 建立銷毀資源的執行計劃
terraform plan -destroy -var-files="secret.tfvars" -out main.tfplan
  • 應用執行破壞計劃
terraform apply main.tfplan
查克尼思·賓
軟體工程師
Chaknith 致力於 IronXL 和 IronBarcode。他在 C# 和 .NET 方面擁有豐富的專業知識,協助改進軟體並支持客戶。他從用戶互動中獲得的洞察力有助於提高產品、文檔和整體體驗。