Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl patch initContainers image doesn't work #27

Closed
tomfotherby opened this issue Jun 9, 2017 · 3 comments
Closed

kubectl patch initContainers image doesn't work #27

tomfotherby opened this issue Jun 9, 2017 · 3 comments

Comments

@tomfotherby
Copy link

Is this a request for help? : Nope

What keywords did you search in Kubernetes issues before filing this one? : "patch"


Is this a BUG REPORT or FEATURE REQUEST? : BUG REPORT?

Kubernetes version (use kubectl version): v1.6.2

Client Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.2", GitCommit:"477efc3cbe6a7effca06bd1452fa356e2201e1ee", GitTreeState:"clean", BuildDate:"2017-04-19T20:33:11Z", GoVersion:"go1.7.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.4+coreos.0", GitCommit:"8996efde382d88f0baef1f015ae801488fcad8c4", GitTreeState:"clean", BuildDate:"2017-05-19T21:11:20Z", GoVersion:"go1.7.5", Compiler:"gc", Platform:"linux/amd64"}

Environment:

  • Cloud provider or hardware configuration: aws
  • OS (e.g. from /etc/os-release): CoreOS
  • Install tools: Tack

What happened:

I have a pod that contains nginx and php-fpm containers that need to reference the same sourcecode. To do this I use a initContainers to copy some sourcecode to a emptyDir volume. It works nicely.

To deploy a new version of the app, the only thing that needs changing is the image of the container in the initContainers. I would like to be able to patch it like this:

$ kubectl patch deployment thedeployment -p'{"spec":{"template":{"spec":{"initContainers":[{"name":"init-sourcecode","image":"vendor/app_data:master.53"}]}}}}'

It returns:

deployment "thedeployment" patched

but checking with kubectl get deployment thedeployment -o json | less shows it's not the case.

What you expected to happen:
The deployment should be updated with a the new image. (and a new deployment triggered)

How to reproduce it :

$ cat nginx-test.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-test-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      initContainers:
      - name: init-webpage
        image: busybox
        command: ["sleep", "3"]
        volumeMounts:
        - mountPath: /work-dir
          name: workdir

      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        volumeMounts:
        - name: workdir
          mountPath: /usr/share/nginx/html
      dnsPolicy: Default
      volumes:
      - name: workdir
        emptyDir: {}
kubectl create -f nginx-test.yaml

Try to patch the image to change from busybox:latest to busybox:1.25:

kubectl patch deployment nginx-test-deployment -p'{"spec":{"template":{"spec":{"initContainers":[{"name":"init-webpage","image":"busybox:1.25"}]}}}}'

deployment "nginx-test-deployment" patched

Even though it says it's patched, check busybox image in the deployment to see it's not changed with:

kubectl get deployment nginx-test-deployment -o json | grep busybox
@mengqiy
Copy link
Member

mengqiy commented Jun 9, 2017

After debugging a bit, kubectl is doing its job. It seems the APIserver just ignore the change. Maybe because initContainer is not allowed to be update after created.
The following is the log. You can find initContainers:[map[image:busybox:1.25.
original:
map[kind:Deployment apiVersion:extensions/v1beta1 metadata:map[namespace:default selfLink:/apis/extensions/v1beta1/namespaces/default/deployments/nginx-test-deployment resourceVersion:293 generation:1 creationTimestamp:2017-06-09T18:21:43Z labels:map[app:nginx] name:nginx-test-deployment uid:7d305803-4d40-11e7-a720-480fcf4a5275 annotations:map[deployment.kubernetes.io/revision:1]] spec:map[strategy:map[type:RollingUpdate rollingUpdate:map[maxUnavailable:1 maxSurge:1]] replicas:1 selector:map[matchLabels:map[app:nginx]] template:map[spec:map[containers:[map[volumeMounts:[map[name:workdir mountPath:/usr/share/nginx/html]] terminationMessagePath:/dev/termination-log terminationMessagePolicy:File imagePullPolicy:Always name:nginx image:nginx ports:[map[containerPort:80 protocol:TCP]] resources:map[]]] restartPolicy:Always terminationGracePeriodSeconds:30 dnsPolicy:Default securityContext:map[] schedulerName:default-scheduler volumes:[map[name:workdir emptyDir:map[sizeLimit:0]]] initContainers:[map[terminationMessagePolicy:File imagePullPolicy:Always name:init-webpage image:busybox command:[sleep 3] resources:map[] volumeMounts:[map[name:workdir mountPath:/work-dir]] terminationMessagePath:/dev/termination-log]]] metadata:map[creationTimestamp: labels:map[app:nginx] annotations:map[pod.alpha.kubernetes.io/init-containers:[{"name":"init-webpage","image":"busybox","command":["sleep","3"],"resources":{},"volumeMounts":[{"name":"workdir","mountPath":"/work-dir"}],"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"Always"}] pod.beta.kubernetes.io/init-containers:[{"name":"init-webpage","image":"busybox","command":["sleep","3"],"resources":{},"volumeMounts":[{"name":"workdir","mountPath":"/work-dir"}],"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"Always"}]]]]] status:map[observedGeneration:1 replicas:1 updatedReplicas:1 readyReplicas:1 availableReplicas:1 conditions:[map[type:Available status:True lastUpdateTime:2017-06-09T18:21:43Z lastTransitionTime:2017-06-09T18:21:43Z reason:MinimumReplicasAvailable message:Deployment has minimum availability.]]]]
patch:
map[spec:map[template:map[spec:map[initContainers:[map[name:init-webpage image:busybox:1.25]]]]]]
merged:
map[kind:Deployment apiVersion:extensions/v1beta1 metadata:map[namespace:default selfLink:/apis/extensions/v1beta1/namespaces/default/deployments/nginx-test-deployment resourceVersion:293 generation:1 creationTimestamp:2017-06-09T18:21:43Z labels:map[app:nginx] name:nginx-test-deployment uid:7d305803-4d40-11e7-a720-480fcf4a5275 annotations:map[deployment.kubernetes.io/revision:1]] spec:map[replicas:1 selector:map[matchLabels:map[app:nginx]] template:map[metadata:map[creationTimestamp: labels:map[app:nginx] annotations:map[pod.alpha.kubernetes.io/init-containers:[{"name":"init-webpage","image":"busybox","command":["sleep","3"],"resources":{},"volumeMounts":[{"name":"workdir","mountPath":"/work-dir"}],"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"Always"}] pod.beta.kubernetes.io/init-containers:[{"name":"init-webpage","image":"busybox","command":["sleep","3"],"resources":{},"volumeMounts":[{"name":"workdir","mountPath":"/work-dir"}],"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"Always"}]]] spec:map[terminationGracePeriodSeconds:30 dnsPolicy:Default securityContext:map[] schedulerName:default-scheduler volumes:[map[name:workdir emptyDir:map[sizeLimit:0]]] initContainers:[map[image:busybox:1.25 command:[sleep 3] resources:map[] volumeMounts:[map[name:workdir mountPath:/work-dir]] terminationMessagePath:/dev/termination-log terminationMessagePolicy:File imagePullPolicy:Always name:init-webpage]] containers:[map[ports:[map[containerPort:80 protocol:TCP]] resources:map[] volumeMounts:[map[name:workdir mountPath:/usr/share/nginx/html]] terminationMessagePath:/dev/termination-log terminationMessagePolicy:File imagePullPolicy:Always name:nginx image:nginx]] restartPolicy:Always]] strategy:map[type:RollingUpdate rollingUpdate:map[maxUnavailable:1 maxSurge:1]]] status:map[observedGeneration:1 replicas:1 updatedReplicas:1 readyReplicas:1 availableReplicas:1 conditions:[map[reason:MinimumReplicasAvailable message:Deployment has minimum availability. type:Available status:True lastUpdateTime:2017-06-09T18:21:43Z lastTransitionTime:2017-06-09T18:21:43Z]]]]

@tomfotherby
Copy link
Author

tomfotherby commented Jun 9, 2017

Thanks. Should I close this and open a feature request to the apiserver to ask if the initContainer can be changed?

@mengqiy
Copy link
Member

mengqiy commented Jun 9, 2017

I believe kubernetes/kubernetes#47264 is an issue with same root cause that filed against main repo.
We can close this one.

@mengqiy mengqiy closed this as completed Jun 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants