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

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:

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

kubectl apply -f - <<EOF
apiVersion: v1
kind: ServiceAccount
  name: build-robot
  • 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
  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
- 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,090 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,090 points
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,090 points
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 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
+4 votes
1 answer

Installing Web UI (Dashboard):kubernetes-dashboard on main Ubuntu 16.04.6 LTS (Xenial Xerus) server

Follow these steps: $ kubeadm reset $ kubeadm init ...READ MORE

answered Apr 12, 2019 in Kubernetes by Kalgi
• 52,370 points

reshown Apr 12, 2019 by Kalgi 3,621 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,090 points