<p>We are using one namespace for the develop environment and one for the staging environment. Inside each one of this namespaces we have several configMaps and secrets but there are a lot of share variables between the two environments so we will like to have a common file for those.</p>

<p>Is there a way to have a base configMap into the default namespace and refer to it using something like:</p>

<pre><code>- envFrom:
    - configMapRef:
        name: default.base-config-map
</code></pre>

<p>If this is not possible, is there no other way other than duplicate the variables through namespaces?</p>

<h3>Kubernetes 1.13 and earlier</h3>
<p>They cannot be shared, because they cannot be accessed from a pods outside of its namespace. Names of resources need to be unique within a namespace, but not across namespaces.</p>
<p>Workaround it is to copy it over.</p>
<h6>Copy secrets between namespaces</h6>
<pre class="lang-sh prettyprint-override"><code>kubectl get secret &lt;secret-name&gt; --namespace=&lt;source-namespace&gt; --export -o yaml \
  | kubectl apply --namespace=&lt;destination-namespace&gt; -f -
</code></pre>
<h6>Copy configmaps between namespaces</h6>
<pre class="lang-sh prettyprint-override"><code>kubectl get configmap &lt;configmap-name&gt;  --namespace=&lt;source-namespace&gt; --export -o yaml \
  | kubectl apply --namespace=&lt;destination-namespace&gt; -f -
</code></pre>
<h3>Kubernetes 1.14+</h3>
<p><a href="https://github.com/kubernetes/kubernetes/pull/73787" rel="noreferrer">The <code>--export</code> flag was deprecated in 1.14</a>
Instead following command can be used:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl get secret &lt;secret-name&gt; --namespace=&lt;source-namespace&gt;  -o yaml \
  | sed 's/namespace: &lt;from-namespace&gt;/namespace: &lt;to-namespace&gt;/' \
  | kubectl create -f -
</code></pre>
<p>If someone still see a need for the flag, there’s an <a href="https://gist.github.com/zoidbergwill/6af8c80cc5b706e2adcf25df3dc2f7e1#file-export_resources-py" rel="noreferrer">export script</a> written by <a href="https://gist.github.com/zoidbergwill" rel="noreferrer">@zoidbergwill</a>.</p>
