<p>I have an application running inside minikube K8 cluster. It’s a simple REST endpoint. The issue is after deployment I am unable to access that application from my local computer.</p>
<p>Using <code>http://{node ip}:{node port}</code> endpoint.</p>
<p>However, if I do:</p>
<pre><code>kubectl port-forward (actual pod name) 8000:8000
</code></pre>
<p>The application becomes accessible at: <code>127.0.0.1:8000</code> from my local desktop.</p>
<p>Is this the right way?
I believe this isn't the right way? as I am directly forwarding my traffic to the pod and this port forwarding won't remain once this pod is deleted.</p>
<p>What am I missing here and what is the right way to resolve this?</p>
<p>I have also configured a <code>NodePort</code> service, which should handle this but I am afraid it doesn’t seem to be working:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: rest-api
  name: rest-api-np
  namespace: rest-api-namespace
spec:
  type: NodePort
  ports:
  - port: 8000
  selector:
    app: rest-api


apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: rest-api
  name: rest-api-deployment
  namespace: rest-api-namespace
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rest-api
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: rest-api
    spec:
      containers:
      - image: oneImage:latest
        name: rest-api
</code></pre>

Maven
<p>You are having issues because your service is placed in <code>default</code> namespace while your deployment is in <code>rest-api-namespace</code> namespace.</p>
<p>I have  deploy you yaml files and when the describe the service there were no endpoints:</p>
<pre class="lang-yaml prettyprint-override"><code>➜  k describe svc rest-api-np 
Name:                     rest-api-np
Namespace:                default
Labels:                   app=rest-api
Annotations:              &lt;none&gt;
Selector:                 app=rest-api
Type:                     NodePort
IP:                       10.100.111.228
Port:                     &lt;unset&gt;  8000/TCP
TargetPort:               8000/TCP
NodePort:                 &lt;unset&gt;  31668/TCP
Endpoints:                &lt;none&gt;
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>
<p>Solution for that is to create service in the the same namespace. Once you do that, an ip address and port will appear in the <code>Endpoints</code> field:</p>
<pre class="lang-yaml prettyprint-override"><code>➜ k describe svc -n rest-api-namespace rest-api-np 
Name:                     rest-api-np
Namespace:                rest-api-namespace
Labels:                   app=rest-api
Annotations:              &lt;none&gt;
Selector:                 app=rest-api
Type:                     NodePort
IP:                       10.99.49.24
Port:                     &lt;unset&gt;  8000/TCP
TargetPort:               8000/TCP
NodePort:                 &lt;unset&gt;  32116/TCP
Endpoints:                172.18.0.3:8000
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>
<p>Alternative way is to add <a href="https://kubernetes.io/docs/concepts/services-networking/service/#services-without-selectors" rel="nofollow noreferrer">endpoints</a> manually:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Endpoints
metadata:
  name: my-service # please note that endpoints and service needs to have the same name
subsets:
  - addresses:
      - ip: 192.0.2.42 #ip of the pod 
    ports:
      - port: 8000
</code></pre>
