Skip to content

Instantly share code, notes, and snippets.

@kvaps
Forked from shalkam/.gitlab-ci.yml
Created March 27, 2020 20:56
Show Gist options
  • Save kvaps/ebfd82c2f5b6894e3cf8a89698b063a2 to your computer and use it in GitHub Desktop.
Save kvaps/ebfd82c2f5b6894e3cf8a89698b063a2 to your computer and use it in GitHub Desktop.
using service account
stages:
- deploy
deploy_app:
image: bitnami/kubectl:latest
stage: deploy
environment: production
script:
- USER_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
- CERTIFICATE_AUTHORITY_DATA=$(cat /var/run/secrets/kubernetes.io/serviceaccount/ca.crt | base64 -i -w0 -)
- kubectl config set-cluster k8s --server="https://kubernetes.default.svc"
- kubectl config set clusters.k8s.certificate-authority-data ${CERTIFICATE_AUTHORITY_DATA}
- kubectl config set-credentials gitlab --token="${USER_TOKEN}"
- kubectl config set-context default --cluster=k8s --user=gitlab
- kubectl config use-context default
- kubectl set image deployment my-app web=${CI_REGISTRY}/user/repo/${CI_PROJECT_PATH_SLUG}:${CI_COMMIT_SHORT_SHA} --kubeconfig ./config --namespace default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment