init container


init container與應用容器在本質上是一樣的, 但它們是僅運行一次就結束的任務, 並且必須在成功執行完成后, 系統才能繼續執行下一個容器, 可以用在例如應用容器啟動前做一些初始化工作,當init container執行失敗, 而且設置了RestartPolicy=Never時, Pod將會啟動失敗, 而設置了RestartPolicy=Always時, pod將會被系統自動重啟

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  namespace: default 
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      initContainers: 
      - name: install
        image: busybox
        imagePullPolicy: IfNotPresent
        command:
        - wget
        - "-O"
        - "/work-dir/index.html"
        - http://kubernetes.io
        volumeMounts:
        - name: workdir
          mountPath: "/work-dir"
      containers:
      - name: nginx
        image: nginx:1.12
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
        volumeMounts:
        - name: workdir
          mountPath: "/usr/share/nginx/html"
      volumes:
      - name: workdir
        emptyDir: {} 

---
apiVersion: v1 
kind: Service
metadata:
  name: nginx-service
  namespace: default 
  labels:
    app: nginx
spec:
  type: NodePort
  selector: 
    app: nginx
  ports:
  - name: http
    port: 80 
    protocol: TCP 
    targetPort: 80 
---


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM