在 Azure 中部署容器實例

使用 在 Azure 上使用 Terraform 部署 IronSecureDoc Docker 容器,並使其可用於具有公共 IP 地址和完全合格域名 (FQDN) 的情況。

先決條件

安裝和配置Terraform

第一步:克隆 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.tfdns_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"

第三步:初始化 Terraform

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

terraform init -upgrade

第 4 步:建立 Terraform 執行計劃

運行 terraform 計劃 創建執行計劃。

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

步驟五:應用 Terraform 執行計劃

執行 執行 terraform apply 將執行計劃應用於您的雲基礎設施。

terraform apply main.tfplan

第六步:驗證結果

  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

第七步:銷毀資源

  • 建立銷毀資源的執行計畫
terraform plan -destroy -var-files="secret.tfvars" -out main.tfplan
  • 應用執行破壞計劃
terraform apply main.tfplan