Skip to main content

Command Palette

Search for a command to run...

Kubernetes Architecture

Day 30 for 90DayOfDevOps

Published
8 min read
Kubernetes Architecture
S

Hello, I am sumit and currently pursing my final year of graduation with IT stream from JSPM BSIOTR Wagholi Pune. I am currently learning DevOps with TrainWIthShubham. I have prior knowledge of Java, JSP, Servlet, SQL and Data structure also.I am a hard worker, smart and quick learner.

What is kubernetes?

Kubernetes is a container orchestration tool designed to deploy, manage, and scale containerized applications. It comprises a collection of clusters, with one serving as the master and others as worker nodes. The master orchestrates the deployment and scaling of applications across the nodes. Kubernetes is particularly known for its capabilities in auto-scaling and auto-healing. It utilizes pods, which encapsulate one or more containers, and enables scaling based on traffic fluctuations. Auto-healing is facilitated by the controller manager service in the master server, automatically restarting containers in case of failures.

Why do we call it k8s?

The term "K8s" is a shorthand or an abbreviation for "Kubernetes." The "8" in "K8s" represents the eight letters between the 'K' and the 's' in "Kubernetes."

What are the benefits of using k8s?

  1. Container Orchestration:

    • Kubernetes automates the deployment, scaling, and management of containerized applications, simplifying complex tasks associated with running containers.
  2. Scalability:

    • K8s allows for easy scaling of applications by adding or removing instances (pods) based on demand, enabling efficient resource utilization.
  3. Portability:

    • Kubernetes provides a consistent environment across various infrastructure platforms, making it easy to move applications between on-premises, cloud, and hybrid environments.
  4. Self-Healing:

    • With its auto-healing capabilities, K8s automatically replaces failed containers or reschedules them to healthy nodes, enhancing the overall reliability of applications.
  5. Service Discovery and Load Balancing:

    • Kubernetes has built-in support for service discovery and load balancing, making it easy to connect different microservices and distribute traffic evenly.
  6. Resource Utilization and Efficiency:

    • K8s optimizes resource utilization by packing containers efficiently on nodes, ensuring that the available resources are used effectively.
  7. Declarative Configuration:

    • Kubernetes allows users to describe the desired state of their applications through declarative configuration files (YAML or JSON), reducing manual intervention and ensuring consistency.
  8. Security:

    • Kubernetes includes features and best practices for securing containerized workloads, ensuring that applications are deployed with a strong focus on security.
  9. Cost Efficiency:

    • By optimizing resource utilization and supporting efficient scaling, Kubernetes contributes to cost savings by enabling organizations to use their infrastructure more efficiently.

The architecture of Kubernetes

  1. Master Node:

    • API Server: Serves as the entry point for all administrative tasks and communication with the cluster. It communicate with all services in master and worker node. Kubectl give order to API server and API server forward this task to other services

    • Controller Manager: Maintains the desired state of the cluster by controlling various controllers. It use to manage the containers. If container crashed or reschedule it use to run or manage the container

    • Scheduler: Assigns nodes to newly created pods based on resource requirements and constraints. Use to create the pods or nodes for application

    • etcd: A distributed key-value store that stores the configuration data of the entire cluster, acting as the cluster's brain. It is a database where application and worker node logs are stored. It keep the track of each and every pod, container, and node information.

  2. Node (Minion) / Worker Node:

    • Kubelet: Ensures that containers are running in a Pod on the node and communicates with the master to receive instructions.

    • Kube Proxy: Maintains network rules on nodes, allowing communication between different pods and external traffic.

    • Container Runtime: The software responsible for running containers, such as Docker or containerd.

  3. Pod:

    • The smallest deployable unit in Kubernetes, representing a group of one or more containers sharing the same network namespace and storage.
  4. Service:

    • An abstraction that defines a logical set of Pods and a policy for accessing them, providing a stable endpoint to access the application.
  5. Volume:

    • A directory that contains data accessible to containers in a Pod, providing persistent storage.
  6. Namespace:

    • A way to divide cluster resources between multiple users or teams, allowing multiple virtual clusters within the same physical cluster.
  7. Label:

    • A key-value pair attached to objects (pods, nodes, etc.) that is used to organize and select subsets of resources.
  8. Annotation:

    • Metadata attached to objects for documentation or other purposes, without affecting the object's function.
  9. Secret:

    • A Kubernetes object used to store sensitive information, such as API keys or passwords.
  10. ConfigMap:

    • A Kubernetes object used to store configuration data in key-value pairs that can be consumed by pods.

What is Control Plane?

The Control Plane in Kubernetes is a set of components responsible for managing the state of the cluster, making decisions about the overall cluster behavior, and responding to user requests. It acts as the brain of the Kubernetes system, ensuring that the desired state of the cluster matches the actual state. The Control Plane components run on the master node in a Kubernetes cluster.

The main components of the Kubernetes Control Plane include:

  1. API Server:

    • Serves as the entry point for all administrative tasks and external communication with the cluster.

    • Validates and configures data for the objects in the cluster, making the API server a key component for communication and coordination.

  2. etcd:

    • A distributed and consistent key-value store that stores the configuration data of the entire cluster.

    • Acts as the persistent storage for the entire cluster state and is the source of truth for the state of the cluster.

  3. Controller Manager:

    • Manages different controllers that regulate the state of the cluster to ensure that the actual state converges toward the desired state.

    • Examples of controllers include the Replication Controller, ReplicaSet Controller, and Node Controller.

  4. Scheduler:

    • Watches for newly created Pods with no assigned node and selects a node for them to run on.

    • Considers factors like resource requirements, hardware or software constraints, and affinity/anti-affinity specifications to make informed scheduling decisions.

These components work together to maintain the overall health, state, and functionality of the Kubernetes cluster. The Control Plane continuously monitors the cluster, responds to changes, and takes actions to reconcile the actual state with the desired state as specified by the users.

Write the difference between kubectl and kubelets:

  1. kubectl:

    • Purpose:

      • kubectl is the command-line interface (CLI) tool used for interacting with Kubernetes clusters.
    • Functionalities:

      • Allows users to perform various operations on the cluster, such as deploying applications, managing resources, inspecting cluster state, and executing commands inside containers.

      • Provides a unified interface to interact with the Kubernetes API server.

  2. kubelet:

    • Purpose:

      • kubelet is an agent that runs on each node in the Kubernetes cluster.
    • Functionalities:

      • Responsible for ensuring that containers are running in a Pod on its node.

      • Listens for Pod specifications from the Kubernetes API server and ensures that the containers described in those Pods are running and healthy.

      • Reports the status of the node and the Pods running on it back to the control plane.

Key Differences:

  • Scope:

    • kubectl operates at the cluster level and is a tool for administrators and developers to interact with the entire Kubernetes cluster.

    • kubelet operates at the node level and is responsible for managing containers on an individual node.

  • User Interaction:

    • Users typically interact with kubectl through the command line to execute various commands and manage the cluster.

    • kubelet operates autonomously and is not directly controlled by users. Its actions are determined by the Pod specifications it receives from the API server.

  • Location:

    • kubectl is typically installed on a user's local machine or on a management server and communicates with the Kubernetes API server.

    • kubelet runs on each node in the cluster and communicates with the API server to get Pod specifications and report node and Pod status.

Functionality:

  • kubectl is a versatile tool that covers a wide range of administrative and developer tasks.

  • kubelet is focused on maintaining the state of containers on a node as specified by the control plane.

Explain the role of the API server:

The API server in Kubernetes plays a central role in facilitating communication between various components in the cluster. It acts as the primary management point and entry point for administrative tasks, serving as the interface for both internal and external communication. The API server is a critical component of the Kubernetes Control Plane, and its role includes:

  1. Endpoint for Cluster Operations:

    • The API server exposes endpoints that allow users, administrators, and components to interact with the Kubernetes cluster. This includes actions such as deploying applications, querying cluster status, and managing resources.
  2. Handling RESTful API Requests:

    • The API server serves a RESTful API that adheres to the principles of Representational State Transfer (REST). It handles HTTP requests and responses for operations related to cluster management.
  3. Authentication and Authorization:

    • The API server is responsible for authenticating and authorizing requests. It verifies the identity of users or components making requests and ensures that they have the necessary permissions to perform the requested actions.
  4. Admission Control:

    • The API server enforces admission control mechanisms, validating and mutating resource configurations before they are persisted. Admission controllers allow administrators to enforce policies and make decisions based on specific criteria.
  5. Validation and Defaulting:

    • The API server validates incoming resource configurations against the schema to ensure they adhere to predefined rules. It also applies default values to fields that are not explicitly set, ensuring consistency in resource specifications.
  6. Cluster State Management:

    • The API server stores the desired state of the cluster, including information about nodes, pods, services, and other resources, in the etcd key-value store. It continuously watches for changes to the desired state and works to reconcile it with the actual state of the cluster.
  7. Communication with etcd:

    • The API server communicates with the etcd key-value store to read and write data related to the configuration and state of the cluster. Etcd serves as the authoritative data store for the entire cluster.
  8. Aggregated API Servers:

    • In large and complex Kubernetes deployments, aggregated API servers may be used to expose additional APIs or to provide specialized functionality. The primary API server interacts with these aggregated API servers to maintain a cohesive cluster API.
M

Great info.Keep it up!

1