Skip to main content

Command Palette

Search for a command to run...

Day 30 : Kubernetes Architecture

DevOps Learning

Updated
5 min read
Day 30 : Kubernetes Architecture

What Is Kubernetes?

Kubernetes (often abbreviated as K8s) is an open-source container orchestration system. Its primary purpose is to manage and automate the deployment, scaling, and operation of containerized applications. Think of it as the control center for your containers, ensuring they run smoothly, efficiently, and harmoniously.

Key Concepts:

  1. Nodes:

    • Nodes are the worker machines in a Kubernetes cluster. They can be physical servers or virtual machines.

    • Each node runs a container runtime (like Docker) and communicates with the control plane (master) to manage containers.

  2. Control Plane (Master):

    • The brain of Kubernetes. It manages the overall state of the cluster.

    • Components:

      • API Server: Exposes the Kubernetes API and processes requests.

      • etcd: Distributed key-value store for configuration data.

      • Controller Manager: Ensures desired state (e.g., maintaining replica sets).

      • Scheduler: Assigns workloads to nodes based on resource availability.

  3. Pods:

    • The smallest deployable unit in Kubernetes.

    • A pod can contain one or more tightly coupled containers.

    • Containers within a pod share the same network namespace and storage.

  4. Services:

    • Abstracts access to pods.

    • Provides a stable IP address and DNS name for a set of pods.

    • Types: ClusterIP (internal), NodePort (external), LoadBalancer (cloud load balancer).

  5. Replica Sets:

    • Ensures a specified number of replicas (pods) are running.

    • Scales pods up or down based on demand.

  6. Deployments:

    • Manages rolling updates and rollbacks.

    • Defines desired state for pods.

Example Scenarios:

  1. Creating a Deployment:

    • Imagine you want to deploy a web application. You define a Deployment resource with the desired number of replicas and the container image.

    • Kubernetes creates pods based on this definition, ensuring they match the desired state.

  2. Scaling Up:

    • Your app becomes popular, and traffic increases. No worries!

    • You update the Deployment’s replica count, and Kubernetes spins up more pods to handle the load.

  3. Rolling Updates:

    • You’ve improved your app and want to release a new version.

    • Update the Deployment’s container image. Kubernetes orchestrates a rolling update—gradually replacing old pods with new ones.

  4. Service Discovery:

    • Your app needs to communicate with a database.

    • Create a Service resource pointing to the database pods. Now your app can reach the database using the service name.

  5. Horizontal Pod Autoscaling (HPA):

    • Set up an HPA based on CPU utilization.

    • When CPU exceeds a threshold, Kubernetes automatically scales up pods.

Why Kubernetes?

  1. Abstraction: Kubernetes abstracts away infrastructure details. Developers focus on code, not servers.

  2. Scalability: Easily scale applications horizontally (add more pods) or vertically (adjust resources per pod).

  3. High Availability: Kubernetes ensures apps stay up even if nodes fail.

  4. Self-Healing: If a pod crashes, Kubernetes restarts it.

  5. Declarative Configuration: Define desired state (YAML files) and let Kubernetes handle the rest.

Learn more:

More about Kubernetes.

What is the difference between kubectl and kubelets.

    1. kubectl:

      • What It Is: kubectl is the command-line interface (CLI) tool that developers use to interact with a Kubernetes cluster.

      • What It Does:

        • Executes commands to query, create, update, and delete Kubernetes resources.

        • Allows you to inspect pods, services, nodes, deployments, and more.

        • Your go-to tool for deploying applications, managing configurations, and troubleshooting.

      • Example Usage:

        • To get basic information about nodes in your cluster:

            kubectl get nodes
          
        • To apply a manifest file (like a YAML or JSON) and create a Kubernetes resource (e.g., a service):

            kubectl apply -f myservice.yaml
          
      1. kubelet:

        • What It Is: kubelet running on each node in your Kubernetes cluster. To ensure that every containers play nicely.

        • What It Does:

          • Takes a set of PodSpecs (provided through various mechanisms) and ensures that the specified containers run and stay healthy within the pods.

          • Creates, destroys, or updates containers based on instructions from the control plane.

          • Manages containers only if they were created by Kubernetes (not external ones).

        • How It Works:

          • When it’s time to create a pod and its containers, the Kubernetes controller node nudges the kubelet on a specific worker node.

          • Kubelet interacts with the node’s container runtime (e.g., Docker) to create the required containers.

          • Kubelet organizes containers within their associated pods.

        • Location:

          • Every worker node (whether virtual or physical) has an instance of kubelet running.

          • On a Linux machine, you can find kubelet at /usr/bin/kubelet.

        • Remember:

          • kubelet is all about creating containers on worker nodes.

          • kubectl is the CLI tool for developers to manage the entire Kubernetes cluster.

So, in a nutshell: kubelet orchestrates containers on individual nodes, while kubectl lets you conduct the Kubernetes from your command line.

Explain the role of the API server.

  1. What Is the API Server?

    • The API server is like the grand conductor of the Kubernetes orchestra. It’s the central hub where all the magic happens.

    • Think of it as the gateway through which different parts of your cluster, external components, and even end users communicate with each other.

  2. What Does It Do?

    • Exposes an HTTP API: The API server provides an HTTP-based interface that lets you query and manipulate the state of various Kubernetes objects. These objects include pods, namespaces, config maps, events, and more.

    • Validation and Configuration: When you create or update resources (like deploying a new pod), the API server validates the data and ensures it adheres to Kubernetes rules.

    • Frontend to Shared State: It acts as the frontend to the cluster’s shared state. All other components—controllers, schedulers, and even your beloved kubectl—interact with this shared state via the API server.

  3. How It Works:

    • When you run kubectl get pods or kubectl apply -f myservice.yaml, guess who’s behind the scenes? Yep, the API server!

    • It processes your requests, checks permissions, and ensures consistency across the cluster.

  4. Why Is It Crucial?

    • Single Source of Truth: The API server maintains the authoritative state of your cluster. If it says a pod exists, you can trust it.

    • Security and Authentication: It handles authentication, authorization, and security policies.

    • Extensibility: Custom resources (like CRDs) are introduced via the API server.

Thank you for reading😉.