Kubernetes Core Concepts
Core Kubernetes concepts such as Pods, Deployments, and namespaces, plus the basics of container orchestration
Contents
Kubernetes is a container orchestration platform that automatically deploys, scales, and recovers many containers.
Running one container and operating hundreds of them are different problems. This post covers the core objects such as Pod, Service, and Deployment, along with the cluster architecture.
Containerization vs container orchestration
Containerization
Containerization packages an application and its dependencies into a single image so it behaves consistently in any environment.
| Property | Description |
|---|---|
| Portability | Minimizes differences between development, test, and production environments |
| Isolation | Independent runtime environment with no interference from other services |
| Lightweight | Lower resource consumption than VMs, with fast startup and shutdown |
Container orchestration
Container orchestration automatically deploys, manages, scales, updates, and monitors many containers.
- Automation: automates repetitive work across hundreds of containers
- Autoscaling: adjusts container count automatically as traffic changes
- Rolling updates: updates in stages and rolls back on problems
- Self-healing: restarts unhealthy containers automatically
Why orchestration is needed
Problems with manual management:
- Monitoring dozens to hundreds of containers is not feasible
- Responding to traffic changes in real time is difficult
- Recovery time after a failure increases
- Operating cost and the chance of error increase
What Kubernetes does
You declare the desired state in YAML, and Kubernetes automatically reconciles the current state to match that declaration. Instead of handling individual containers, the operator describes only the target state.
| Capability | Description |
|---|---|
| Automatic deployment and scaling | Maintains the state defined in YAML automatically |
| Service discovery | Provides a stable endpoint despite dynamic IPs |
| Load balancing | Distributes traffic evenly |
| Resource management | Allocates CPU and memory efficiently |
| Portability | Same operations on-premises and in the cloud |
Kubernetes architecture
Control plane (master)
| Component | Role |
|---|---|
| API Server | The single API entry point to the cluster |
| Controller | Reconciles current state with desired state |
| Scheduler | Selects the node on which to place a new Pod |
| etcd | Distributed key-value store holding cluster state |
Worker nodes
| Component | Role |
|---|---|
| kubelet | Communicates with the control plane and maintains Pod state |
| kube-proxy | Handles Service network proxying and load balancing |
| Container Runtime | Runs the actual containers (containerd, CRI-O, and others) |
Core objects
Pod
A Pod is the smallest deployable unit in Kubernetes.
- Contains one or more containers
- Shares the same network namespace
- Can share the same storage volumes
- Is ephemeral by nature
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: app
image: nginx:latest
ports:
- containerPort: 80apiVersion and kind specify the object type and its schema version. spec.containers lists the containers the Pod runs, and containerPort gives the port the container exposes.
Service
A Service provides a stable network endpoint for a set of Pods.
| Type | Description |
|---|---|
| ClusterIP | Cluster-internal only (default) |
| NodePort | External access through a node port |
| LoadBalancer | Integrates with a cloud load balancer |
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
ports:
- port: 80
targetPort: 8080
type: ClusterIPThe selector groups Pods labeled app: my-app as the traffic target. port is the port the Service accepts, and targetPort is the Pod-side port that traffic is forwarded to. The two may differ, and the Service translates between them.
Deployment
A Deployment manages declarative updates to Pods.
- Supports rolling updates
- Provides rollback
- Handles scaling
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: app
image: my-app:v1replicas is the number of Pods to maintain. selector.matchLabels identifies the Pods the Deployment manages, and template defines the shape of the Pods it creates. The labels in template must match matchLabels for the Deployment to recognize the Pods as its own.
Basic kubectl commands
# Cluster information
kubectl cluster-info
# List resources
kubectl get pods
kubectl get services
kubectl get deployments
# Resource details
kubectl describe pod <pod-name>
# Check logs
kubectl logs <pod-name>
# Deploy
kubectl apply -f deployment.yaml
# Scale
kubectl scale deployment my-deployment --replicas=5
# Roll back
kubectl rollout undo deployment my-deploymentSummary
Kubernetes is the de facto standard for container orchestration. A Pod is the smallest deployable unit, and a Service provides a stable network endpoint in front of Pods that change dynamically. A Deployment manages the desired Pod state declaratively and handles rolling updates and rollbacks. A cluster is divided into the control plane, which decides state, and the worker nodes, which run the actual containers. Networking policies, storage provisioning, and RBAC (Role-Based Access Control) security settings are the next step in operating a production cluster.