Deploying to Kubernetes cluster using runner from GitLab

9/28/2019

I've integrated GitLab with my Digital Ocean Kubernetes cluster. I am trying to set up a simple manual build that will deploy to my Kubernetes cluster.

My gitlab-ci-yml file details are below:

deploy:
  stage: deploy
  image: bitnami/kubectl:latest
  script:
    - kubectl version
    - kubectl apply -f web.yaml

I am not sure why this is not working. Currently getting the following error:

Error from server (Forbidden): error when retrieving current configuration ... from server for: "web.yaml": ingresses.extensions "hmweb-ingress" is forbidden: User "system:serviceaccount:gitlab-managed-apps:default" cannot get resource "ingresses" in API group "extensions" in the namespace "hm-ns01"

As far as I can understand it cannot execute the kubectl apply .. commands

Am I doing something wrong?

-- Rutnet
gitlab
gitlab-ci-runner
kubernetes

1 Answer

4/5/2020

I think you are missing the environment in your deploy job. Modify your job definition to look something like this:

deploy:
  stage: deploy
  image: bitnami/kubectl:latest
  environment:
    name: production
  script:
    - kubectl version
    - kubectl apply -f web.yaml

Where "production" is interchangable with any environment name.

At least that fixed the issue for me.

-- stefanpartheym
Source: StackOverflow