How to create a service account and kubeconfig
Create a service account
Command line
create a
service account
calleddev
inapp
namespace1
kubectl -n app create sa dev
create a
cluster role binding
binddev
service account andcluster-admin
cluster role1
2
3kubectl create clusterrolebinding app-cluster-admin \
--clusterrole=cluster-admin \
--serviceaccount=app:devget
secret
ofdev
service account1
2
3
4
5# get token name
TOKENNAME=`kubectl -n app get serviceaccount/dev -o jsonpath='{.secrets[0].name}'`
# get token
TOKEN=`kubectl -n app get secret $TOKENNAME -o jsonpath='{.data.token}'| base64 --decode`
Yaml
1 |
|
Generate a kubeconfig of service account
1 |
|
可以搭配 merge multiple configs 使用
Test kubeconfig
1 | kubectl --kubeconfig=dev.conf cluster-info |