Introduction to Kubernetes (K8s)
Kubernetes (often abbreviated as K8s) is an open-source container orchestration platform originally designed by Google. It automates the deployment, scaling, and management of containerized applications (like Docker containers).
When your application grows and you need to run hundreds of containers across dozens of physical or virtual machines, managing them manually becomes impossible. That's where Kubernetes shines.
Learning Objectives
- Understand the purpose of container orchestration.
- Identify the components of a Kubernetes Cluster (Master vs Worker Nodes).
- Grasp the concept of a Pod, the smallest deployable unit.
Kubernetes Architecture
A Kubernetes environment consists of multiple machines working together. This group of machines is called a Cluster. The cluster is split into two primary roles:
1. The Control Plane (Master Node)
Think of the Control Plane as the "brain". It maintains the desired state of the cluster, schedules containers, and monitors machine health.
- kube-apiserver: The frontend of the cluster. Every command you run goes through the API server.
- etcd: A consistent, highly-available key-value store containing all cluster data.
- kube-scheduler: Watches for newly created Pods with no assigned node, and selects a node for them to run on.
- kube-controller-manager: Runs controller processes that watch the cluster state (acting like a thermostat).
2. Worker Nodes
Worker nodes are the actual workhorses where your application containers run.
- kubelet: An agent running on each node ensuring that containers are running in a Pod.
- kube-proxy: Maintains network rules on nodes allowing communication to your Pods from network sessions.
What is a Node?
What is a Pod?
In Kubernetes, you don't run containers directly. Instead, containers are wrapped inside Pods.
A Pod is the smallest and most basic deployable object in Kubernetes. It represents a single instance of a running process in your cluster.
- A Pod usually contains one container.
- However, it can contain multiple containers that are tightly coupled and share the same network namespace and storage volumes.
Analogy Time
If your application container (Docker) is a whale, then the Pod is the protective cage or tank surrounding it that gets transported across the ocean. Kubernetes manages the Pods, not the raw container directly.
Creating Your First Pod
Normally, you define Kubernetes resources using declarative YAML files.
yaml# nginx-pod.yaml apiVersion: v1 kind: Pod metadata: name: my-first-pod labels: app: webserver spec: containers: - name: nginx-container image: nginx:latest ports: - containerPort: 80
You apply this file to your cluster using the CLI tool kubectl:
bashkubectl apply -f nginx-pod.yaml
Next Steps
While creating raw Pods is helpful for learning, production applications never run bare Pods because if a Pod dies, it doesn't restart automatically! To fix this, we use higher-level controllers.
Next Lesson
Deployments and Services