These are three of the most fundamental Kubernetes objects. Pod - The smallest deployable unit in Kubernetes. A Pod wraps one or more containers that share the same network namespace (one IP address, communicate over localhost) and can share storage volumes. - Usually one main container per Pod, sometimes with sidecar containers (logging agents, proxies) or init containers that run setup tasks before the main container starts. - Pods are ephemeral: if a Pod dies, it is not resurrected; a new Pod with a new IP replaces it. You rarely create Pods directly. Deployment - A controller that manages a set of identical Pods (replicas) through a ReplicaSet and keeps the desired state. - Responsibilities: - Maintain the desired number of replicas (self-healing: recreate failed Pods). - Rolling updates: replace Pods gradually with a new version (configurable maxSurge and maxUnavailable). - Rollbacks: kubectl rollout undo deployment/orders-api. - Scaling: kubectl scale or automatically with the Horizontal Pod Autoscaler. - Used for stateless applications. Stateful workloads use StatefulSets; per-node agents use DaemonSets; batch work uses Jobs and CronJobs. Service - Provides a stable network endpoint (virtual IP and DNS name) for a set of Pods selected by labels, and load-balances traffic across them. Because Pod IPs change, clients talk to the Service instead. - Types: - ClusterIP (default): internal-only access within the cluster (orders-api.default.svc.cluster.local). - NodePort: exposes the Service on a port on every node. - LoadBalancer: provisions a cloud load balancer with an external IP. - ExternalName: maps the Service to an external DNS name. - HTTP routing from outside is usually handled by an Ingress (or the newer Gateway API) in front of ClusterIP Services. Example apiVersion: apps/v1 kind: Deployment metadata: name: orders-api spec: replicas: 3 selector: matchLabels: { app: orders-api } template: metadata: labels: { app: orders-api } spec: containers: - name: api image: myregistry.azurecr.io/orders-api:1.4.2 ports: [{ containerPort: 8080 }] resources: requests: { cpu: 250m, memory: 256Mi } limits: { memory: 512Mi } readinessProbe: httpGet: { path: /health/ready, port: 8080 } livenessProbe: httpGet: { path: /health/live, port: 8080 } --- apiVersion: v1 kind: Service metadata: name: orders-api spec: selector: { app: orders-api } ports: - port: 80 targetPort: 8080 type: ClusterIP How they fit together 1. The Deployment creates a ReplicaSet, which creates three Pods labelled app: orders-api. 2. The Service selects Pods with that label and distributes traffic across the ready ones (readiness probes decide which Pods receive traffic). 3. When you update the image, the Deployment rolls out new Pods and removes old ones; the Service keeps routing to whichever Pods are ready, so clients see no downtime. Useful commands kubectl get pods,deployments,services kubectl describe pod <name> kubectl logs <pod> kubectl rollout status deployment/orders-api Interview summary: "A Pod runs one or more tightly coupled containers and is ephemeral. A Deployment manages replicated Pods, handling self-healing, scaling, rolling updates and rollbacks. A Service gives those Pods a stable name and IP and load-balances traffic to them."
Ravindra Wadile · · 0 likes