Kubernetes pods explained: What they are and how to use them

Learn what Kubernetes pods are and how to create, inspect and debug them. Covers pod YAML structure, kubectl run, kubectl logs, kubectl describe, and kubectl exec with working examples.

9 lessons · 27 min · Intermediate

3 minutes reading time

Written by

Civo Team
Civo Team

Marketing Team at Civo

A pod is the smallest deployable unit in Kubernetes. It is a group of one or more containers, along with shared storage and network resources, and a specification defining how those containers run. Every workload in Kubernetes ultimately runs inside a pod.

All containers in a pod share the same IP address, port space, and storage. They can communicate with each other via localhost and share volumes mounted into the pod.

Pod YAML structure

apiVersion: v1
kind: Pod
metadata:
name: sample-pod
labels:
app: sample
spec:
containers:
- name: sample-pod-container
image: nginx
ports:
- containerPort: 80

The four essential fields:

  • apiVersion: v1 — the API version for pods
  • kind: Pod — the type of object to create
  • metadata — the pod's name and labels
  • spec — the containers to run inside the pod, including image, name, and ports

Create a pod from a YAML file

kubectl create -f sample-pod.yaml

Verify the pod is running:

kubectl get pods

Expected output:

NAME READY STATUS RESTARTS AGE
sample-pod 1/1 Running 0 10s

Get additional details including the pod IP and the node it is running on:

kubectl get pods -o wide

Expected output:

NAME READY STATUS RESTARTS AGE IP NODE
sample-pod 1/1 Running 0 30s 10.244.1.5 node1

Create a pod imperatively

For quick testing and debugging, you can create a pod without a YAML file:

kubectl run demo --image=nginx --port=80

Now you have two pods running:

kubectl get pods

Expected output:

NAME READY STATUS RESTARTS AGE
demo 1/1 Running 0 5s
sample-pod 1/1 Running 0 2m

Pods created without a namespace specification go into the default namespace.

View pod logs

kubectl logs -f demo

The -f flag follows the log stream in real time. Remove it to see a snapshot of current logs and return to the terminal.

Describe a pod

When something goes wrong, kubectl describe is usually the first command to run. It shows the pod's configuration, status, and the event log:

kubectl describe pod demo

The Events section at the bottom shows what Kubernetes did: assigning a node, pulling the image, creating the container, and starting it. If any step failed, the reason appears here.

Exec into a pod

To open a shell inside a running container:

kubectl exec -it demo -- sh

This works like docker exec. You are now inside the running container and can run commands directly. Type exit to return to your terminal.

Delete a pod

kubectl delete pod demo
kubectl get pods

Only sample-pod remains. The demo pod is gone and will not be recreated because it was not managed by a Deployment or other controller.

Common pod issues

pod-issues-diagnostic

Pod stuck in Pending

The pod has been accepted by Kubernetes but has not been scheduled to a node yet. Common causes are insufficient CPU or memory on available nodes, or node selector / affinity rules that no node satisfies.

kubectl describe pod <pod-name>

Look at the Events section for a FailedScheduling message with a specific reason.

Pod in CrashLoopBackOff

The container is starting and then crashing repeatedly. Kubernetes backs off the restart attempts with increasing delays. Check the logs to find the crash reason:

kubectl logs <pod-name>

If the container has already crashed and restarted, check the previous container's logs:

kubectl logs <pod-name> --previous

ImagePullBackOff

Kubernetes cannot pull the container image. Common causes are a typo in the image name, a missing tag, or missing registry credentials for a private registry.

kubectl describe pod <pod-name>

Look for a Failed to pull image message in the Events section. Verify the image name and tag are correct and that any required pull secrets are configured.

Civo Team
Civo Team

Marketing Team at Civo

Civo is the Sovereign Cloud and AI platform designed to help developers and enterprises build without limits. We bridge the gap between the openness of the public cloud and the rigorous security of private environments, delivering full cloud parity across every deployment. As a team, we are dedicated to providing scalable compute, lightning-fast Kubernetes, and managed services that are ready in minutes. Through CivoStack Enterprise and our FlexCore appliance, we empower organizations to maintain total data sovereignty on their own hardware.

Our mission is to make the cloud faster, simpler, and fairer. By providing enterprise-grade NVIDIA GPUs and streamlined model management, we ensure that high-performance AI and machine learning are accessible to everyone. Built for transparency and performance, the Civo Team is here to give you total control over your infrastructure, your data, and your spend.

View author profile