<p>im using this tutorial :
<a href="https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-deploy-elasticsearch.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-deploy-elasticsearch.html</a><br />
if i run it as is . it creates the cluster in the default namespace.<br />
i want to create it in a custom namespace for example &quot;my-cluster&quot;<br />
when running kubectl create -f elasticsearch.yml</p>
<pre><code>apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: my-cluster
  namespace: my-cluster
spec:
  version: 7.10.1
  nodeSets:
  - name: default
    count: 1
    config:
      node.store.allow_mmap: false
</code></pre>
<p>I'm getting error :</p>
<pre><code>Error from server (NotFound): error when creating &quot;elasticsearch.yaml&quot;: namespaces &quot;my-cluster&quot; not found
</code></pre>
<p>can i even use namespace here ?</p>

user63898
<p>The namespace needs to exist before you start deploying Elasticsearch. The error is complaining about the absence of <code>my-cluster</code> namespace</p>
<p>You can create namespace by either of below approach</p>
<p>1 - <code>kubectl create namespace my-cluster</code></p>
<p>or</p>
<p>2 - <code>kubectl create -f ns.yaml</code> with content of <code>ns.yaml</code> as below</p>
<pre><code>apiVersion: v1
kind: Namespace
metadata:
  name: my-cluster
</code></pre>
