Kubernetes operation - unable to recreate the namespace

Today I’ve stumbled upon the strange problem, after kubernetes cluster restart I was unable to connect using kubernates operations, I’ve got an error in my job:

Error: Kubernetes cluster unreachable: the server has asked for the client to provide credentials

33error: You must be logged in to the server (Unauthorized)

This was an error when doing kubectl operation from the script, but the namespace was not created, so I assumed the configuration is broken and I’ve deleted the configuration and created it again, after that everything worked.

But I’ve inspected it more carefully and stated, that the gitlab CI is unable to recreate the namespace, if it was deleted.

We are using dynamic environments, specified by ENV variable, so that when starting the pipeline, we can deploy to the other stage. Sometimes we need more stages, that need to be cleaned up. Because Gitlab doesn’t delete created namespaces, we’ve done that manually. And after that, the job has failed, when trying to use one of the ‘stages’, for which the namespace was deleted.

Steps to replicate:

  1. Run the pipeline
  2. Delete the namespace created by the pipeline
  3. Run the pipeline again with the same parameter

Actual behavior

Errors stating that you are unauthorized. The namespace is not created.

Expected behavior

The namespace is created. No errors.

Hi @riag.llech
while you can post bug reports here, if it might be better to post it directly to GitLab project issues.