Disclaimer: Long Story Short series are personal learning experiences as I encounter different development journeys. The aim of these series are to summarize and simplify difficult development concepts and teach them in different levels of proficiency.
The most important lesson I want you to take from this blog is to understand what kubernetes is? and why we use it?
In the era of micro-service architecture, applications are structured as a collection of services which are loosely coupled, easily maintained, independently organized, and owned by smaller teams. This is possible by containerizing different services within an application and using API calls to communicate among them.
This all sounds great until your organization thinks of scaling up or achieving above 90% up-time for the application. Managing couple of containers is not an exhausting activity but when thinking of configuring, deploying, and maintaining 100s of containers simultaneously our approach should be re-evaluated. This is where Kubernetes comes in the picture and automates the container management tasks.
Kunernetes: Is an open-source software which helps managing and orchestrating containers.
- It was first developed by google engineers and later donated to Cloud Native Computing Foundation (CNCF).
- It is an orchestration tool to deploy, scale up, and manage multiple containers together, therefore automating and enhancing the maintenance process of micro-services. Kubernetes main benefits are:
- assist communicating among containers
- Deploy them properly
- Manage them carefully
- Auto scaling: Always making sure there is certain number of container's copies available.
- Load balancing: Distributing the traffic.
- Kubernetes cluster are usually made up of two main parts:
- Master (schedules application services)
- Nodes (listens to the orders from the master)
Now that we have a bigger picture of kubernetes and why we use it, let's dive inside of the cluster architecture and learn about the different components.
Master: Is the control plane (main controller) of the cluster. Usually, users communicate with the master through dashboard graphical interface (GUI) or the command line interface (CLI) via YAML config files. Master's responsibility is to manage all the node events to keep the overall cluster configuration stable and healthy. The multiple components of master are as such:
- Kube-APIserver: The front-end of kubernetes which exposes API calls and deals with REST services so developers can communicate with the cluster.
- ETCD: Manages state of the cluster. Try to look at it as the database of kubernetes. As a developer, you have to find a reliable method to backup these information in case of a master's crash.
- Kube-Scheduler: As the name suggests, it schedules the newly created pods into the nodes based on the given resource requirements.
kube-controller-manager: consists of multiple controllers which manages the cluster and nodes. For example:
- Replication Controller: handles the replicas (series of identical pods)
NODE: Is a part of the kubernetes run-time environment and is hosted on a separate VM or physical machine than the master. Nodes have a series of pods inside of them which allow containers to run inside of them. Node responsibility is to monitor pods and report back to the master. Node's components consist of:
Pods: A logical collection of containers (like docker containers) which need to interact with each other for an application to work. Furthermore, Pods have series of
union file systemsinside of them.
Kubelet: Each node has a kubelet which makes sure required podSpects are running healthy on the node. This agent can then report back to the master. their other tasks are to:
- Communicate With API server.
- Execute pods' containers via a container-engine.
- Mount and run pod-volumes and secrets.
- Execute health checks and report back to master.
Podspec: Is a YAML file that describes what each pod should have.
Good to note that kubelets usually use an endpoint to communicate such as
- Kube-proxy: Allows network traffic finds the right node and right pod inside (learn more about networking).
I hope by now you have a high level understanding of different kubernete's components and their role to enable orchestration.
Cool beans, but how do I control and use all of these?
As a devops specialist, you should be able to talk to this kubernetes beast by configuring certain controllers. Therefore, you can spin up your cluster and run your containers reliably inside.
Controllers help with application reliability, scaling, and Load balancing. We need to understand different kinds of controllers within kubernetes:
- Replicates: Ensures the certain number of pods are running at all times. We use replica-sets to scale up and scale down the pods.
- Deployments: Declare updates for pods and replicates. Basically, a deployment manages replicates and replicates manage pods.
- DaemonSets: Ensures all nodes copy a specific pod. Monitoring the pods on the nodes to make sure there are all identical.
- Jobs: Usually a supervisor process. Jobs are individual processes that happen once or periodically such as database backup.
Services: Allow communication between a set of deployment. Services can be:
- Internal: IP only reachable within cluster.
- External: Endpoint available from node ip.
- Load balancer: Expose the application.
Labels: As the name suggests, it helps us to label and organize components. you can search, delete, and run services based on their labels. We use selectors to find labels.
Selectors: You can use them in two different method:
- equality-based selectors: (==, !=)
- Set-based selectors: (IN , NOTIN, EXISTS)
Namespaces: Give authentication and authorization to different users. extremely useful for bigger teams.
Congratulations! now you know the basic knowledge needed to start getting your hands dirty with the code...
Next step .... code