1. 程式人生 > 其它 >【K8s任務】配置 Pod 初始化

【K8s任務】配置 Pod 初始化

參考:https://kubernetes.io/zh/docs/tasks/configure-pod-container/configure-pod-initialization/

建立一個包含 Init 容器的 Pod

本例中你將建立一個包含一個應用容器和一個 Init 容器的 Pod。Init 容器在應用容器啟動前執行完成。

下面是 Pod 的配置檔案:

apiVersion: v1
kind: Pod
metadata:
  name: init-demo
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80
    volumeMounts:
    - name: workdir
      mountPath: /usr/share/nginx/html
  # These containers are run during pod initialization
  initContainers:
  - name: install
    image: busybox
    command:
    - wget
    - "-O"
    - "/work-dir/index.html"
    - http://info.cern.ch
    volumeMounts:
    - name: workdir
      mountPath: "/work-dir"
  dnsPolicy: Default
  volumes:
  - name: workdir
    emptyDir: {}

配置檔案中,你可以看到應用容器和 Init 容器共享了一個卷。

Init 容器將共享卷掛載到了 /work-dir 目錄,應用容器將共享卷掛載到了 /usr/share/nginx/html 目錄。 Init 容器執行完下面的命令就終止:

wget -O /work-dir/index.html http://info.cern.ch

請注意 Init 容器在 nginx 伺服器的根目錄寫入 index.html。

作者:Varden 出處:http://www.cnblogs.com/varden/ 本文內容如有雷同,請聯絡作者! 本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段宣告,且在文章頁面明顯位置給出原文連線,否則保留追究法律責任的權利。