- What is Kubernetes?
- Architecture
- Setting Up (minikube)
- Core Concepts
- kubectl โ The CLI
- Deployments
- Services
- ConfigMaps & Secrets
- Persistent Storage
- Helm โ Package Manager
- Practice Exercises
Kubernetes (K8s) automates container deployment, scaling, and management.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CONTROL PLANE โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ API โ โ etcd โ โ Controller Manager โโ
โ โ Server โ โ (state) โ โ + Scheduler โโ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโโโผโโโโโโโ โโโโโโผโโโโโโโโ โโโโโผโโโโโโโโโโโ
โ Node 1 โ โ Node 2 โ โ Node 3 โ
โ โโโโโโโโโโโโ โ โ โโโโโโโโโโ โ โ โโโโโโโโโโโโ โ
โ โ kubelet โ โ โ โkubelet โ โ โ โ kubelet โ โ
โ โ kube- โ โ โ โkube- โ โ โ โ kube- โ โ
โ โ proxy โ โ โ โproxy โ โ โ โ proxy โ โ
โ โโโโโโโโโโโโค โ โ โโโโโโโโโโค โ โ โโโโโโโโโโโโค โ
โ โ Pod Pod โ โ โ โPod Pod โ โ โ โ Pod Pod โ โ
โ โโโโโโโโโโโโ โ โ โโโโโโโโโโ โ โ โโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
# Install minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
# Install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install kubectl /usr/local/bin/kubectl
# Start cluster
minikube start
kubectl cluster-info
kubectl get nodes| Resource | Description |
|---|---|
| Pod | Smallest unit โ one or more containers |
| Deployment | Manages pod replicas and rollouts |
| Service | Stable networking endpoint for pods |
| ConfigMap | External configuration data |
| Secret | Sensitive data (base64 encoded) |
| Namespace | Virtual cluster isolation |
| Ingress | HTTP routing / load balancing |
| PV/PVC | Persistent storage |
# Get resources
kubectl get pods # List pods
kubectl get pods -o wide # With more info
kubectl get services # List services
kubectl get all # Everything
kubectl get all -n kube-system # In a namespace
# Describe (detailed info)
kubectl describe pod <name>
kubectl describe service <name>
# Logs
kubectl logs <pod-name>
kubectl logs -f <pod-name> # Follow
kubectl logs <pod-name> -c <container> # Specific container
# Exec into pod
kubectl exec -it <pod-name> -- bash
# Apply manifest
kubectl apply -f deployment.yaml
kubectl delete -f deployment.yaml
# Shortcuts
kubectl get po # pods
kubectl get svc # services
kubectl get deploy # deployments
kubectl get ns # namespaces# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
labels:
app: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.25
ports:
- containerPort: 80
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "256Mi"
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 3
periodSeconds: 5kubectl apply -f deployment.yaml
kubectl get deployments
kubectl rollout status deployment/web-app
kubectl scale deployment web-app --replicas=5
kubectl rollout undo deployment/web-app # Rollback# service.yaml
apiVersion: v1
kind: Service
metadata:
name: web-service
spec:
type: ClusterIP # Internal only
selector:
app: web
ports:
- port: 80
targetPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: web-external
spec:
type: NodePort # Accessible externally
selector:
app: web
ports:
- port: 80
targetPort: 80
nodePort: 30080 # Access via node:30080
---
apiVersion: v1
kind: Service
metadata:
name: web-lb
spec:
type: LoadBalancer # Cloud load balancer
selector:
app: web
ports:
- port: 80
targetPort: 80# configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
APP_ENV: production
DB_HOST: postgres-service
LOG_LEVEL: info
---
# secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: app-secrets
type: Opaque
stringData:
DB_PASSWORD: supersecret
API_KEY: my-api-key-123# Use in deployment
spec:
containers:
- name: app
envFrom:
- configMapRef:
name: app-config
- secretRef:
name: app-secrets# pv.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: db-storage
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
# Use in pod
spec:
containers:
- name: db
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: db-data
volumes:
- name: db-data
persistentVolumeClaim:
claimName: db-storage# Install Helm
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
# Add repository
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
# Search
helm search repo nginx
# Install
helm install my-nginx bitnami/nginx
helm install my-db bitnami/postgresql --set auth.postgresPassword=secret
# List releases
helm list
# Upgrade
helm upgrade my-nginx bitnami/nginx --set replicaCount=3
# Uninstall
helm uninstall my-nginx- Setup: Install minikube and start a local cluster
- Deploy: Create a deployment with 3 Nginx replicas
- Service: Expose the deployment with a NodePort service
- Scale: Scale up to 5 replicas and back to 2
- ConfigMap: Create a ConfigMap and use it in a pod
- Logs: View logs from a specific pod
- Rollout: Deploy a new image version and then rollback
- Helm: Install a chart from the Bitnami repository
โ Previous: Docker & Containers ยท ๐ Home ยท Next: Advanced Filesystems โ