Deploy to google kubernetes engine using gitlab ci

Philip Heltweg

September 3, 2019

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.

I am a freelancer and would love to help you!
EMAIL ME 👋

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 a full stack developer and digital product enthusiast. I am available for freelance work and always looking for the next exciting project :).
You can reach me online either by email (pheltweg@gmail.com) or on twitter https://twitter.com/rhanarion.