<p>I see the following error when I run my deployment:</p>

<p><code>Error from server (NotFound): error when creating "n3deployment.yaml": namespaces "n2" not found</code></p>

<p>My n3deployment.yaml has no reference to n2?</p>

<p><strong>Step By Step</strong></p>

<ol>
<li>Ensure everything is empty</li>
</ol>

<pre><code>c:\temp\k8s&gt;kubectl get pods
No resources found.

c:\temp\k8s&gt;kubectl get svc
No resources found.

c:\temp\k8s&gt;kubectl get deployments
No resources found.

c:\temp\k8s&gt;kubectl get namespaces
NAME          STATUS    AGE
default       Active    20h
docker        Active    20h
kube-public   Active    20h
kube-system   Active    20h
</code></pre>

<ol start="2">
<li>Create files</li>
</ol>

<pre><code>n3namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: n3

n3service.yaml
apiVersion: v1
kind: Service
metadata:
  name: my-app-n3
  namespace: n3
  labels:
    app: my-app-n3
spec:
  type: LoadBalancer
  ports:
  - name: http
    port: 80
    targetPort: http
    protocol: TCP
  selector:
    app: my-app-n3

n3deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-n3
  labels:
    app: my-app-n3
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app-n3
  template:
    metadata:
      labels:
        app: my-app-n3
    spec:
      containers:
      - name: waiter
        image: waiter:v1
        ports:
        - containerPort: 80
</code></pre>

<ol start="3">
<li>Apply configuration</li>
</ol>

<pre><code>c:\temp\k8s&gt;kubectl apply -f n3namespace.yaml
namespace "n3" created

c:\temp\k8s&gt;kubectl apply -f n3service.yaml
service "my-app-n3" created

c:\temp\k8s&gt;kubectl apply -f n3deployment.yaml
Error from server (NotFound): error when creating "n3deployment.yaml": namespaces "n2" not found
</code></pre>

<p>I used to have a namespace called <code>n2</code> but, as you can see, it no longer exists.</p>

A. Gardner
<p>I had previously created two contexts and my minikube cluster was set to still be in the <code>n2</code> context. I deleted the context, re-ran the command and it worked.</p>
