我正在为CKAD考试做练习,遇到了一个有趣的问题,它有一个多容器的pod,我似乎找不到答案。假设我运行此命令式命令来创建pod.yaml:
kubectl run busybox --image=busybox --dry-run=client -o yaml -- /bin/sh -c 'some commands' > pod.yaml然后,我编辑该yaml定义,添加一个仅包含名称和图像的sidecar nginx容器。当我使用以下命令创建此pod时
kubectl create -f pod.yaml
kubectl get pods我得到了一个只有一个nginx容器的pod,尽管busybox容器仍然是在pod规范yaml中定义的。我怀疑这是由于--dry-run=client和/或将命令与预演结合运行而导致的,但我似乎找不到一个好的答案。提前谢谢。
编辑: pod.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: busybox
name: busybox
spec:
containers:
- args:
- /bin/sh
- -c
- while true; do echo ‘Hi I am from Main container’ >> /var/log/index.html; sleep
5; done
image: busybox
name: busybox
volumeMounts:
- mountPath: /var/log
name: log-vol
image: nginx
name: nginx
volumeMounts:
- mountPath: /usr/share/nginx/html
name: log-vol
ports:
- containerPort: 80
volumes:
- name: log-vol
emptyDir: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}发布于 2021-02-24 00:07:27
对我的评论进行扩展:
YAML中的列表是一系列用前导-标记的项,就像下面的字符串列表:
- one
- two
- three或者这个字典列表:
containers:
- image: busybox
name: busybox
- image: nginx
name: nginx或者甚至是下面的列表:
outerlist:
-
- item 1.1
- item 1.2
- item 1.3
-
- item 2.1
- item 2.2
- item 2.3您编写的pod.yaml在containers列表中只有一项。您需要标记第二项:
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: busybox
name: busybox
spec:
containers:
- args:
- /bin/sh
- -c
- while true; do echo ‘Hi I am from Main container’ >> /var/log/index.html; sleep
5; done
image: busybox
name: busybox
volumeMounts:
- mountPath: /var/log
name: log-vol
- image: nginx
name: nginx
volumeMounts:
- mountPath: /usr/share/nginx/html
name: log-vol
ports:
- containerPort: 80
volumes:
- name: log-vol
emptyDir: {}
dnsPolicy: ClusterFirst
restartPolicy: Alwayshttps://stackoverflow.com/questions/66336414
复制相似问题