<p>I use k8s and deploy my application with gitlab. My cluster has for example the namespace <code>production</code>. If I install initially the application I run:</p>

<pre><code>$ helm install --name super-app -f values.yml ./Path/To/Project/helm
</code></pre>

<p>This command will install successfully install the application in the namespace production since its specified in the helm values:</p>

<pre><code>replicaCount: 3
imagePullSecret: regcred
namespace: production
</code></pre>

<p>In the project helm charts the I se the default namespace:</p>

<pre><code>replicaCount: 3
imagePullSecret: regcred
namespace: default
</code></pre>

<p>When I run the following command from my gitlab ci runner:</p>

<pre><code>helm upgrade -f ./values.yaml --set image.tag=master-$DOCKER_IMAGE_TAG super-app ./helm
</code></pre>

<p>In the values.yaml is again the namespace production specified, I get the following result:</p>

<pre><code>Release "super-app has been upgraded.
LAST DEPLOYED: Wed Oct 23 12:15:36 2019
NAMESPACE: production
STATUS: DEPLOYED

RESOURCES:
==&gt; v1/ConfigMap
NAME        DATA  AGE
super-app  1     0s

==&gt; v1/Deployment
NAME        READY  UP-TO-DATE  AVAILABLE  AGE
super-app  0/3    3           0          0s

==&gt; v1/Pod(related)
NAME                        READY  STATUS             RESTARTS  AGE
super-app-5d6dc6c9d-25q9g  0/1    ContainerCreating  0         0s
super-app-5d6dc6c9d-tdfhh  0/1    ContainerCreating  0         0s
super-app-5d6dc6c9d-z7h96  0/1    ContainerCreating  0         0s

==&gt; v1/Secret
NAME        TYPE    DATA  AGE
super-app  Opaque  0     0s

==&gt; v1/Service
NAME        TYPE          CLUSTER-IP      EXTERNAL-IP  PORT(S)         AGE
super-app  LoadBalancer  10.100.115.194  &lt;pending&gt;    8080:32645/TCP  0s
</code></pre>

<p>The application is now deployed in the namespace default and not in production. Even though the existing application (before the helm upgrade command) is running in production namespace. Helm just creates a new Service and application in default namespace.
The same logic works for other applications, why does k8s ignore my namespace config?</p>

<p>Thanks</p>

<p>Although it's not documented in <a href="https://helm.sh/docs/chart_best_practices/" rel="nofollow noreferrer">Chart Best Practices</a> yet, this issue (<a href="https://github.com/helm/helm/issues/5465#issuecomment-473942223" rel="nofollow noreferrer">#5465</a>) addresses namespaces considerations:</p>

<blockquote>
  <p>In general, templates should not define a namespace. This is because
  Helm installs objects into the namespace provided with the <code>--namespace</code>
  flag. By omitting this information, it also provides templates with
  some flexibility for post-render operations (like <code>helm template |
  kubectl create --namespace foo -f -</code>)</p>
</blockquote>

<p>As quoted, your best option is to add the <code>--namespace</code> to your install/upgrade commands instead of defining it on your templates.</p>
