Introduction to Kubernetes
🎯 Introduction
Suppose you have built a Node.js order service and deployed it to a server using Docker. With just one service instance, everything works well.
As your user base grows, you decide to run three instances. If one stops, what replaces it? If an entire server fails, can another server take over? And when you release a new version, how do you gradually replace the running instances?
These questions go beyond starting containers: they concern managing multiple containers over time. This article uses those challenges to introduce Kubernetes and the relationship between a cluster, its nodes, Pods, and the control plane.
🧱 Why use Kubernetes alongside Docker?
Docker lets you package the order service into an image and start containers from it. You can also manually start three order service containers or configure an automatic restart policy.
Things become more complicated when containers run across multiple servers:
- Placement: Which server should run a new instance?
- Failure recovery: If an entire server goes offline, how do you run the service on other servers?
- Releases: How do you gradually replace an old version while minimizing service interruptions?
- Access: If instance counts or addresses change, how do requests keep reaching available instances?
Kubernetes, often abbreviated to K8s, is a container orchestration platform. For now, think of orchestration as coordinating where containers run and continuously managing their running state.
For example, you tell Kubernetes, “I want three instances of the order service.” Kubernetes places them according to the resources available in the cluster and continuously checks their actual state. If there are too few instances, it attempts to create replacements.
This illustrates a core Kubernetes principle: declare the desired state, then let the system continuously work toward it.
Kubernetes does not replace your Node.js business logic, nor is it another way to write Docker commands. Docker is commonly used to build container images, while Kubernetes deploys and manages containerized applications in a cluster. Nodes do not need Docker Engine installed to run containers with Kubernetes.
🧩 Four basic concepts through the order service
To understand how Kubernetes manages the order service, start with four concepts:
| Name | What it is | Role in the order service |
|---|---|---|
| Cluster | The collection of nodes and associated management components | Provides the environment for running and managing the order service |
| Node | A machine in the cluster, either physical or virtual | Provides CPU, memory, and other resources for running Pods |
| Pod | The basic unit for deploying and running containers in Kubernetes | Can host an order service container |
| Control plane | The components that manage the cluster | Receives the desired state, arranges for Pods to run, and coordinates state changes |
Here is an example with two nodes and three order service Pods:
courseComponents.mermaid.loading
The diagram shows that:
- A cluster is the whole system, not an individual server.
- A node is a machine that runs Pods. One node can run multiple Pods.
- A Pod is not a server. Initially, you can think of each Pod as running one order service container. A Pod can actually contain multiple containers that need to work closely together.
- The control plane coordinates and manages work in the cluster; it is not an application Pod. It also needs machines to run on. The diagram simplifies this to show the management relationships.
In this example, “three instances of the order service” means three Pods, each running an order service container.
🔄 How Kubernetes maintains the desired state
Suppose you have declared that the order service should run three Pods.
Initially, all three are running. Then one Pod unexpectedly stops, leaving only two. Kubernetes detects the difference between the actual and desired counts and attempts to create a replacement Pod.
courseComponents.mermaid.loading
If an entire node fails, Kubernetes also attempts to run the affected workloads on other available nodes after detecting that the node is unavailable. However, the cluster needs sufficient available resources, and recovery can take time. Immediate success is not guaranteed.
Beyond failure recovery, Kubernetes can help with two other common requirements:
- Rolling updates: Gradually replace old Pods with new ones when releasing a version, instead of stopping all instances at once.
- Stable access: A Kubernetes Service provides a relatively stable access point for a group of Pods. Even when Pods are replaced, requests do not need to depend on a particular Pod's address.
We will cover these features in later articles. For now, understand that Kubernetes manages the desired running state of an application; it cannot automatically resolve every failure. For example, restoring a Pod does not restore external dependencies such as a database or payment API. Your application must still ensure that order data is correct.
⚖️ When should you use it?
Kubernetes is powerful, but not every project needs it.
| Scenario | Recommendation |
|---|---|
| A personal website or a few services with infrequent deployment changes | Docker Compose is often simpler |
| Multiple services requiring deployment across machines, independent scaling, rolling updates, and failure recovery | Kubernetes offers more value |
| A team planning to adopt Kubernetes | Account for cluster maintenance, networking, permissions, storage, and monitoring costs |
If you only need to deploy one Node.js service to one server, Docker or Docker Compose is usually sufficient. More features do not mean every project should use Kubernetes.
This course focuses on Kubernetes deployment and management tasks commonly needed by Node.js backend engineers. It does not begin by building a highly available control plane.
❓ Questions and answers
Q: Do I have to choose between Kubernetes and Docker?
No. Docker is commonly used to build images, and Kubernetes can use those images to deploy and manage applications. They solve different problems, and Kubernetes does not require nodes to use Docker Engine.
Q: Is a Pod a server?
No. A node is a machine in the cluster, while a Pod is a unit of work running on a node. One node can run multiple Pods.
Q: Can Kubernetes guarantee uninterrupted service?
No. It attempts to restore workloads after failures, but recovery takes time and may be affected by insufficient resources, application errors, or external dependency failures.
🧪 Exercise
A Kubernetes cluster has two nodes and runs three order service Pods: two on Node A and one on Node B.
Answer the following questions:
- If one order service Pod on Node A unexpectedly stops, what will Kubernetes attempt to do?
- If Node A goes offline but Node B remains available, does that necessarily mean the cluster can no longer run the order service? Why?
- What do cluster, node, and Pod refer to in this example?
Success criteria: Distinguish machines from Pods, explain how Kubernetes attempts to restore the instance count, and recognize that recovery after a node failure depends on factors such as remaining resources.
🎉 You now understand why Kubernetes exists, how it manages the order service, and how clusters, nodes, Pods, and the control plane relate. As you learn deployment commands next, you will know which problem each step addresses.
Deployment and Scaling
Learn about statelessness, health checks, and version compatibility through independent order releases, instance scaling, and rolling updates.
Environment Setup and Basic Operations
Create a local Kubernetes cluster with kind and kubectl, inspect nodes, create a Namespace using YAML, and check resource status.
