Why Use Kubernetes?
Key advantages of Kubernetes:- Self-Healing: Automatically restarts or replaces failed containers.
- Automated Rollouts & Rollbacks: Gradually roll out changes and roll back if there’s an issue.
- Efficient Scheduling: Optimizes placement of containers based on resource requirements.
- Built-In Load Balancing: Distributes traffic across containers to ensure reliability.
- Service Discovery & DNS Management: Simplifies communication between microservices.
Core Resource Types
| Resource Type | Purpose | Example Command |
|---|---|---|
| Pod | Smallest deployable unit, encapsulates one or more containers | kubectl run nginx-pod --image=nginx --restart=Never |
| ReplicaSet | Maintains a stable set of pod replicas | kubectl apply -f replicaset.yaml |
| Deployment | Declarative updates for pods and ReplicaSets | kubectl apply -f deployment.yaml |
Pod
A Pod is the basic building block in Kubernetes. It represents one or more containers that share storage, network, and a specification for how to run the containers.Pods are ephemeral. When a Pod dies, it won’t be recreated unless managed by a higher-level controller (e.g., ReplicaSet).
ReplicaSet
A ReplicaSet ensures a specified number of pod replicas are running at all times. It will create or delete Pods to match the desired replica count.Deployment
A Deployment provides declarative updates for Pods and ReplicaSets. You can easily roll out new versions, pause, or roll back to a previous state without downtime.Always specify
selector.matchLabels correctly in your Deployment to avoid orphaned ReplicaSets.