Terraform vs. YAML Deployment for Kubernetes Objects
In this post, we will look at what points to consider one we are looking for deployment in the EKS server.
Join the DZone community and get the full member experience.Join For Free
Terraform: It is a tool for creating, updating, and versioning infrastructure efficiently. It can be used with many providers to create the Infrastructure. It maintains the state of objects in a state file. Kubernetes provider is used in terraform to communicate with Kubernetes Server.
YAML Deployment: YAML stands for Yet Another Markup Language, which is easy to use, a human-readable language file. It is used with many programming languages. It is easy to create Complex Kubernetes Objects using the YAML file instead of using the command line.
Understanding the differences: If you want to create one time objects in the Kubernetes Server to deploy any microservice, Then one need to evaluate possible options for good, dynamic, seamless for different environments, easily maintainable option. Let us see the differences between the Terraform And YAML file:
- Terraform maintains the state of objects created through terraforming in a state file. This state file can be stored on file System, S3 Bucket, or some source control system. Every time terraform is run, It compares the current state of infrastructure with the state file preserved by Terraform. This way if anything was deleted/Updated manually in a cluster by someone. It will show the differences to the user if Any, And it will revert back to the desired state as maintained by Terraform code. YAML file deployment won't show any difference in the state of Objects.
- One can create dynamic resources in Terraform code, for which values can be derived from the property file. So there is no need to duplicate the code if you want to deploy the same type of resources with different values. It becomes easy to maintain code with terraforming. e.g. If you have 2 deployments of microservice with different docker images, that can be done with the same code, by having 2 Modules calling the same resource with different values. Dynamic Templating is not that easy with the Yaml file.
- When Creating Objects through terraforming, It will wait for the response to returned by the Kubernetes server about the state of the objects. So In case of any exception, the Execution of code will be stopped for remaining resources, And the Error message will be shown. But with the YAML deployment, you have to connect to Server and check the state of the object manually.
- The response returned by the Kubernetes server for any object can be used in the creation of the next Object, e.g. deploying a Service of Type Loadbalancer will return the endpoint of the created load balancer, that can be used for Route 53 Or Ingress resource. It is not possible with the YAML file.
- Through terraform, we can talk to multiple providers like AWS and Kubernetes at the same time. One can create new EFS in AWS and use the EFS in Kubernetes resources.
I think the above differences will help in choosing terraform over the Yaml file.
Opinions expressed by DZone contributors are their own.