โฐ Run Batch Jobs and Scheduled Tasks in Kubernetes Pods run forever. Jobs run to completion. CronJobs run on schedule. Perfect for backups, reports, data processing. ๐ Job Example (One-Time) apiVersion: batch/v1 kind: Job metadata: name: database-backup spec: template: spec: containers: – name: backup image: postgres:15 command: [‘pg_dump’, ‘-h’, ‘postgres’, ‘-U’, ‘user’, ‘dbname’, ‘>’, ‘/backup/db.sql’] […]
Category: Kubernetes
Kubernetes: Configure Liveness, Readiness, and Startup Probes
โค๏ธ Is Your App Alive AND Ready? Liveness = restart if dead. Readiness = don’t send traffic until ready. Startup = extra time for slow-starting apps. Use all three for reliability. ๐ Probe Configuration livenessProbe: httpGet: path: /healthz port: 8080 initialDelaySeconds: 30 periodSeconds: 10 timeoutSeconds: 5 failureThreshold: 3 readinessProbe: httpGet: path: /ready port: 8080 initialDelaySeconds: […]
Kubernetes: Use Helm Charts to Package and Deploy Apps
๐ฆ Kubernetes Apps Need a Package Manager 50 YAML files for one app? Helm packages them. Templates, values, versioning, rollback. Like apt-get for Kubernetes. ๐ Install Helm # Install Helm curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash # Add repos helm repo add bitnami https://charts.bitnami.com/bitnami helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm repo update # Install popular charts helm […]
Kubernetes: Use Ingress for HTTP Load Balancing and SSL
๐ One IP, Multiple Services, SSL Termination NodePort exposes high ports. LoadBalancer costs money. Ingress exposes HTTP/HTTPS routes, SSL termination, name-based virtual hosting. ๐ Basic Ingress apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: myapp-ingress spec: rules: – host: myapp.example.com http: paths: – path: / pathType: Prefix backend: service: name: myapp-service port: number: 80 – path: /api […]
Kubernetes: Use Labels and Selectors to Organize Resources
๐ท๏ธ Labels = Tags for Kubernetes Resources How to find all pods for an app? Labels and selectors group resources. Services find pods by labels. Deployments manage pod sets. Essential for organization. ๐ Adding Labels apiVersion: v1 kind: Pod metadata: name: myapp-pod labels: app: myapp environment: production tier: backend version: v1.0.0 team: payments spec: containers: […]
Kubernetes: Use ConfigMap and Secrets for External Configuration
๐ Never Hardcode Config in Container Images Environment variables are okay. ConfigMap and Secrets are better. Separate config from code. Change without rebuild. ๐ ConfigMap # configmap.yaml apiVersion: v1 kind: ConfigMap metadata: name: app-config data: database.host: postgres-service database.port: “5432” app.properties: | app.name=myapp app.environment=production log.level=info # Use as environment variables apiVersion: v1 kind: Pod spec: containers: […]
Kubernetes: Use Namespaces to Organize Your Cluster
๐ Virtual Clusters Inside One Physical Cluster All pods in default namespace? Chaos. Namespaces separate environments, teams, or components. Resource quotas, RBAC per namespace. ๐ Create and Use Namespaces # Create namespace kubectl create namespace development kubectl create namespace staging kubectl create namespace production # List namespaces kubectl get namespaces # Run pod in specific […]
Kubernetes: Always Set CPU and Memory Requests and Limits
โ๏ธ No Requests = Unpredictable Scheduling Without resource requests, pods can starve others. Requests and limits ensure fair sharing and prevent resource exhaustion. ๐ Setting Resources apiVersion: v1 kind: Pod metadata: name: myapp spec: containers: – name: app image: myapp:latest resources: requests: memory: “256Mi” cpu: “250m” limits: memory: “512Mi” cpu: “500m” # CPU units: 1000m […]
Kubernetes: Use Priority Classes to Ensure Critical Pods Run First
โญ DNS Pods Should Evict Batch Jobs When cluster is full, which pods get evicted? Priority Classes define importance. Critical pods survive. Batch jobs go first. ๐ Define Priority Classes apiVersion: scheduling.k8s.io/v1 kind: PriorityClass metadata: name: critical value: 1000000000 globalDefault: false description: “Critical system pods that must never be evicted” — apiVersion: scheduling.k8s.io/v1 kind: PriorityClass […]
Kubernetes: Use PodDisruptionBudget to Prevent Service Interruption
๐ก๏ธ Don’t Drain All Pods at Once Node draining, cluster upgrades kill pods. PodDisruptionBudget (PDB) ensures minimum availability during voluntary disruptions. ๐ PDB Examples # At least 2 pods available at all times apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: app-pdb spec: minAvailable: 2 selector: matchLabels: app: myapp # No more than 1 pod unavailable apiVersion: […]
Kubernetes: Enforce Pod Security Standards at Namespace Level
๐ PodSecurityPolicy is Deprecated. PSS is Here. PSP was complex. Pod Security Standards (PSS) are built-in. Three levels: Privileged, Baseline, Restricted. Apply per namespace. ๐ Apply PSS to Namespace # Label namespace for enforcement kubectl label namespace production pod-security.kubernetes.io/enforce=baseline kubectl label namespace production pod-security.kubernetes.io/enforce-version=latest # Warn mode (logs warning, doesn’t block) kubectl label namespace staging […]
Kubernetes: Use Kustomize to Manage Multiple Environments Without Templates
๐ No Helm. No Templating. Pure YAML. Helm templates are complex. Kustomize is built into kubectl. Overlay configs for dev, staging, prod. No new syntax to learn. ๐ Folder Structure k8s/ โโโ base/ โ โโโ deployment.yaml โ โโโ service.yaml โ โโโ kustomization.yaml โโโ overlays/ โโโ dev/ โ โโโ replica_count.yaml โ โโโ configmap.yaml โ โโโ kustomization.yaml […]
Kubernetes: Use Topology Spread Constraints for Even Pod Distribution
๐บ๏ธ Spread Pods Across Zones, Nodes, Racks All pods on same node? Node failure = downtime. Topology spread constraints spread pods evenly across zones, nodes, or custom domains. ๐ Pod Topology Spread apiVersion: apps/v1 kind: Deployment metadata: name: myapp spec: replicas: 6 template: spec: topologySpreadConstraints: – maxSkew: 1 topologyKey: kubernetes.io/hostname whenUnsatisfiable: DoNotSchedule labelSelector: matchLabels: app: […]
Kubernetes: Use VPA to Automatically Adjust CPU/Memory Requests
๐ HPA Scales Pods. VPA Scales Pod Resources. Guessing CPU/memory requests is hard. Vertical Pod Autoscaler recommends or automatically adjusts resource requests based on actual usage. ๐ Install VPA git clone https://github.com/kubernetes/autoscaler.git cd autoscaler/vertical-pod-autoscaler ./hack/vpa-up.sh kubectl get pods -n kube-system | grep vpa ๐ฏ VPA Configuration apiVersion: autoscaling.k8s.io/v1 kind: VerticalPodAutoscaler metadata: name: myapp-vpa spec: targetRef: […]
Kubernetes: Use Pod Affinity to Schedule Related Pods Together
๐ฏ Keep Related Pods Close (or Far Apart) Cache and app should be on same node. Database replicas should be on different nodes. Pod affinity/anti-affinity controls pod placement. ๐ Pod Affinity (Same Node) apiVersion: v1 kind: Pod metadata: name: web-app spec: affinity: podAffinity: requiredDuringSchedulingIgnoredDuringExecution: – labelSelector: matchLabels: app: cache topologyKey: kubernetes.io/hostname containers: – name: app […]
Kubernetes: Use Resource Quotas to Prevent One Namespace from Draining Cluster
๐ Don’t Let One Team Hog All Resources One namespace uses all CPU? Others starve. Resource quotas limit total CPU, memory, storage per namespace. Fair sharing for multi-tenant clusters. ๐ Basic Quota apiVersion: v1 kind: ResourceQuota metadata: name: namespace-quota namespace: development spec: hard: requests.cpu: “4” requests.memory: “8Gi” limits.cpu: “8” limits.memory: “16Gi” persistentvolumeclaims: “10” pods: “20” […]
Kubernetes: Use Taints and Tolerations to Control Pod Placement
๐ซ Dedicated Nodes for Special Workloads Some nodes have GPUs. Some are spot instances. Taints repel pods. Tolerations allow them. Control exactly where workloads run. ๐ Add Taint to Node # Taint effects: # NoSchedule: Pods without toleration won’t be scheduled # PreferNoSchedule: Avoid if possible # NoExecute: Evict existing pods without toleration # Add […]
Kubernetes: Use PodDisruptionBudget to Prevent Service Interruption
๐ก๏ธ Don’t Drain All Pods at Once Node draining, cluster upgrades, autoscaling down โ they all kill pods. PodDisruptionBudget ensures minimum availability during voluntary disruptions. ๐ PDB Examples # At least 2 pods available at all times apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: app-pdb spec: minAvailable: 2 selector: matchLabels: app: myapp # No more than […]
Kubernetes: Use Network Policies to Restrict Pod Communication
๐ Zero Trust for Pods By default, all pods can talk to all pods. That’s a security risk. Network policies define who can talk to whom. ๐ Deny All Ingress apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: deny-all-ingress spec: podSelector: {} # Applies to all pods policyTypes: – Ingress ingress: [] # Empty = deny all […]
Kubernetes: Readiness vs Liveness Probes โ What’s the Difference?
โค๏ธ Is Your App Alive AND Ready? Liveness = restart if dead. Readiness = don’t send traffic until ready. Use both for zero-downtime deployments. ๐ Liveness Probe livenessProbe: httpGet: path: /healthz port: 8080 initialDelaySeconds: 30 periodSeconds: 10 If fails โ Kubernetes restarts container. โ Readiness Probe readinessProbe: httpGet: path: /ready port: 8080 initialDelaySeconds: 5 periodSeconds: […]
Kubernetes: Use Init Containers for Setup Tasks Before App Starts
โณ Wait for Database, Then Start App needs database schema? Cache warmup? File permissions? Init containers run to completion before your main container starts. apiVersion: v1 kind: Pod metadata: name: my-app-pod spec: initContainers: – name: init-myservice image: busybox:1.28 command: [‘sh’, ‘-c’, ‘until nslookup myservice; do echo waiting; sleep 2; done;’] – name: init-db image: busybox:1.28 […]
Kubernetes: Use HPA to Auto-Scale Pods Based on CPU/Memory
๐ Auto-Scale Based on Load Fixed 3 replicas? CPU spikes, users wait. Traffic drops, you waste money. HPA (Horizontal Pod Autoscaler) scales pods automatically based on metrics. How HPA Works # deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: web-app spec: replicas: 2 template: spec: containers: – name: app image: myapp:latest resources: requests: cpu: 100m # […]
Kubernetes: Use HPA to Auto-Scale Pods Based on CPU/Memory
๐ Auto-Scale Based on Load Fixed 3 replicas? CPU spikes, users wait. Traffic drops, you waste money. HPA (Horizontal Pod Autoscaler) scales pods automatically based on metrics. How HPA Works # deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: web-app spec: replicas: 2 # Initial replicas template: spec: containers: – name: app image: myapp:latest resources: requests: […]
Kubernetes: Use ConfigMaps and Secrets to Separate Configuration from Code
๐ Never Hardcode Config Again API keys in code? Database passwords committed to Git? ConfigMaps and Secrets externalize all configuration. ConfigMaps vs Secrets ๐ ConfigMaps Non-sensitive configuration API endpoints Feature flags Environment settings Application config files ๐ Secrets Sensitive data (base64 encoded) Database passwords API keys TLS certificates OAuth tokens Creating ConfigMaps # configmap.yaml apiVersion: […]
Kubernetes: Use kubectl port-forward to Debug Services Locally
๐ Access K8s Services Like They’re Local Service running in cluster. Need to test it. Don’t want to expose it publicly. Port-forward to localhost. Basic Port Forward # Forward pod port to localhost kubectl port-forward pod/my-pod 8080:80 # Now access: http://localhost:8080 # Traffic goes to pod’s port 80 # Forward service instead kubectl port-forward svc/my-service […]
Kubernetes: Use kubectl get events to Debug Pod Issues
Pod won’t start. kubectl describe pod shows nothing useful. What happened? Events: Kubernetes event log shows everything. # All events in namespace kubectl get events –sort-by=’.lastTimestamp’ # Filter by pod kubectl get events –field-selector involvedObject.name=my-pod # Watch live events kubectl get events –watch Common Issues Revealed: – Image pull failures – OOMKilled (out of memory) […]
Kubernetes: Use kubectl logs –tail=100 -f to Debug Faster
๐ Log Debugging Shortcut Scrolling through 10,000 log lines? See only what matters. # Last 100 lines, follow mode (like tail -f) kubectl logs my-pod –tail=100 -f # From specific container in multi-container pod kubectl logs my-pod -c sidecar –tail=50 -f # Previous crashed pod kubectl logs my-pod –previous # All pods with label kubectl […]
Kubernetes: Managing Clusters Visually with Lens IDE
The terminal is great, but visualizing 100+ pods is hard. Lens is the ‘World’s Most Powerful Kubernetes IDE’. Real-time stats of CPU/RAM for every container. One-click access to Pod logs and Shell. Stop typing kubectl get pods every 5 seconds. Use Lens to see the health of your infrastructure at a glance.
Kubernetes: Mastering HPA for Elastic Traffic Management
Static pod counts are either wasteful or dangerous. HPA scales your deployment based on real-time metrics. Standard Config: Scale up when CPU exceeds 70%. Pro Config: Scale based on Custom Metrics (like Request-per-Second) using Prometheus and Keda. This reacts much faster to traffic spikes than CPU metrics.
Kubernetes: Mastering Helm Charts for Templated Deployments
Manually editing YAML files for Dev, Staging, and Prod is a recipe for disaster. Helm acts as the package manager for K8s. “Treat your infrastructure like code, but treat your deployments like templates.” Using values.yaml, you can change replicas, image tags, and resource limits per environment without touching the core manifest. This is the cornerstone […]




