Kubernetes (often abbreviated as K8s) is an open-source system that automates the deployment, scaling, and management of containerized applications. It works by transforming a group of physical or virtual machines into a unified cluster that acts as a single powerful computer.
The Core Mechanism: Desired State
The fundamental way Kubernetes works is through a declarative model:
- You define a "Desired State": You tell Kubernetes exactly how you want your application to look (e.g., "I want 3 copies of my web app running") using a configuration file, typically in YAML.
- Kubernetes ensures the "Actual State" matches: It constantly monitors your applications. If a container crashes, Kubernetes automatically restarts it; if a whole machine fails, it moves those containers to a healthy one to maintain your desired count.
Cluster Architecture
A Kubernetes cluster is divided into two main parts that work together:
1. The Control Plane (The "Brain")
This layer makes global decisions about the cluster and responds to events.
- API Server: The front door for all commands. Whether you use the Kubernetes CLI (kubectl) or a dashboard, you are talking to this server.
- etcd: A highly available database that stores all cluster data and the "source of truth" for your desired state.
- Scheduler: Decides which node should run a new container based on available resources. Matches your containers to the best available worker machines based on resource needs (like CPU or RAM).
- Controller Manager: The "watchman" that constantly compares the actual state to your desired state and makes changes if they don't match.
These are the machines (VMs or physical servers) that actually run your applications.
- Kubelet: An agent that runs on every node. It receives instructions from the Control Plane and ensures the containers on that node are running and healthy.
- Kube-proxy: Handles the networking rules so your applications can talk to each other and the outside world.
- Container Runtime: The software (like containerd or Docker) responsible for actually running the containers.
Key Building Blocks
- Pods: The smallest deployable unit. A Pod wraps one or more containers that share the same network and storage.
- Deployments: A script that tells Kubernetes how to create and update instances of your application. A blueprint that defines how many replicas of a pod should run and how to update them without downtime.
- Services: Provides a single, stable entry point (IP address) for a group of Pods so that other applications can find them even if individual Pods are replaced.
No comments:
Post a Comment