Understanding Kubernetes starts with one key idea: you have containers, and you need to run them reliably at scale. This guide assumes you've never touched a YAML file — we'll define every term and walk through your first production-ready setup.
What is Kubernetes?
Kubernetes (often shortened to K8s) is an open-source platform for automating deployment, scaling, and management of containerized applications. Think of it as the operating system for your cluster of machines.
- Container: A lightweight, standalone executable package that includes everything needed to run software (code, runtime, system tools, libraries). Docker is the most common container runtime.
- Pod: The smallest deployable unit in Kubernetes. A pod runs one or more containers, sharing storage and network. Usually one container per pod.
- Node: A worker machine (physical or virtual) that runs pods. The control plane manages nodes.
- Cluster: A set of nodes, plus the control plane components (API server, scheduler, etcd, controller manager).
Core Concepts You Need
Deployments
A Deployment manages a set of identical pods. You tell it how many replicas (copies) you want, and it ensures that number is always running. Deployments make rolling updates and rollbacks easy.
Services
Pods are ephemeral — they come and go. A Service gives you a stable IP and DNS name to reach your pods. Services also provide load balancing across pod replicas.
Ingress
For HTTP/HTTPS traffic from outside the cluster, an Ingress routes requests to services based on hostnames or paths. It's like a reverse proxy.
ConfigMaps and Secrets
Store configuration data (ConfigMap) and sensitive data (Secret) separately from your container images. Mount them as environment variables or files inside pods.
Your First Deployment
Let's build a simple web application and deploy it. You'll need kubectl (the command-line tool) and a local cluster like Minikube.
1. Install Prerequisites
- Install Minikube - runs a single-node K8s cluster locally.
- Install kubectl - the CLI to interact with K8s.
Start Minikube:
minikube start
2. Your First Pod
Pods are usually created via Deployments, but let's see one manually first.
Create my-pod.yaml:
apiVersion: v1
kind: Pod
metadata:
name: hello-pod
spec:
containers:
- name: hello
image: nginx:latest
ports:
- containerPort: 80
Apply it:
kubectl apply -f my-pod.yaml
Verify:
kubectl get pods
3. Deploy Your Application
Now use a Deployment for reliability.
Create deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-deployment
spec:
replicas: 3
selector:
matchLabels:
app: hello
template:
metadata:
labels:
app: hello
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
Apply it:
kubectl apply -f deployment.yaml
Watch the pods spin up:
kubectl get deployments
kubectl get pods
4. Expose Your Deployment
Create a Service to make the app accessible.
Create service.yaml:
apiVersion: v1
kind: Service
metadata:
name: hello-service
spec:
type: NodePort
selector:
app: hello
ports:
- protocol: TCP
port: 80
targetPort: 80
Apply:
kubectl apply -f service.yaml
Get the URL to reach your app:
minikube service hello-service --url
Open that URL in a browser — you should see the default Nginx page.
5. Clean Up
kubectl delete deployment hello-deployment
kubectl delete service hello-service
minikube stop
Scaling and Updates
To scale your deployment from 3 to 5 replicas:
kubectl scale deployment hello-deployment --replicas=5
To update the image version (rolling update):
kubectl set image deployment/hello-deployment nginx=nginx:1.21-alpine
Check the rollout status:
kubectl rollout status deployment/hello-deployment
If something goes wrong, rollback:
kubectl rollout undo deployment/hello-deployment
Going Production
A local cluster is fine for learning, but production requires more:
- High Availability: Run multiple control plane nodes and worker nodes. Use managed Kubernetes (EKS, AKS, GKE) or set up kubeadm.
- Persistent Storage: For stateful applications, use PersistentVolumeClaims (PVCs) connected to cloud storage (EBS, GCE PD) or NFS.
- Monitoring & Logging: Deploy Prometheus for metrics and Grafana for dashboards. Centralize logs with the ELK stack or Loki.
- Security: Enable RBAC (Role-Based Access Control), use Secrets, and scan images for vulnerabilities.
- Ingress Controller: For real HTTP traffic, install an Ingress controller (e.g., NGINX Ingress) and define Ingress resources.
Questions Before Deploying
- Do I need StatefulSets instead of Deployments? (For databases like MySQL.)
- How do I handle configuration across environments? (Use Kustomize or Helm.)
- What about network policies? (Restrict traffic between pods.)
From Zero to Production: The Takeaway
You've gone from knowing nothing to deploying a multi-replica web app on Kubernetes. The core concepts — Deployments, Services, and scaling — are the same whether you run on a laptop or a 100-node cluster. As you move toward production, layer on persistence, monitoring, and security. Skip none of them. The path is well-trodden; use it.
Next steps: Learn how to use Helm to package your apps, and how to write tests that verify rolling updates. Keep your YAML files in Git. And never, ever commit secrets.
