考试题:
向lumpy—koala添加一个init容器(已在/opt/kucc00100/pod-spec-kucc00100.yaml中定义)
init容器应该创建一个名为/workdir/calm.txt的空文件
如果/workdir/calm.txt没有检测到,Pod应该退出
一旦使用init容器定义更新了 spec文件,就应该创建Pod
解答:
(1)已有的yaml文件最后加上
initContainers: - name: busybox image: busybox command: ["/bin/sh", "-c", "touch /workdir/calm.txt"]
全貌如下:
apiVersion: v1 kind: Pod metadata: name: kumpy-koala spec: volumes: - name: workdir emptyDir: {} containers: - name: checker image: alpine command: ["/bin/sh", "-c", "if [ -f /workdir/calm.txt ];then sleep 100000;else exit 1;fi"] volumeMounts: - name: workdir mountPath: /workdir initContainers: - name: busybox image: busybox command: ['/bin/sh', '-c', 'touch /workdir/calm.txt'] volumeMounts: - name: workdir mountPath: /workdir
(2)更改完成后,创建该pod
kubectl apply -f /opt/kucc00100/pod-spec-KUCC00100.yaml