Ankit KanojiyaIntermediate
Evergreen guide by Ankit Kanojiya · Intermediate · DevOps & Cloud
Kubernetes Basics: Pods, Deployments, and Services
An orientation to the core Kubernetes objects that most workloads rely on: pods, deployments, and services. Explains the declarative model and how traffic reaches a container.
- Kubernetes
- Containers
- Orchestration
- DevOps
- Cloud Native
Kubernetes orchestrates containers across a cluster of machines, handling scheduling, scaling, and recovery. Its power comes from a declarative model: you describe the desired state, and controllers continuously reconcile reality toward it. Three objects cover most of what beginners need.
The Declarative Model
Instead of issuing commands like start this container, you submit a manifest describing what should exist. A controller compares desired state against actual state and acts to close the gap. If a pod dies, the controller notices the mismatch and creates a replacement. This reconciliation loop is the heart of Kubernetes and explains why the system is self-healing.
Pods
A pod is the smallest deployable unit. It wraps one or more containers that share a network namespace and storage. Containers in the same pod reach each other over localhost, which is why tightly coupled helpers such as a logging sidecar live together in one pod.
Pods are deliberately disposable. They are not meant to be created directly for long-running work, because nothing would recreate them if the node failed. Instead they are managed by higher-level controllers.
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
containers:
- name: web
image: nginx:1.27
ports:
- containerPort: 80
Deployments
A Deployment manages a set of identical pods through a ReplicaSet, maintaining a desired replica count and handling rollouts. This is the object most applications are deployed with.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.27
ports:
- containerPort: 80
Updating the image field triggers a rolling update: Kubernetes creates new pods, waits for them to become ready, and removes old ones gradually. If something goes wrong, a rollback restores the previous revision:
kubectl rollout status deployment/web
kubectl rollout undo deployment/web
The selector and the pod template labels must match, or the Deployment will not manage the pods it creates. This is a frequent source of confusion.
Services
Pods get individual IP addresses, but those addresses change as pods are rescheduled. A Service provides a stable virtual IP and DNS name that load-balances across the pods matching its selector.
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 80
The main Service types:
- ClusterIP (default): reachable only inside the cluster. Used for service-to-service traffic.
- NodePort: exposes a port on every node. Simple but awkward for production.
- LoadBalancer: provisions an external load balancer from the cloud provider.
For HTTP routing with host and path rules, an Ingress sits in front of Services and is usually preferred over many LoadBalancers, since it consolidates external entry points.
Health Checks and Resources
Two settings make workloads reliable. Readiness probes tell Kubernetes when a pod can receive traffic; liveness probes tell it when to restart a stuck pod. Resource requests and limits let the scheduler place pods sensibly and prevent one container from starving others.
readinessProbe:
httpGet:
path: /healthz
port: 80
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
memory: 256Mi
Setting a memory limit without a request, or omitting probes, is a common cause of unstable deployments.
Trade-offs
Kubernetes is powerful but carries real operational cost. For a single small service, a managed container platform may be simpler and cheaper. Kubernetes earns its complexity when running many services that benefit from shared scheduling, autoscaling, and self-healing. Managed control planes from cloud providers remove much of the maintenance burden and are a sensible default over self-hosting the control plane.
Summary
Pods run containers, Deployments keep the right number of pods running and roll out changes safely, and Services give pods a stable address and load balancing. Combined with probes and resource limits, these objects cover the majority of everyday Kubernetes work.