Kubernetes: The King of Containers

Kubernetes: The King of Containers

📍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:

  1. 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.

  2. Automated Load Balancing: Kubernetes includes built-in load balancing to distribute network traffic across multiple instances of an application, ensuring high availability and reliability.

  3. 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.

  4. Horizontal Scaling: Kubernetes allows you to easily scale your applications by adding or removing instances (containers) based on resource utilization or custom metrics.

  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. Resource Management: Kubernetes enables you to allocate and manage resources (CPU, memory, storage) for your containers, ensuring fair distribution and optimal utilization.

  12. 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.

  13. 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.

  14. 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.

  15. 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.

  1. Update your Ubuntu package list:

      sudo apt-get update
    
  2. To install k8s, first, you have to Install Docker:

      sudo apt install docker.io -y
      sudo systemctl start docker
      sudo systemctl enable docker
    
  3. 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
    
  4. 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
    
  5. 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
    
  6. Initialize the cluster (Master):

      sudo su
      kubeadm init
    
  7. 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
    
  8. Generate the Token for the configuration of the Worker Node:

      kubeadm token create --print-join-command
    

    Worker Node

  9. Paste the above output in the Worker Node:

      sudo su
      ---Paste the Join command on worker node with `--v=5`
    
  10. Now execute this command in the Master Node :

    kubectl get nodes
    

    Thank You! Stay Connected ☁️