有时需要在k8s 集群上给比如开发人员创建一个只读的service account,在这里记录一下创建方法:
先创建oms-viewonly.yaml:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: oms-viewonly
您暂时无权查看此隐藏内容!
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: oms-read
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: oms-read
labels:
k8s-app: oms-read
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: oms-viewonly
subjects:
- kind: ServiceAccount
name: oms-read
namespace: kube-system
然后创建:
kubectl apply -f oms-viewonly.yaml
最后就可以使用以下命令查找刚刚创建SA的token:
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep oms-read | awk '{print $1}')