Kubernetes Overview - Architecture

Kubernetes Overview - Architecture

Kubernetes Architecture Overview

Kubernetes orchestrates containerized applications across multiple servers. Here are the key components and concepts:

  1. Control Plane:

    • The control plane manages the overall cluster state.

    • It includes the following components:

      • API Server: Exposes the Kubernetes API and acts as the entry point for all commands.

      • etcd: A distributed key-value store that stores configuration data.

      • Controller Manager: Watches for changes in the desired state and ensures the actual state matches it.

      • Scheduler: Assigns pods to nodes based on resource requirements and constraints.

  2. Nodes (Compute Machines):

    • Nodes are the worker machines where containers run.

    • Each node runs its own Linux environment.

    • Nodes can be physical or virtual machines.

    • Key components on nodes:

      • Kubelet: Ensures containers are running in a pod.

      • Container Runtime: Executes containers (e.g., Docker, containerd).

      • Kube Proxy: Maintains network rules for pod communication.

  3. Pods:

    • The smallest deployable units in Kubernetes.

    • Pods contain one or more containers sharing the same network and storage.

    • They are scheduled onto nodes.

  4. Services:

    • Abstracts access to pods.

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

    • Types: ClusterIP, NodePort, LoadBalancer, and ExternalName.

  5. Volumes:

    • Provides persistent storage for pods.

    • Mounts data into containers.

  6. Add-ons:

    • Additional components for extended functionality.

    • Examples: DNS, Dashboard, Ingress Controllers.

Remember, Kubernetes simplifies container management by automating deployment, scaling, and maintenance. It’s a powerful tool for modern application development! 🚀

Nodes(Minions)

Kubernetes, a node (previously known as a minion) is a fundamental component. Let’s explore what nodes are and their role in the Kubernetes architecture:

  1. What is a Node?

    • A node represents a worker machine within a Kubernetes cluster.

    • It can be either a virtual machine (VM) or a physical machine, depending on the specific cluster setup.

    • Each node hosts the necessary services to run pods (the smallest deployable units in Kubernetes).

  2. Node Components:

    • The services running on a node include:

      • Container Runtime: Responsible for executing containers (e.g., Docker, containerd).

      • Kubelet: Ensures that containers within pods are running correctly.

      • Kube Proxy: Manages network rules for pod communication.

  3. Managed by the Control Plane:

    • Nodes are managed by the control plane (the brain of the Kubernetes cluster).

    • The control plane oversees the overall cluster state and ensures that nodes function properly.

    • Typically, a cluster consists of several nodes, but in resource-limited environments, you might have only one node.

  4. Node Registration:

    • Nodes can be added to the Kubernetes API server in two ways:

      • Self-Registration: When the kubelet flag --register-node is set to true (which is the default), the kubelet automatically registers itself with the API server.

        • The kubelet starts with options like --kubeconfig (path to credentials), --cloud-provider (for cloud metadata), and --register-node.
      • Manual Registration: You (or another user) can manually create a Node object.

        • The control plane validates the Node object and checks if the kubelet has registered with the API server.

        • If the node is healthy (all necessary services are running), it becomes eligible to run pods.

  5. Node Naming and Uniqueness:

    • Each node has a unique name (DNS subdomain).

    • Two nodes cannot share the same name simultaneously.

    • Kubernetes assumes that resources with the same name represent the same object (e.g., network settings, labels).

Remember, nodes form the backbone of your Kubernetes cluster, providing the computational power to execute your containerized workloads!

Cluster

what a Kubernetes cluster is and how it plays a crucial role in managing containerized applications.

What is a Kubernetes Cluster?

A Kubernetes cluster is a fundamental construct in the world of container orchestration. Here are the key points:

  1. Definition:

    • A Kubernetes cluster consists of a group of nodes (either physical or virtual machines) working together.

    • These nodes collaborate to achieve a common goal: running and managing containerized applications.

  2. Node Machines:

    • Nodes are the building blocks of a cluster.

    • Each node hosts services necessary for running containers.

    • These services include the container runtime (like Docker), the Kubelet (which ensures container health), and the Kube Proxy (managing network rules).

  3. Control Plane and Compute Machines:

    • At a minimum, a Kubernetes cluster includes:

      • Control Plane: Responsible for maintaining the desired state of the cluster.

        • Components: API Server, etcd, Controller Manager, and Scheduler.
      • One or more Compute Machines (nodes): Where containers run.

  4. Benefits:

    • Containerization: Kubernetes clusters allow applications to be packaged with their dependencies into lightweight containers.

    • Flexibility: Applications can be easily developed, moved, and managed within the cluster.

    • Scalability: Kubernetes scales seamlessly without burdening your operations team.

    • Freedom: You can run Kubernetes anywhere—on-premises, hybrid, or public cloud infrastructure.

  5. Google’s Influence:

    • Kubernetes builds upon Google’s 15 years of experience in running production workloads.

    • It combines community-driven best practices with Google’s battle-tested ideas.

Remember, a well-orchestrated Kubernetes cluster empowers you to deploy, scale, and manage your containerized applications effectively!

Master

Kubernetes Master: The Control Center

The Kubernetes Master is the central brain of your Kubernetes cluster. Here’s what you need to know:

  1. Responsibilities:

    • Cluster Management: The master maintains the desired state of the entire cluster.

    • Communication Hub: It communicates with worker nodes (also known as minions) to keep the cluster and your applications running smoothly.

    • Administrative Tasks: All administrative tasks start at the master.

  2. Components:

    • The master includes several critical components:

      • API Server: Acts as the entry point for all commands and exposes the Kubernetes API.

      • etcd: A distributed key-value store that stores configuration data.

      • Controller Manager: Watches for changes in the desired state and ensures the actual state aligns with it.

      • Scheduler: Assigns pods to nodes based on resource requirements and constraints.

  3. Node Communication:

    • The master instructs worker nodes on how many instances of your application to run and where.

    • It coordinates activities inside the cluster, ensuring everything works harmoniously.

  4. Separate Server:

    • Typically, the master runs on a separate server or VM.

    • It remains dedicated to managing the cluster, while worker nodes focus on running containers.

Remember, the Kubernetes Master orchestrates the entire show, making sure your applications dance gracefully in the containerized world!

Component

  1. API Server

    • The Kubernetes API Server serves as the interface for handling, developing, and configuring Kubernetes clusters. Here are the key points:

      1. Role and Importance:

        • The API Server is the core component of the control plane.

        • It acts as the front end for all interactions within the cluster.

        • Users, external modules, and other components communicate with each other through the API Server.

      2. Responsibilities:

        • Validation and Configuration: The API Server validates and configures data for various Kubernetes objects (such as pods, services, and replication controllers).

        • REST Operations: It services REST operations, allowing users and components to interact with the cluster’s shared state.

        • Central Hub: All other components in the cluster interact with the shared state via the API Server.

      3. Components and Functionality:

        • API Exposed: The API Server exposes the Kubernetes API via HTTP.

        • Validation: It ensures that requests are valid before processing them.

        • Configuration: The API Server handles configuration data for the entire cluster.

        • Secure Port: Requests to the secure port of the API Server are authenticated and processed.

        • Anonymous Requests: Anonymous requests (with a username of system:anonymous) are allowed if not rejected by other authentication methods.

      4. Control Plane Backbone:

        • Think of the API Server as the gateway through which all cluster activities flow.

        • It orchestrates the dance of containers, services, and other resources within your Kubernetes environment.

  2. etcd

    • Etcd plays a crucial role in Kubernetes, acting as the persistent data store. Here’s what you need to know:

      1. What is Etcd?

        • Etcd is a distributed key-value store.

        • It ensures consistency and high availability.

        • Etcd records the state of all resources in a Kubernetes cluster.

        • Think of it as the single source of truth for your cluster data.

      2. Responsibilities:

        • Storage: Etcd stores configuration data, state data, and metadata.

        • Backend Service Discovery: It acts as a backend service discovery and database.

        • Monitoring Changes: Etcd monitors changes in the cluster and stores state/configuration data accessed by the Kubernetes master or clusters.

      3. Why Etcd Matters:

        • Etcd is the control center for your Kubernetes cluster.

        • It ensures that your cluster operates smoothly, maintaining the integrity of your applications.

  3. Kubelet

    • The Kubelet is like the diligent caretaker of each node in your Kubernetes cluster. Here’s what it does:

      1. Role and Responsibilities:

        • The Kubelet runs on every node in the cluster.

        • Its primary job is to manage the lifecycle of containers within pods.

        • It communicates with the Kubernetes control plane (the brain of the cluster) and ensures that containers are running as intended.

      2. Tasks of the Kubelet:

        • PodSpec Management: The Kubelet works with a PodSpec, which is a YAML or JSON object describing a pod.

        • Container Health: It ensures that containers described in the PodSpecs are healthy and running.

        • Container Manifests:

          • The Kubelet receives container manifests (descriptions of containers) through various mechanisms:

            • File Path: Monitors files periodically for updates.

            • HTTP Endpoint: Checks an HTTP endpoint for changes.

          • It doesn’t manage containers that were not created by Kubernetes.

      3. Communication Bridge:

        • The Kubelet bridges the gap between the control plane and the nodes where actual workloads run.

        • It’s responsible for keeping the containers in check, reporting any issues, and maintaining the desired state.

  4. Container Runtime

    • The container runtime is a foundational technology that powers the execution of containers across a Kubernetes cluster. Here are the key points:

      1. Role and Importance:

        • The container runtime is responsible for several critical tasks:

          • Image Management: Pulling, storing, and managing container images.

          • Container Execution: Running containers based on specified images.

          • Networking: Handling network communication between containers.

          • Storage: Managing storage volumes for containers.

        • It provides the necessary isolation and resource management required by containers.

      2. Supported Runtimes:

        • Kubernetes supports various container runtimes, including:

          • containerd: A lightweight, high-performance runtime.

          • CRI-O: A lightweight implementation of the Kubernetes CRI (Container Runtime Interface).

          • Docker Engine: Although direct integration with Docker Engine (using dockershim) was removed from Kubernetes, Docker Engine can still be used as a container runtime.

          • Mirantis Container Runtime: Another option for managing containers.

      3. CRI and Compatibility:

        • Kubernetes 1.29 and later require runtimes that conform to the Container Runtime Interface (CRI).

        • Ensure your chosen runtime adheres to CRI standards for seamless compatibility with Kubernetes.

  5. Controller Manager

    • The Kubernetes Controller Manager (also known as kube-controller-manager) is like the conductor of an intricate symphony. Here’s what it does:

      1. Continuous Control Loop:

        • The controller manager acts as a non-terminating loop that regulates the state of the Kubernetes system.

        • It watches the shared state of the cluster through the API server.

        • Its mission: to move the current state towards the desired state described in the cluster’s declarative configuration.

      2. Built-in Controllers:

        • The controller manager embeds core control loops shipped with Kubernetes.

        • Examples of controllers it manages:

          • Replication Controller: Ensures the desired number of pod replicas.

          • Endpoints Controller: Populates the Endpoints resource.

          • Namespace Controller: Maintains namespaces.

          • Service Accounts Controller: Manages service accounts.

      3. API Server Interaction:

        • The controller manager communicates with the API server to orchestrate changes.

        • It ensures that pods, services, and other resources waltz gracefully within the cluster.

  6. Scheduler

    • The Kubernetes Scheduler is like a matchmaker for pods and nodes. Here’s how it works:

      1. Role and Responsibilities:

        • The scheduler assigns pods to nodes based on resource requirements, constraints, and other factors.

        • It ensures that each pod finds its ideal dance partner (node) within the cluster.

      2. How It Operates:

        • When a new pod is created, the scheduler:

          • Checks the pod’s resource requests (CPU, memory).

          • Evaluates node suitability (available resources, affinity rules, taints, tolerations).

          • Ranks nodes based on fitness.

          • Selects the best node for the pod.

        • The scheduler then binds the pod to the chosen node.

      3. Custom Scheduling Rules:

        • You can customize scheduling behavior using:

          • Node Affinity: Specify preferred or required nodes.

          • Taints and Tolerations: Influence pod placement.

          • Pod Priority: Prioritize critical workloads.

          • Topology Spread Constraints: Distribute pods across nodes.

      4. Default Behavior:

        • By default, the scheduler balances resource utilization across nodes.

        • It aims for an even dance floor where no node is overwhelmed.

Master vs Worker Nodes

the distinction between Kubernetes Master and Worker Nodes in your cluster:

  1. Kubernetes Master (Control Plane):

    • The Master Node serves as the central brain of your Kubernetes cluster.

    • Its primary responsibilities include:

      • Cluster Management: Maintaining the desired state of the entire cluster.

      • Communication Hub: Interacting with worker nodes to ensure smooth operations.

      • Administrative Tasks: All administrative actions start at the master.

    • Key components on the master node:

      • API Server: The entry point for commands, allowing interaction via tools like kubectl.

      • etcd: A distributed key-value store storing configuration data.

      • Controller Manager: Watches for state changes and reconciles the desired state with the actual state.

      • Scheduler: Assigns pods to nodes based on resource requirements.

    • The master orchestrates the show, ensuring your applications dance gracefully in the containerized world! 🚀

  2. Worker Nodes:

    • Worker nodes execute your containerized workloads.

    • Components on worker nodes:

      • Kubelet: Manages containers, ensuring they are healthy and running.

      • Kube Proxy: Handles network rules for pod communication.

      • Container Runtime: Executes containers (e.g., Docker).

    • When a new worker node joins the cluster, the kubelet introduces itself, provides available resources, and asks if any containers need to run.

    • Think of the kubelet as a diligent worker node manager.

  3. Comparison:

    • Master Nodes:

      • Manage the control plane.

      • Host API server, etcd, controllers, and scheduler.

      • Vital for cluster health.

    • Worker Nodes:

      • Execute containers.

      • Run kubelet, kube proxy, and container runtime.

      • The muscle behind your applications.

Remember, the master orchestrates, and the workers execute—the perfect harmony for a robust Kubernetes cluster!

That's great if you have make till here you have covered Kubernetes Architecture.

If you liked what you read, do follow and any feedback for further improvement will be highly appreciated!

Thank you and Happy Learning!👏