Useful Resources: Persistent Volumes Claim , Pod to Use a PV
题干
For this question, please set this context (In exam, diff cluster name)
kubectl config use-context kubernetes-admin@kubernetes
An existing nginx pod, my-pod-cka and Persistent Volume Claim (PVC) named my-pvc-cka are available. Your task is to implement the following modifications:
- NOTE:- PVC to PV binding and my-pod-cka pods sometimes takes around 2Mins to Up & Running So Please wait
- Update the pod to include a sidecar container that uses the busybox image. Ensure that this sidecar container remains operational by including an appropriate command “tail -f /dev/null” .
- Share the shared-storage volume between the main application and the sidecar container, mounting it at the path /var/www/shared . Additionally, ensure that the sidecar container has read-only access to this shared volume.
现有的nginx pod、
my-pod-cka
和名为my-pvc-cka
的持久卷声明(PVC)是可用的。你的任务是实现以下修改。
- 注意:PVC到PV绑定和my-pod-cka pods有时需要大约2分钟的时间来启动和运行,所以请等待
- 更新pod以包含一个使用busybox镜像的sidecar容器。通过添加适当的命令“
tail -f /dev/null
”来确保sidecar容器保持正常运行。- 在主应用程序和sidecar容器之间共享共享存储卷,将它挂载到路径
/var/www/shared
。另外,确保sidecar容器对这个共享卷具有只读访问权限。
解题思路
- 切换集群环境
kubectl config use-context kubernetes-admin@kubernetes
- 按照题目的要求修改Pod的资源清单。内容如下
apiVersion: v1
kind: Pod
metadata:
name: my-pod-cka
spec:
containers:
- name: nginx-container
image: nginx:latest
ports:
- containerPort: 80
volumeMounts:
- name: shared-storage
mountPath: /var/www/html
- name: sidecar-container
image: busybox:latest
command: ["tail", "-f", "/dev/null"]
volumeMounts:
- name: shared-storage
mountPath: /var/www/shared
readOnly: true
volumes:
- name: shared-storage
persistentVolumeClaim:
claimName: my-pvc-cka