iaquobe
iaquobe

Reputation: 737

Why is `KUBE_NAMESPACE` not set anymore?

I'm using Gitlab autodevops with a Kubernetes cluster(Gitlab runner with the Kubernetes Executor).

A while ago the deployments used to be in project specific namespaces like project-5648-nut-qa-9yg86f, but now they are deployed in default.

The namespace is determined with KUBE_NAMESPACE which should be automatically set by gitlab accoriding to the docs. I created a simple Job to get the environment variables:

env build:
  extends: .auto-deploy
  stage: build
  tags: 
    - nut
  script:
    - env
    - auto-deploy ensure_namespace
  environment:
    name: nut/staging
    url: https://$CI_PROJECT_PATH_SLUG.nut.$KUBE_INGRESS_BASE_DOMAIN

But there is no variable called KUBE_NAMESPACE in there and auto-deploy ensure_namespace uses the defaultnamespace

$ auto-deploy ensure_namespace
NAME      STATUS   AGE
default   Active   230d

Why is KUBE_NAMESPACE not set?
The server with the cluster has been rebooted a few times. Everytime it reboots a new runner is created, is it possible that this is the cause of the error?
And how can I get a value for KUBE_NAMESPACE again?

Upvotes: 6

Views: 1193

Answers (1)

Věroš K.
Věroš K.

Reputation: 116

I've spend few hours figuring out that my KUBE_NAMESPACE is empty too.

I don't know which part of configuration should I modify. I've add its setup to default .gitlab-ci.yml. In my case I've added it to global templates.

variables:
 KUBE_NAMESPACE: "$CI_PROJECT_NAME-$CI_PROJECT_ID-$CI_ENVIRONMENT_SLUG"

It works (at the moment).

Upvotes: 0

Related Questions