<p>I am using <code>kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml</code> to create deployment.</p>

<p>I want to create deployment in my namespace <code>examplenamespace</code>.</p>

<p>How can I do this?</p>

<p>There are three possible solutions.</p>
<ol>
<li>Specify namespace in the <code>kubectl</code> <code>apply</code> or <code>create</code> command:</li>
</ol>
<pre><code>kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml -n my-namespace
</code></pre>
<ol start="2">
<li>Specify namespace in your <code>yaml</code> files:</li>
</ol>
<pre><code>  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: my-deployment
    namespace: my-namespace
</code></pre>
<ol start="3">
<li>Change default namespace in <code>~/.kube/config</code>:</li>
</ol>
<pre><code>apiVersion: v1
kind: Config
clusters:
- name: &quot;k8s-dev-cluster-01&quot;
  cluster:
    server: &quot;https://example.com/k8s/clusters/abc&quot;
    namespace: &quot;my-namespace&quot;
</code></pre>
