In this post, I’m going to explain what Kubernetes (k8s for short) is, what it is not, what it solves, its architectural components, how to get it up and running locally and lastly some alternatives in the market. This blog post assumes you are new to Kubernetes and want to get a good understanding of its concepts and building blocks.
So what is Kubernetes?
To begin to understand Kubernetes usefulness, we have to first understand two other concepts. Immutable Infrastructure and Containers. Well what are those? Immutable infrastructure is the concept where servers are never modified after deployment. The idea is that if something needs to be changed, it’s never modified directly on the server, instead a new server is built from a base image with all changes needed baked in with it so that we can just replace new server with the old one without any further modification. Containers are a way to package your code, runtime, system tools, system libraries and configs so that it can be shipped as a lightweight, standalone executable. The idea is that your application will behave the same every time no matter where (e.g Ubuntu or Windows) it is running. It is worth mentioning that containerization is not a new concept, it was just made popular with the rise of microservices and Docker.
Now that we understand those two concepts we can answer our question, which is what is Kubernetes? I will define it as a container or microservice platform that orchestrates computing, networking, and storage infrastructure workloads for us. As you can see from the definition, Kubernetes extends how we scale containerized application so that we can enjoy all the benefits of a true immutable infrastructure.
If you are like me and wondering where the name “Kubernetes” came from, it is a Greek word, meaning helmsman or pilot and K8s is an abbreviation derived by replacing the 8 letters “ubernete” with “8”.
What does Kubernetes offer out of the box?
K8s provides some key features that make your containerized application scale efficiently.
- Horizontal scaling – Scale your application up and down from command line or UI.
- Automated rollouts and rollbacks – Rolls outs changes will monitor the health of your application to ensure all instances does not go down at the same time. If something goes wrong, k8s will rollback the change automatically.
- Service discovery and load balancing – Containers will get their own IP and you can put a set of containers behinds a single DNS name to be load-balanced.
- Storage orchestration – Auto mount local, public cloud or a network storage.
- Secret and configuration management – Create and Update secrets and configs without rebuilding your image.
- Self-healing – Restarts failed containers, replaces and reschedules containers when nodes die, kills containers that don’t respond to your user-defined health check, and doesn’t advertise them to clients until they are ready to serve.
- Batch execution – Manage your batch and Continuous Integration workloads. It also makes sure it replaces failed containers.
- Automatic binpacking – k8s is smart enough to schedule containers based on resource requirements and other constraints.
As you can see, kubernetes offers us a lot out of the box. It allows us to run a true immutable infrastructure where our application container can be killed, self-heal, and the new container gets access to all supporting volume, secret, configs etc that it needs to function, all in an automated fashion.
Kubernetes Basic Terms & Definitions
To begin to understand how to use k8s, we must first understand the objects in the API. There are basic k8s objects and several higher-level abstractions that are called Controllers. These are the building block of your application lifecycle.
- Pod – a group of one or more containers
- Service – An abstraction that defines a logical set of Pods and a policy by which to access them.
- Volume – Containers are ephemeral so data is deleted when container is deleted. Volume is an abstraction that lets us persist data.
- Namespace – Allows us to separate a segment of the cluster dedicated to a certain purpose like for example a certain project or team of devs.
- ReplicaSet – Ensures that the amount of pod we want is what is running.
- Deployment – provides declarative updates for pods and replicaset.
- StatefulSet – workload API object used to manage stateful applications like databases.
- DaemonSet – Ensures that all or some worker nodes run a copy of a pod. This is useful for daemon applications like fluentd.
- Job – creates one or more pods and run a certain task or tasks to completion, then delete pods.
Kubernetes Architecture & Components
A k8s cluster is made up of a Master node which is what exposes the API, schedules deployments and manage the cluster in general. Multiple Worker nodes responsible for container runtime, like Docker or rkt, along with an agent that communicates with the master.
- Kube-apiserver – This is what exposes the API.
- Etcd – This is Key-Value store that stores all the cluster data.
- Kube-scheduler – This is what schedules new pods on worker nodes
- Kube-controller-manager – This is what runs the controllers.
- Cloud-controller-manager – This is what talks to cloud providers
These things are what make up a master node. Etcd can be ran on the same server as a master node or on a dedicated cluster.
- Kubelet – An agent that makes sure containers are running in a pod.
- Kube-proxy – Keeps network rules and perform forwarding.
- Container Runtime – Responsible for running containers.
Here is a basic architectural diagram.
How to Install Kubernetes
- Kubectl – CLI tool used to interact with the cluster.
- Minikube – This is a binary that deploys a k8s cluster locally on a development machine.
With these two things you can start deploying your containerized apps to a k8s cluster locally within few minutes. For a production grade cluster that is highly available, you can use tools like Kops, EKS, which is a managed service provided by AWS or GKE provided by Google to name a few.
What will Kubernetes not do for you?
So far, we have touched on the cool things k8s will do for us. Let’s briefly touch on what it does not do.
- It doesn’t limit the type of apps you can deploy. It allows any type of app written in any language. As long as it fits in a container, it will deploy it.
- It does not replace tools like Jenkins so it will not build your application for you.
- It is not a middleware so it will not perform tasks that a middleware performs like message bus or caching to name a few.
- Does not care which logging solution is used. Have your app log to stdout, then you can collect the logs with whatever you want.
- Does not care about your config language (e.g json).
K8s is not opinionated with these things simply to allow us to build our app the way we want, expose any type of information and collect that information however we want.
There are other tools similar to k8s. For example, there is Docker Compose, which is good for staging but not production ready or Nomad which allows us to do cluster management and scheduling but it does not solve our secret and config management, service discover and monitoring needs, Netflix just open sourced their orchestration platform called Titus therefor there aren’t enough people using it in production except for the Netflix folks. Overall, k8s offers the best features out of the box with 3rd party add-ons projects to extend its functionality.
These postings are my own and do not necessarily represent BMC's position, strategies, or opinion.
See an error or have a suggestion? Please let us know by emailing firstname.lastname@example.org.