Search code examples
.netkuberneteskubernetes-pod

Kubernetes configuration: Specify different service account


I develop a .NET API and I want to deploy it in a Kubernetes pod. I'm using InClusterConfig():

var config = KubernetesClientConfiguration.InClusterConfig();
_client = new Kubernetes(config);

I follow this issue (Accessing kubernetes service from C# docker) and I understand that InClusterConfig uses the default service account of the namespace where you are deploying the pod.

Is it possible to specify that the configuration is taken from another service account than default? Are there other methods to retrieve configuration from a Kubernetes pod?


Solution

  • The Pod will use the ServiceAccount specified in the Pod-manifest, if not specified the default ServiceAccount in the namespace will be used.

    You can specify the ServiceAccount for a Pod with the serviceAccountName:-field:

    apiVersion: v1
    kind: Pod
    metadata:
      name: my-pod
    spec:
      serviceAccountName: my-service-account
      ...
    

    Also see Configure Service Accounts for Pods