Kubernetes in Plain English
Kubernetes (K8s) takes your Docker containers and decides where to run them, restarts them if they crash, scales them up when traffic increases, and routes traffic to the right containers.
| Object | What It Does | Analogy |
|---|---|---|
| Pod | Runs one or more containers together | A single process group |
| Deployment | Manages replicas of Pods, handles rolling updates | A supervisor managing workers |
| Service | Stable network endpoint for a set of Pods | A load balancer / DNS name |
| Ingress | HTTP/HTTPS routing from external traffic to Services | An Nginx reverse proxy |
| ConfigMap | Non-secret configuration as key-value pairs | Environment variables file |
| Secret | Sensitive data (base64-encoded) | Encrypted .env file |
1. Deploy Django to Kubernetes
ConfigMap β Application Settings
apiVersion: v1
kind: ConfigMap
metadata:
name: django-config
namespace: production
data:
DJANGO_SETTINGS_MODULE: "reqpulse.settings"
ALLOWED_HOSTS: "kashiiupdatez.online"
DEBUG: "False"
DATABASE_HOST: "postgres-service"
REDIS_URL: "redis://redis-service:6379/0"
Deployment β Django App with Rolling Updates
apiVersion: apps/v1
kind: Deployment
metadata:
name: django-web
namespace: production
spec:
replicas: 3
selector:
matchLabels:
app: django-web
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
template:
metadata:
labels:
app: django-web
spec:
containers:
- name: django
image: ghcr.io/kashichavan/kashii-updatez:latest
ports:
- containerPort: 8000
envFrom:
- configMapRef:
name: django-config
- secretRef:
name: django-secrets
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
readinessProbe:
httpGet:
path: /health/
port: 8000
initialDelaySeconds: 15
livenessProbe:
httpGet:
path: /health/
port: 8000
initialDelaySeconds: 30
initContainers:
- name: migrate
image: ghcr.io/kashichavan/kashii-updatez:latest
command: ["python", "manage.py", "migrate", "--noinput"]
envFrom:
- configMapRef:
name: django-config
- secretRef:
name: django-secrets
Ingress β External HTTP Routing with TLS
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: kashii-ingress
namespace: production
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
ingressClassName: nginx
tls:
- hosts:
- kashiiupdatez.online
secretName: kashii-tls-cert
rules:
- host: kashiiupdatez.online
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: django-service
port:
number: 80
2. Horizontal Pod Autoscaler
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: django-hpa
namespace: production
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: django-web
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
3. Essential kubectl Commands
kubectl apply -f k8s/ # Apply all YAML in directory
kubectl set image deployment/django-web django=ghcr.io/kashichavan/kashii:v2.1.0
kubectl get pods -n production # List pods
kubectl describe pod django-web-abc123 # Detailed pod info
kubectl logs django-web-abc123 --follow # Stream logs
kubectl exec -it django-web-abc123 -- bash # Shell into pod
kubectl rollout history deployment/django-web
kubectl rollout undo deployment/django-web
kubectl scale deployment django-web --replicas=5
4. Packaging with Helm
helm create kashii-chart # Generates scaffold
# values.yaml
image:
repository: ghcr.io/kashichavan/kashii-updatez
tag: "latest"
replicaCount: 3
ingress:
enabled: true
host: kashiiupdatez.online
tls: true
resources:
requests:
memory: "256Mi"
cpu: "250m"
helm upgrade --install kashii ./kashii-chart --namespace production --set image.tag=$(git rev-parse --short HEAD)
helm rollback kashii 2 # Roll back to revision 2