Search

What Kubernetes Does and Why Companies Use It

The short answer

Quick answer: Kubernetes is a system for running containers across a group of machines. You tell it what you want, for example "run five copies of this container and expose them on port 443", and it works continuously to make that true. It decides which machine each container runs on, restarts containers that crash, replaces ones on failed machines, spreads network traffic across healthy copies, scales the number up and down, and rolls out new versions without downtime. Companies use it because it gives them one consistent, automated way to operate hundreds of services on any cloud or their own hardware.

The problem it solves

Running one container on one server is simple. Running hundreds of containers across dozens of servers raises questions immediately:

  • Which server has room for this container?
  • What happens when a container crashes at 3 a.m.?
  • What happens when a whole server dies?
  • How do containers find each other when their addresses keep changing?
  • How do you update to a new version without an outage?
  • How do you add capacity when traffic rises?

Doing this by hand, or with home-made scripts, does not scale. A container orchestrator automates it. Kubernetes, released by Google in 2014 and drawing on its experience running containers internally, became the standard. It is now maintained by the Cloud Native Computing Foundation. The name is often shortened to K8s.

The key idea: declare the desired state

Traditional operations are imperative: "start this container on that server". Kubernetes is declarative. You describe the end result in a file, and Kubernetes makes it happen and keeps it that way.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 3
  selector:
    matchLabels: { app: web }
  template:
    metadata:
      labels: { app: web }
    spec:
      containers:
        - name: web
          image: registry.example.com/web:1.4.2
          ports:
            - containerPort: 8080
          resources:
            requests: { cpu: "250m", memory: "256Mi" }

This says: three copies of this image should always be running. If one dies, Kubernetes starts another. If you change replicas to 10, it starts seven more. If you change the image tag, it rolls out the new version.

Underneath is a reconciliation loop: small programs called controllers constantly compare the desired state with the actual state and act to close any gap. A thermostat is the usual analogy. You set the temperature; it does whatever is needed to reach and hold it.

The main building blocks

ObjectWhat it is
PodThe smallest unit: one or more containers that run together, share a network address and can share storage. Pods are disposable
DeploymentManages a set of identical pods: how many, which version, how to update
ServiceA stable name and virtual IP address in front of a changing set of pods, with load balancing between them
Ingress / GatewayRoutes HTTP traffic from outside the cluster to services, by hostname and path
ConfigMap and SecretConfiguration and sensitive values, kept separate from the image
NamespaceA way to divide a cluster between teams or environments
StatefulSetLike a Deployment, for workloads that need stable identities and storage, such as databases
DaemonSetRuns one pod on every node, for things like log collectors
Job / CronJobRuns a task to completion, once or on a schedule
PersistentVolumeStorage that outlives any individual pod

Pods are deliberately temporary. They come and go, and their IP addresses change. That is why you never address a pod directly. You address a Service, which always points at whichever healthy pods currently match its label selector.

How the cluster is organised

A cluster has two parts, described in the Kubernetes architecture documentation.

The control plane

ComponentJob
API serverThe front door. Every command and every component talks to it
etcdA consistent, replicated key-value store holding all cluster state. It uses the Raft algorithm; see how consensus algorithms work
SchedulerChooses a node for each new pod, based on available resources and constraints
Controller managerRuns the reconciliation loops

The worker nodes

ComponentJob
kubeletAn agent on every node that starts and monitors the containers assigned to it
Container runtimeActually runs containers (commonly containerd)
kube-proxy / network pluginSets up networking so services and pods can reach each other

What happens when you deploy

  1. You submit the file with kubectl apply.
  2. The API server validates it and stores it in etcd.
  3. The deployment controller notices that three pods should exist and none do, and creates three pod objects.
  4. The scheduler assigns each pod to a node with enough free capacity.
  5. The kubelet on each of those nodes pulls the image and starts the containers.
  6. The service starts sending traffic to pods that pass their readiness checks.

What you get

  • Self-healing. Crashed containers are restarted. Pods on a failed node are recreated elsewhere. Pods that fail health checks stop receiving traffic.
  • Scaling. Change a number, or let an autoscaler adjust it from CPU or other metrics. See how auto-scaling works.
  • Rolling updates and rollbacks. New pods are brought up and old ones removed gradually. If the new version fails its checks, the rollout stops, and you can revert with one command. See blue-green and canary deployments.
  • Service discovery and load balancing. Services get DNS names inside the cluster.
  • Efficient use of machines. The scheduler packs workloads onto nodes according to their declared resource needs.
  • Portability. The same definitions work on any conforming cluster, on any cloud or on your own servers.
  • Extensibility. You can add your own resource types and controllers. This is how tools for databases, certificates and machine learning plug in.

Health checks deserve a mention. A liveness probe tells Kubernetes when to restart a container. A readiness probe tells it when a container can receive traffic. A startup probe covers slow-starting applications.

Why companies adopt it

  • Standardisation. Every service is deployed, scaled and monitored the same way.
  • A huge ecosystem. Monitoring, security, networking and deployment tools all integrate with it.
  • Avoiding lock-in. It runs on every major cloud.
  • Skills. It is widely known, which makes hiring and onboarding easier.
  • Automation at scale. Operating thousands of containers by hand is not feasible.

The costs

Kubernetes is powerful and it is complex.

  • A steep learning curve. There are many concepts, and many ways to misconfigure them.
  • Operational overhead. Someone must upgrade the cluster, manage networking and security, and debug it.
  • YAML sprawl. Real applications involve a lot of configuration.
  • Easy to get security wrong. Permissions, network policies and secrets all need deliberate setup.
  • Cost. Clusters often run with a lot of unused capacity.

Managed services such as Amazon EKS, Google GKE and Azure AKS run the control plane for you, which removes much of the burden but not all of it.

Do you need it?

Your situationProbably better
One application, a small teamA platform-as-a-service, or a managed container service
Occasional or event-driven workloadsServerless; see what serverless really means
A handful of containers on one serverDocker Compose
Many services, several teams, a need for consistency and portabilityKubernetes

A common mistake is adopting Kubernetes before having the problems it solves. It pays off when you have many services and a team able to run the platform.

Frequently asked questions

What is Kubernetes in simple terms?

A system that automatically runs and manages containers across many machines, keeping the number and version you asked for running at all times.

What is the difference between Docker and Kubernetes?

Docker builds and runs containers on a single machine. Kubernetes coordinates containers across a cluster of machines.

What is a pod?

The smallest deployable unit in Kubernetes: one or more containers that share a network address and are scheduled together.

Is Kubernetes only for large companies?

No, but its complexity is easier to justify at scale. Small teams are often better served by simpler managed platforms.

Conclusion

Kubernetes turns a group of machines into a single platform that you program with declarations: say what should be running, and controllers keep it running. That brings self-healing, scaling and safe rollouts as standard. The price is real complexity, so the question is not whether Kubernetes is good, but whether your situation has reached the point where it is worth it.

Related articles

Sources and further reading

Usama Muneer

Usama Muneer

Coder, Blogger, Tech Speaker & Web Technologies Enthusiast. Passionate about working on open-source Programming languages & Tools while utilizing my Product Development skills.

Your experience on this site will be improved by allowing cookies Cookie Policy