[CKS] K8S ServiceAccount Set Up

最近准备花一周的时间准备CKS考试,在准备考试中发现有一个题目关于Rolebinding的题目。

​ 专栏其他文章:

Question 1

The buffy Pod in the sunnydale namespace has a buffy-sa ServiceAccount with permissions the Pod doesn't need. Modify the attached Role so that it only has the ability to list pods.

Then, create a new Role called watch-services-secrets that grants permission to watch, services, and secrets.

Bind the Role to the ServiceAccount with a RoleBinding called buffy-sa-watch-rb.

这段话的意思是:在 Sunnydale 命名空间中的 buffy Pod 有一个名为 buffy-sa 的 ServiceAccount,该 ServiceAccount 具有 Pod 不需要的权限。修改附加的 Role,使其只能具有列出 Pod 的能力。 然后,创建一个名为 watch-services-secrets 的新 Role,该 Role 授予观看 services 和 secrets 的权限。 使用名为 buffy-sa-watch-rb 的 RoleBinding 将该 Role 绑定到该 ServiceAccount。

Practice

修改 sunnydale下的rolebinding

先查看sunnydale下面的rolebinding然后对rolebinding进行修改

shell 复制代码
# 获取sunnydale下面的rolebinding
kubectl get rolebinding -n sunnydale
# 获取buffy-rb下面的rolebinding的serviceaccount name
kubectl describe rolebinding -n sunnydale buffy-rb

可以看到buffy-rb对应绑定的role是buffy-role

修改buffy-role

修改需要达到一下目的

  • 只能列出pod的能力
shell 复制代码
kubectl edit role buffy-role

修改成以下内容:

创建watch-services-secrets新的role

Tips:如果你不知道怎么创建,可以参照上面我们修改的这个yaml文件进行修改

shell 复制代码
vi watch-services-secrets.yml
shell 复制代码
kubectl create -f watch-services-secrets.yml

好了 现在你就讲role创建好了

Bind the role to a SA

如果你不知道怎么绑定,在考试的时候你可以参考buffy-role是怎么绑定的

创建新的rolebinding

shell 复制代码
kubectl create -f buffy-sa-watch-rb.yml

Question 2

A Pod in the cluster cannot be created properly because its ServiceAccount is misconfigured.

The Pod is meant to live in the bespin namespace. Delete the existing ServiceAccount from this namespace.

Create a new ServiceAccount called lando-sa.

Configure the Pod to use the lando-sa ServiceAccount.

Create the Pod.

这个问题的意思是在集群中的一个 Pod 无法正确创建,因为它的 ServiceAccount 配置有误。

这个 Pod 应该存在于 bespin 命名空间中。首先删除该命名空间下已存在的 ServiceAccount。 创建一个名为 lando-sa 的新的 ServiceAccount。 配置 Pod 使用 lando-sa ServiceAccount。 最后创建 Pod。

查看bespin下面的serviceaccount

shell 复制代码
kubectl get serviceaccount -n bespin

删除查找到的serviceaccount

shell 复制代码
kubectl delete serviceaccount -n bespin lando

创建新的serviceaccount lando-sa

shell 复制代码
kubectl create serviceaccount -n bespin lando-sa

创建pod(pod文件已经存在 你只需要修改serviceAccountName就可以了)

shell 复制代码
kuebctl create -f lando.yml
相关推荐
flytalei1 分钟前
从YAML到Nginx服务访问:动手理解 Kubernetes Pod、Deployment 与 Service
运维·nginx·kubernetes
白帽攻防录9 分钟前
SRC 挖洞:DHCP 服务器上的四个 UAF,内网原生 RCE 怎么打域管
运维·服务器·网络安全·内网安全
木雷坞40 分钟前
Docker Compose部署Docmost:数据库、附件持久化与首次协作
数据库·docker·容器
VidDown1 小时前
用户说“卡顿“,服务器一切正常:播放质量监测与 QoE 指标
运维·服务器·ffmpeg·音视频·视频
暖核1 小时前
从零搭建 Ubuntu24.04 服务器:虚拟机安装 + Netplan 静态 IP+SSH 远程登录
服务器·tcp/ip·ssh
程序员-Benothing1 小时前
Linux性能分析方法论:USE、RED、火焰图与perf实战
linux·运维·服务器
问心无愧05131 小时前
[ACTF2020 新生赛]Exec
运维·服务器·笔记
cg.family1 小时前
K8S:scale 与 delete pod 核心区别
运维·docker·容器
微订校园外卖平台1 小时前
同城外卖跑腿平台需要服务器吗?交付方式、部署架构与上线核对
服务器·架构·github·外卖系统·本地生活·微订
发量惊人的中年网工1 小时前
游戏出海服务器选哪个IDC?开服卡顿、延迟抖动的排查与选节点思路
服务器·idc