Deploy a C# Container Instance in Azure
使用Azure上的Terraform來部署IronSecureDoc Docker容器,並使用公共IP地址和FQDN使其可用。
先決條件
步驟1:克隆GitHub儲存庫範本
我們已經準備好了GitHub儲存庫範本,您可以立即克隆並開始:
https://github.com/iron-software/IronSecureDoc-Terraform/步驟2:修改所有資源名稱
在variables.tf中修改所有資源名稱
resource_group_name:資源群組的名稱。REGIONS.md查找區域,並使用第二列填寫此變數。container_group_name:容器群組的名稱。container_name:容器的名稱。image_tag:要部署的映像標籤; 可以是latest或任何特定的版本號。- 其他變數不需要更改。
建立secret.tfvars來存放所有敏感資料
在secret.tfvars中填寫以下變數。
Azure容器註冊表
在dns_name_label = var.dns_name_label:
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."
}新增到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 -upgradeterraform init -upgrade步驟4:建立Terraform執行計畫
運行terraform plan來建立執行計畫。
terraform plan -var-file="secret.tfvars" -out main.tfplanterraform plan -var-file="secret.tfvars" -out main.tfplan步驟5:應用Terraform執行計畫
運行terraform apply來將執行計畫應用到您的雲基礎設施。
terraform apply main.tfplanterraform apply main.tfplan步驟6:驗證結果
當您應用執行計畫時,Terraform會輸出公共IP地址。 要再次顯示IP地址,請運行
terraform output。terraform output -raw container_ipv4_addressterraform output -raw container_ipv4_addressSHELL或顯示FQDN。
terraform output -raw container_fqdnterraform output -raw container_fqdnSHELL使用Postman或
curl進行驗證。 預期結果應返回pong。curl http://<container_ipv4_address>:8080/v1/document-services/pingcurl http://<container_ipv4_address>:8080/v1/document-services/pingSHELL或使用FQDN。
curl http://<container_fqdn>:8080/v1/document-services/pingcurl http://<container_fqdn>:8080/v1/document-services/pingSHELL
步驟7:銷毀資源
為銷毀資源建立執行計畫。
terraform plan -destroy -var-file="secret.tfvars" -out main.tfplanterraform plan -destroy -var-file="secret.tfvars" -out main.tfplanSHELL應用執行銷毀計畫。
terraform apply main.tfplanterraform apply main.tfplanSHELL
常見問題
如何使用Terraform在Azure中部署Docker容器?
要使用Terraform在Azure中部署Docker容器,您需要克隆IronSecureDoc的GitHub資料庫範本,修改`variables.tf`中的資源名稱,並建立包含敏感資料的`secret.tfvars`文件。然後,使用terraform init初始化部署,並使用terraform plan和terraform apply建立和應用執行計畫。
設置Terraform以進行Azure部署的必要步驟是什麼?
首先,安裝並配置Terraform,然後將其身份驗證到Azure。克隆IronSecureDoc的特定GitHub資料庫,修改`variables.tf`文件中的資源名稱,並在`secret.tfvars`中管理敏感資料。最後,初始化Terraform並建立部署的執行計畫。
在此部署中,Azure容器註冊表的角色是什麼?
Azure容器註冊表用於儲存Docker映像。您需要在`main.tf`文件中附加註冊表憑證,並在`variables.tf`和`secret.tfvars`中指定註冊表資訊,以便部署存取和部署所需的Docker映像。
如何確認我的Terraform部署在Azure中是否成功?
應用Terraform執行計畫後,運行terraform output獲取公眾IP地址或FQDN。使用Postman或curl等工具發送ping請求給服務。成功部署會返回'pong'。
用於初始化Azure部署的Terraform的命令是什麼?
要初始化Azure部署的Terraform,請使用命令terraform init -upgrade。這會下載管理Azure資源所需的提供者插件。
如何在Terraform配置中處理敏感資料?
諸如註冊表憑證和授權金鑰之類的敏感資料應儲存在`secret.tfvars`文件中。在Terraform計畫與應用過程中參考此文件以安全地管理敏感資訊。
使用Terraform在Azure中銷毀已部署的資源的過程是什麼?
要在Azure中使用Terraform銷毀已部署的資源,使用terraform plan -destroy -var-file='secret.tfvars' -out main.tfplan建立銷毀執行計畫並使用terraform apply main.tfplan應用它。





