How do you assign a custom service account to a Kubernetes pod?

Experience Level: Junior
Tags: Kubernetes

Answer

In the Pod manifest spec, modify the serviceAccountName field.

spec.serviceAccountName: your-custom-service-account

You can also edit the serviceAccountName by editing the JSON using jq.

Run the following command:

kubectl run mypod --image=busybox --dry-run=client -o json|jq '.spec.serviceAccountName="your-custom-service-account"'|kubectl apply -f -

Comments

No Comments Yet.
Be the first to tell us what you think.
Kubernetes Certified Application Developer (CKAD) preparation
Kubernetes Certified Application Developer (CKAD) preparation

Are you learning Kubernetes ? Try our test we designed to help you progress faster.

Test yourself
Kubernetes
Kubernetes

Are you learning Kubernetes ? Try our test we designed to help you progress faster.

Test yourself