Last updated
Last updated
Terraform is an open source infrastructure as code tool that allows users to manage their infrastructure easily and efficiently across different cloud platforms, such as VNG Cloud, AWS, Google Cloud and Azure. Terraform Server refers to the instance of the Terraform engine running on a specific server or machine. This is where infrastructure code is written and executed, allowing users to create, modify, and destroy resources on the cloud platform.
Terraform itself does not have a graphical user interface, instead users interact with it using a command line interface. Terraform requires a cloud provider account and key to be configured along with a Terraform configuration file to execute the infrastructure as code. Additionally, Terraform can operate in clustered environments where multiple users can collaborate on the same infrastructure codebase, making it a powerful and flexible tool for infrastructure management. cloud.
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.
On the main.tf file , you need to be able to add resources to create a Cluster/ Node Group:
Create independent Cluster my-vks-cluster and Node Group my-nodegroup:
Create Cluster with Default Node Group
Attention:
We recommend that you create and manage Clusters and Node Groups as separate resources, as in the example below. This allows you to add or remove Node Groups without recreating the entire Cluster. If you declare Node Group Default directly in the vngcloud_vks_cluster resource, you cannot delete them without recreating the Cluster itself.
In the main.tf file, to successfully create a cluster with a node group, you must enter information in the following 4 fields:
Example 1:
Below is the main.tf file I used to initialize the Cluster with the following parameters:
Cluster name: cluster-demo
K8S Version: v1.29.1
Mode: Public Cluster and Public Node Group
Node Group name: nodegroup1
Initial Node: 3
Turn on AutoScaling: scale from 0 to 5 nodes
Example 2
Below is the main.tf file I used to initialize the Cluster with the following parameters:
Cluster name: my-cluster
K8S Version: v1.29.1
Mode: Public Cluster and Private Node Group
Node Group name: my-nodegroup
Initial Node: 3 nodes
Turn on AutoScaling: scale from 0 to 5 nodes
First, apply the main file according to the following structure:
Then, if you need to add Whitelist IP for Control Plane, add this field to the main.tf file and reapply this file:
Attention:
After completing the above information, run the command below:
Then, to see the changes that will be applied to the resources that terraform is managing, you can run:
Finally, you choose to run the command line:
Select YES to initiate Cluster and Node Group via Terraform
After successfully initializing Terraform, you can go to VKS Portal to view the newly created Cluster information.
To get the image_id you want to use, you can access VKS Portal, select System Image menu and get the ID you want or get this information .
To get the flavor_id you want to use for your Node group, please get the ID .
See more about how to use Terraform to work with VKS .