Skip to content
Go back

Deploy to google kubernetes engine using gitlab ci

In a previous blogpost I showed how I build and publish docker images on gitlab ci (Build a docker image on gitlab ci)

Make sure to read that post first for an overview and permission setup.

Update the kubernetes service with the new docker image

You can easily set up a deploy step using google’s own cloud SDK docker images. Note the service account with the permissions to change the kubernetes setup is saved as “GCLOUD_K8S_KEY” variable here.

This job changes the image of my deployment for the app. You will need to change the last line in the script to whatever change you want to make to your kubernetes setup on deploy.

deploy:
  stage: deploy
  image: google/cloud-sdk:257.0.0
  script:
    - echo $GCLOUD_K8S_KEY | base64 -d > ${HOME}/gcloud-k8s-key.json
    - gcloud auth activate-service-account --key-file ${HOME}/gcloud-k8s-key.json
    - gcloud config set project personal-cloud-project-id
    - gcloud config set compute/zone your-compute-zone
    - gcloud container clusters get-credentials production
    - kubectl set image deployment/???-app ???-app=eu.gcr.io/docker-project-id/app:${CI_COMMIT_SHA}
  only:
    - master
  when: manual

About Me

I am an indie maker & researcher with a doctorate in computer science, interested in (among others): Software engineering, open data, data science, startups and esports.

See /about for details.

Have feedback, comments? Email me: philip@heltweg.org.

I (very occasionally) send out a newsletter when publishing new articles like this.

Subscribe ↗

Share this post on:

Previous Post
Build a docker image on gitlab ci and publish it to google container registry
Next Post
Build a progressive web app in docker with nginx to deploy to kubernetes or docker swarm