Kubernetes (K8s) orchestrates containers at scale. While platform teams manage clusters, developers need to understand K8s concepts to deploy and debug applications effectively. This guide covers what developers actually need to know.
Core Concepts#
Pods#
The smallest deployable unit. Usually one container, sometimes sidecars:
1apiVersion: v1
2kind: Pod
3metadata:
4 name: my-app
5spec:
6 containers:
7 - name: app
8 image: myapp:1.0.0
9 ports:
10 - containerPort: 3000Deployments#
Manage pod replicas and updates:
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: my-app
5spec:
6 replicas: 3
7 selector:
8 matchLabels:
9 app: my-app
10 template:
11 metadata:
12 labels:
13 app: my-app
14 spec:
15 containers:
16 - name: app
17 image: myapp:1.0.0
18 ports:
19 - containerPort: 3000
20 resources:
21 requests:
22 memory: "128Mi"
23 cpu: "100m"
24 limits:
25 memory: "256Mi"
26 cpu: "500m"Services#
Expose pods to network traffic:
1apiVersion: v1
2kind: Service
3metadata:
4 name: my-app
5spec:
6 selector:
7 app: my-app
8 ports:
9 - port: 80
10 targetPort: 3000
11 type: ClusterIPConfiguration Management#
ConfigMaps#
1apiVersion: v1
2kind: ConfigMap
3metadata:
4 name: app-config
5data:
6 LOG_LEVEL: "info"
7 API_URL: "https://api.example.com"
8 config.json: |
9 {
10 "feature_flags": {
11 "new_ui": true
12 }
13 }Using in deployments:
1spec:
2 containers:
3 - name: app
4 envFrom:
5 - configMapRef:
6 name: app-config
7 volumeMounts:
8 - name: config-volume
9 mountPath: /app/config
10 volumes:
11 - name: config-volume
12 configMap:
13 name: app-configSecrets#
1apiVersion: v1
2kind: Secret
3metadata:
4 name: app-secrets
5type: Opaque
6stringData:
7 DATABASE_URL: "postgres://user:pass@host:5432/db"
8 API_KEY: "secret-key-here"Using secrets:
1spec:
2 containers:
3 - name: app
4 env:
5 - name: DATABASE_URL
6 valueFrom:
7 secretKeyRef:
8 name: app-secrets
9 key: DATABASE_URLHealth Checks#
Liveness and Readiness Probes#
1spec:
2 containers:
3 - name: app
4 livenessProbe:
5 httpGet:
6 path: /health
7 port: 3000
8 initialDelaySeconds: 10
9 periodSeconds: 10
10 failureThreshold: 3
11
12 readinessProbe:
13 httpGet:
14 path: /ready
15 port: 3000
16 initialDelaySeconds: 5
17 periodSeconds: 5
18 failureThreshold: 3
19
20 startupProbe:
21 httpGet:
22 path: /health
23 port: 3000
24 failureThreshold: 30
25 periodSeconds: 10Liveness: Is the container alive? Failure triggers restart. Readiness: Can it receive traffic? Failure removes from service. Startup: For slow-starting apps, delays other probes.
Debugging Applications#
Common Commands#
1# List resources
2kubectl get pods
3kubectl get deployments
4kubectl get services
5
6# Describe (detailed info)
7kubectl describe pod my-app-xyz
8
9# Logs
10kubectl logs my-app-xyz
11kubectl logs -f my-app-xyz # Follow
12kubectl logs my-app-xyz --previous # Crashed container
13
14# Execute commands
15kubectl exec -it my-app-xyz -- sh
16kubectl exec my-app-xyz -- cat /app/config.json
17
18# Port forwarding
19kubectl port-forward pod/my-app-xyz 3000:3000
20kubectl port-forward svc/my-app 3000:80Debugging Checklist#
Pod not starting:
1. kubectl describe pod <name> - Check events
2. kubectl logs <name> - Check application logs
3. Verify image exists and is pullable
4. Check resource limits (OOMKilled?)
Pod running but not accessible:
1. kubectl get endpoints <service> - Any endpoints?
2. Verify selector labels match
3. Check service port configuration
4. Test with port-forward
Application errors:
1. kubectl logs -f <name> - Live logs
2. kubectl exec -it <name> -- sh - Interactive debug
3. Check ConfigMaps and Secrets mounted correctly
4. Verify environment variables
Deployment Strategies#
Rolling Update (Default)#
1spec:
2 strategy:
3 type: RollingUpdate
4 rollingUpdate:
5 maxSurge: 25%
6 maxUnavailable: 25%Blue-Green with Services#
1# Blue deployment (current)
2apiVersion: apps/v1
3kind: Deployment
4metadata:
5 name: my-app-blue
6spec:
7 selector:
8 matchLabels:
9 app: my-app
10 version: blue
11---
12# Green deployment (new)
13apiVersion: apps/v1
14kind: Deployment
15metadata:
16 name: my-app-green
17spec:
18 selector:
19 matchLabels:
20 app: my-app
21 version: green
22---
23# Service points to active version
24apiVersion: v1
25kind: Service
26metadata:
27 name: my-app
28spec:
29 selector:
30 app: my-app
31 version: blue # Switch to green for cutoverResource Management#
Requests and Limits#
1resources:
2 requests:
3 memory: "128Mi" # Guaranteed
4 cpu: "100m" # 0.1 CPU cores
5 limits:
6 memory: "256Mi" # Maximum (OOMKilled if exceeded)
7 cpu: "500m" # Throttled if exceededHorizontal Pod Autoscaler#
1apiVersion: autoscaling/v2
2kind: HorizontalPodAutoscaler
3metadata:
4 name: my-app
5spec:
6 scaleTargetRef:
7 apiVersion: apps/v1
8 kind: Deployment
9 name: my-app
10 minReplicas: 2
11 maxReplicas: 10
12 metrics:
13 - type: Resource
14 resource:
15 name: cpu
16 target:
17 type: Utilization
18 averageUtilization: 70Ingress#
Expose to Internet#
1apiVersion: networking.k8s.io/v1
2kind: Ingress
3metadata:
4 name: my-app
5 annotations:
6 kubernetes.io/ingress.class: nginx
7 cert-manager.io/cluster-issuer: letsencrypt
8spec:
9 tls:
10 - hosts:
11 - myapp.example.com
12 secretName: myapp-tls
13 rules:
14 - host: myapp.example.com
15 http:
16 paths:
17 - path: /
18 pathType: Prefix
19 backend:
20 service:
21 name: my-app
22 port:
23 number: 80Jobs and CronJobs#
One-Time Jobs#
1apiVersion: batch/v1
2kind: Job
3metadata:
4 name: db-migration
5spec:
6 template:
7 spec:
8 containers:
9 - name: migrate
10 image: myapp:1.0.0
11 command: ["npm", "run", "migrate"]
12 restartPolicy: Never
13 backoffLimit: 3Scheduled Jobs#
1apiVersion: batch/v1
2kind: CronJob
3metadata:
4 name: nightly-cleanup
5spec:
6 schedule: "0 2 * * *" # 2 AM daily
7 jobTemplate:
8 spec:
9 template:
10 spec:
11 containers:
12 - name: cleanup
13 image: myapp:1.0.0
14 command: ["npm", "run", "cleanup"]
15 restartPolicy: OnFailureLocal Development#
Minikube#
1# Start cluster
2minikube start
3
4# Use local images
5eval $(minikube docker-env)
6docker build -t myapp:dev .
7
8# Access services
9minikube service my-appSkaffold#
1# skaffold.yaml
2apiVersion: skaffold/v4beta5
3kind: Config
4build:
5 artifacts:
6 - image: myapp
7deploy:
8 kubectl:
9 manifests:
10 - k8s/*.yaml# Hot reload development
skaffold devConclusion#
Kubernetes knowledge empowers developers to deploy confidently and debug effectively. Focus on deployments, services, config management, and debugging—leave cluster administration to platform teams.
AI helps generate manifests, troubleshoot issues, and understand complex configurations. Start with simple deployments, add health checks, then expand to autoscaling and advanced patterns as needed.