CKA 模拟真题 Killer.sh | Question 13 | Multi Containers and Pod shared Volume
Task weight: 4%
Use context: kubectl config use-context k8s-c1-H
Create a Pod named multi-container-playground in Namespace default with three containers, named c1 , c2 and c3 . There should be a volume attached to that Pod and mounted into every container, but the volume shouldn’t be persisted or shared with other Pods.
Container c1 should be of image nginx:1.17.6-alpine and have the name of the node where its Pod is running available as environment variable MY_NODE_NAME.
Container c2 should be of image busybox:1.31.1 and write the output of the date command every second in the shared volume into file date.log . You can use while true; do date >> /your/vol/path/date.log; sleep 1; done for this.
Container c3 should be of image busybox:1.31.1 and constantly send the content of file date.log from the shared volume to stdout. You can use tail -f /your/vol/path/date.log for this.
Check the logs of container c3 to confirm correct setup.
译文
在Namespace default中创建一个名为 multi-container-playground 的Pod,有三个容器,分别名为 c1 、c2 和 c3 。应该有一个卷连接到该Pod并挂载到每个容器中,但该卷不应该被持久化或与其他Pod共享。
容器 c1 应该是 nginx:1.17.6-alpine 镜像,并且其Pod运行的节点名称可以作为环境变量 MY_NODE_NAME 。
容器 c2 应该是 busybox:1.31.1 镜像,并在共享卷中每秒钟将 date 命令的输出写入文件 date.log 中。你可以使用 while true; do date >> /your/vol/path/date.log; sleep 1; done 来实现这一点。
容器 c3 应该是 busybox:1.31.1 镜像 ,并不断地从共享卷中发送 date.log 文件的内容到stdout。你可以使用 tail -f /your/vol/path/date.log 来实现。
检查容器 c3 的日志以确认正确的设置。
解答
kubectl config use-context k8s-c1-H |
创建一个pod模板
k run multi-container-playground --image=nginx:1.17.6-alpine $do > 13.yaml |
13.yaml
# 13.yaml |
创建pod
k -f 13.yaml create |
检查验证C1 env , c3 logs
k get pod multi-container-playground |



