Kubernetes 部署未检测到init容器中容器映像标记的更改

Kubernetes 部署未检测到init容器中容器映像标记的更改,kubernetes,google-cloud-platform,google-kubernetes-engine,Kubernetes,Google Cloud Platform,Google Kubernetes Engine,自从init容器可用以来,我一直在使用它们,并发现它们非常有用。我的核心映像(以下称为web开发人员)变化不大,但我的init容器映像(以下称为web数据开发人员)确实经常变化 init容器使用具有版本号的容器映像。我将此版本号更改为最新值,然后执行kubectl apply-f部署。yaml 例如,在运行kubectl apply之前,我将eu.gcr.io/project/web数据开发:187更改为eu.gcr.io/project/web数据开发:188 但是,当我这样做时,不会发生部署

自从init容器可用以来,我一直在使用它们,并发现它们非常有用。我的核心映像(以下称为web开发人员)变化不大,但我的init容器映像(以下称为web数据开发人员)确实经常变化

init容器使用具有版本号的容器映像。我将此版本号更改为最新值,然后执行kubectl apply-f部署。yaml

例如,在运行kubectl apply之前,我将eu.gcr.io/project/web数据开发:187更改为eu.gcr.io/project/web数据开发:188

但是,当我这样做时,不会发生部署,如果我对init容器使用的映像进行任何更改,部署仍然不会发生。我假设这是因为没有检测到init容器的更改

然后我尝试在image字段中放入一些垃圾,如:“image”:“thisIsNotAnImage”并再次运行kubectl apply-f,但更新仍然没有应用

我的问题是-如何让kubectl应用-f检测init容器中的图像标记更改?我是否做错了什么,这是一个bug,还是因为init容器是Alpha的,所以还没有实现

完整部署YAML如下所示

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: web-deployment
spec:
  replicas: 1
  strategy:
    rollingUpdate:
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: web
        tier: frontend
      annotations:
        pod.alpha.kubernetes.io/init-containers: '[
            {
                "name": "initialiser1",
                "image": "eu.gcr.io/project/web-data-dev:187",
                "command": ["cp", "-r", "/data-in/", "/opt/"],
                "volumeMounts": [
                    {
                        "name": "file-share",
                        "mountPath": "/opt/"
                    }
                ]
            }
        ]'
    spec:
      containers:

        - image: eu.gcr.io/project/web-dev:20
          name: web
          resources:
            requests:
              cpu: 10m
              memory: 40Mi
          ports:
            - containerPort: 80
              name: http
            - containerPort: 443
              name: https
          volumeMounts:
            - name: file-share
              mountPath: /opt/

      volumes:
        - name: file-share
          emptyDir: {}

如果您使用的是Kubernetes 1.4,请尝试将
pod.alpha.Kubernetes.io/init容器
更改为
pod.beta.Kubernetes.io/init容器

我在GitHub上找不到合适的问题,但这两个注释的行为是不同的。我可以使用第二个应用程序执行
kubectl apply-f
,部署将被更新

您可以使用以下示例对其进行测试:

kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: nginx
spec:
  template:
    metadata:
      labels:
        app: nginx
      annotations:
        pod.beta.kubernetes.io/init-containers: '[
            {
                "name": "install",
                "image": "busybox",
                "command": ["/bin/sh", "-c", "echo foo > /work-dir/index.html"],
                "volumeMounts": [
                  {
                    "name": "workdir",
                    "mountPath": "/work-dir"
                    }
                ]
            }
        ]'
    spec:
      volumes:
        - name: workdir
          emptyDir: {}
      containers:
        - name: nginx
          image: nginx
          ports:
            - containerPort: 80
          volumeMounts:
            - name: workdir
              mountPath: /usr/share/nginx/html
尝试将
foo
更改为
bar
,然后查看结果:

$ cat nginx.yaml | kubectl apply -f -
deployment "nginx" created
$ curl $(minikube service nginx --url)
Waiting, endpoint for service is not ready yet...
foo
$ cat nginx.yaml | sed -e 's/foo/bar/g' | kubectl apply -f -
deployment "nginx" configured
$ curl $(minikube service nginx --url)
Waiting, endpoint for service is not ready yet...
bar
使用
pod.alpha.kubernetes.io/init容器时也会遇到同样的问题

$ curl $(minikube service nginx --url)
Waiting, endpoint for service is not ready yet...
foo
$ cat nginx.yaml | sed -e 's/foo/bar/g' | kubectl apply -f -
deployment "nginx" configured
$ curl $(minikube service nginx --url)
foo

谢谢,这成功了-一定是Alpha版本的小故障-干杯!