What Kubernetes is and how it works
Kubernetes (K8s) is an open source platform for running containerised applications on a cluster of machines. You describe the desired state: which images to run, in how many replicas and how to expose them to the network. Kubernetes brings the cluster to that description and keeps it there.
Kubernetes is what you need when an application runs on several servers and must not sit idle. It restarts containers that have crashed, balances traffic between replicas, rolls out new versions at a controlled pace and rolls them back, and scales the application with CPU load. Kubernetes does not build images from source code and provides no ready-made databases, queues or caches: these run in the cluster like any other application.
What a cluster is made of
A cluster is the control plane and the worker nodes that run Pods — groups of the application’s containers. The control plane makes the decisions for the whole cluster. Its entry point is kube-apiserver: it serves the Kubernetes HTTP API that kubectl talks to. etcd stores all cluster data, kube-scheduler picks a node for each new Pod, and kube-controller-manager runs the controllers. In the cloud a cloud-controller-manager is added on top: it links the cluster to the cloud provider’s API, for example by creating load balancers.
On every node runs kubelet — an agent that keeps the containers of a Pod up and healthy. The containers themselves are run by the container runtime: containerd, CRI-O or another CRI implementation. kube-proxy sets up the node’s network rules for Services; with some networking plugins it is not needed.
Desired state and manifests
A Kubernetes object is a record of intent. In a manifest you set spec — the desired state — and Kubernetes fills in status — the actual one. Controllers keep narrowing the gap between the two: if a Deployment’s spec asks for three replicas and only two are running, the controller will start the third.
# API version and kind of the objectapiVersion: apps/v1kind: Deployment# name and metadatametadata: name: web# desired statespec: replicas: 3 selector: matchLabels: app: web template: metadata: labels: app: web spec: containers: - name: web image: nginx:1.30kubectl apply -f web.yaml# the full spec and status of the objectkubectl get deployment web -o yamlEvery manifest requires apiVersion, kind and metadata, and almost always spec. Manifests are written in YAML, and kubectl converts them to JSON for the API. By default, kubectl validates fields on the server in strict mode: a typo in a field name returns an error instead of disappearing silently.
How Kubernetes differs from Docker Compose
| Feature | Docker Compose | Kubernetes |
|---|---|---|
| Where it runs | a single host with Docker | a cluster: control plane and worker nodes |
| How it is described | one compose.yaml file: services, networks, volumes | API objects in YAML manifests |
| Networking | services are connected through Compose networks | DNS names and traffic balancing between Pods |
| Updates | containers of unchanged services are reused | rollout at a controlled pace, with rollback |
| What for | development, test environments in CI, production on a single host | several nodes, self-healing, autoscaling |
Choose Compose if the application fits on a single server, or you need an environment for development and testing. Choose Kubernetes when the application must run on several nodes, survive failures and update without downtime.
You set up a learning cluster on your own machine — see the section “Installation and first run”. Production clusters are deployed with kubeadm, kops or Kubespray, or you use managed Kubernetes from a cloud provider: the provider then runs the control plane for you.
What to know in advance
- Containers and images: tags, registries, builds — the Docker reference, sections “Images and registries” and “Dockerfile instructions”.
- YAML: indentation with spaces, dictionaries and lists — every manifest is written in it.
- Networking: IP addresses, ports and DNS — the TCP/IP and DNS reference.
- The Linux command line and permissions — the Linux reference.
Section sources
the section is written from these pages- Overviewkubernetes.io/docs/concepts/overview/(opens in a new tab)
- Cluster Architecturekubernetes.io/docs/concepts/architecture/(opens in a new tab)
- Objects In Kuberneteskubernetes.io/docs/concepts/overview/working-with-objects/(opens in a new tab)
- Why use Compose?docs.docker.com/compose/intro/features-uses/(opens in a new tab)
- How Compose worksdocs.docker.com/compose/intro/compose-application-model/(opens in a new tab)