Can I create a Pod in one namespace that uses a Service Account from another Namespace?

Viewed 1416

I have a pod in namespace Foo and a service account in namespace Bar. Can I run the pod as the service account from the other namespace? Or will the fact that the pod & service account belong to different namespaces block me?

1 Answers

No, you cannot. Your pod and service account need to be in the same namespace. As, Service accounts and Pods are namespaced.

As far the k8s doc:

When you create a pod, if you do not specify a service account, it is automatically assigned the default service account in the same namespace. The service account has to exist at the time the pod is created, or it will be rejected.

It is also a logical thing, as they are namespaced object. So they need to be in the same namespace.

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

You can see the k8s doc and also this

Related