Create and Inspect a Pod

KubernetesBeginner
Practice Now

Introduction

A Pod is the smallest workload object you normally create in Kubernetes. It wraps one or more containers, gives them a shared network identity, and lets Kubernetes schedule them onto a node.

In this lab, you will create a single Pod with a small preloaded container image, wait for Kubernetes to make it Ready, and inspect the object from several angles. You will use kubectl get, kubectl describe, and kubectl get -o yaml so that later manifest-writing labs feel grounded in real object state rather than memorized YAML.

Prepare a Pod Workspace

In this step, you will prepare a dedicated namespace for your first Pod and make that namespace the default target for your commands.

Start in /home/labex/project, the shared workspace used throughout CKAD Prep.

mkdir -p /home/labex/project
cd /home/labex/project

The Kubernetes API server may need a short moment to become reachable after the VM starts. Run this command first. If it reports that the server is not ready yet, wait a few seconds and run it again until the node is Ready.

kubectl get nodes --request-timeout=5s

Expected output includes one ready control-plane node:

NAME         STATUS   ROLES           AGE   VERSION
labex-v135   Ready    control-plane   ...   v1.35...

Create a namespace named ckad-prep-pod. A namespace gives this lab its own object scope, so the Pod you create will not mix with objects from other labs.

kubectl create namespace ckad-prep-pod

The command should confirm the namespace creation:

namespace/ckad-prep-pod created

Set the current context namespace to ckad-prep-pod. After this, namespaced commands such as kubectl get pods will read from this namespace by default.

kubectl config set-context --current --namespace=ckad-prep-pod

The output should confirm the current context was modified:

Context "labex-v135" modified.

Check that the current namespace changed:

kubectl config view --minify --output 'jsonpath={..namespace}'; echo

Expected output:

ckad-prep-pod

Create the Pod

In this step, you will create a single Pod with kubectl run and wait for it to become Ready.

kubectl run can create a basic Pod directly from the command line. The --image option chooses the container image, and --restart=Never keeps this as a standalone Pod rather than creating a higher-level controller.

This lab uses registry.k8s.io/pause:3.10.1, a tiny image that is already present in the prepared Kubernetes environment. It stays running without needing application configuration, which lets you focus on the Pod lifecycle instead of image pulls or application behavior.

kubectl run sample-pod --image=registry.k8s.io/pause:3.10.1 --restart=Never

The command should report that Kubernetes accepted the Pod object:

pod/sample-pod created

Creation is not the same as readiness. Kubernetes still needs to schedule the Pod, start the container, and mark the Pod Ready. Use kubectl wait to wait for the Pod's Ready condition.

kubectl wait --for=condition=Ready pod/sample-pod --timeout=60s

Expected output:

pod/sample-pod condition met

Now list Pods in the current namespace:

kubectl get pods

You should see sample-pod with 1/1 ready containers and Running status:

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

Inspect Pod Placement and Events

In this step, you will inspect where the Pod is running and read the event trail that Kubernetes recorded while starting it.

The ordinary kubectl get pods view is compact. Add -o wide to see scheduling details such as the node name and Pod IP address.

kubectl get pod sample-pod -o wide

Expected output includes the node and an internal Pod IP:

NAME      READY   STATUS    RESTARTS   AGE   IP           NODE
sample-pod   1/1     Running   0          ...   ...        labex-v135

kubectl describe gives a human-readable view of the object. It includes metadata, container details, conditions, and recent events. For beginners, the Events section is especially useful because it shows what Kubernetes did after you created the Pod.

kubectl describe pod sample-pod

Look for these kinds of lines in the output:

Name:             sample-pod
Namespace:        ckad-prep-pod
Status:           Running
Containers:
  sample-pod:
    Image:        registry.k8s.io/pause:3.10.1
Conditions:
  Type                        Status
  Ready                       True
Events:
  Type    Reason     Age   From               Message
  Normal  Scheduled  ...   default-scheduler  Successfully assigned ...
  Normal  Pulled     ...   kubelet            Container image "registry.k8s.io/pause:3.10.1" already present ...
  Normal  Created    ...   kubelet            Created container ...
  Normal  Started    ...   kubelet            Started container ...

The exact event ages and messages can vary, but the important idea is stable: Kubernetes schedules the Pod, prepares the image, creates the container, and starts it.

Read the Pod Object Fields

In this step, you will inspect selected Pod fields in YAML form and connect them to the object concepts you saw in the previous lab.

kubectl get can print an object as YAML with -o yaml. This is the actual object representation returned by the API server, including fields that Kubernetes added after creation. The command below uses sed -n '1,80p' to show only the first 80 lines, so the output stays readable.

kubectl get pod sample-pod -o yaml | sed -n '1,80p'

In the output, look for the top-level fields and the container image:

apiVersion: v1
kind: Pod
metadata:
  name: sample-pod
  namespace: ckad-prep-pod
spec:
  containers:
  - image: registry.k8s.io/pause:3.10.1
    name: sample-pod
...
status:
...

You do not need to memorize all generated fields. For now, focus on the basic shape: apiVersion, kind, metadata, spec, and status. You will write the important parts yourself in the next lab.

Use a targeted JSONPath query to print only the image field. JSONPath expressions are useful when you need one precise value from a large object.

kubectl get pod sample-pod -o jsonpath='{.spec.containers[0].image}'; echo

Expected output:

registry.k8s.io/pause:3.10.1

Summary

You created a standalone Pod, waited for Kubernetes to mark it Ready, inspected scheduling and event details, and read key object fields from YAML and JSONPath output. This gives you a concrete Pod to connect with the next lab, where you will write a Pod manifest instead of creating the object directly with kubectl run.