題目:創建多容器的pod(名稱: multi-con),指定需有2個containers,規格如下:
名稱/image/command
(1) john/nginx
(2) doe/busybox/sleep 4800
可以使用命令式指令創建pod,不過無法指定多個containers,所以先假執行匯出底板後,再進入文件編輯
kubectl run multi-con --image=nginx --dry-run=client -o yaml > multi-con.yaml
vi multi-con.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: multi-con
name: multi-con
spec:
containers: # 各container 為list形式
- image: nginx
name: john # 注意container名稱
imagePullPolicy: IfNotPresent # 可寫可不寫,若已有此image則不須重新下載,加速啟動時間
- image: busybox
name: doe
command: ["sleep", "4800"]
imagePullPolicy: IfNotPresent
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
kubectl apply -f multi-con.yaml
kubectk get pod multi-con
或 kubectl describe pod multi-con