跳转到内容

Terraform 创建 CCE 集群

The following extra overheads are required on each node. If these overheads are excluded, the real service workload is running.

  1. Operating system
  2. kubelet and kube-proxy
  3. Docker or other container runtime service

k8s architecture

When creating a cluster, you can determine the cluster scale based on the actual project load and resource usage.

versions.tf

terraform {
required_providers {
huaweicloud = {
source = "huaweicloud/huaweicloud"
version = ">= 1.36.0"
}
}
}

variables.tf

variable "name" {
description = "Name of the cce cluster"
}
variable "flavor_id" {
description = "Flavor of the cce cluster"
default = "cce.s1.small"
}
variable "vpc_id" {
description = "Id of the vpc"
}
variable "subnet_id" {
description = "Id of the subnet"
}
variable "node_pool" {
description = "cce node pool feature"
default = {
simple = {
name = "generic"
os = "EulerOS 2.5"
flavor_id = "s6.large.2"
}
}
}
variable "node_pool_key_pair" {
description = "public ssh key of cce node pool"
}

main.tf

Modify the AK/SK information to the actual Information

provider "huaweicloud" {
region = "sa-brazil-1"
access_key = "your ak"
secret_key = "you sk"
}
resource "huaweicloud_cce_cluster" "this" {
name = var.name
flavor_id = var.flavor_id
vpc_id = var.vpc_id
subnet_id = var.subnet_id
multi_az = false
container_network_type = "overlay_l2"
}
resource "huaweicloud_cce_node_pool" "this" {
for_each = var.node_pool
name = each.value.name
os = each.value.os
flavor_id = each.value.flavor_id
availability_zone = try(each.value.availability_zone, "random")
scall_enable = try(each.value.scall_enable, false)
initial_node_count = try(each.value.initial_node_count, 1)
min_node_count = try(each.value.min_node_count, 0)
max_node_count = try(each.value.max_node_count, 0)
scale_down_cooldown_time = try(each.value.scale_down_cooldown_time, 0)
priority = try(each.value.priority, 0)
cluster_id = huaweicloud_cce_cluster.this.id
key_pair = var.node_pool_key_pair
type = "vm"
root_volume {
size = 40
volumetype = "SAS"
}
data_volumes {
size = 100
volumetype = "SAS"
}
}

We can create the VPC,subenet,sskey in advance, And we can create use terraform also.

  • vpcid 5269e46b-9bac-495d-bdf8-072589e2a572
  • subnetid 7a20b2d5-f879-4a5b-919b-e0456364a2cd
  • key testkey

Initialization

If you use it for the first time, you need to initialize for download provider plugins.

Initialization

终端窗口
PS D:\soft\hashicorp\cce-create> ..\terraform.exe apply
var.name
Name of the cce cluster
Enter a value: cceculster01
var.node_pool_key_pair
public ssh key of cce node pool
Enter a value: testkey
var.subnet_id
Id of the subnet
Enter a value: 7a20b2d5-f879-4a5b-919b-e0456364a2cd
var.vpc_id
Id of the vpc
Enter a value: 5269e46b-9bac-495d-bdf8-072589e2a572
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the
following symbols:
+ create
Terraform will perform the following actions:
# huaweicloud_cce_cluster.this will be created
+ resource "huaweicloud_cce_cluster" "this" {
+ authentication_mode = "rbac"
+ billing_mode = (known after apply)
+ certificate_clusters = (known after apply)
+ certificate_users = (known after apply)
+ charging_mode = (known after apply)
+ cluster_type = "VirtualMachine"
+ cluster_version = (known after apply)
+ container_network_cidr = (known after apply)
+ container_network_type = "overlay_l2"
+ description = (known after apply)
+ eni_subnet_cidr = (known after apply)
+ eni_subnet_id = (known after apply)
+ enterprise_project_id = (known after apply)
+ flavor_id = "cce.s1.small"
+ highway_subnet_id = (known after apply)
+ id = (known after apply)
+ kube_config_raw = (known after apply)
+ multi_az = false
+ name = "cceculster01"
+ region = (known after apply)
+ security_group_id = (known after apply)
+ service_network_cidr = (known after apply)
+ status = (known after apply)
+ subnet_id = "7a20b2d5-f879-4a5b-919b-e0456364a2cd"
+ vpc_id = "5269e46b-9bac-495d-bdf8-072589e2a572"
+ masters {
+ availability_zone = (known after apply)
}
}
# huaweicloud_cce_node_pool.this["simple"] will be created
+ resource "huaweicloud_cce_node_pool" "this" {
+ availability_zone = "random"
+ billing_mode = (known after apply)
+ charging_mode = (known after apply)
+ cluster_id = (known after apply)
+ current_node_count = (known after apply)
+ flavor_id = "s6.large.2"
+ id = (known after apply)
+ initial_node_count = 1
+ initialized_conditions = (known after apply)
+ key_pair = "testkey"
+ max_node_count = 0
+ max_pods = (known after apply)
+ min_node_count = 0
+ name = "generic"
+ os = "EulerOS 2.5"
+ priority = 0
+ region = (known after apply)
+ runtime = (known after apply)
+ scale_down_cooldown_time = 0
+ scall_enable = false
+ security_groups = (known after apply)
+ status = (known after apply)
+ type = "vm"
+ data_volumes {
+ dss_pool_id = (known after apply)
+ kms_key_id = (known after apply)
+ size = 100
+ volumetype = "SAS"
}
+ root_volume {
+ dss_pool_id = (known after apply)
+ kms_key_id = (known after apply)
+ size = 40
+ volumetype = "SAS"
}
+ storage {
+ groups {
+ cce_managed = (known after apply)
+ name = (known after apply)
+ selector_names = (known after apply)
+ virtual_spaces {
+ lvm_lv_type = (known after apply)
+ lvm_path = (known after apply)
+ name = (known after apply)
+ runtime_lv_type = (known after apply)
+ size = (known after apply)
}
}
+ selectors {
+ match_label_count = (known after apply)
+ match_label_metadata_cmkid = (known after apply)
+ match_label_metadata_encrypted = (known after apply)
+ match_label_size = (known after apply)
+ match_label_volume_type = (known after apply)
+ name = (known after apply)
+ type = (known after apply)
}
}
}
Plan: 2 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ certificate_clusters = (known after apply)
+ certificate_users = (known after apply)
+ kubeconfig = (known after apply)
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
huaweicloud_cce_cluster.this: Creating...
huaweicloud_cce_cluster.this: Still creating... [10s elapsed]
huaweicloud_cce_cluster.this: Still creating... [20s elapsed]
huaweicloud_cce_cluster.this: Still creating... [30s elapsed]
huaweicloud_cce_cluster.this: Still creating... [40s elapsed]
huaweicloud_cce_cluster.this: Still creating... [50s elapsed]
huaweicloud_cce_cluster.this: Still creating... [1m0s elapsed]
huaweicloud_cce_cluster.this: Still creating... [1m10s elapsed]
huaweicloud_cce_cluster.this: Still creating... [1m20s elapsed]
huaweicloud_cce_cluster.this: Still creating... [1m30s elapsed]
huaweicloud_cce_cluster.this: Still creating... [1m40s elapsed]
huaweicloud_cce_cluster.this: Still creating... [1m50s elapsed]
huaweicloud_cce_cluster.this: Still creating... [2m0s elapsed]
huaweicloud_cce_cluster.this: Still creating... [2m10s elapsed]
huaweicloud_cce_cluster.this: Still creating... [2m20s elapsed]
huaweicloud_cce_cluster.this: Still creating... [2m30s elapsed]
huaweicloud_cce_cluster.this: Still creating... [2m40s elapsed]
huaweicloud_cce_cluster.this: Still creating... [2m50s elapsed]
huaweicloud_cce_cluster.this: Still creating... [3m0s elapsed]
huaweicloud_cce_cluster.this: Still creating... [3m10s elapsed]
huaweicloud_cce_cluster.this: Still creating... [3m20s elapsed]
huaweicloud_cce_cluster.this: Still creating... [3m30s elapsed]
huaweicloud_cce_cluster.this: Still creating... [3m40s elapsed]
huaweicloud_cce_cluster.this: Still creating... [3m50s elapsed]
huaweicloud_cce_cluster.this: Still creating... [4m0s elapsed]
huaweicloud_cce_cluster.this: Still creating... [4m10s elapsed]
huaweicloud_cce_cluster.this: Still creating... [4m20s elapsed]
huaweicloud_cce_cluster.this: Still creating... [4m31s elapsed]
huaweicloud_cce_cluster.this: Still creating... [4m41s elapsed]
huaweicloud_cce_cluster.this: Still creating... [4m51s elapsed]
huaweicloud_cce_cluster.this: Still creating... [5m1s elapsed]
huaweicloud_cce_cluster.this: Still creating... [5m11s elapsed]
huaweicloud_cce_cluster.this: Creation complete after 5m19s [id=8f979fa0-434a-11ee-acab-0255ac100099]
huaweicloud_cce_node_pool.this["simple"]: Creating...
huaweicloud_cce_node_pool.this["simple"]: Still creating... [10s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Still creating... [20s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Still creating... [30s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Still creating... [40s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Still creating... [50s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Still creating... [1m0s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Still creating... [1m10s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Still creating... [1m20s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Still creating... [1m30s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Still creating... [1m40s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Still creating... [1m50s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Still creating... [2m0s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Still creating... [2m10s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Still creating... [2m20s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Still creating... [2m30s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Still creating... [2m40s elapsed]
huaweicloud_cce_node_pool.this["simple"]: Creation complete after 2m48s [id=4f95a70d-434b-11ee-acab-0255ac100099]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

create

create-finish

github huaweicloud terraform

Huaweicloud Offical document

Name Version
huaweicloud 1.31.0
Name Version
huaweicloud 1.31.0

No modules.

Name Type
huaweicloud_cce_addon.ingress resource
huaweicloud_cce_addon.metrics resource
huaweicloud_cce_cluster.this resource
huaweicloud_cce_node_pool.this resource
huaweicloud_cce_addon_template.ingress data source
Name Description Type Default Required
addon_ingress_config nginx config for nginx-ingress addon map(any) {} no
addon_ingress_enable If you need nginx-ingress addon bool false no
addon_ingress_loadbalancer_ip Load balancer ip for nginx-ingress addon string "" no
addon_ingress_resource nginx resource for nginx-ingress addon map(any)
{
“limitsCpu”: “1024m”,
“limitsMem”: “1024Mi”,
“name”: “nginx-ingress”,
“requestsCpu”: “256m”,
“requestsMem”: “256Mi”
}
no
flavor_id Flavor of the cce cluster string "cce.s2.small" no
name Name of the cce cluster any n/a yes
node_pool cce node pool feature map
{
“simple”: {
“flavor_id”: “s3.large.4”,
“name”: “generic”,
“os”: “EulerOS 2.5”
}
}
no
node_pool_key_pair public ssh key of cce node pool any n/a yes
subnet_id Id of the subnet any n/a yes
vpc_id Id of the vpc any n/a yes
Name Description
certificate_clusters certificate of cce cluster
certificate_users certificate users of cce cluster
kubeconfig kubeconfig file of cce cluster
终端窗口
hcloud CCE CreateCluster --cli-region="sa-brazil-1" --Content-Type="application/json" --metadata.name="ccetest" --apiVersion="v3" --kind="Cluster" --spec.flavor="cce.s2.small" --spec.hostNetwork.subnet="7a20b2d5-f879-4a5b-919b-e0456364a2cd" --spec.hostNetwork.vpc="5269e46b-9bac-495d-bdf8-072589e2a572" --spec.category="CCE" --spec.containerNetwork.mode="vpc-router" --spec.containerNetwork.cidrs.1.cidr="10.0.0.0/16"