创建k8s-admin.yaml文件
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: admin
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: admin
namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin
namespace: kube-system
labels:
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
~
根据yaml文件配置内容创建更新资源对象,可以看到没有生成admin-token类似字眼
root@ubt:/# kubectl apply -f k8s-admin.yaml
clusterrolebinding.rbac.authorization.k8s.io/admin created
serviceaccount/admin created
root@ubt:/# kubectl get secrets -n kube-system
NAME TYPE DATA AGE
bootstrap-token-q7dfxz bootstrap.kubernetes.io/token 6 20h
bootstrap-token-xcpobh bootstrap.kubernetes.io/token 7 21h
kubernetes-dashboard-certs Opaque 0 19h
kubernetes-dashboard-key-holder Opaque 2 107m
较早版本会自动生成secret,v1.28.2版本需要手动生成,执行命令即可。
root@ubt:/# kubectl create token admin --namespace kube-system
eyJhbGciOiJSUzI1NiIsImtpZCI6InV2SUtYXzI2WEk4XzVwX1I4OEZvU0Y3TktBdUpReGNyeGY1Mlg0dlJGWGMifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWwiXSwiZXhwIjoxNzE1OTI3MDI3LCJpYXQiOjE3MTU5MjM0MjcsImlzcyI6Imh0dHBzOi8va3ViZXJuZXRlcy5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsInNlcnZpY2VhY2NvdW50Ijp7Im5hbWUiOiJhZG1pbiIsInVpZCI6ImRlOTEyZDI0LTUzOTgtNGFiYi1hYjYyLTdiYjhiMzIxYzBlZiJ9fSwibmJmIjoxNzE1OTIzNDI3LCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4ifQ.wYAbvl7_de5K-Sl1CyZbQsvwmLqwR6nJOS5AKEOEsvDFCXYFHAFfSNOMutZ0tbc-eeTMkwpHgRgyJeEs6qkIWEZRt3uWLSiLAtMPYENmaVxdogqBNtqG9Ldcaknt2eCu8mdA599ezkSC9F5lHK07kNpuyVCRTktdAviy3iu736wWUrw0n8-_GiWZDRkTUW7_C46Ym603SckW_7Z5TyoyK_Jv0Hinb3D89UztOlonqDEuzMgTeZxDx01rE6UxkMc8acIGUZfh8o7aRs2BGyKBSDSrFnslZIP2XDESk0Ma3w0MLAd3luzosRZHyaSqkSZc7ZOOdDN3uQykrrJQyOGJjA