在 Azure 中部署容器實例
This article was translated from English: Does it need improvement?
TranslatedView 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 容器註冊處
main.tf
在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."
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 計劃創建執行計劃。
terraform plan -var-file="secret.tfvars" -out main.tfplan
步驟 5:應用 Terraform 執行計劃
執行執行 terraform apply將執行計劃應用於您的雲基礎設施。
terraform apply main.tfplan
步驟 6:驗證結果
- 當您應用執行計劃時,Terraform 會輸出公共 IP 地址。 要再次顯示 IP 地址,請執行 terraform output。
terraform output -raw container_ipv4_address
或顯示完整域名 (FQDN)。
terraform output -raw container_fqdn
- 使用 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