<p>I did a small deployment in K8s using Docker image but it is not showing in deployment but only showing in pods.
Reason: It is not creating any default namespace in deployments.</p>

<p>Please suggest:</p>

<p>Following are the commands I used.</p>

<pre><code>$ kubectl run hello-node --image=gcr.io/$DEVSHELL_PROJECT_ID/hello-node:1.0 --port=8080 --namespace=default
pod/hello-node created

$ kubectl get pods
NAME         READY   STATUS    RESTARTS   AGE
hello-node   1/1     Running   0          12s

$ kubectl get pods --all-namespaces
NAMESPACE     NAME                                                       READY   STATUS    RESTARTS   AGE
default       hello-node                                                 1/1     Running   0          9m9s
kube-system   event-exporter-v0.2.5-599d65f456-4dnqw                     2/2     Running   0          23m
kube-system   kube-proxy-gke-hello-world-default-pool-c09f603f-3hq6      1/1     Running   0          23m

$ kubectl get deployments
**No resources found in default namespace.**

$ kubectl get deployments --all-namespaces
NAMESPACE     NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
kube-system   event-exporter-v0.2.5                      1/1     1            1           170m
kube-system   fluentd-gcp-scaler                         1/1     1            1           170m
kube-system   heapster-gke                               1/1     1            1           170m
kube-system   kube-dns                                   2/2     2            2           170m
kube-system   kube-dns-autoscaler                        1/1     1            1           170m
kube-system   l7-default-backend                         1/1     1            1           170m
kube-system   metrics-server-v0.3.1                      1/1     1            1           170m
</code></pre>

NewLearner
<p>Arghya Sadhu's answer is correct. In the past <code>kubectl run</code> command indeed created by default a <code>Deployment</code> instead of a <code>Pod</code>. Actually in the past you could use it with so called <a href="https://v1-17.docs.kubernetes.io/docs/reference/kubectl/conventions/#generators" rel="nofollow noreferrer">generators</a> and you were able to specify exactly what kind of resource you want to create by providing <code>--generator</code> flag followed by corresponding value. Currently <code>--generator</code> flag is deprecated and has no effect.   </p>

<p>Note that you've got quite clear message after running your <code>kubectl run</code> command:</p>

<pre><code>$ kubectl run hello-node --image=gcr.io/$DEVSHELL_PROJECT_ID/hello-node:1.0 --port=8080 --namespace=default
pod/hello-node created
</code></pre>

<p>It clearly says that the <code>Pod</code> <code>hello-node</code> was created. It doesn't mention about a <code>Deployment</code> anywhere.</p>

<p>As an alternative to using <strong>imperative commands</strong> for creating either <code>Deployments</code> or <code>Pods</code> you can use <strong>declarative approach</strong>:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-node
  namespace: default
  labels:
    app: hello-node
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello-node
  template:
    metadata:
      labels:
        app: hello-node
    spec:
      containers:
      - name: hello-node-container
        image: gcr.io/$DEVSHELL_PROJECT_ID/hello-node:1.0
        ports:
        - containerPort: 8080
</code></pre>

<p>Declaration of <code>namespace</code> can be ommitted in this case as by default all resources are deployed into the <code>default</code> namespace.</p>

<p>After saving the file e.g. as <code>nginx-deployment.yaml</code> you just need to run:</p>

<pre><code>kubectl apply -f nginx-deployment.yaml
</code></pre>

<h3>Update:</h3>

<p>Expansion of the environment variables within the yaml manifest actually doesn't work so the following line from the above deployment example cannot be used:</p>

<pre><code>image: gcr.io/$DEVSHELL_PROJECT_ID/hello-node:1.0
</code></pre>

<p>The simplest workaround is a fairly simple <code>sed</code> "trick".</p>

<p>First we need to change a bit our project id's placeholder in our deployment definition yaml. It may look like this:</p>

<pre><code>image: gcr.io/{{DEVSHELL_PROJECT_ID}}/hello-node:1.0
</code></pre>

<p>Then when applying the deployment definition instead of simple <code>kubectl apply -f deployment.yaml</code> run this one-liner:</p>

<pre><code>sed "s/{{DEVSHELL_PROJECT_ID}}/$DEVSHELL_PROJECT_ID/g" deployment.yaml | kubectl apply -f -
</code></pre>

<p>The above command tells <code>sed</code> to search through <code>deployment.yaml</code> document for <code>{{DEVSHELL_PROJECT_ID}}</code> string and each time this string occurs, to substitute it with the actual value of <code>$DEVSHELL_PROJECT_ID</code> environment variable.</p>
