📍Introduction
Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.
🔹Features of Kubernetes:
Container Orchestration: Kubernetes automates the deployment, scaling, and management of containerized applications. It handles tasks like container placement, scaling, and rolling updates, making it easier to manage complex applications.
Automated Load Balancing: Kubernetes includes built-in load balancing to distribute network traffic across multiple instances of an application, ensuring high availability and reliability.
Self-Healing: Kubernetes monitors the health of applications and automatically restarts containers that fail or become unresponsive. It can also replace failed nodes and reschedule containers on healthy nodes.
Horizontal Scaling: Kubernetes allows you to easily scale your applications by adding or removing instances (containers) based on resource utilization or custom metrics.
Service Discovery: Kubernetes provides an internal DNS service that automatically assigns DNS names to containers and services. This enables seamless communication between containers and services using human-readable names.
Rolling Updates and Rollbacks: Kubernetes supports rolling updates, allowing you to update applications without downtime by gradually replacing old containers with new ones. If issues arise, you can also roll back to a previous version.
Configuration Management: Kubernetes provides a declarative approach to managing application configurations using YAML files. This allows you to define the desired state of your applications and Kubernetes ensures that the actual state matches the desired state.
Storage Orchestration: Kubernetes offers storage orchestration, allowing you to attach, mount, and manage storage solutions for your containers. This includes various types of storage, such as local storage, network-attached storage, and cloud storage.
Secrets and ConfigMaps: Kubernetes provides mechanisms to manage sensitive information and configuration data separately from the application code. Secrets and ConfigMaps allow you to manage passwords, API keys, and other sensitive data securely.
Multi-Environment Support: Kubernetes is designed to work across various environments, including on-premises data centers and public, private, and hybrid clouds. This flexibility enables you to deploy applications in a consistent manner across different environments.
Resource Management: Kubernetes enables you to allocate and manage resources (CPU, memory, storage) for your containers, ensuring fair distribution and optimal utilization.
Pods: The smallest deployable unit in Kubernetes is a pod, which can consist of one or more tightly coupled containers. Containers within the same pod share the same network namespace and storage volumes.
Networking: Kubernetes manages networking between containers, allowing pods to communicate with each other within the same cluster. It also supports network policies for controlling traffic between pods.
Batch Jobs and Cron Jobs: Kubernetes supports running batch workloads and scheduled tasks using Batch Jobs and Cron Jobs, making it suitable for various use cases beyond continuous services.
Extensibility and Ecosystem: Kubernetes has a rich ecosystem of extensions, plugins, and APIs that allow you to customize and extend its functionality to suit your specific requirements.
🔷What is a node?
In Kubernetes, a "node" is a worker machine within the cluster that runs containerized applications. It hosts containers, managed by the control plane, and includes components like the kubelet and container runtime for managing container execution and resources.
🔷What is a Cluster?
A Kubernetes Cluster is a set of nodes that run containerized applications.
🔷Architecture of Kubernetes:
Kubernetes architecture is a distributed system that consists of a master node and multiple worker nodes. The master node manages the overall state of the cluster and the worker nodes run the containerized applications. The system uses a set of APIs to communicate between nodes and manage resources, such as storage and networking. The architecture is designed to be scalable, fault-tolerant, and extensible to support a wide range of applications and workloads.
Master Components: The master components are responsible for managing the overall Kubernetes cluster.
etcd: etcd is a distributed key-value store that is used to store the configuration data and the state of the Kubernetes cluster.
Kubernetes API Server: The API server is the central control plane of the Kubernetes cluster. It provides a RESTful interface for communication with other components of the cluster.
Kube-Controller Manager: The controller manager is responsible for managing the various controllers that are responsible for maintaining the desired state of the cluster.
Kube-Scheduler: The scheduler is responsible for scheduling the containerized workloads to the worker nodes.
Node Components: The node components are responsible for running the containerized workloads.
Kubelet: The kubelet is responsible for managing the containerized workloads on a node. It communicates with the API server to receive instructions on how to manage the containers.
Container Runtime: The container runtime is responsible for running the containers on a node. It could be Docker, rkt, or any other container runtime that supports the Kubernetes Container Runtime Interface (CRI).
kube-proxy: The kube-proxy is responsible for managing the network connectivity of the containers running on a node.
🔹Kubernetes installation:
EC2 instances with the instance type of t2.medium.
Update your Ubuntu package list:
sudo apt-get update
To install k8s, first, you have to Install Docker:
sudo apt install docker.io -y sudo systemctl start docker sudo systemctl enable docker
Install the necessary packages for Kubernetes.
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
Add the Kubernetes signing key:
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
Update the system and install Kubernetes:
sudo apt update -y sudo apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y
Initialize the cluster (Master):
sudo su kubeadm init
Run this command on the Master Node:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
Generate the Token for the configuration of the Worker Node:
kubeadm token create --print-join-command
Worker Node
Paste the above output in the Worker Node:
sudo su ---Paste the Join command on worker node with `--v=5`
Now execute this command in the Master Node :
kubectl get nodes
Thank You! Stay Connected ☁️