有一种方法可以像How to Add Users to Kubernetes (kubectl)?那样创建服务帐户并获取令牌,但有没有办法为普通用户获取或创建令牌?
关注Configure RBAC In Your Kubernetes Cluster并创建了普通用户。
将群集角色绑定到用户,如下所示(不确定这是否正确,感谢建议)。我想为用户创建一个令牌,并使用它来访问仪表板,但不知道该怎么做。
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
namespace: kube-system
name: dashboard-admin-role
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["get", "list", "watch"]
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: dashboard-admin-rolebinding
namespace: office
subjects:
- kind: User
name: myuser
apiGroup: "rbac.authorization.k8s.io"
roleRef:
kind: ClusterRole
name: dashboard-admin-role
apiGroup: "rbac.authorization.k8s.io"
答案 0 :(得分:5)
kubectl create serviceaccount ACCOUNT_NAME
命令即可。这将在当前命名空间中创建一个服务帐户,并创建一个关联的秘密,用于保存API服务器的公共CA和签名的JSON Web令牌(JWT)。因此,您可以创建一个serviceaccount然后use that token to authenticate the requests to the API。
类似于这个例子的东西
$ kubectl create serviceaccount jenkins
serviceaccount "jenkins" created
$ kubectl get serviceaccounts jenkins -o yaml
apiVersion: v1
kind: ServiceAccount
metadata:
# ...
secrets:
- name: jenkins-token-1yvwg
然后获取令牌
$ kubectl get secret jenkins-token-1yvwg -o yaml
apiVersion: v1
data:
ca.crt: (APISERVER'S CA BASE64 ENCODED)
namespace: ZGVmYXVsdA==
token: (BEARER TOKEN BASE64 ENCODED)
kind: Secret
metadata:
# ...
type: kubernetes.io/service-account-token