Cannot deploy on Kubernetes after removing namespace

I installed the gitlab-runner in our Kubernetes cluster and copied the auto deploy Helm template into a project. It deploys nicely, although the url paramter seems to be ignored.

To clean up the deployment I removed the namespace that the project was deployed in. Following deployments fail with:

$ ensure_namespace
error: the server doesn't have a resource type "namespace"
error: You must be logged in to the server (Unauthorized)

The only way I have found to fix this is to remove the Kubernetes cluster from Gitlab and add it again, but I would like something simpler. What am I doing wrong?

I am having the same problem. Our workaround is to manage the $KUBE_NAMESPACE in .gitlab-ci.yml so we don’t depend on some of the hidden scripts in GitLab anymore.

GitLab creates a namespace and service account for your environment the first time it runs. This account is used to create your deployments, services and ingresses. The account seems to be cached somewhere, it’s the only explanation I can come up with. If you remove the namespace (we sometimes do to start fresh), GitLab tries to use the credentials it has stored and fails.

I have contacted support about this but haven’t yet received a reply.

I ran into the same problem.

It looks like if you delete a namespace manually or removed the service account. Gitlab doesn’t know the service account disappeared so it will fail with the old account. In theory it should check this and do the right thing.

I was able to fix it but you have to know how to manipulate postgres

The account should be in clusters_kubernetes_namespaces table and remove the associated account there.

1 Like

Looks like in 12.6 there will be a way to clear the cache.