<p>As I'm playing around with K8s deployment and Gitlab CI my deployment got stuck with the state <code>ContainerStarting</code>.</p>

<p>To reset that, I deleted the K8s namespace using <code>kubectl delete namespaces my-namespace</code>.</p>

<p>Now my Gitlab runner shows me </p>

<pre><code>$ ensure_namespace
Checking namespace [MASKED]-docker-3
error: the server doesn't have a resource type "namespace"
error: You must be logged in to the server (Unauthorized)
</code></pre>

<p>I think that has something to do with RBAC and most likely Gitlab created that namespace with some arguments and permissions (but I don't know exactly when and how that happens), which are missing now because of my deletion.</p>

<p>Anybody got an idea on how to fix this issue?</p>

<p>In my case I had to delete the namespace in Gitlab database, so gitlab would readd service account and namespace:</p>

<p>On the gitlab machine or task runner enter the PostgreSQL console:</p>

<pre><code>gitlab-rails dbconsole -p
</code></pre>

<p>Then select the database:</p>

<pre><code>\c gitlabhq_production
</code></pre>

<p>Next step is to find the namespace that was deleted:</p>

<pre><code>SELECT id, namespace FROM clusters_kubernetes_namespaces;
</code></pre>

<p>Take the id of the namespace to delete it:</p>

<pre><code>DELETE FROM clusters_kubernetes_namespaces WHERE id IN (6,7);
</code></pre>

<p>Now you can restart the pipeline and the namespace and service account will be readded.</p>
