<p>I'm using docker desktop on Mac in order to learn Kubernetes. I'm creating a deployment like this:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend-k8s-hands-on
  annotations:
    kubernetes.io/change-cause: "Changing image"
  labels:
    app: backend
spec:
  replicas: 3
  selector:
    matchLabels:
      app: backend
  template:
    metadata:
      labels:
        app: backend
    spec:
      containers:
      - name: nginx
        image: k8s-hands-on
        imagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
  name: backend-k8s-hands-on
  labels:
    app: backend 
spec:
  selector:
    app: backend
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9090
</code></pre>

<p>Then I create another pod (a temporary one) which will work as a frontend, in order to access the service I've just created with this command:</p>

<pre><code>kubectl run --rm -ti --generator=run-pod/v1 podtest3 --image=nginx:alpine -- sh
</code></pre>

<p>So I run nginx inside the pod. Then I check the IP of the pod with <code>kubectl get pods -o wide</code></p>

<pre><code>NAME                                    READY   STATUS    RESTARTS   AGE   IP           NODE             NOMINATED NODE   READINESS GATES
backend-k8s-hands-on-6489c76ff4-4q9th   1/1     Running   0          60m   10.1.0.153   docker-desktop   &lt;none&gt;           &lt;none&gt;
backend-k8s-hands-on-6489c76ff4-6tvns   1/1     Running   0          60m   10.1.0.151   docker-desktop   &lt;none&gt;           &lt;none&gt;
backend-k8s-hands-on-6489c76ff4-jrc7k   1/1     Running   0          60m   10.1.0.152   docker-desktop   &lt;none&gt;           &lt;none&gt;
podtest3                                1/1     Running   0          39m   10.1.0.155   docker-desktop   &lt;none&gt;           &lt;none&gt;
</code></pre>

<p>And finally when I type into my browser the IP 10.1.0.155 it tells me that safari can't find the page.</p>

sergiomahi
<p>You can create a <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">Service</a> first and port forward to that service:</p>

<pre><code>kubectl -n &lt;namespace&gt; port-forward svc/&lt;svc-name&gt; &lt;localhost-port&gt;:&lt;pod-port&gt; 
</code></pre>

<p>The other choice is directly port forward to your pod:</p>

<pre><code>kubectl -n &lt;namespace&gt; port-forward pod/&lt;podname&gt; &lt;localhost-port&gt;:&lt;pod-port&gt; 
</code></pre>

<p>And then:</p>

<pre><code>curl localhost:&lt;localhost-port&gt;
</code></pre>

<p>Here's more direct example:</p>

<pre><code>✗ kubectl run nginx-example --image=nginx --port=80
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/nginx-example created
✗ kubectl port-forward pod/nginx-example 8080:80
Error from server (NotFound): pods "nginx-example" not found
✗ kubectl get po
NAME                                  READY   STATUS    RESTARTS   AGE
nginx-example-6cdd6bf4c5-km8mh        1/1     Running   0          55s
✗ kubectl port-forward pod/nginx-example-6cdd6bf4c5-km8mh  8080:80
Forwarding from 127.0.0.1:8080 -&gt; 80
Forwarding from [::1]:8080 -&gt; 80
✗ curl localhost:8080
Handling connection for 8080
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Welcome to nginx!&lt;/title&gt;
&lt;style&gt;
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Welcome to nginx!&lt;/h1&gt;
&lt;p&gt;If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.&lt;/p&gt;

&lt;p&gt;For online documentation and support please refer to
&lt;a href="http://nginx.org/"&gt;nginx.org&lt;/a&gt;.&lt;br/&gt;
Commercial support is available at
&lt;a href="http://nginx.com/"&gt;nginx.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thank you for using nginx.&lt;/em&gt;&lt;/p&gt;
&lt;/body&gt;

</code></pre>
