This is an exhaustive Kubernetes developers guide which gives an overview of Kubernetes, Kubernetes Architecture, Features of Kubernetes, and Components of Kubernetes. This K8s guide explains why Kubernetes is popular among developers as more companies are electing to use Kubernetes for Container Orchestration and Workload Management, Dev/Ops Engineers, Engineering Managers, and Software Developers are all looking to add Kubernetes as a skill to their tool-belt because this platform is designed to be fault-tolerant scalable and known for its robust architecture.
What are Virtual Machines?
The way we build and run the applications has been changed dramatically over the years. In the beginning, apps used to run on top of the physical machines and eventually they started running over the virtual machines. Though, in both cases, the applications and their dependencies are installed on top of OS.
Every OS provides you with binaries and libraries as well as compute, storage and networking. The biggest disadvantage of using VMs is, each OS is many gigabytes in size, which not only requires storage space, but also increases the memory footprint. There are many other disadvantages of using VMs, such as:
- When the OS version gets upgraded, the new version and its components have to be installed on the older version of OS, which leads to version conflict problems and the problem of increased storage.
- When we use VMs, they limit the approach of portability of applications to public cloud or private cloud and data centers.
Containers
Containers, package your applications and their dependencies. In containers you don’t need to have a separate OS for each of your applications. Containers sit on top of OS and usually share all the OS resources. There are many advantages of using Containers over VMs, such as:
- They are exceptionally light and only take seconds to start.
- A server can run multiple workloads with a single operating system installation.
- A container is portable thus, it can be spun up on different hosts, clouds or clusters.
- Containers allow easier and automated updating because when the new version of OS comes up the old version is automatically discarded.
- When the newer version of the application comes inside the container, instead of updating that container, a new container is deployed and traffic is diverted to the new container.
- The biggest advantage is, the cost is reduced to a large extent since many applications get installed on a single OS.
Kubernetes
It is one of the most popular projects these days. It is an open-source system for automating deployment, scaling, and management of containerized applications. It groups containers that make up an application into logical units for easy management and discovery.
Kubernetes is the orchestration layer that manages containers across a group of physical servers. Kubernetes is specifically designed to manage the containers spinning up, scaling up and scaling down. Kubernetes manages versioning of containers, figures out how containers can talk to each other over the network, exposes services running inside containers and handle storage considerations.
Kubernetes Architecture Overview
A Kubernetes cluster consists of a set of worker machines known as nodes that run containerized applications. Every cluster has at least one worker node. The worker node(s) host the pods that are the components of the application workload.
Kubernetes cluster consists of at least one master and multiple nodes.
Kubernetes Architecture
- Master: It is responsible for exposing the application program interface (API), scheduling the deployments and managing the overall cluster.
- API Server: It performs all the administrative tasks through the API server within the master node.
- Nodes: It is a physical server that has pods inside them that are responsible for running applications inside them.
- Pods: A pod is one or more containers that logically go together. There are multiple pods in one node and they all share the same content.
- Scheduler: It schedules the tasks to worker nodes. It stores the resource usage information for each slave node.
- Controller Manager: The controller watches the desired state of the objects it manages and ensures that their current state through the API server. If the current state of the objects it manages does not meet the desired state, then the control loop takes corrective steps to make sure that the current state is the same as the desired state.
- ETCD: etcd is a distributed key-value store that stores the cluster state and can also be used to store configuration details such as subnets, ConfigMaps, Secrets, etc. It can be part of the Kubernetes Master, or it can be configured externally.
- Container Runtime: It runs and manages the container’s lifecycle on the worker node.
- Kubelet: It is an agent that communicates with the Master node and executes on the worker nodes. It gets the Pod specifications through the API server and executes the containers associated with the Pod and ensures that the containers running within the pods are running and in a healthy state.
- Kube-Proxy: Kube-proxy runs on each node to deal with individual host sub-netting and ensures that the services are available to external parties. For each Service endpoint, Kube-proxy sets up the routes so that it can reach to it.
Salient Features of Kubernetes
- Kubernetes makes it easy to quickly ramp up the container instances to manage the demands.
- Kubernetes also deals with the failed hardware and maintaining container availability.
- Kubernetes has much of the flexibility of Iaas(Infrastructure-as-a-Service), it provides developer-friendly constructs such as deployment, logging, monitoring, balancing, scaling and many more.
- Kubernetes help developers to focus entirely on container-centric workflows by abstracting other constructs such as compute, network and storage resources.
- Kubernetes help developers to achieve higher-level automation as it integrates into the continuous integration/continuous delivery(CI/CD) pipelines, developers can use it to bring in their code into production in a controlled, tested and automated manner.
- Kubernetes platform usually includes monitoring, logging, tracing, release management for blue/green or canary deployments, automated testing in the pipeline, and automated deployment. All of these factors make it easy to deploy software to production.
Components of Kubernetes
- Ingress: It is an API object that exposes HTTP and HTTPS routes from outside the cluster to access the services inside the cluster. There are three ways in which you can expose your application.
- NodePort: It is an open port on every node of your cluster. Kubernetes transparently routes incoming traffic on the NodePort to your service, even if your application is running on a different node.
- LoadBalancer: This service automatically deploys an external load balancer. This external load balancer is associated with a specific IP address and routes external traffic to Kubernetes service in your cluster.
- Ingress Controller: It is responsible for reading the Ingress Resource Information and processing that data accordingly. It simply adds an additional layer of routing and control behind the load balancer.
- Replica Sets: It ensures how many replicas of the pod should be running at a given time. It is often used to guarantee the availability of a specified number of identical pods. It fulfills its purpose by creating and deleting Pods as needed to reach the desired number.
- ConfigMaps and Secrets: Kubernetes has ConfigMaps and Secrets that can inject configuration data into a container when it starts up. Secrets can be intended for storing a small amount of sensitive information such as MYSQL_ROOT_PASSWORD. Whereas, ConfigMaps are intended for non-sensitive data like config files and environment variables.
- Service: It is a REST object and an abstract way to expose an application running on a set of Pods as a network service. With Kubernetes, you don’t need to modify your application to use an unfamiliar service discovery mechanism. Kubernetes gives pods their own IP addresses and a single DNS name for a set of Pods and load balance across them.
- Deployments: Deployments provide updates for Pods and ReplicaSets. You can define Deployments to create new ReplicaSets or to remove existing Deployments and adopt their resources with new Deployments. Deployments provide many key features.
- Easily deploy a ReplicaSet: To create pods in the background
- Clear up old ReplicaSets: If you don’t need the old ReplicaSets, you can clear them up.
- Update Deployment: A new ReplicaSet is created and the Deployment manages to move the Pods from the old ReplicaSet to the new one at a controlled rate. Each new ReplicaSet updates the revision of the Deployment. A Deployment’s rollout is triggered if Deployment’s Pod Template(.spec.template) is updated.
- Determine the status of Deployment: It is used as an indicator if a rollout has stuck.
- Scale Deployment: To facilitate more load.
- Pausing and Resuming a Deployment: To apply multiple fixes to PodTemplateSpec and then resume it to start a new deployment.
- Rolling Back a Deployment: If the current state of Deployment is not stable, update to the previous Deployment.
Conclusion
Kubernetes is growing popular among developers as more companies are electing to use Kubernetes for container orchestration and workload management, Dev/Ops engineers, engineering managers, and software developers are all looking to add Kubernetes as a skill to their toolbelt because this platform is designed to be fault-tolerant scalable and known for its robust architecture. I hope this detailed guide to Kubernetes for developers proved to be effective for you to deploy your code quickly in the Production Environment.
Check out How to create a production-grade cluster using EKS