What is Kubernetes⁉️
Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. It's a portable, extensible, and scalable platform that can be used to run applications anywhere, from laptops to data centers to the cloud.
In simple terms, Kubernetes is a "container orchestration system". It allows you to easily deploy and manage containerized applications across a cluster of hosts.
Let's understand with a simple example:
Think of Kubernetes like a magical manager for your computer programs. Imagine you have a bunch of toys you want to play with – like building blocks, action figures, and puzzles.
Without Kubernetes, you'd have to organize and play with each toy separately, and if you needed more toys or if some broke, you'd have to fix everything by hand.
But with Kubernetes, it's like having a super organizer. You tell it how you want to play, and it sets up all the toys for you. If you want to play more or if something breaks, it automatically brings new toys or fixes the broken ones.
So, Kubernetes helps you enjoy your toys (programs) without worrying about how they work or if they break, making playtime (app management) much easier and fun!
Why do we call it k8s🤔
Its first letter is “K,” and the last letter is “S.” It is composed of 10 words, but between the first and the last letter, there are 8 additional letters “ubernete.” This is where the 8 come from. Combining all of them, we get “K8s.” — a simple yet effective short form of the word Kubernetes.
Another example would be “Internationalization” which when shortened leads to “i18n.” The whole purpose is to make long words short so that communications can become simple yet effective.
What are the benefits of using k8s⁉️
Using Kubernetes (K8s) offers several benefits for managing your applications and infrastructure:
Automated Deployment and Scaling:
- Think of it like a chef who prepares more food when a lot of guests arrive and less when fewer are there. Kubernetes does the same but with your programs, making sure they run smoothly and efficiently.
Container Orchestration:
- Imagine a traffic director who tells cars where to go in a busy intersection. Kubernetes does this with your programs, making sure they run on the right computer and work well together.
High Availability:
- It's like having a spare light bulb ready when the one in your room goes out. Kubernetes keeps extra copies of your programs running, so if one stops working, a new one instantly takes its place.
Load Balancing:
- Think of it as a cashier who makes sure each checkout lane at the store has about the same number of people. Kubernetes spreads out the work for your programs so that no single computer gets overwhelmed.
Rolling Updates and Rollbacks:
- Imagine updating your phone's apps one by one, so you always have a working version. Kubernetes does this with your programs, replacing them slowly to avoid hiccups and easily going back if needed.
Self-Healing:
- It's like a robot pet that fixes itself when it gets a scratch. Kubernetes notices when a program isn't working and restarts it automatically, just like your pet robot healing itself.
Declarative Configuration:
- Think of it as a recipe book for cooking. You write down how you want your programs to run, and Kubernetes follows the recipe to set them up exactly as you want.
Resource Management:
- Imagine a water regulator that gives just the right amount of water to different plants in your garden. Kubernetes does this with your programs, making sure they have enough power to run well.
Secrets and Configuration Management:
- It's like keeping your secret treasure map locked in a special box. Kubernetes keeps your important info safe and separate from your programs, so they're more secure.
Extensibility and Ecosystem:
- Think of it as a collection of cool accessories for your favorite toy. Kubernetes has lots of extra tools that you can add to make your programs even better and more useful.
Cost Efficiency:
- Imagine turning off lights in rooms you're not using to save energy. Kubernetes helps you use only the computer power you need, which saves money on the cloud bill.
Multi-Cloud and Hybrid Cloud Support:
- It's like being able to play the same video game on different game consoles. Kubernetes lets your programs work on different cloud services or even on your own computers.
☸️Architecture of Kubernetes
The above is the Kubernetes architecture
- Here we have two major servers : Master and node
Role of Master:
Kubernetes cluster contains containers running or Bare Metal / VM instances/cloud instances/ all mix. The collection of servers is called a Cluster.
Kubernetes designates one or more of these as masters and all others as workers.
The master is now going to run a set of K8s processes. These processes will ensure the smooth functioning of the cluster. These processes are called the Control Plane.
Master runs control plane to run cluster smoothly.
What is this Control Plane ⁉️
☸️ Components of Control Plane :
Kube-api-server → (For all communications)
This api-server interacts directly with the user ,we can apply .yml or .json manifest to kube-api-server .
This kube-api-server is meant to scale automatically as per load.
Kube-api-server is the front end of the control plane. Basically manages all the worker nodes.
Kubectl is the CLI tool for working with a Kubernetes cluster and interact with worker nodes . Similarly on the worker node we have Kubelet
etcd
Stores metadata and status of the cluster.
etcd is a consistent and high-available store (key-value-store)
Source of touch for cluster state (info about the state of the cluster)
Kube-schedular (action)
When users request the creation & management of Pods, Kube-scheduler is going to take action on these requests.
Handles POD creation and Management
Kube-scheduler match/assign any node to create and run pods.
A scheduler watches for newly created pods that have no node assigned. For every pod that the scheduler discovers, the scheduler becomes responsible for finding the best node for that pod to run.
Controller-Manager
Make sure the actual state of the cluster matches the desired state.
Two possible choices for controller manager:
If K8s is on the cloud, then it will be a cloud controller manager.
If K8s is on non-cloud, then it will be kube-controller-manager.
Components on the master that runs the controller:
Node Controller : For checking the cloud provider to determine if a node has been detected in the cloud after it stops responding.
Route-Controller : Responsible for setting up a network, and routes on your cloud.
Service-Controller : Responsible for load Balancers on your cloud against services of type Load Balancer.
Volume-Controller : For creating, attaching, and mounting volumes and interacting with the cloud provider to orchestrate volume.
What is there in Worker Node / Node :
In nodes we have
Kubelet :
The agent running on the node.
Kubelet is a process that runs on each node in a Kubernetes cluster. It is responsible for managing the containers that are running on the node. The kubelet communicates with the Kubernetes API server to get instructions about which containers to run and how to manage them.
Container Engine:
The container engine in Kubernetes is responsible for the following tasks:
Works with kubelet
Pulling container images from a registry
Creating and running containers
Managing container lifecycles
Exposing containers to the network
Monitoring and managing container resources
Kube-Proxy:
- Kube-proxy is a network proxy that runs on each node in a Kubernetes cluster. It is responsible for maintaining network rules on the nodes that allow network communication to your Pods from network sessions inside or outside of your cluster.
Difference Between Kubectl and Kubelet🤔
What is a Pod ⁉️
A pod in Kubernetes is the smallest unit of deployment. It is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers.
A Pod is a Kubernetes abstraction that represents a group of one or more application containers (such as Docker), and some shared resources for those containers.
Those resources include:
Shared storage, as Volumes
Networking, as a unique cluster IP address
Information about how to run each container, such as the container image version or specific ports to use
POD is a group of one or more containers that are deployed together on the same host
A cluster is a group of nodes.
A cluster has at least one worker node and a master node.
Kubernetes only knows about PODs (Does not know about individual containers).