Docker Advanced: Security, Limits and Production
Orchestration and Kubernetes Basics
In this lesson you will
- Explain what an orchestrator does
- Name core Kubernetes objects and what they are for
- Judge when Compose is enough and when Kubernetes is worth it
Introduction
Running a few containers on one server is easy. Running hundreds across many servers, restarting failures, updating without downtime and scaling with demand is hard to do by hand. An orchestrator automates this. The most widely used one is Kubernetes.
What an orchestrator does
- Schedules containers onto machines with enough resources
- Restarts containers that fail, and replaces machines that die
- Scales the number of copies up and down
- Rolls out new versions gradually, and rolls back if needed
- Connects containers with stable network addresses and load balancing
- Stores configuration and secrets
Core Kubernetes ideas
You describe the desired state in files, usually YAML, and Kubernetes continuously works to make reality match.
- Cluster: a set of machines (nodes) managed together.
- Pod: the smallest unit. One or more containers that run together and share a network.
- Deployment: says "keep three copies of this pod running", and handles rolling updates.
- Service: a stable address and load balancer in front of a set of pods, because pods come and go.
- ConfigMap and Secret: configuration and sensitive values supplied to pods.
- Namespace: a way to separate teams or environments inside a cluster.
A small Deployment:
YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: registry.example.com/team/my-app:3f9a2c1
ports:
- containerPort: 3000Apply it with kubectl apply -f deployment.yaml, and look with kubectl get pods.
Quick quiz
In Kubernetes, which object keeps a chosen number of identical pods running and handles rolling updates?
Do you need it?
Kubernetes is powerful, and it is also complex to learn, run and secure.
- Compose on one server is often enough for small apps and teams.
- Consider managed platforms that run containers for you, such as managed Kubernetes services or simpler container hosting, so you do not run the cluster yourself.
- Choose Kubernetes when you need many services, scaling across machines, zero-downtime updates or a platform used by many teams.
Do not adopt it just because it is popular. Start simple, and move when you feel real limits.
Security in clusters
All the earlier hardening still applies: non-root, least privilege, scanned images and no secrets in images. Also use access controls, network policies to limit which pods can talk, and keep the cluster itself updated.
Where to go next
- Practise with a local tool that runs a small cluster on your laptop.
- Learn
kubectlbasics, then Helm for packaging. - Learn monitoring and logging for clusters.
Try it yourself
Take the application you containerised, and sketch which Kubernetes objects it would need: how many pods, what service in front, what config and secrets. Then decide honestly whether Compose would be enough for it today.
Summary
- Orchestrators schedule, restart, scale and update containers across machines.
- Kubernetes uses pods, deployments and services, driven by desired state files.
- Choose it for real scale and complexity, and prefer simpler options until then.
Lesson complete
+20 XP
Nice work. Keep going while it is fresh.
Sources and further reading