Use Terraform to create a Cluster and Node Group
Last updated
Last updated
Terraform is an open source tool used to automate the provisioning and management of infrastructure such as virtual machines, networking, storage, and Kubernetes.
With Terraform, you can describe your desired infrastructure in code, then Terraform will perform the necessary operations to create or update the infrastructure to match your description.
To initialize a Kubernetes Cluster using Terraform, you need to perform the following steps:
Access the IAM Portal here , create a Service Account with Full Access authority . Specifically, at the IAM site, you can:
Select " Create a Service Account ", enter a name for the Service Account and click Next Step to assign permissions to the Service Account.
Find and select Policy: VKSFullAccess then click " Create a Service Account " to create a Service Account, Policy: VKSFullAccess is created by VNG Cloud, you cannot delete these policies.
After successful creation, you need to save the Client_ID and Secret_Key of the Service Account to perform the next step.
Access the VKS Portal here , Activate VKS service on the Overview tab. Please wait until we successfully create your VKS account.
Install Terraform:
Download and install Terraform for your operating system from .
Initialize Terraform configuration:
Create a file variable.tf
and declare Service Account information in this file.
Create a file main.tf
and define the Kubernetes Cluster resources you want to create.
For example:
The file variable.tf:
you need to replace the Client ID and Client Secret created in step 1 in this file.
The file main.tf:
in this example I initialize a Cluster and a Node Group has the following information:
Cluster name: my-cluster
K8S Version: v1.28.8
Mode: Public Cluster and Public Node Group
Node Group name: my-nodegroup
Turn on AutoScaling: scale from 0 to 5 nodes
Attention:
In the main.tf file, to initialize a cluster with a node group, you must pass in the following parameters:
The sample file main.tf
helps you create Cluster and Node Group according to the configuration above:
Initialize Terraform:
Run the command terraform init.
This command will download the necessary plugins and initialize the Terraform state.
Apply Terraform configuration:
Run command terraform apply.
This command will create a Kubernetes Cluster as described in the main.tf
.
See more about how to use Terraform to work with VKS .