在 Azure 中部署 C# 容器实例
使用Azure 上的 Terraform部署 IronSecureDoc Docker 容器,并使其具有公共 IP 地址和 FQDN。
前提条件
步骤 1:克隆 GitHub 仓库模板
我们已为您准备好 GitHub 仓库模板,您可以克隆并立即开始使用,链接如下:
https://github.com/iron-software/IronSecureDoc-Terraform/步骤二:修改所有资源名称
修改variables.tf中的所有资源名称
resource_group_name:资源组名称。resource_group_location:资源组的位置。您可以从 REGIONS.md 文件中找到区域,并使用第二列来填充此变量。container_group_name:容器组的名称。container_name: 容器的名称。image_tag: 要部署的镜像的标签; 可以是latest,也可以是任何特定版本号。- 其他变量无需更改。
创建secret.tfvars以包含所有敏感数据
在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."
}添加到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步骤六:验证结果
应用执行计划时,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 创建和应用执行计划。
在 Azure 部署中设置 Terraform 的必要步骤是什么?
首先,安装并配置 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 中已部署资源的过程是什么?
要使用 Terraform 销毁 Azure 中已部署的资源,请用 terraform plan -destroy -var-file='secret.tfvars' -out main.tfplan 创建销毁执行计划,并使用 terraform apply main.tfplan 应用它。





