Search code examples
dockergitlabdevopsgcloudkaniko

Can someone tell me how to deploy a docker image build with kaniko on gcloud kubernetes cluster using .git-ci.yml file?


Can someone tell me what commands can be written in deploy: stages script tag to push the code on gcloud Kubernetes cluster ?

build:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]

  before_script:
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    - |
      echo "-----BEGIN CERTIFICATE-----
      ...
      -----END CERTIFICATE-----" >> /kaniko/ssl/certs/ca-certificates.crt


  script:
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
  only:
    - master


deploy:
  stage: deploy

  script:

Solution

  • Here are some articles that have examples about how to write the ‘stage: deploy’ section. They can be used as further guidance through the process. You can refer to deployment section.

    • GitLab + Kubernetes: Using GitLab CI's Kubernetes Cluster feature [1].
    • How to create a CI/CD pipeline with Auto Deploy to Kubernetes using GitLab and Helm [2].
    • Automated deployments to Kubernetes with GitLab [3].
    • Automated Kubernetes deployments with GitLab, Helm and Traefik [4].

    Sincerely,

    [1] https://edenmal.moe/post/2018/GitLab-Kubernetes-Using-GitLab-CIs-Kubernetes-Cluster-feature/#step-6-add-docker-login-information-to-kubernetes [2] https://about.gitlab.com/2017/09/21/how-to-create-ci-cd-pipeline-with-autodeploy-to-kubernetes-using-gitlab-and-helm[3] https://sanderknape.com/2019/02/automated-deployments-kubernetes-gitlab/ [4] https://medium.com/@yanick.witschi/automated-kubernetes-deployments-with-gitlab-helm-and-traefik-4e54bec47dcf