<p>I am a bit confused about the individual roles of Kubernetes and Terraform when using them both on a project.</p>
<p>Until very recently, I had a very clear understanding of both their purposes and everything made sense to me. But, then <strong>I heard in one of <a href="https://youtu.be/l5k1ai_GBDE" rel="nofollow noreferrer">Nana's videos on Terraform</a>, that Terraform was also very advanced in orchestration and I got confused</strong>.</p>
<p>Here's my current understanding of both these tools:</p>
<ul>
<li><p><strong>Kubernetes</strong>: Orchestration software that controls many docker containers working together seamlessly. Kubernetes makes sure that new containers are deployed based on the desired infrastructure defined in configuration files (written with the help of a tool like Terraform, as IaC).</p>
</li>
<li><p><strong>Terraform</strong>: Tool for provisioning, configuring, and managing infrastructure as IaC.</p>
</li>
</ul>
<p>Clarification:</p>
<p>According to RedHat, “Orchestration is the <strong>automated</strong> configuration, management, and coordination of infrastructure.”</p>
<p>For example, if we manually describe a Docker container as a resource, and that said Docker container is then deleted, we need to manually run that Terraform plan again for the Docker container to be re-deployed. To automatically handle this, that's where Kubernetes comes into play (orchestration).</p>
<p>So, when we say that Terraform is a good tool for orchestration, what are we really saying?</p>
<p>I hope someone can clear that out for me!</p>

Em De Barros
<p>Terraform is an infrastructure as code tool, which allows declaring a resources and their desired state as code and it will determine the plan and execute it to take the infrastructure to a desired state. Terraform needs providers for managing these resources using respective API's. Once resources are provisioned terraform cannot take care of keeping the desired state unless you again run terraform plan to determine if resources are in desired state or not and apply the script to take it to desired state.</p>
<p>On the other hand, kubernetes is expert is orchestrating container workloads which takes care of keeping the workloads in desired state throughout the life cycle of resources. It continuously monitors cluster and make changes to keep desired state of workloads.</p>
<p>Major difference between both is kubernetes is an container orchestration platform which manage desired state of container workloads and many other features. Whereas terraform is a tool which helps you write, provision and maintain the state of resources as a code. It uses provider API's to create resources to match the desired state by identifying difference between current state and desired state of resources.</p>
<p>Both terraform and kubernetes can be used together. There are kubernetes providers for terraform which can help you define desired state of your cluster resources. Once you apply the terraform state, kubernetes takes care of maintaining the desired state.</p>
<p>Kubernetes is very specific to container workload orchestration whereas terraform can be used to work with any resource state management like provisioning cloud resources, server resources or anything that provides terraform provider to manage resources.</p>
<p>Simple example I can think of to better understand the difference is, You can use terraform with docker provider to declare that you want to create a container and once you apply that state container will spin up, but if you delete the container it won't get recreated automatically unless you again run terraform plan which will determine the difference from desired state and apply will recreate the container.
To solve this specific problem of maintaining a desired state of container workloads kubernetes orchestration helps. Kubernetes has much more features and flexibility than just container orchestration but this is the core idea of container orchestration.</p>
<p>I hope that helps you understand the difference. In case my understanding is wrong please correct me.</p>
