> ## 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 Configure a Kubernetes Pod with a ServiceAccount
- URL: https://skills.devopscube.com/configure-a-pod-with-a-service-account/
- Published: 2026-09-16T11:18:37.000Z
- Updated: 2026-10-14T14:26:02.000Z
- Author: Sulaiman
- Tags: #blog, #CKA-Exam-question, Cluster Architecture, Installation & Configuration, #docs

The DevOpscube team is deploying a microservice that needs to interact with Kubernetes API resources. The application must run using a dedicated ServiceAccount rather than the default identity.

Your task is to create a ServiceAccount named `devopscube-sa` in the cluster.

Create a Pod named `devopscube-pod` using the `nginx:alpine-perl` image and expose container port 80\. Configure the Pod to use the `devopscube-sa` ServiceAccount.

Verify that:

- The ServiceAccount exists.
- `devopscube-pod` is in the Running state.
- The Pod is using `devopscube-sa` as its ServiceAccount.
- The Pod exposes port `80`.

📚

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

---

### Create the ServiceAccount

A ServiceAccount provides an identity that Pods can use to authenticate with the Kubernetes API.

Create a ServiceAccount named `devopscube-sa`:

```sh
$ kubectl create serviceaccount devopscube-sa

serviceaccount/devopscube-sa created
```

### Create the Pod Manifest

Generate the Pod manifest without creating the Pod:

```sh
kubectl run devopscube-pod \
  --image=nginx:alpine-perl \
  --port=80 \
  --dry-run=client -o yaml > pod.yaml
```

Edit `pod.yaml` and add the ServiceAccount under the Pod's `spec`:

pod.yaml Copy 

apiVersion: v1 kind: Pod metadata:  name: devopscube-pod  labels:  run: devopscube-pod spec:  serviceAccountName: devopscube-sa  containers:  \- name: devopscube-pod  image: nginx:alpine-perl  ports:  \- containerPort: 80 

This configures the Pod to run using the `devopscube-sa` ServiceAccount.

💡

****Important:** The ServiceAccount name must exactly match the ServiceAccount you created: `devopscube-sa`.

### Apply the Pod

Apply the manifest to create the Pod:

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

pod/devopscube-pod created
```

Check the Pod status:

```sh
$ kubectl get pod devopscube-pod
NAME             READY   STATUS    RESTARTS   AGE
devopscube-pod   1/1     Running   0          36s
```

The Pod should reach the `**Running**` state and use the `devopscube-sa` ServiceAccount.

### Verify the ServiceAccount

Verify that the Pod is using the `devopscube-sa` ServiceAccount:

```sh
$ kubectl get pod devopscube-pod \
  -o jsonpath='{.spec.serviceAccountName}{"\n"}'
  
devopscube-sa
```

You can also use:

```sh
$ kubectl describe pod devopscube-pod | grep -i "Service Account"

Service Account:  devopscube-sa
```

This confirms that the Pod is associated with the correct ServiceAccount.

## Why use `serviceAccountName`?

It tells Kubernetes which ServiceAccount identity the Pod should use. A ServiceAccount by itself does not grant permissions; RBAC Roles and RoleBindings are used when the application needs specific API permissions.

🤔

How to delete the Pod and the ServiceAccount.

### Delete the Pod and ServiceAccount

After completing the verification, delete the Pod:

```sh
kubectl delete pod devopscube-pod
```

Delete the ServiceAccount:

```sh
kubectl delete serviceaccount devopscube-sa
```

Verify that the ServiceAccount no longer exists:

```sh
kubectl get serviceaccount devopscube-sa
```

You should see a NotFound error, confirming that the ServiceAccount has been deleted.

## CKA Exam Tips

These tips will help you quickly identify the important Kubernetes concepts and avoid common mistakes during the exam.

### 1\. Remember `serviceAccountName`

A Pod uses a specific ServiceAccount through the **`serviceAccountName`** field:

```
spec:
  serviceAccountName: devopscube-sa
```

### 2\. Create a ServiceAccount Quickly

You can create a ServiceAccount with:

```
kubectl create serviceaccount devopscube-sa
```

### 3\. Verify the Association with JSONPath

Use JSONPath to quickly check which ServiceAccount the Pod uses:

```
kubectl get pod techiescamp-pod \
  -o jsonpath='{.spec.serviceAccountName}{"\n"}'
```

### 4\. Don't Confuse ServiceAccounts with Permissions

A ServiceAccount provides an **identity** for a Pod, but it does not automatically grant permissions. Access to Kubernetes resources is typically configured using **RBAC**.