Kubernetes Basics — Pods, Deployments, Services

Why Kubernetes Matters

Kubernetes (K8s) is the industry standard for container orchestration. It automates deployment, scaling, and management of containerized applications. If you are deploying microservices, web applications, or data pipelines to production, Kubernetes is the platform you will most likely encounter.

Why this matters for your career:

  • Kubernetes powers 80%+ of cloud-native deployments worldwide
  • K8s skills are among the highest-paying DevOps and platform engineering requirements
  • Understanding Kubernetes is essential for deploying and scaling containerized apps
  • Every major cloud provider offers managed Kubernetes (EKS, AKS, GKE)

What Is Kubernetes?

Kubernetes is an open-source platform for managing containerized workloads and services. It provides:

  • Service discovery and load balancing: Expose containers via DNS or IP
  • Storage orchestration: Automatically mount storage systems
  • Automated rollouts and rollbacks: Deploy changes with zero downtime
  • Self-healing: Restart failed containers, kill unresponsive ones
  • Secret and configuration management: Manage sensitive data without building it into images

Core Concepts

Pod

The smallest deployable unit in Kubernetes. A pod represents one or more containers that share networking and storage.

apiVersion: v1
kind: Pod
metadata:
  name: my-app
spec:
  containers:
  - name: my-container
    image: nginx:latest
    ports:
    - containerPort: 80

Key facts:

  • One pod usually runs one main container (plus optional sidecars)
  • Each pod gets a unique IP address
  • Pods are ephemeral — they can be killed and replaced at any time

Deployment

A Deployment manages a set of identical pods. It handles rolling updates, scaling, and self-healing.

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: my-container
        image: nginx:latest
        ports:
        - containerPort: 80

Key facts:

  • Desired state: you say "I want 3 replicas" — Kubernetes maintains that
  • Rolling updates: deploys new version with zero downtime
  • Rollback: reverts to previous version if something goes wrong

Service

A Service provides a stable network endpoint for accessing one or more pods.

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  ports:
  - port: 80
    targetPort: 80
  type: ClusterIP

Service types:

| Type | Access | Use Case | |------|--------|----------| | ClusterIP | Internal cluster IP | Inter-service communication | | NodePort | External via node IP:port | Development, debugging | | LoadBalancer | External via cloud load balancer | Production web services | | ExternalName | External DNS name | External service proxy |

Namespaces

Namespaces provide logical isolation within a cluster:

kubectl create namespace production
kubectl get pods -n production

Common namespace patterns: dev, staging, production, team-a, team-b.

kubectl Commands Reference

| Command | Purpose | |---------|--------| | kubectl get pods | List all pods | | kubectl get deployments | List all deployments | | kubectl get services | List all services | | kubectl apply -f file.yaml | Create or update resources | | kubectl delete -f file.yaml | Delete resources | | kubectl logs pod-name | View pod logs | | kubectl exec -it pod-name -- sh | Shell into a container | | kubectl describe pod pod-name | Detailed pod information | | kubectl port-forward pod-name 8080:80 | Forward local port to pod | | kubectl get nodes | List cluster nodes |

Practical Example: Deploy a Web App

# 1. Deployment (3 replicas of nginx)
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: nginx
        image: nginx:alpine
        ports:
        - containerPort: 80
        resources:
          requests:
            cpu: "100m"
            memory: "128Mi"
          limits:
            cpu: "500m"
            memory: "256Mi"
---
# 2. Service (LoadBalancer to expose to internet)
apiVersion: v1
kind: Service
metadata:
  name: web-service
spec:
  selector:
    app: web
  ports:
  - port: 80
    targetPort: 80
  type: LoadBalancer

Deploy:

kubectl apply -f web-app.yaml
kubectl get services  # Wait for EXTERNAL-IP

Common Patterns

| Pattern | Description | |---------|-------------| | Sidecar | Additional container in the same pod (logging, proxy) | | Ambassador | Proxy container that handles external communication | | Adapter | Container that adapts the main container's output | | Init Container | Runs before main container starts (setup tasks) | | Health Probes | Liveness + Readiness probes for self-healing | | Resource Limits | CPU/memory requests and limits for fair scheduling | | ConfigMap + Secret | Configuration and sensitive data management |

Summary

Kubernetes provides a powerful platform for running containerized applications at scale. Pods are the smallest unit, Deployments manage replicas and updates, and Services provide stable networking. Master these three concepts and you have the foundation for production Kubernetes.

Key takeaways:

  • Pods run one or more containers with shared networking
  • Deployments maintain desired replica count and handle rolling updates
  • Services provide stable endpoints to access pods
  • Namespaces provide logical isolation
  • Use kubectl apply -f file.yaml to manage resources
  • Resource limits prevent one app from starving others
  • Health probes enable self-healing
  • Managed K8s (EKS, GKE, AKS) reduce operational overhead

What's Next: Deploy to Kubernetes

The next chapter walks through deploying a complete application to Kubernetes — building images, writing manifests, and managing the deployment lifecycle.

Unlock Full Tutorial

This chapter is paid content. Join the project to unlock over 5000 words of deep analysis, including 10+ god-tier Prompts and real Source Code examples!