On this page
Kubernetes, often abbreviated as K8s, is an open-source container orchestration platform initially developed by Google and now maintained by the Cloud Native Computing Foundation (CNCF). Kubernetes simplifies the management of containerized applications by providing powerful orchestration capabilities. Its declarative approach to configuration and automation of deployment and scaling tasks makes it an essential tool for modern application development and deployment. As organizations embrace cloud-native technologies, Kubernetes has emerged as a fundamental building block for deploying and managing applications at scale.
Hello Everyone!! Hope y'all doing great in your life and upskilling everyday. Today, I will be writing up about Kubernetes. In this blog, I will be covering basic concepts of kubernetes. Before you start diving into I would like to mention that this is just another blog written on kubernetes but I believe that every single resource that's out there might be helpful on any minor/major topic that you might be struggling to understand. As a learner and k8s struggler I have written this blog to simplify basic concepts and tried to keep it short.
Introduction to Kubernetes
Kubernetes aka k8s is a container orchestration technology used to manage the deployment and management of hundreds and thousands of containers in a cluster environment.
A lot of stuff in single definition right? Let me break down things for you.
Container Orchestration? - Process of deploying and managing containers is known as Container Orchestration.
Why managing containers? Isn't docker there for that?
Well, yeah! but docker couldn't address certain challenges better than kubernetes. Below are some challenges kubernetes don't hesitate to address it's efficiency and error-proof.
Also I mentioned Cluster in definition?
Cluster here refers as machines (entire running system). Cluster has 3 important components i.e. - Nodes, Pods, Containers.
Nodes are 2 types - Worker node and Master Node.
Kubernetes has several main components. These components play an important role.
Pods, Services, Ingress, Deployment, Volumes, ConfigMaps, Secrets.
K8S Architecture
Kubernetes is known for its Master-Slave Architecture. Cluster has 2 nodes i.e. Master Node and Worker Node.
Worker Node
- Each node has multiple pods to it.
- Worker node does the actual work.
- 3 process must be installed on every node.Container Runtime - Provides the underlying runtime environment for containers, such as Docker, Containerd, and CRI-O for communication with the Kubelet.
Kubelet - Responsible for managing pods on the local node, including starting, stopping, and monitoring containers based on pod specifications.
KubeProxy - Manages network routing and load balancing for services running on the node, ensuring that communication between pods and services is properly routed.
Master Node
4 components that runs on every Master Node.
- API Server: Exposes the Kubernetes API, which serves as the primary interface for interacting with the cluster. Also, client communicates with Master node through this component. API Server is load balanced.
- Scheduler: Assigns pods to nodes based on resource availability and scheduling policies. For example, lets assume if you have worker_node_1 30% occupied and worker_node_2 60% occupied. Since worker_node_1 is free and available, scheduler assign pods.
- Controller Manager: Monitors the state of the cluster and ensures that the desired state matches the current state. Controller Manager is also responsibile to reschedule dead pods and bring back alive.
- etcd: A distributed key-value store that stores cluster state and configuration data. Basically, it stores cluster state information. It does not store information regarding application data.
- etcd is distributed storage across all Master Nodes.
So this is a Master-slave architecture of Kubernetes. Let us simplify and understand components as how they are created and utilized.
K8S Components
Pods
- Pods are the fundamental building blocks in Kubernetes.
- Each pod can contain one or more containers.
- pod is an abstraction over container.
- Pods share a container network, enabling communication between any pods, regardless of their nodes.
- Each pod is assigned a single IP address by Kubernetes.
- Deletion and recreation of the pod are required for port changes.
- New IP address is allocated on re-creation of pods.
- Pods are created using Manifest files written in YAML.
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: nginx
apiVersion
: Specifies the version of the Kubernetes API you're interacting with.
kind
: Defines the type of Kubernetes resource, in this case, a Pod.metadata
: Contains metadata about the Pod, such as its name.spec
: Describes the specification of the Pod, including its containers.containers
: An array of containers running within the Pod.name
: Name of the container.image
: Docker image to be used for the container. In this case, it's just the Nginx official image without specifying the tag, so it defaults to the latest version.
You can create above basic_pod.yaml file using kubectl create -f basic_pod.yaml
Minikube, Kind and Kubectl
Minikube: Minikube is a one node cluster where master processes and worker processes run on one-node(one machine).
- Minikube have docker runtime pre-installed.
- Minikube creates virtual box on your device.
- Node runs in that virtual box.
- Therefore, Minikube is 1 node k8s cluster.
- Can be used for testing k8s on local setup.
KIND: KIND stands for Kubernetes in Docker.
It's an open-source project that allows you to run local Kubernetes clusters using Docker container "nodes". With KIND, you can spin up a Kubernetes cluster quickly on your local machine by creating Docker containers that act as individual nodes in the cluster. These nodes can then interact with each other to form a fully functional Kubernetes cluster.
Benifits of KIND: Light Weight, Isolated, Easy Setup, Versatile
Kubectl: kubectl is a cli tool for k8s cluster.
As we know Master Processes have a component called "API Server" which enables interaction with cluster by help of 3 clients (UI, API, CLI). Therefore, CLI tool called kubectl is more efficient among 3 clients. Once kubectl sends command to API Server it can create, update, delete pods. Worker Processes enables to pod run on node.
#Get Nodes information
kubectl get nodes
#Get pods information
kubectl get pod
#Create a pod for first time in Node.
kubectl create -f basic_pod.yaml
#After updating/editing basic_pod.yaml.
kubectl apply -f basic_pod.yaml
#Description of pod
kubectl describe pod basic_pod.yaml
#Delete pod
kubectl delete pod basic_pod.yaml
#Execute a command in a specific container within a Pod
kubectl exec -it basic_pod.yaml -c ngnix -- <command>
#Run a Pod named my-pod with an Nginx image
kubectl run my-pod --image=nginx
kubectl create
is used for creating pod for first time in node. If you edited/updated pod yaml file and use create
command it will throw error saying pod already exists. Therefore, edited/updated files should be created again using kubectl apply
command.Pod Accessibility Challenges
- Pods dynamic IP addresses make direct access inconvenient.
- Rescheduled Pods may receive different IP addresses.
- How do we overcome these accessibility challenges???
And that's how Services
come into the picture.
Wrapping Up
So, wrapping up this blog here. In next blog, we will be exploring more crucial components like Services, Deployments, Ingress, Namespaces, Stateful etc., of k8s and how they go hand-in-hand with each other.
Want more of simplified blogs visit sysxplore. Thank you for your time and we will meet each other with simple explanations soon. Stay tuned!!!