在 Azure 中部署 C# 容器实例
使用 Terraform on Azure 部署 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 来包含所有敏感数据
填充 secret.tfvars 中的以下变量。
Azure容器注册表
在 dns_name_label = var.dns_name_label 之后附加到 main.tf:
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 -upgrade
步骤 4:创建 Terraform 执行计划
运行 terraform plan 创建执行计划。
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_addressSHELL或者显示完全限定域名 (FQDN)。
terraform output -raw container_fqdnSHELL -
使用 Postman 或
curl进行验证。 预期结果应返回pong。curl http://<container_ipv4_address>:8080/v1/document-services/pingSHELL或者使用完全限定域名 (FQDN)。
curl http://<container_fqdn>:8080/v1/document-services/pingSHELL
步骤 7:销毁资源
-
制定销毁资源的执行计划。
terraform plan -destroy -var-file="secret.tfvars" -out main.tfplanSHELL -
应用销毁计划。
terraform apply main.tfplanSHELL
常见问题
使用Terraform在Azure上部署IronSecureDoc的主要目的是什么?
其主要目的是在Azure上安全地管理和部署IronSecureDoc容器,通过公共IP地址和FQDN实现公用访问的同时确保文档安全。
在Azure上使用Terraform设置IronSecureDoc需要哪些先决条件?
要在Azure上使用Terraform设置IronSecureDoc,您需要安装和配置Terraform,并根据提供的指南将其认证到Azure。
如何克隆IronSecureDoc的GitHub仓库模板?
您可以从以下URL克隆IronSecureDoc的GitHub仓库模板:https://github.com/iron-software/IronSecureDoc-Terraform/.
我应该修改哪个Terraform文件来更改IronSecureDoc部署的资源名称?
修改variables.tf文件以更改资源名称,例如资源组名称、容器组名称和容器名称,以便部署IronSecureDoc。
我应该如何处理IronSecureDoc Azure部署的敏感数据?
敏感数据应存储在secret.tfvars文件中,其中包括注册表服务器、用户名、密码和许可证密钥等敏感变量,必要时用于安全部署。
如何在Azure中存储IronSecureDoc图像使用私有注册表?
要使用私有注册表,将图像注册表凭据块追加到main.tf并在variables.tf和secret.tfvars中添加必要的变量,以提供注册表服务器、用户名和密码。
初始化IronSecureDoc的Terraform部署的命令是什么?
terraform init命令初始化IronSecureDoc的Terraform部署,下载必要的Azure提供程序。
如何验证IronSecureDoc容器的部署?
您可以运行terraform output获得公共IP或FQDN并使用Postman或curl执行ping以期望得到pong响应来验证部署。
在Azure上销毁IronSecureDoc资源的过程是什么?
若要销毁资源,请创建一个销毁执行计划使用terraform plan -destroy,然后应用它使用terraform apply从Azure中删除IronSecureDoc资源。
我可以在部署过程中指定IronSecureDoc Docker镜像的标签吗?
是的,您可以通过在variables.tf文件中设置image_tag变量来指定IronSecureDoc Docker镜像的标签,使用latest或特定版本号。
Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。