Explain the difference between Pods, Services, and Deployments.

Beginner

Answer

  • Pod: The smallest deployable unit in Kubernetes, containing one or more containers that share storage and network. Pods are ephemeral and typically not created directly.
  • Deployment: Higher-level abstraction that manages ReplicaSets and provides declarative updates to Pods. It ensures the desired number of pod replicas are running.
  • Service: Abstraction that defines a logical set of Pods and provides stable networking. It enables communication between different parts of an application.
    Example:
# Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.20