What are Kubernetes, Terraform and Ainsible

18 views

Hi guys.

I am new to the whole DevOps area. I have used Docker/docker-compose before but now I have to learn about Kubernetes. However, the concepts are hard to grasp. Ok so Kubernetes is Docker for multiple hosts, but what are the other 2 (i know they are somehow the same thing and they manage K8s, but what are they managing? Sorry, a bit too complicated for me :D). Thanks to anyone who is willing to help!

In: 5

Kubernetes orchestrates pods so it’s more like docker compose and will place pods where they can go depending on resources requested.

Terraform is a cloud agnostic infrastructure as code language. Think like AWS cloud formation.

Ansible is configuration management software for setting up and configuring the OS, like Chef or Puppet.

Terraform is part of a classification of tools that allow you to do infrastructure as code. Meaning, you define what you want your infrastructure to look like via code. So you can I want 3 ec2 instances/servers built using X image and then also provision a load balancer with it and attach the servers to the load balancer. Your end result is now you have 3 servers with a load balancer but the servers don’t have anything configured but the base OS (assuming your image wasn’t pre-configured). So you’re routing traffic to something that does nothing. A similar tool would be cloud formation. The difference between cloud formation and Terraform is that terraform can work with multiple vendors of different kinds and different assets (IaaS, PaaS, etc). Cloudformation is from AWS and exclusively only works on AWS offerings. Terraform is a state dependent tool meaning it keeps track of what it builds via a state file. This state file is terraforms source of truth. If you build something via terraform and then manually delete it, the next time you run terraform it’s going to check the state file to say yup I built that already. But it also uses the state file to detect drift. So if it builds out a system using specific declarations (amount of memory, cpu. Etc) and someone modifies it, it will flag and say whoa, what’s in the config you gave me and the state file I wrote is different than what’s in the environment, do you want me to fix it? If yes terraform will either modify the object or it will blow it away and recreate it.

Ansible is what you should invoke after you have terraform build your stuff. Ansible is what’s called a configuration management tool. What that means is it shines in doing stuff inside the OS that terraform either can’t do or is too clunky to do. Meaning you have your server built out but it’s just a basic OS, using ansible you instruct the server to do some post build tasks such as installing updates, install/modify any applications, and any other changes you want made **within** the OS. Ansible does not keep track of what changes it made. It’s just is just to run the playbook you wrote and will do what it can based on your logic.

Now one thing to note between terraform and ansible. There is indeed overlap. Both ansible and terraform can build infrastructure and both can modify the OS. But ansible was deigned to configure the OS as it’s primary purpose where as tereaforms primary purpose is to build infrastructure. I personally maintain as well as the creator of these products that you should use both together. Terraform can modify the OS but it’s clunky and limited compared to ansible. Ansible can build infrastructure but it doesn’t know what it builds and if you run the same playbook 100 times you’ll get 100 instances of whatever you are trying to build. Similar tools would be chef, puppet, and salt stack.

Finally kubernetes. So I’m going to assume you have a good understanding of what docker is and what containers are. Kubernetes is basically container orchestration. It was built to fill in a gap docker was missing until docker swarm. Think of it like a distant cousin of virtual machine hypervisors. It takes your container and tries to figure where to run, who has capacity, what to do if a container goes down, what the network should look like between your kubernetes cluster members and other things. Basically it’s the micromanage platform for containers. Docker swarm would be the direct competitor and then ECS would be what macos is to Linux server OS. It’s has all the basics you need to keep your containers up but it isn’t feature rich.