Graduate from Docker Compose to enterprise-grade container orchestration. Install MicroK8s locally, write Kubernetes YAML manifests for all services, understand pods/deployments/services/ingress, implement horizontal pod autoscaling, and perform rolling deployments — all on your Ubuntu VM.
Kubernetes (K8s) is an open-source container orchestration system that automates deployment, scaling, and management of containerized applications. It was created by Google (based on internal system "Borg") and donated to the CNCF (Cloud Native Computing Foundation). Every major cloud provider offers managed Kubernetes: AWS EKS, Azure AKS, and Google GKE. Understanding K8s is arguably the most valuable skill in modern cloud engineering.
| K8s Object | What It Does | Docker/Linux Equivalent | When to Use |
|---|---|---|---|
| Pod | Smallest deployable unit — one or more containers that share network and storage | docker run (single container) | Usually don't create directly — use Deployments instead |
| Deployment | Manages a set of identical Pods; handles rolling updates and rollbacks automatically | docker-compose service with replicas | All stateless applications (web servers, APIs) |
| StatefulSet | Like Deployment but for stateful apps — pods get stable network IDs and persistent storage | docker-compose with persistent volumes | Databases, message queues, caches |
| Service | Stable network endpoint for Pods — acts as load balancer between pod replicas | HAProxy / Docker network hostname | Every Deployment needs a Service to be reachable |
| Ingress | HTTP/HTTPS routing — maps domain names and URL paths to Services | Nginx reverse proxy configuration | Exposing multiple services via single IP/domain |
| ConfigMap | Stores non-sensitive configuration data (environment variables, config files) | Environment variables / .env file | Application config that varies by environment |
| Secret | Like ConfigMap but base64-encoded — for passwords, API keys, TLS certs | HashiCorp Vault secrets | Database passwords, API tokens, TLS certificates |
| PersistentVolumeClaim | Request for storage — K8s finds a matching PersistentVolume and binds it | Docker named volume | Database data, uploaded files, logs |
| HPA | Horizontal Pod Autoscaler — automatically scales replicas based on CPU/memory usage | Manual: docker run more containers | Any Deployment that handles variable load |
| Namespace | Virtual cluster — isolates groups of resources within a cluster | Docker networks (isolation) | Separate dev/staging/prod on the same cluster |
MicroK8s is a lightweight, official Kubernetes distribution by Canonical (the company behind Ubuntu). It runs on a single machine, making it perfect for local development and learning. The same kubectl commands you use with MicroK8s work identically with AWS EKS, Azure AKS, and Google GKE in production.
--classic flag grants MicroK8s full system access (required for a Kubernetes cluster to manage networking and storage). --channel=1.28/stable installs a specific Kubernetes version — pinning to a version is important in production to prevent unexpected upgrades. Version 1.28 is an LTS (Long Term Support) release.microk8s group grants permission to run MicroK8s commands without sudo. The alias kubectl='microk8s kubectl' lets you use the standard kubectl command name instead of microk8s kubectl — making your commands identical to what you'd type in a cloud Kubernetes cluster. The kubectl tool is the primary interface for all Kubernetes operations.microk8s status --wait-ready command blocks until the cluster is fully initialized. kubectl get nodes lists all nodes in the cluster — on a single-machine MicroK8s setup, you should see one node with STATUS "Ready". A Kubernetes cluster needs at least one ready node before you can deploy workloads. In production, a cluster might have dozens or hundreds of worker nodes.dns — adds CoreDNS for service name resolution (containers find each other by service name). storage — adds local storage provisioner so PersistentVolumeClaims work. ingress — adds Nginx Ingress Controller for HTTP routing. metrics-server — collects CPU/memory usage metrics (required for HPA autoscaling). These are equivalent to managed services that cloud Kubernetes providers include by default.abc-retail namespace. Use -n abc-retail with every kubectl command to target this namespace.DB_HOST value is mariadb-service — the name of the Kubernetes Service that will front-end the database pods. Kubernetes DNS automatically resolves service names within the cluster, so pods don't need IP addresses — they use service names. This means services can be scaled and moved without updating application configuration.---). The StatefulSet is used instead of Deployment because MariaDB is stateful — each pod gets a persistent identity and its own PersistentVolumeClaim. Key concepts: envFrom: configMapRef loads ALL ConfigMap keys as environment variables automatically. valueFrom: secretKeyRef loads a specific key from a Secret. resources.requests specifies how much CPU/memory to reserve for the pod, and resources.limits sets the maximum. The Service with clusterIP: None creates a "headless" service — pods in the StatefulSet get DNS names like mariadb-0.mariadb-service.abc-retail.svc.cluster.local.kubectl apply -f command applies the YAML manifest — creating or updating the resources defined in it. The -w flag watches for changes in real-time (press Ctrl+C to stop watching). You should see the mariadb pod go through states: Pending → ContainerCreating → Running. Once Running, the database is accepting connections.rules section says: requests for abc-retail.local on path / should be forwarded to web-service on port 80. To test: add [VM-IP] abc-retail.local to your host's /etc/hosts file, then open http://abc-retail.local in your browser.kubectl get all command lists all resources in the namespace: pods, deployments, services, statefulsets, HPAs, and more. This is the equivalent of checking your entire infrastructure in one command. The STATUS column shows if everything is Running and READY.kubectl describe command shows detailed information about a resource: current state, events, conditions, environment variables, volume mounts, and health check results. The Events section at the bottom is particularly useful for debugging — it shows what Kubernetes did and any errors encountered. If a pod is stuck in "Pending" or "CrashLoopBackOff" state, the Events section usually explains why.kubectl logs command retrieves container output. The -l app=abc-retail-web uses a label selector — it shows logs from all pods with that label (your 2+ web replicas). --tail=20 shows only the last 20 lines. Add -f to follow logs in real-time (like tail -f). This is how you debug application issues in production Kubernetes clusters.kubectl set image command triggers a rolling update — Kubernetes starts new pods with the v2.0 image, waits for them to become ready, then removes v1.0 pods, one at a time (based on the RollingUpdate strategy settings). The kubectl rollout status command shows the progress of the update. During the entire update process, the application continues serving traffic from v1.0 pods until v2.0 pods are confirmed healthy.kubectl rollout undo command immediately rolls back to the previous version — Kubernetes knows what the previous state was (stored in the Deployment's revision history). This rollback takes effect within seconds, even for a deployment with many replicas. The rollout history command shows all previous versions and when they were deployed. This automated rollback capability is one of the most valuable features of Kubernetes — in a manual Docker setup, a rollback requires manually stopping containers, pulling old images, and restarting — a process that takes much longer and is prone to human error.kubectl run --rm creates a pod that is automatically deleted when you exit. This is the Kubernetes equivalent of docker exec — you jump into the cluster's network namespace to debug connectivity issues. Cloud engineers use this technique constantly to diagnose network or DNS problems in production clusters.C:\Windows\System32\drivers\etc\hosts as Administrator
sudo nano /etc/hosts
[VM-IP] abc-retail.local
http://abc-retail.local in browser
kubectl get all -n abc-retail (all Running)kubectl rollout status