问题描述
我在 Azure 上有一个 kubernetes 集群,我创建了 2 个命名空间和 2 个服务帐户,因为我有两个团队在集群上部署.我想为每个团队为我创建的 serviceaccount 提供他们自己的 kubeconfig 文件.
I have a kubernetes cluster on Azure and I created 2 namespaces and 2 service accounts because I have two teams deploying on the cluster.I want to give each team their own kubeconfig file for the serviceaccount I created.
我对 Kubernetes 还很陌生,在 kubernetes 网站上找不到明确的说明.如何为 serviceaccount 创建 kube 配置文件?希望有人可以帮助我:),我宁愿不将默认的 kube 配置文件提供给团队.
I am pretty new to Kubernetes and haven't been able to find a clear instruction on the kubernetes website. How do I create a kube config file for a serviceaccount?Hopefully someone can help me out :), I rather not give the default kube config file to the teams.
亲切的问候,
布拉姆
推荐答案
# your server name goes here
server=https://localhost:8443
# the name of the secret containing the service account token goes here
name=default-token-sg96k
ca=$(kubectl get secret/$name -o jsonpath='{.data.ca.crt}')
token=$(kubectl get secret/$name -o jsonpath='{.data.token}' | base64 --decode)
namespace=$(kubectl get secret/$name -o jsonpath='{.data.namespace}' | base64 --decode)
echo "
apiVersion: v1
kind: Config
clusters:
- name: default-cluster
cluster:
certificate-authority-data: ${ca}
server: ${server}
contexts:
- name: default-context
context:
cluster: default-cluster
namespace: default
user: default-user
current-context: default-context
users:
- name: default-user
user:
token: ${token}
" > sa.kubeconfig
这篇关于如何为 serviceaccount 创建 kubectl 配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!