A Pod is the smallest deployable unit in Kubernetes and the building block of every microservice you run on a cluster. This step-by-step guide shows how to create a Pod in Kubernetes for a microservice: containerise the service, write a Pod manifest, deploy and test it, add configuration, health checks and resource limits, and then move to a Deployment, which is how Pods should run in production.
Quick answer: build and push a container image, write a YAML manifest with kind: Pod, run kubectl apply -f pod.yaml, check it with kubectl get pods, and test it with kubectl port-forward. For real microservices, wrap the same Pod template in a Deployment and expose it with a Service.
Understanding Pods
A Pod is a group of one or more containers that share storage and network resources and run together on the same node.
Key characteristics of Pods:
- Co-located: all containers in a Pod share the same network namespace (one IP address) and are scheduled onto the same node.
- Ephemeral: Pods are not permanent. If a node fails or a Pod is deleted, it is not recreated unless a controller (such as a Deployment) manages it.
- Basic unit of scheduling: Kubernetes schedules Pods, not individual containers, onto nodes.
Most Pods run a single container. Multiple containers in one Pod are used for tightly coupled helpers, such as a log shipper or proxy sidecar.
Prerequisites
- A running Kubernetes cluster: local (kind, minikube, Docker Desktop) or managed (Amazon EKS, Azure AKS, Google GKE).
kubectlinstalled and configured for your cluster.- Docker or another tool to build container images, and a container registry.
- A microservice to deploy. This guide uses a small Node.js service listening on port 3000.
Step 1: containerise your microservice
Create a Dockerfile in your project:
FROM node:22-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
USER node
EXPOSE 3000
CMD ["node", "index.js"]
Build the image and push it to a registry your cluster can pull from:
docker build -t registry.example.com/orders-service:1.0.0 .
docker push registry.example.com/orders-service:1.0.0
Use a specific version tag rather than latest, so you always know which code is running.
Free resource
Upgrade and patching checklist
Want this applied to your project? Our engineers will send it with notes for your stack.
Step 2: create a Pod manifest
A Pod manifest is a YAML file that describes the desired state of the Pod. Save this as pod.yaml:
apiVersion: v1
kind: Pod
metadata:
name: orders-service
labels:
app: orders-service
spec:
containers:
- name: orders
image: registry.example.com/orders-service:1.0.0
ports:
- containerPort: 3000
What the fields mean:
- apiVersion: the Kubernetes API version for the object (
v1for Pods). - kind: the type of object, here a
Pod. - metadata: the Pod’s name and labels. Labels let Services and other objects find the Pod.
- spec.containers: the list of containers, each with a name, an image and the ports it listens on.
Step 3: create the Pod
kubectl apply -f pod.yaml
Step 4: verify the Pod
kubectl get pods
kubectl describe pod orders-service
kubectl logs orders-service
The Pod should show the status Running. If it shows ImagePullBackOff, check the image name and registry credentials; if it shows CrashLoopBackOff, check the logs.
Step 5: access the Pod
For local testing, forward a port from your machine to the Pod:
kubectl port-forward pod/orders-service 3000:3000
Now open http://localhost:3000. For access from other services or the internet, use a Service (see below) rather than connecting to Pods directly, because Pod IP addresses change.
Advanced Pod configuration
Environment variables, ConfigMaps and Secrets
spec:
containers:
- name: orders
image: registry.example.com/orders-service:1.0.0
env:
- name: NODE_ENV
value: "production"
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: orders-db
key: password
Keep configuration in ConfigMaps and sensitive values in Secrets, never in the image.
Resource requests and limits
resources:
requests:
cpu: "100m"
memory: "256Mi"
limits:
memory: "512Mi"
Requests help the scheduler place Pods; limits stop one container using all of a node’s memory.
Health checks (probes)
readinessProbe:
httpGet:
path: /health/ready
port: 3000
periodSeconds: 10
livenessProbe:
httpGet:
path: /health/live
port: 3000
initialDelaySeconds: 15
periodSeconds: 20
The readiness probe controls when the Pod receives traffic; the liveness probe restarts the container if it stops responding.
Volumes
spec:
volumes:
- name: cache
emptyDir: {}
containers:
- name: orders
image: registry.example.com/orders-service:1.0.0
volumeMounts:
- name: cache
mountPath: /data
Multiple containers (sidecars)
spec:
containers:
- name: orders
image: registry.example.com/orders-service:1.0.0
- name: log-shipper
image: fluent/fluent-bit:3.0
Production: use a Deployment and a Service
Bare Pods are useful for learning and debugging, but they are not recreated if they fail. In production, define a Deployment, which keeps the desired number of Pod replicas running and supports rolling updates, and a Service, which gives them a stable address:
apiVersion: apps/v1
kind: Deployment
metadata:
name: orders-service
spec:
replicas: 3
selector:
matchLabels:
app: orders-service
template:
metadata:
labels:
app: orders-service
spec:
containers:
- name: orders
image: registry.example.com/orders-service:1.0.0
ports:
- containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: orders-service
spec:
selector:
app: orders-service
ports:
- port: 80
targetPort: 3000
Other microservices in the cluster can now call http://orders-service. Use an Ingress or Gateway to expose services outside the cluster, and a HorizontalPodAutoscaler to scale replicas with load.
Pod vs Deployment vs Service
| Object | What it does | Use it for |
|---|---|---|
| Pod | Runs one or more containers | Learning, debugging, one-off tasks |
| Deployment | Manages replicas of a Pod and rolling updates | Stateless microservices in production |
| StatefulSet | Pods with stable identity and storage | Databases and stateful services |
| Job / CronJob | Pods that run to completion | Batch tasks and scheduled jobs |
| Service | Stable network address and load balancing | Connecting to Pods |
Best practices
- Use clear names and consistent labels (
app,version,team). - Pin image versions and scan images for vulnerabilities.
- Run containers as a non-root user with minimal permissions.
- Always set resource requests, memory limits and health probes.
- Store configuration in ConfigMaps and Secrets.
- Use Deployments, not bare Pods, for anything that must stay running.
- Keep manifests in Git and deploy them through CI/CD or GitOps tools such as Argo CD or Flux.
Frequently asked questions
What is a Pod in Kubernetes? The smallest deployable unit in Kubernetes: one or more containers that share networking and storage and run together on one node.
How do I create a Pod in Kubernetes? Write a YAML manifest with kind: Pod, then run kubectl apply -f pod.yaml. You can also run kubectl run name --image=image for quick tests.
Should I deploy microservices as Pods or Deployments? Use Deployments. They recreate failed Pods, scale replicas and roll out new versions safely.
Can a Pod have more than one container? Yes, for tightly coupled helpers such as sidecars, but most Pods run a single application container.
Need help running microservices on Kubernetes?
Vibidsoft Pvt Ltd containerises applications, designs Kubernetes deployments on AWS, Azure and Google Cloud, and sets up CI/CD, monitoring and auto-scaling. See our cloud and DevOps services or contact us.
