How to update a Kubernetes deployment on Google Container Engine?

9/28/2016

I've followed a few guides, and I've got CI set up with Google Container Engine and Google Container Registry. The problem is my updates aren't being applied to the deployment.

So this is my deployment.yml which contains a Kubernetes Service and Deployment:

apiVersion: v1
kind: Service 
metadata:
  name: my_app
  labels:
    app: my_app
spec:
  type: LoadBalancer 
  ports:
    - port: 80
      targetPort: 3000
  selector:
    app: my_app
--- 
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my_app
spec:
  replicas: 1 
  template: 
    metadata:
      labels:
        app: my_app
    spec:
      containers:
        - name: node 
          image: gcr.io/me/my_app:latest
          ports:
            - containerPort: 3000
          resources:
            requests:
              memory: 100

        - name: phantom
          image: docker.io/wernight/phantomjs:2.1.1
          command: ["phantomjs", "--webdriver=8910", "--web-security=no", "--load-images=false", "--local-to-remote-url-access=yes"]
          ports: 
            - containerPort: 8910
          resources:
            requests:
              memory: 1000

As part of my CI process I run a script which updates the image in google cloud registry, then runs kubectl apply -f /deploy/deployment.yml. Both tasks succeed, and I'm notified the Deployment and Service has been updated:

2016-09-28T14:37:26.375Zgoogleclouddeploymentservice "my_app" configured
2016-09-28T14:37:27.370Zgoogleclouddeploymentdeployment "my_app" configured

Since I've included the :latest tag on my image, I thought the image would be downloaded each time the deployment is updated. Acccording to the docs a RollingUpdate should also be the default strategy.

However, when I run my CI script which updates the deployment - the updated image isn't downloaded and the changes aren't applied. What am I missing? I'm assuming that since nothing is changing in deployment.yml, no update is being applied. How do I get Kubernetes to download my updated image and use a RollingUpdate to deploy it?

-- Sam P
docker
google-cloud-platform
google-kubernetes-engine
kubernetes

2 Answers

1/15/2018

We have recently published a technical overview of how the approach that we call GitOps approach can be implemented in GKE.

All you need to do is configure GCR builder to pick-up code changes from Github and run builds, you then install Weave Cloud agent in your cluster and connect to a repo where YAML files are stored, and the agent will take care of updating the repo with new images and applying the changes to the cluster.

For a more high-level overview, see also:


Disclaimer: I am a Kubernetes contributor and Weaveworks employee. We build open-source and commercial tools that help people to get to production with Kubernetes sooner.

-- errordeveloper
Source: StackOverflow

9/28/2016

You can force an update of a deployment by changing any field, such as a label. So in my case, I just added this at the end of my CI script:

kubectl patch deployment fb-video-extraction -p \
  "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
-- Sam P
Source: StackOverflow