Kubernetes 配置:指定不同的服务账号

Kubernetes configuration: Specify different service account

我开发了一个 .NET API,我想将它部署在 Kubernetes pod 中。 我正在使用 InClusterConfig():

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

我关注了这个问题 (),我了解到 InClusterConfig 使用您部署 pod 的命名空间的默认服务帐户。

是否可以指定配置取自其他服务帐户而不是默认帐户? 还有其他方法可以从 Kubernetes pod 检索配置吗?

Pod 将使用 Pod 清单中指定的 ServiceAccount,如果未指定,将使用命名空间中的 default ServiceAccount。

您可以使用 serviceAccountName: 字段为 Pod 指定 ServiceAccount:

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

另见 Configure Service Accounts for Pods