Summary
In this article we will learn about Pod, Replication Controller, Deployment and Services.
Perquisite
Linux Physical or virtual machine for Master and Linux/Windows physical or virtual machine as Nodes (Minions)
PODs:
- Atomic unit of deployment and scaling in Kubernetes. POD is ring fenced environment (Sandbox or Namespace) to run Containers. It contains Network Stack, Kernel namespace, Shared Memory, Storage, etc
- All Containers always runs inside PODs, shares POD environment.
- One Pod can have multiple Containers. A Pod can’t be spread across multiple Nodes, rather Pod run on single Node.
- Pods are Mortal: If any Pod dies, new Pod is created on other Nodes with different IP (No Resurrection, No Lazarus Experience)
- Pods are either deployed through Deployment Manifest (YMAL or JSON) to API Server or Replication Controller (Replicas)
Replication Controllers:
- Replication Controller maintains Desired state of an Application
Example
- We want of deploy 4 replicas of an Application, we create a YMAL file, kind: Replication Controller, replicas: 4 and share it to API Server. API Server spins 4 Pods on the Cluster
- If any Pod becomes unresponsive, Kubernetes will deploy new Pods (Create New Pods on available Nodes) to maintain Desired healthy state
Deployments:
- Deployments are declarative REST API objects in Kubernetes . Use YMAL (or JSON) file for declaration (creates Manifest Files) and send manifest file to API Server
- As Replication controllers adds feature and functionalities around Pods, Deployment do the same for Replica Set (Replication Controller are replaced by Replica Sets)
- Deployments add Powerful Update Model (Versioning, Rolling Updates, Concurrent Releases) and Rollbacks
Declarative Model and Desired State
- Kubernetes works on Declarative Model: We fetch API Server with manifest files (YMAL or JSON) that describes Desired State of the Cluster
i.e ‘How Cluster should looks like and feels like’. Then it is a job of API Server to implement this desired state and maintain it (at any given point of time Desired State = Current State )
- Changes the state of a ReplicaSet to desired state at a control rate, managing the transition between two ReplicaSet (Moving between two version of application, e.g Version Control (Update application from one version to another version in control way))
- Deployment control the rate of the transition and even provides Rollback functionality
Service
- Services is Kubernetes Object that provides stable IP and DNS Name for front-end PODs (Application/Service) to reach backend PODs
- The way the Service belongs to pods is via Labels (Tags). We create Labels on the Service object: Service will load balance incoming request across all the Pods with same Labels
- Service IP and DNS name load balances incoming request from front-end Application/Service across multiple backend Pods
- Services only send traffic to healthy Pods, uses TCP (default) and can be configured with Session Affinity (YMAL file)
- Service is higher-level stable abstraction point for multiple pods and provides Load Balancing. Services add persistency to PODs based on the state of the System
Example
- K8s Service is a Network abstraction to the service (Eg: backend Database service) that Pods provides. So Kubernetes persistently allocates an DNS and IP for an Application services that are provided by the collection of Pods
- As the Pods are created or deleted, Kubernetes dynamically update the service with new information for these Pods
- So Users will still simply access front end IP and DNS, and Kubernetes will maintain the plumbing or infrastructure underneath as the pods come and go based on their lifecycle. Kubernetes will update the routing information to make sure that traffic comes in on that persistent IP and is routed directly to the pods that are up and healthy
- Scale up and down service by adding or removing Pods based on demands by updating TAGs (on PODs and Service)
- Service will Load Balance to distribute application requests across those Pods with same Tag as those on Service
- This is also helpful in PODs rolling update and Rollback