4

I'm trying to set up a full CI/CD pipeline for a SpringBoot application, starting from a GitLab repository (see https://gitlab.com/pietrom/clock-api) and automatically deploying to a Kubernetes Cluster backed by Google Cloud Platform.

My pipeline works quite fine (the app is built, it is packaged as a Docker image, the image is published on my project registry and containers are started for both staging and production environment), except for a detail: Operation/Environments page shows me both environments, with the following warning:

Kubernetes deployment not found To see deployment progress for your environments, make sure your deployments are in Kubernetes namespace <projectname>, and annotated with app.gitlab.com/app=$CI_PROJECT_PATH_SLUG and app.gitlab.com/env=$CI_ENVIRONMENT_SLUG. 

I googled around a bit but I can't resolve this problem: my deployment.yml contains requested annotation, both for deployment and pod:

apiVersion: extensions/v1beta1 kind: Deployment metadata: name: clock-api-ENVIRONMENT annotations: app.gitlab.com/app: "PROJECT_PATH_SLUG" app.gitlab.com/env: "ENVIRONMENT" spec: replicas: 1 template: metadata: labels: app: ENVIRONMENT annotations: prometheus.io/scrape: "true" prometheus.io/port: "8080" prometheus.io/path: "/actuator/prometheus" app.gitlab.com/app: "PROJECT_PATH_SLUG" app.gitlab.com/env: "ENVIRONMENT" spec: containers: - name: clock-api-ENVIRONMENT image: registry.gitlab.com/pietrom/clock-api imagePullPolicy: Always ports: - containerPort: 8080 imagePullSecrets: - name: registry.gitlab.com 

PROJECT_PATH_SLUG and ENVIRONMENT placeholder are substituded (using sed) during pipeline execution with values provided by GitLab infrastructure ($CI_PROJECT_PATH_SLUG and $CI_ENVIRONMENT_SLUG, respectively) and I can see the expected values in my GCP console, but GitLab integration does not seem to work.

I'm missing something but I can't figure what differences there are between my deployment setup and the official documentation available here.

Thanks in advance for your help!

8
  • What about namespace? Did you check it too? Commented Jul 17, 2019 at 21:39
  • I deploy on Kubernates using the project name (clock-api in my case) as the namespace value... Should I use any other value?? Commented Jul 18, 2019 at 5:24
  • I tried with --namespace $CI_PROJECT_PATH_SLUG (i.e. pietrom-clock-api in my case), too, but the result is the same: everything in the pipeline works fine, but Environment page shows the Kubernetes deployment not found warning... Commented Jul 18, 2019 at 7:01
  • Does namespace itself exist on the cluster? Sometimes GitLab fails to create it, for example when cluster is added after project is created. See how they do it in AutoDevOps: gitlab.com/gitlab-org/gitlab-ce/blob/… Commented Jul 18, 2019 at 7:57
  • 1
    It works!! Thank you very much! If you want write an answer with your suggestion, I'll accept it. Commented Jul 18, 2019 at 11:27

1 Answer 1

4

This is also an important part:

make sure your deployments are in Kubernetes namespace

GitLab tries to manage namespaces in the attached Kubernetes cluster - creates a new namespace for every new GitLab project. It generates namespace from project name and project id.

Sometimes GitLab fails to create namespace, for example when cluster is added after project is created. It's probably a bug, and here is how they overcome it in AutoDevOps:

 function ensure_namespace() { kubectl get namespace "$KUBE_NAMESPACE" || kubectl create namespace "$KUBE_NAMESPACE" } 

This env var $KUBE_NAMESPACE - is defined by GitLab automatically, as well as many other Kubernetes-related variables: https://docs.gitlab.com/ee/user/project/clusters/#deployment-variables

Then GitLab relies on this namespace internally and uses for various UI pages of the project, including Operations/Environment. So if you follow their convention, and apply your Kubernetes deployment to this namespace, GitLab will see your application.

In our work we go one step further and at the beginning of a job even set this namespace as the default.

kubectl config set-context --current --namespace="$KUBE_NAMESPACE" 

Then all further kubectl commands will by default use this namespace.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.