在 Azure 中部署容器实例

查克尼特·宾
查克尼特·宾
2024年七月2日
更新 2024年十一月19日
分享:
This article was translated from English: Does it need improvement?
Translated
View the article in English

使用Azure 上的 Terraform来部署 IronSecureDoc Docker 容器,并使其可通过公网 IP 地址和 FQDN 访问。

先决条件

步骤1:克隆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"

步骤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 方面拥有深厚的专业知识,帮助改进软件并支持客户。他从用户互动中获得的洞察力,有助于提升产品、文档和整体体验。