What is Kubernetes?
Kubernetes (often abbreviated as K8s) is an open-source container orchestration platform originally developed by Google. It automates the deployment, scaling, and management of containerized applications across clusters of servers.
When should you use Kubernetes?
Kubernetes is a good fit when you need to:
- Run multiple containers across multiple servers
- Automatically scale applications based on demand
- Ensure high availability with zero-downtime deployments
- Manage microservices architectures
- Automate rollouts and rollbacks
For simple applications running on a single server, Kubernetes may be overkill. Consider Docker Compose or a managed PaaS instead.
Architecture overview
A Kubernetes cluster consists of two types of components:
Control Plane (Master)
The control plane manages the overall state of the cluster:
-
API Server (
kube-apiserver): The front-end for the Kubernetes control plane. All communication (CLI, dashboard, internal components) goes through this API. - etcd: A distributed key-value store that holds all cluster configuration and state data.
-
Scheduler (
kube-scheduler): Assigns newly created Pods to worker nodes based on resource requirements and constraints. - Controller Manager: Runs controllers that watch the cluster state and make changes to reach the desired state (e.g., restarting failed Pods).
Worker Nodes
Worker nodes run your actual application containers:
- kubelet: An agent running on each node that ensures containers are running as expected.
- kube-proxy: Manages network rules and load balancing for Services on each node.
- Container runtime: The software that runs containers (containerd, CRI-O, etc.).
Core concepts
Pod
The smallest deployable unit in Kubernetes. A Pod wraps one or more containers that share the same network namespace and storage. In most cases, a Pod runs a single container.
apiVersion: v1
kind: Pod
metadata:
name: my-app
spec:
containers:
- name: app
image: nginx:latest
ports:
- containerPort: 80
Deployment
A Deployment manages a set of identical Pods (replicas). It handles rolling updates, rollbacks, and scaling. This is the most common way to run applications on Kubernetes.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: app
image: nginx:latest
ports:
- containerPort: 80
Service
A Service provides a stable network endpoint (IP and DNS name) to access a group of Pods. Since Pods are ephemeral and their IPs change, Services act as a stable front door.
- ClusterIP: Accessible only within the cluster (default).
- NodePort: Exposes the Service on a static port on each node's IP.
- LoadBalancer: Provisions an external load balancer (cloud providers).
Namespace
Namespaces provide a way to divide cluster resources between multiple teams or projects. They act as virtual clusters within a physical cluster.
ConfigMap and Secret
ConfigMaps store non-sensitive configuration data (environment variables, config files). Secrets store sensitive data (passwords, API keys, certificates) in an encoded format.
Key commands
| Command | Description |
|---|---|
kubectl get pods |
List all Pods in the current namespace |
kubectl get deployments |
List all Deployments |
kubectl get services |
List all Services |
kubectl apply -f file.yaml |
Create or update resources from a YAML file |
kubectl logs pod-name |
View logs from a Pod |
kubectl describe pod pod-name |
Show detailed information about a Pod |
kubectl delete pod pod-name |
Delete a Pod |
kubectl scale deployment my-app --replicas=5 |
Scale a Deployment to 5 replicas |
Next steps
- Try the official Kubernetes tutorials for hands-on practice.
- Learn about Ingress controllers for routing external HTTP traffic.
- Explore Helm for managing Kubernetes application packages.