您的位置:首页 > 新闻 > 会展 > 东莞关键词排名优化_安卓开发是做什么的_企业培训心得_windows优化大师有什么功能

东莞关键词排名优化_安卓开发是做什么的_企业培训心得_windows优化大师有什么功能

2025/6/2 19:22:12 来源:https://blog.csdn.net/agjllxchjy/article/details/143660929  浏览:    关键词:东莞关键词排名优化_安卓开发是做什么的_企业培训心得_windows优化大师有什么功能
东莞关键词排名优化_安卓开发是做什么的_企业培训心得_windows优化大师有什么功能

最近准备花一周的时间准备CKS考试,在准备考试中发现有一个题目关于读取、创建以及挂载secret的题目。

​ 专栏其他文章:

  • [CKS] Create/Read/Mount a Secret in K8S-CSDN博客
  • [CKS] Audit Log Policy-CSDN博客
    -[CKS] 利用falco进行容器日志捕捉和安全监控-CSDN博客
  • [CKS] K8S NetworkPolicy Set Up-CSDN博客
  • [CKS] K8S AppArmor Set Up-CSDN博客
  • [CKS] 利用Trivy对image进行扫描-CSDN博客
  • [CKS] kube-batch修复不安全项-CSDN博客
  • [CKS] K8S ServiceAccount Set Up-CSDN博客
  • [CKS] K8S Admission Set Up-CSDN博客
  • [CKS] K8S Dockerfile和yaml文件安全检测-CSDN博客
  • CKS真题
  • CKA真题

What’s the Secret

详细介绍参见这篇官方介绍: https://v1-28.docs.kubernetes.io/docs/concepts/configuration/secret/

Question 1

Get the username data from the curly Secret in the larry namespace and save it to /home/cloud_user/username.txt on the CLI server.

Then, get the password data and save it to /home/cloud_user/password.txt on the CLI server.

这个题目就是要求我们读取username和password在larry命令空间下的curly secret资源下。并且将结果存在username.txt和password.txt文件中

Practice

在这里需要明确的是secret存储的内容是base64编码的,所以这儿第一步需要将base64的编码数据给获取到,我们可以使用下面的命令打印出该secret的详细内容

kubectl get secret curly -n larry -o yaml

这里我们将会获得如下结果
在这里插入图片描述
这里我们就知道了以下内容:

  • password的base64编码为:MTIzNDUK
  • username的base64编码为:YWRtaW4K

由此,现在我们就需要对这个base64进行解码,并存储在username.txt和password.txt文件中,我们可以使用以下两条命令完成

echo MTIzNDUK | base64 --decode > password.txt
echo YWRtaW4K | base64 --decode > username.txt

Question 2

Create a new secret in the larry namespace called moe.

Provide fields called username and password and store the following username and password credentials in the Secret:

username dbuser
password A83MaeKoz
Create a Pod called secret-pod in the larry namespace.

Mount the new Secret to /etc/credentials in the Pod’s container.

这个题目要求我们创建一个moe的secret,里面需要存储username为dbuser,password为A83MaeKoz,然后创建一个secret-pod,将这个secret进行挂载在pod的/etc/credentials

Practice

刚才我们说了,secret里面存储的是base64编码的内容,所以第一步我们需要将这个明文的username和password进行一个base64的编码,可以使用如下两个命令:

echo dbuser | base64
# 结果为: ZGJ1c2VyCg==
echo A83MaeKoz | base64
# 结果为: QTgzTWFlS296Cg==

然后创建moe.yaml, 文件内容如下:

apiVersion: v1
data:password: QTgzTWFlS296Cg==username: ZGJ1c2VyCg==
kind: Secret
metadata:name: moenamespace: larry
type: Opaque

使用下面的命令创建secret:

kubectl create -f moe.yaml

最后,修改并创建/home/cloud_user/secret-pod.yml对应的pod,修改的内容如下:

apiVersion: v1
kind: Pod
metadata:name: secret-podnamespace: larry
spec:volumes:- name: secret-volumesecret:secretName: moecontainers:- name: busyboximage: busybox:1.33.1command: ['sh', '-c', 'cat /etc/credentials/username; cat /etc/credentials/password; while true; do sleep 5; done']volumeMounts:- name: secret-volumereadOnly: truemountPath: /etc/credentials

最后使用kubectl create -f secret-pod.yml创建pod

验证

kubectl logs secret-pod -n larry

结果如下:

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com