首页 > 其他 > 详细

k8s使用rbac实现多租户

时间:2020-07-09 18:45:44      阅读:122      评论:0      收藏:0      [点我收藏+]
### 制作租户访问证书 ###

openssl genrsa -out ethan.key 2048

openssl req -new -key ethan.key -out ethan.csr -subj "/CN=ethan/O=test"

openssl x509 -req -in ethan.csr -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.key -CAcreateserial -out ethan.crt -days 10000

### 配置config文件 ###
kubectl config set-credentials ethan --client-certificate=ethan.crt --client-key=ethan.key 

kubectl config set-context ethan-context --cluster=cluster.local --namespace=test --user=ethan


### 新建一条属于自己命令空间的Role ###
cat > roleByNamespaces.yaml <<EOF
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: test #< namespace 需新建>
  name: myrole
rules:
- apiGroups: ["*"]
  resources: ["*"]
  verbs: ["get", "watch", "list", "create", "update", "patch", "delete"]
EOF


### 租户绑定命名空间以及Role ###
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: ethan-test
  namespace: test
subjects:
- kind: User
  name: ethan
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: myrole
  apiGroup: rbac.authorization.k8s.io


kubectl --context=ethan-context get po

  

k8s使用rbac实现多租户

原文:https://www.cnblogs.com/EthanSun/p/13275204.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!