> ## Content Index
> Fetch the complete content index at: https://skills.devopscube.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Create a Kubernetes Pod with a Specific Image, Label, and Restart Policy
- URL: https://skills.devopscube.com/create-a-pod-with-a-specific-image-label-and-restart-policy/
- Published: 2026-09-17T14:52:55.000Z
- Updated: 2026-10-14T13:27:48.000Z
- Author: Sulaiman
- Tags: #blog, #CKA-Exam-question, #docs, Workloads & Scheduling

You are working on a Kubernetes cluster where a web application requires a dedicated Pod.

Your task is to create a Pod named with the following configuration:

- Pod name: `webserver`
- Container name: `webserver-container`
- Image: `nginx:1.25.4`
- Restart policy: `OnFailure`
- Label: `type=web-application`

💡

You may use `kubectl run` with `--dry-run=client` and `-o yaml` to generate a basic Pod manifest if needed.

📚

For more details about `pods`, refer to the official [Kubernetes documentation](https://kubernetes.io/docs/concepts/workloads/pods/?ref=skills.devopscube.com).

---

### Generate the Pod Manifest

Use `kubectl run` to generate the basic Pod YAML:

```sh
$ kubectl run webserver \
  --image=nginx:1.25.4 \
  --restart=OnFailure \
  --labels=type=web-application \
  --dry-run=client -o yaml > webserver.yaml
```

The `--dry-run=client` option generates the manifest without creating the Pod.

The `-o yaml` option outputs the Pod configuration in YAML format.

### Edit the Container Name

Open `webserver.yaml` in a text editor and verify that it contains the required image, label, and restart policy. Update the container name to **`webserver-container`**.

The final manifest should look like this:

webserver.yaml Copy 

apiVersion: v1 kind: Pod metadata:  name: webserver  labels:  type: web-application spec:  containers:  \- image: nginx:1.25.4  name: webserver-container  restartPolicy: OnFailure 

The generated YAML may contain additional fields such as `creationTimestamp: null`, `resources: {}`, `dnsPolicy`, or `status: {}`. These are not required for this task and can be removed to keep the manifest cleaner.

### Apply the Manifest

Deploy the Pod:

```sh
$ kubectl apply -f webserver.yaml

pod/webserver created
```

### Verify the Pod Status

Check the Pod:

```sh
$ kubectl get pod webserver

NAME        READY   STATUS    RESTARTS   AGE
webserver   1/1     Running   0          70s
```

The important value is `STATUS: Running`. Since the Pod uses the `nginx:1.25.4` image and the nginx process continues running, the expected Pod status is Running.

> **Important:** Do not expect `Completed` for this task. `Completed` is normally associated with a container that has finished its command successfully. The nginx container continues running, so the expected status here is `Running`.

### Verify the Pod Label

Check the label with the following command: 

```
$ kubectl get pod webserver --show-labels

NAME        READY   STATUS    RESTARTS   AGE     LABELS
webserver   1/1     Running   0          5m55s   type=web-application
```

You should see:

```
type=web-application
```

You can also use the label selector:

```
kubectl get pods -l type=web-application
```

The `webserver` Pod should be listed.

### Verify the Container Image

Execute the command below:

```
kubectl get pod webserver -o jsonpath='{.spec.containers[0].image}'
```

The expected output is **`nginx:1.25.4`**, confirming that the Pod is using the required image.

### Verify the Restart Policy

Execute the command below:

```
kubectl get pod webserver -o jsonpath='{.spec.restartPolicy}'
```

Run the command to verify the Pod's restart policy. The expected output is **`OnFailure`**, confirming that the Pod is configured with the required restart policy.

## CKA Exam Tips

These tips will help you quickly identify key Kubernetes concepts and avoid common mistakes during the CKA exam and hands-on practice

### Tip 1: Use `kubectl run` to Generate Pod YAML

Instead of writing a Pod manifest from scratch, you can quickly generate one:

```
kubectl run webserver --image=nginx:1.25.4 --dry-run=client -o yaml
```

This can save time during the CKA exam.

### Tip 2: Know the `--dry-run=client` Option

This command:

```
kubectl run webserver --image=nginx:1.25.4 --dry-run=client -o yaml
```

generates the YAML without creating the Pod.

You can redirect the output to a file:

```
kubectl run webserver \
  --image=nginx:1.25.4 \
  --dry-run=client -o yaml > webserver.yaml
```

Then edit the manifest before applying it.

### Tip 3: Know the Restart Policies

Kubernetes Pods support these restart policies:

```
Always
OnFailure
Never
```

### Tip 4: Use `jsonpath` for Specific Values

When you need to quickly verify a particular field, `jsonpath` is useful.

For the image:

```
kubectl get pod webserver -o jsonpath='{.spec.containers[0].image}'
```

For the restart policy:

```
kubectl get pod webserver -o jsonpath='{.spec.restartPolicy}'
```