杨梅冲
每天在想什么呢?
随笔 - 198,  文章 - 0,  评论 - 8,  阅读 - 17万

官方参考地址:https://kubernetes.io/zh-cn/docs/reference/access-authn-authz/rbac/#privilege-escalation-prevention-and-bootstrapping  # 看参考的目录可以看到:kubectl create命令行

复制代码
设置答题配置环境:
kubectl config use-context k8s

Context:
为部署流水线创建一个新的 ClusterRole 并将其绑定到范围为特定的 namespace 的特定 ServiceAccount。

Task:
创建一个名为 deployment-clusterrole 且仅允许创建以下资源类型的新 ClusterRole:
Deployment
StatefulSet
DaemonSet
在现有的 namespace app-team1 中创建一个名为 cicd-token 的新 ServiceAccount。
限于 namespace app-team1 中,将新的 ClusterRole deployment-clusterrole 绑定到新的 ServiceAccount cicd-token。
复制代码
复制代码
# 帮助命令
kubectl create clusterrole -h
kubectl create serviceaccount -h
kubectl create rolebinding -h

0.切换答题环境
kubectl config use-context k8s
# 1.创建clusterrole
[root@master2 k8s]# kubectl create clusterrole deployment-clusterrole --verb=create --resource=Deployment,StatefulSet,DaemonSet
clusterrole.rbac.authorization.k8s.io/deployment-clusterrole created

# 2.创建ServiceAccount
[root@master2 k8s]# kubectl create serviceaccount cicd-token -n app-team1
serviceaccount/cicd-token created

# 3.绑定ClusterRole到ServiceAccount中
# rolebinding 后面的名字 cicd-token-binding 随便起的,因为题目中没有要求,如果题目中有要求,就不能随便起了
[root@master2 k8s]# kubectl create rolebinding cicd-token-binding --clusterrole=deployment-clusterrole --serviceaccount=app-team1:cicd-token -n app-team1
rolebinding.rbac.authorization.k8s.io/cicd-token-binding created

# 4.检查命令执行是否有问题
[root@master2 k8s]# kubectl describe rolebinding  cicd-token-binding -n app-team1
Name:         cicd-token-binding
Labels:       <none>
Annotations:  <none>
Role:
  Kind:  ClusterRole
  Name:  deployment-clusterrole
Subjects:
  Kind            Name        Namespace
  ----            ----        ---------
  ServiceAccount  cicd-token  app-team1
复制代码

 

posted on   杨梅冲  阅读(1107)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示