Spring Boot + Kubernetes Tutorial - What is Kubernetes? Need for it?
In previous tutorial series we have already covered docker in depth. In todays world Docker containers have become very popular. Containers are extremely lightweight, modular virtual machines. We get flexibility with those containers. We can create, deploy, copy, and move them from environment to environment.
Video
This tutorial is explained in the below Youtube Video.Spring Boot + Kubernetes Tutorial
What is Kubernetes? Need for it? Install Ubuntu on Windows using WSL Installing Kubectl, Minikube and Docker on Ubuntu Create Docker Image Deploy to Minikube Pods Difference between ClusterIP, NodePort and LoadBalancer Service Service Hello World Example
Need for Kubernetes
Consider a scenario where we have multiple docker containers interacting with each other.Now suppose a container crashes. Admin will need to rectify it immediately and restore the container to previous state. Suppose if there are less number of containers then this approach is fine. But if we have hundred of thousands of containers running, then monitoring them manually is not feasible. So it is difficult to monitor the container cluster 24/7.
This is why we need Kubernetes. Kubernetes also called as K8s is an open-source container-orchestration system for automating deployment, scaling and management of containerized applications.
Kubernetes does not allow containers to run on their own. Instead containers run inside a construct called Pods. We can have multiple containers running inside a pod. This makes Pods the fundamental building block in Kubernetes. Multiple containers running inside a pod is usually not a common occurrence. Usually there is a single container running in a pod.
Kubernetes performs following functions -
- Create and run pods.
- Run pods across multiple nodes.
- Load balance traffic across pods.
- Set up networking so nodes can communicate with each other.
Kubernetes Architecture
Kubernetes consists of several smaller components that work together. These components can be catagorized in two groups.- Master Components - Manage the Kubernetes Platform.
- Node Components(Worker Components) - These are responsible for actual running of pods.
Kubernetes deployment
-
Single Node Setup
This setup is used for development purpose. Limited to vertical scalability. No high availibility.
Minikube is an example of Single Node Setup which we will be using for this tutorial series. -
Multi Node Setup
This setup is used in actual production environment. It has horizontal and vertical scaling.
Kube cluster consists of 2 types of nodes
-
Kube Masters - These nodes are responsible for managing the kube cluster.
It consists of the following master components-
- API Server - This acts as the frontend for the Kubernetes cluster. We give commands/manage the cluster using the
API Server. We can connect to the API server using
- UI
- API
- CLI Tool
- Controller Manager -
Controller Manager controls the working of the Kubernetes cluster. The Controller manager is composed of
- Node Controller - It is responsible for monitoring if any node is down. If down then it responds accordingly.
- Replication Controller - It is responsible for making sure that the number of pods have replicas as specified in the configuration
- Endpoint Controller - Responsible for inter pod and services communication
- Service Account and Token Controller - Responsible for creating API Token for new namespaces.
- Scheduler - The scheduler is reponsible for determining how the pods run on the worker nodes. If a new pod is to be created then the scheduler is responsible for selecting the appropriate worker node.
- etcd - The etcd is a key value store for persisting cluster data. It stores the data about the cluster state. So all the information of what is happening in the kubernetes cluster is stored using etcd.
- API Server - This acts as the frontend for the Kubernetes cluster. We give commands/manage the cluster using the
API Server. We can connect to the API server using
-
Kube Workers - These servers run the actual pods, that the kube master instructs to run.
They have following worker components installed on them.
- Kubelet - It is an agent that runs on all the nodes. Its responsiblity is to communicate with the Master Node. If the master node gives any instructions these are implemented by the kubelet.
- Pods - These are the fundamental building block in Kubernetes. These are responsible for running and controlling the containers.