DEV Community

Cover image for Deploy to google kubernetes engine using gitlab ci
rhazn
rhazn

Posted on • Edited on • Originally published at heltweg.org

1 1

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
Enter fullscreen mode Exit fullscreen mode

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 at https://heltweg.org.

Top comments (0)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay