Created
May 20, 2019 08:52
-
-
Save shalkam/f815cae93e6fa5858c14e0ddf5cd70f6 to your computer and use it in GitHub Desktop.
using service account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Cool idea when using kubectl in gitlab-runner in K8S pod. May a one-line way be: