Kubernetes Terraform Provider — Provisioned YAML Manifests

Kasun Rajapakse
Ascentic Technology
3 min readSep 19, 2022

Provisioned YAML manifests to Azure Kubernetes Service.

Terraform is an open-source tool used for provisioning cloud or on-premises infrastructure. Compared to other IaC tools, Terraform has features that stand out from others. A few of those are mentioned below:

  • Easy to learn Domain Specific Language(DSL)
  • Manage the state of the existing cloud resources
  • Support many cloud providers and vendors

With this in mind, let's look at how we can use Terraform provider for Kubernetes to provision Kubernetes manifests. This helps organizations automate the application and infrastructure provision via Terraform.

Provisioned Application to Azure Kubernetes Service from Terraform

1. Create Azure Kubernetes Service from Terraform

First, we need a Kubernetes cluster to deploy our Kubernetes YAML manifest. Let's look at how we can provide a basic Azure Kubernetes Service via, Terraform. Azure Kubernetes Service is a managed offering of Kubernetes, and you can learn more about Azure Kubernetes Service from here.

Specify Azure provider for Terraform

Next, we are going to create the Azure Kubernetes Service cluster. For this demo, I use a basic cluster with minimal configuration. Please refer to Azure Kubernetes Service best practice guide when provisioning for the production environment.

First, create a resource group, then provision the AKS cluster. This cluster does not have any application installed. In the next step, we will look at deploying the Kubernetes application with Terraform with the Kubernetes provider. As you can see below, the cluster is provisioned.

Figure — 1
Figure — 2

2. Deploy Kubernetes Application from Terraform Provider

Next, we already prepared the Kubernetes manifest files (YAML), and we used the Kubernetes provider to deploy the manifest files to AKS cluster.

To work with the Kubernetes Terraform provider, we need to add the Kubernetes provider to the Terraform. We can add the provider ad below. Kubernetes provider needs the credential of the Kubernetes cluster, so we use Terraform interpolation reference to provide the required credentials for the provider.

After the Kubernetes provider is authenticated, we can use the resource kubernetes_manifests for provisioning the existing manifest. When we use this provider, we have to use the Terraform function yamldecode() to decode YAML into HCL language.

Figure — 3

The following figures show us the deployment and service have been created

Figure — 4
Figure — 5

We can access the Nginx from the service public IP

Figure — 6

Conclusion

Terraform is a powerful IaC tool that can be used to provide not only cloud resources but also create applications with relevant providers. So these are very helpful in automating the infrastructure and application provisioning.

You can find the demo files from the following GitHub link.

Learn More

--

--

Kasun Rajapakse
Ascentic Technology

Anything related to Azure, AWS, GCP, Containers & Kubernetes. Technology enthusiastic, Learner, Blogger