How to use Terraform and Kubernetes to manage the IT worlds
-
9102
-
0
-
1
-
0
Terraform and Kubernetes are the next generation of DevOps tools enabling the whole new layer of DevOps services. Terraform allows literally creating or destroying the whole IT worlds…
Terraform is a configuration orchestration tool released by Hashicorp, available both as an open-source DevOps solution and as an enterprise-grade DevOps-as-a-Service offer. Being a part of Hashicorp infrastructure-as-code stack, it significantly simplifies the provisioning, management, and disposal of immutable infrastructure with many cloud service providers, be it public, private or on-prem.
The closest analog would be the AWS CloudFormation, an infrastructure automation service. However, while CloudFormation allows composing the needed AWS infrastructure with ease, Terraform does this for any underlying virtual components, be it an AWS region, Digital Ocean droplet or a vSphere virtual data center. While spawning such a virtual world, Terraform would configure the required resources and networking, register the DNS and create the required number of virtual machines.
Normally, this is when configuration management (CM) tools like Puppet or Ansible would come into play. They would handle the creation of the OSEs (Operating System Environments), complete with installing the needed software and patching it to the required versions. Ansible fans would now mention that Ansible playbooks can do so much more — including provisioning the infrastructure in the first place — and they would be right, no doubt.
However, the point is as Terraform manifests are descriptive, they are cloud-agnostic. They work with equal ease on any cloud platform, orchestrating the immutable infrastructure with an efficiency that outweighs the possibilities of other DevOps tools by far.
Using Kubernetes for container management
When we discuss composing the immutable infrastructure environments for software delivery pipelines, app containerization is one of the cornerstone topics. The whole point of Infrastructure as Code approach to DevOps services is the ability to provision new environments and launching new apps in mere seconds, instead of enduring long and laborious recovery after any malfunction. Containers are vital for that, as these are the code envelopes with everything needed to run an app – from OS to drivers and libraries. Once the Docker image composed, the Docker containers with it can be launched, stopped and multiplied per need.
The desired state of your infrastructure is defined in code and it’s CM tool’s job to enforce that state, through a CM agent working inside the OSE. Should the state be altered, the CM agent informs the tool, an alert is raised and some response is made.
If this OSE works as a wrapper for a customer-facing application, the CM tools will install the VM agent, configure the OSE to run the application, configure the application itself, etc. If the OSE is a part of a greater container cluster, the container management tool will configure the kublet and hand it off to Kubernetes to take care afterward. The Kubernetes management tool then keeps the containers linked, builds nodes out of them, builds clusters out of nodes, handles the networking, proxies and container discovery.
Kubernetes reads YAML configuration files and creates namespaces, where pods with Docker containers reside. By this time you might be wondering — why all the complexity? Why so many layers? It’s simple — this allows destroying only the levels that need to be destroyed and keeping what needs to be kept intact! This is the main benefit of the immutable infrastructure — it’s easier to create a new instance than repair the broken one.
Final thoughts on using Terraform and Kubernetes to manage the IT infrastructure
When the required infrastructure state is described in Terraform manifests, the developers can treat it like any other code — use the versioning system to fork the required states of the infrastructure, restore them at any moment or adjust them in mere minutes. This allows to rebuild the faulty environments from a clean state with ease, should something go awry.
Such an approach to software delivery shortens the development time drastically. The companies that imbued their software development with the best DevOps practices experienced nearly 50 times more frequent code deployment along with multiple other benefits, described in our article on the state of DevOps adoption as of 2017.
The coin has two sides, however. Using Terraform efficiently requires also using Hashicorp Consul and Vault, or opting for custom-tailored DevOps solutions. Mastering Kubernetes is also quite a hard task, best delegated to a trustworthy managed services provider. Thus said, fitting all the pieces of the composable infrastructure puzzle in their place is quite a laborious task… yet only the sky is the limit once it is done.
For example, your system can monitor the pricing discounts at various cloud providers and move all the systems to another provider in a blink of an eye once it suits you. As Terraform is cloud-agnostic, your business will get exactly the infrastructure it needs, and Kubernetes will allow juggling the containers to keep the end user’s experience uninterrupted while saving you time and money. Would you like to experience such a workflow?