全部產品
Search
文件中心

Enterprise Distributed Application Service:使用Terraform建立K8s叢集並部署應用

更新時間:Jun 30, 2024

使用Terraform能夠在Container ServiceKubernetes版中建立K8s叢集並匯入EDAS,然後在K8s叢集中部署應用。您可以參見文本查看可用的介面資訊和配置樣本。

介面說明

Data Sources

Resources

配置樣本

下文列出了在EDAS的K8s叢集中部署應用的操作樣本。請根據您的實際情況修改配置參數。

  1. 在Container ServiceKubernetes版中建立託管版K8s叢集。
    說明 Terraform支援在Container ServiceKubernetes版中建立各種類型叢集,此處僅以託管版K8s叢集為例。
    resource "alicloud_cs_managed_kubernetes" "default" {
     worker_instance_types = [data.alicloud_instance_types.default.instance_types.0.id]
     name = var.name
     worker_vswitch_ids = [alicloud_vswitch.default.id]
     worker_number = "1"
     password =          "Test12345"
     pod_cidr =          "172.20.0.0/16"
     service_cidr =        "172.21.0.0/20"
     worker_disk_size =      "50"
     worker_disk_category =     "cloud_ssd"
     worker_data_disk_size =    "20"
     worker_data_disk_category =  "cloud_ssd"
     worker_instance_charge_type = "PostPaid"
     slb_internet_enabled =    "true"
    }
  2. 將託管版K8s叢集匯入到EDAS中。
    resource "alicloud_edas_k8s_cluster" "default" {
      cs_cluster_id = "xxxx-xxx-xxx"
    }
  3. 在K8s叢集中建立並部署應用。
    resource "alicloud_edas_k8s_application" "default" {
     application_name = "shesheng-test-k8s"
     cluster_id = "45bc8232-3233-46be-ab20-6d4a9b506d5c"
     replicas = 1
     package_type = "Image"
     image_url = "cr.registry.cloud.ste2.com/test/gw-provider:1028"
     command = "/bin/sh"
     command_args = ["-c", "while true; do echo hello; sleep 1000;done"]
    }