<p>I create a pod to test my service in kubernetes. But i didn't get anythings. Here is my command</p>

<pre><code>kubectl run --generator=run-pod/v1 nginx-resolver --image=nginx
kubectl expose pod nginx-resolver --name=nginx-resolver-service --port=80 --target-port=80 --type=ClusterIP

kubectl run --generator=run-pod/v1 test-nslookup --image=busybox:1.28 --rm -it -- nslookup nginx-resolver-service

</code></pre>

<p>Please help me explain why. Thanks</p>

Shane
<p>Run the following command and get things what you are thinking wrong about this cmd.</p>

<pre class="lang-sh prettyprint-override"><code>$ kubectl run --help
Create and run a particular image, possibly replicated.

 Creates a deployment or job to manage the created container(s).

Examples:
  # Start a single instance of nginx.
  kubectl run nginx --image=nginx

  # Start a single instance of hazelcast and let the container expose port 5701 .
  kubectl run hazelcast --image=hazelcast --port=5701
...
</code></pre>

<p>So, <code>kubectl run</code> cmd creates a deployment or a job</p>

<ul>
<li>If it is a deployment, it creates (a) first, a replicaset, (b) then Pod(s).</li>
<li>If it is a job, it creates a Pod.</li>
</ul>

<p>But you are trying to expose a Pod which name is not the correct one. You can see the name of the Pod that is/are created by the cmd <code>kubectl run</code>.</p>

<pre class="lang-sh prettyprint-override"><code>$ kubectl get pods --namespace=&lt;namespace&gt; | grep "nginx-resolver"
$ kubectl get pods --namespace=&lt;namespace&gt; | grep "test-nslookup"
</code></pre>

<p>Then use those names to expose Pod.</p>

<p>You can optionally expose your <code>Deployment</code>. To do so, see the help of <code>$ kubectl expose deployment --help</code>. Run:</p>

<pre class="lang-sh prettyprint-override"><code>$ kubectl expose deployment --help
Expose a resource as a new Kubernetes service.

 Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that
resource as the selector for a new service on the specified port. A deployment or replica set will be exposed as a
service only if its selector is convertible to a selector that service supports, i.e. when the selector contains only
the matchLabels component. Note that if no port is specified via --port and the exposed resource has multiple ports, all
will be re-used by the new service. Also if no labels are specified, the new service will re-use the labels from the
resource it exposes.

 Possible resources include (case insensitive):

 pod (po), service (svc), replicationcontroller (rc), deployment (deploy), replicaset (rs)

Examples:
...
  # Create a service for an nginx deployment, which serves on port 80 and connects to the containers on port 8000.
  kubectl expose deployment nginx --port=80 --target-port=8000
...
</code></pre>
