CKS认证-Secret

8. Secret

问题:

参考链接
在 namespace monitoring 中获取名为db1-test 的现有 secret 的内容。
将 username 字段存储在名为/home/candidate/user.txt 的文件中,
并将password 字段存储在名为/home/candidate/old-password.txt 的文件中。
:::info
您必须创建以上两个文件;它们还不存在
:::

不要在以下步骤中使用/修改先前创建的文件,如果需要,创建新的临时文件。

在 monitoring namespace 中创建一个名为dev-mark 的新 secret,内容如下:

username:production-instance
password: aV7HR7nU3JLX

最后,创建一个新的 Pod,它可以通过卷访问secret dev-mark:
Pod 名 secret-pod
Namespace monitoring
容器名 test-secret-container
镜像 redis
卷名 secret-volume
挂载路径 /etc/test-secret

正确答案:

记住这里这个参数:jsonpath={.data.username},是需要符合yaml文件编写标准的。如果你要查询username的字段,必须要写清楚是在哪个模板下。

root@hk8s-master01:~# kubectl get secrets -n monitoring db1-test -o jsonpath={.data.username} | base64 -d > /home/candidate/user.txt
root@hk8s-master01:~# cat /home/candidate/user.txt
admin
root@hk8s-master01:~# kubectl get secrets -n monitoring db1-test -o jsonpath={.data.password} | base64 -d ># cat /home/candidate/passwd.txt
root@hk8s-master01:~# cat /home/candidate/old-password.txt 
pass

在 monitoring namespace 中创建一个名为dev-mark 的新 secret

root@hk8s-master01:~# vim 8.yaml
  1 apiVersion: v1
  2 kind: Secret
  3 metadata:
  4   name: dev-mark
  5   namespace: monitoring
  6 type: kubernetes.io/basic-auth
  7 stringData:
  8   username: production-instance
  9   password: aV7HR7nU3JLX

做第三问的时候注意了,hostpath是挂载到主机的路径,而我们题干的要求是挂载到secret。所以写的时候就不能加hostpath这个参数了.

apiVersion: v1
kind: Pod
metadata:
  name: secret-pod
  namespace: monitoring
spec:
  containers:
  - name: test-secret-container
    image: redis
    imagePullPolicy: IfNotPresent
    volumeMounts:
    - name: secret-volume
      mountPath: /etc/test-secret
   volumes:
   - name: secret-volume
     secret:     #只写secret就行
       secretName: dev-mark
  #    hostPath: 不加这个参数

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值