Kubernetes Deployments and Init Containers

前端 未结 2 1760
离开以前
离开以前 2021-02-13 05:46

I learned recently that Kubernetes has a feature called Init Containers. Awesome, because I can use this feature to wait for my postgres service and create/migrate the database

2条回答
  •  终归单人心
    2021-02-13 06:30

    To avoid confusion, ill answer your specific question. i agree with oswin that you may want to consider another method.

    Yes, you can use init containers with a deployment. this is an example using the old style (pre 1.6) but it should work

    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: 'nginx'
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: 'nginx'
    
      template:
        metadata:
          labels:
            app: 'nginx'
          annotations:
            pod.beta.kubernetes.io/init-containers: '[
                {
                    "name": "install",
                    "image": "busybox",
                    "imagePullPolicy": "IfNotPresent",
                    "command": ["wget", "-O", "/application/index.html", "http://kubernetes.io/index.html"],
                    "volumeMounts": [
                        {
                          "name": "application",
                          "mountPath": "/application"
                        }
                    ]
                }
            ]'
        spec:
          volumes:
            - name: 'application'
              emptyDir: {}
    
          containers:
    
          - name: webserver
            image: 'nginx'
            ports:
            - name: http
              containerPort: 80
            volumeMounts:
              - name: 'application'
                mountPath: '/application'
    

提交回复
热议问题