使用 Azure Cloud Kit 快速入门
- 先决条件
- 下载 Azure Cloud Kit
- 配置 Azure CLI
- 为 Terraform 状态准备环境
- 初始化 Terraform
- 定制化
- 检查计划
- 应用 Terraform
- 连接到 Kubernetes 集群
- 清理 Terraform 部署的项目
Azure Cloud Kit 可以让您将 Vaadin 应用程序快速部署到 Microsoft 的 Azure Cloud。该套件包含一组 Terraform 蓝图,用于将您的应用部署到 Azure Cloud,特别是部署到 Azure Kubernetes Service(AKS)。
Terraform 是一款开源的基础设施即代码(IaC)软件工具,提供一致的 CLI 工作流,使您能够安全、可预测地创建、更改 和完善云基础设施。
配置 Azure CLI
首先,需通过终端使用 Azure CLI 登录您的 Azure 帐户。然后选择您希望用于部署的 Azure 订阅。
在终端执行以下命令登录 Azure:
Source code
terminal
az login现在,选择用于部署的 Azure 订阅:
Source code
terminal
az account set --subscription <SUBSCRIPTION_ID>请务必验证您已登录,并选择了正确的订阅。您可以执行以下命令进行验证:
Source code
terminal
az account show为 Terraform 状态准备环境
要使用 Azure Cloud Kit,您需要创建一个用于 Terraform 状态的存储账户和容器。Terraform 状态用于跟踪已创建的资源。Terraform 根据这些信息,在您运行 terraform apply(用于将应用部署到 Azure)时判断需要做出的更改。
Azure Cloud Kit 中包含一个名为 create_terraform_storage.sh 的脚本。运行该脚本后,它将在所选 Azure 订阅下创建用于 Terraform 状态的存储账户和容器。
运行脚本的方法是,打开终端窗口,导航到您解压 Azure Cloud Kit 的文件夹,然后运行以下命令:
Source code
Terminal
create_terraform_storage.sh脚本的输出会包含存储账户的名称(即 storageaccount)。该名称是随机生成的,在您的 Azure 订阅中是唯一的。您需要在下一步中使用该名称,请确保记录 storageaccount 的值。
初始化 Terraform
接下来,需将解压 Azure Cloud Kit 的目录初始化为 Terraform 工作目录。为此,打开终端,切换至该目录,并执行如下命令:
Source code
terminal
terraform initTerraform 随后会下载 Azure provider 及其它必需插件。初始化过程中,Terraform 会要求您输入在上一步创建的存储账户名称。
Source code
terminal
Initializing modules...
- acr in modules/acr
- aks in modules/aks
- keyvault in modules/keyvault
- network in modules/network
Initializing the backend...
storage_account_name
The name of the storage account.
Enter a value: <enter storageaccount name>
Successfully configured the backend "azurerm"! Terraform will automatically
use this backend unless the backend configuration changes.
Initializing provider plugins...
...定制化
Azure Cloud Kit 将定义部署的配置存储在两个文件中:variables.tf 和 settings.tf。您可以在 Azure Cloud Kit 根目录下找到这些文件。
variables.tf 文件包含描述部署的大多数变量,包括:
-
应用程序名称和环境名称;
-
希望部署应用的 Azure 区域;
-
Kubernetes 集群中的节点数目;
-
节点的规格。
该列表并非完全,还可能有其他变量。
settings.tf 文件包含部署的网络设置。
variables.tf 和 settings.tf 文件都已填充有默认值,您可根据需要编辑它们。