Use context: kubectl config use-context k8s-c1-H

Write the names of all namespaced Kubernetes resources (like Pod, Secret, ConfigMap…) into /opt/course/16/resources.txt .

Find the project-* Namespace with the highest number of Roles defined in it and write its name and amount of Roles into /opt/course/16/crowded-namespace.txt .


译文

将所有命名的 Kubernetes 资源(如 Pod、Secret、ConfigMap……)的名称写入 /opt/course/16/resources.txt 中。

查找定义角色数量最多的 *project-*** 命名空间,并将其名称和角色数量写入 /opt/course/16/crowded-namespace.txt 中。


解答

bash

kubectl config use-context k8s-c1-H

将被命名的资源写入文件

bash

k api-resources --namespaced -o name > /opt/course/16/resources.txt

resources-0

file

检查命名空间中角色数量 通过脚本循环检查

bash

for i in `k get ns -o name | cut -d / -f 2` ; do echo $i ; k -n $i get role --no-headers | wc -l; done

resources-1

file

vim /opt/course/16/crowded-namespace.txt

yaml

project-c14 with 300 resources