Pod
🎯 Introduction
In the previous article, we created a Kubernetes cluster with kind and used kubectl to inspect nodes and create a Namespace. We have not yet run our own Node.js application in it.
With Docker, we can start a container directly. In Kubernetes, application containers usually run inside a Pod. What is a Pod? How does it differ from a container or a node? How can you check that the application is running and access it from your computer?
We will reuse the node-course cluster and course Namespace to run a simple Node.js order service, following the complete workflow: prepare an image → create a Pod → check its status → access the application → delete the Pod. Each step includes simulated output so you can follow the results even without running the commands.
🧱 Why Pods exist
As you learned earlier, a node is a machine in the cluster. When Kubernetes places the order service on a node, the basic unit it schedules is a Pod.
A Pod can run one or more containers. For a typical Node.js service, start with the model of one application container per Pod.
courseComponents.mermaid.loading
The diagram shows that:
- A node provides CPU, memory, and other resources. One node can run multiple Pods.
- A Pod is the basic unit Kubernetes deploys and schedules, not another server.
- A container is where the Node.js program actually executes.
Why not manage containers directly? Kubernetes needs a consistent unit for scheduling applications and providing a shared runtime environment for containers within that unit. For example, containers in the same Pod share a network namespace and can reach each other's ports through localhost. This article uses only one container and does not cover multi-container scenarios.
Distinguish two cases: when a container process inside a Pod exits, Kubernetes usually attempts to restart it according to the restart policy. However, if you manually delete a Pod that has no managing controller, it is not automatically recreated. We will verify the second case later.
🛠 Preparing a runnable order service image
The Pod needs an image to run. To avoid relying on a separate download, we will create a minimal Express order service.
If you already have the course's order service project, you can reuse it. However, the code and output in this article refer to the minimal example below.
1. Create the Node.js project
Create an orders-app directory containing these files:
orders-app/
├── package.json
├── server.js
└── Dockerfile
package.json:
{
"name": "course-orders",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "5.1.0"
}
}
server.js:
import express from 'express'
const app = express()
const port = 3000
app.get('/healthz', (req, res) => {
res.json({ status: 'ok' })
})
app.get('/api/info', (req, res) => {
res.json({ service: 'orders', version: 'v1' })
})
app.listen(port, '0.0.0.0', () => {
console.log(`Order service started, listening on port ${port}`)
})
These endpoints serve different purposes: /healthz simply checks that the program can respond, while /api/info identifies the running service and version. No database is connected, so we can focus on Pods.
Dockerfile:
FROM node:22-alpine
WORKDIR /app
COPY package.json ./
RUN npm install --omit=dev
COPY server.js ./
EXPOSE 3000
CMD ["npm", "start"]
This Dockerfile uses Node.js 22, installs dependencies inside the container, copies the program, and starts the service. EXPOSE 3000 documents the application's port; it does not expose it to your computer automatically. To keep the example short, no lockfile is included. In real projects, commit package-lock.json and build with npm ci instead.
2. Build the Docker image
Make sure Docker is running, then run this in orders-app:
docker build -t course-orders:v1 .
Simulated output; build steps and duration vary by environment:
[+] Building ... FINISHED
=> [internal] load build definition from Dockerfile
=> [1/4] FROM docker.io/library/node:22-alpine
=> [2/4] WORKDIR /app
=> [3/5] COPY package.json ./
=> [4/5] RUN npm install --omit=dev
=> [5/5] COPY server.js ./
=> exporting to image
=> => naming to docker.io/library/course-orders:v1
-t course-orders:v1 sets the image name and version tag. The final . uses the current directory as the build context. Continue once the build succeeds and names the image course-orders:v1.
Only key log lines are shown. Docker output will not always match this example exactly.
3. Load the image into the kind cluster
Although the image exists in your local Docker environment, kind nodes have their own container image storage. To make it available to the Kubernetes node, run:
kind load docker-image course-orders:v1 --name node-course
Simulated output:
Image: "course-orders:v1" with ID "sha256:..." not yet present on node "node-course-control-plane", loading...
This means kind is loading the local image into the node-course cluster node. The image ID depends on the build, and repeated loads may produce different output.
We do not need an image registry for this local exercise. The image name in the Pod configuration must match this name.
🧩 Writing your first Pod configuration
Create pod.yaml in orders-app:
apiVersion: v1
kind: Pod
metadata:
name: orders-demo
namespace: course
labels:
app: orders
spec:
containers:
- name: orders
image: course-orders:v1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
You already know apiVersion, kind, and metadata. Focus on the new fields:
| Field | Purpose |
|---|---|
kind: Pod | Creates a Pod resource |
metadata.name | Names the Pod orders-demo |
metadata.namespace | Places it in the course Namespace created earlier |
metadata.labels | Adds labels so resources can be identified by label later |
spec.containers | Defines the containers to run in the Pod |
image | Uses the course-orders:v1 image you built and loaded |
imagePullPolicy: IfNotPresent | Uses the node's image if present; otherwise attempts to pull it |
containerPort: 3000 | Declares that the application container uses port 3000; it does not expose it externally |
Think of spec as describing how you want this Pod to run. Since kind has already loaded the image onto the node, IfNotPresent allows the node to use its local copy first.
course Namespace in the previous article, run kubectl create namespace course first. If it already exists, you do not need to create it again.🔎 Starting, inspecting, and accessing the Pod
Each key command in this section includes simulated output and an explanation of what to check. Times, IP addresses, and events may differ in your environment.
1. Create the Pod
Run this in the directory containing pod.yaml:
kubectl apply -f pod.yaml
Simulated output after successful initial creation:
pod/orders-demo created
This means Kubernetes accepted the creation request; it does not mean the application is already running and ready.
2. Check Pod status
kubectl get pods -n course -o wide
Simulated output after the Pod starts:
NAME READY STATUS RESTARTS AGE IP NODE
orders-demo 1/1 Running 0 35s 10.244.0.5 node-course-control-plane
-n course limits the query to the course Namespace, and -o wide displays additional columns.
| Field | Meaning |
|---|---|
READY | Ready containers / total containers; 1/1 means the single container is ready |
STATUS | The displayed Pod status, such as Pending or Running |
RESTARTS | Number of container restarts |
IP | The Pod's IP within the cluster, not a public address on your computer |
NODE | The node running the Pod |
Immediately after creation, you may see Pending or ContainerCreating before Running. This example has no application health probes, so Running and READY 1/1 do not fully guarantee that the business endpoints work. We will test them directly next.
3. Inspect Pod details
kubectl describe pod orders-demo -n course
Excerpt of simulated output:
Name: orders-demo
Namespace: course
Node: node-course-control-plane/...
Status: Running
Containers:
orders:
Image: course-orders:v1
State: Running
Ready: True
Events:
Type Reason Message
---- ------ -------
Normal Scheduled Successfully assigned course/orders-demo to node-course-control-plane
Normal Started Started container orders
describe shows the Pod's node, container image, runtime state, and recent events. When troubleshooting startup failures, pay particular attention to State and Events. Events vary by environment and may not exactly match the example.
4. Read Node.js application logs
kubectl logs orders-demo -n course
Based on the earlier server.js, the simulated output is:
> course-orders@1.0.0 start
> node server.js
Order service started, listening on port 3000
This shows that the container ran npm start and printed the Node.js application's startup log.
5. Access the service from your computer
The Pod is running inside the Kubernetes cluster, but containerPort: 3000 does not automatically expose the service to your computer. Use kubectl port-forward for temporary access.
courseComponents.mermaid.loading
Run this in terminal A and leave it running:
kubectl port-forward -n course pod/orders-demo 3000:3000
Simulated output:
Forwarding from 127.0.0.1:3000 -> 3000
Forwarding from [::1]:3000 -> 3000
Your computer's local port 3000 now forwards to port 3000 in the Pod. The command keeps running; leave terminal A open.
In terminal B, run:
curl http://127.0.0.1:3000/api/info
Based on this article's server.js, the simulated response is:
{"service":"orders","version":"v1"}
You can also check the health endpoint:
curl http://127.0.0.1:3000/healthz
Simulated response:
{"status":"ok"}
You have now verified that a request goes from your computer through port forwarding to the Express service inside the Pod and receives a response. Return to terminal A and press Ctrl+C to stop port forwarding.
3000 is already in use, run kubectl port-forward -n course pod/orders-demo 3001:3000 and visit http://127.0.0.1:3001/api/info. The left port is on your computer; the right port is inside the Pod.⚠️ Why production applications usually need more than a Pod
What we created is a bare Pod: no workload controller, such as a Deployment, manages it.
Delete it:
kubectl delete -f pod.yaml
Simulated output:
pod "orders-demo" deleted
Check again:
kubectl get pods -n course
If the Namespace contains no other Pods, the simulated output is:
No resources found in course namespace.
Why did the Pod not reappear? We created only a Pod, without a controller responsible for maintaining the Pod replica count.
Do not confuse restarting a container after its process exits unexpectedly with automatically recreating a deleted Pod resource.
Production applications commonly use a Deployment, introduced next, to manage Pod replicas and version updates. For now, focus on creating, running, and deleting a bare Pod; Deployment configuration comes later.
❓ Questions and answers
Q: Are Pods and containers the same thing?
No. A Pod is the basic unit Kubernetes schedules, and it can contain one or more containers. Containers actually run the Node.js program.
Q: Why run kind load docker-image after successfully building the Docker image?
The kind node in this example has its own image storage. Loading the image lets the Pod use course-orders:v1 directly on the node without fetching it from an external registry.
Q: Is a bare Pod automatically recreated after deletion?
No. A bare Pod has no replica controller to replace it. The Deployment in the next article addresses this application management problem.
🧪 Exercise
Simulate a Pod failing to start because of an incorrect image name:
- Confirm that you deleted the
orders-demoPod using the earlier command. - Temporarily change the image in
pod.yamlfromcourse-orders:v1tocourse-orders:missing-demo. - Run
kubectl apply -f pod.yaml, followed bykubectl get pods -n course. - Run
kubectl describe pod orders-demo -n courseand find the image pull failure inEvents. - Delete the failed Pod with
kubectl delete -f pod.yaml, restore the image name tocourse-orders:v1, and runkubectl apply -f pod.yamlagain.
With an incorrect image, the displayed status may initially be ErrImagePull, then ImagePullBackOff after retries. describe may show messages like these simulated excerpts:
Warning Failed Failed to pull image "course-orders:missing-demo"
Normal BackOff Back-off pulling image "course-orders:missing-demo"
Success criteria: Explain why the node cannot find the image, locate the problem through Events, and see the Pod running after restoring the correct image. If you completed the exercise, leave the restored Pod in place for the next article.
🎉 You now understand how Pods relate to nodes and containers, and have built a Node.js image, created a Pod, checked its status and logs, and accessed it through port forwarding. Next, you will use a Deployment to manage these Pods instead of creating bare Pods manually.
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.
Deployment
Understand Deployments, ReplicaSets, and Pods, run two Node.js replicas, and verify automatic Pod replacement and manual scaling.
