Can i configure my kubernetes pod to use multiple service accounts

0 votes
I want my kubernetes pod to use a service account other than the default . How to configure my pod to use multiple service accounts?
Jul 17, 2019 in Kubernetes by Sam
• 6,260 points
7,684 views

1 answer to this question.

0 votes
  • A service account provides an identity for processes that run in a Pod.

  • When you create a pod, if you do not specify a service account, it is automatically assigned the defaultservice account in the same namespace.

  • Every namespace has a default service account resource called default. 

  • You can list this and any other serviceAccount resources in the namespace with this command:

kubectl get serviceAccounts
  • The output would be something like this:

NAME      SECRETS    AGE
default   1          1d
  • You can create additional ServiceAccount objects like this:

kubectl apply -f - <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
  name: build-robot
EOF
  • If you get a complete dump of the service account object, like this:

kubectl get serviceaccounts/build-robot -o yaml
  • The output is similar to this:

apiVersion: v1
kind: ServiceAccount
metadata:
  creationTimestamp: 2015-06-16T00:12:59Z
  name: build-robot
  namespace: default
  resourceVersion: "272500"
  selfLink: /api/v1/namespaces/default/serviceaccounts/build-robot
  uid: 721ab723-13bc-11e5-aec2-42010af0021e
secrets:
- name: build-robot-token-bvbk5
  • then you will see that a token has automatically been created and is referenced by the service account.

  • You may use authorization plugins to set permissions on service accounts.

  • To use a non-default service account, simply set the spec.serviceAccountName field of a pod to the name of the service account you wish to use.

  • The service account has to exist at the time the pod is created, or it will be rejected.

  • You cannot update the service account of an already created pod.

  • You can clean up the service account from this example like this:

kubectl delete serviceaccount/build-robot

Source : Kubernetes docs.

answered Jul 17, 2019 by Sirajul
• 59,230 points

Related Questions In Kubernetes

0 votes
1 answer

What all packages do i need to install to use kubernetes on my machine?

Install below packages on all of your ...READ MORE

answered Jul 11, 2019 in Kubernetes by Sirajul
• 59,230 points
903 views
0 votes
1 answer

Configure a Kubernetes-pod to use persistent volume for storage.

The output shows that the PersistentVolume has ...READ MORE

answered Jul 23, 2019 in Kubernetes by Sirajul
• 59,230 points
2,807 views
0 votes
1 answer
0 votes
2 answers

How can I access a service installed on Kubernetes from anywhere?

if u want to directly want to ...READ MORE

answered Jul 26, 2020 in Kubernetes by Akash Gupta
1,318 views
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
15,477 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,036 views
0 votes
1 answer

Can I configure my kubernetes job to run for a specified time?

When we create a job spec, we ...READ MORE

answered Jul 17, 2019 in Kubernetes by Sirajul
• 59,230 points
1,345 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP