<p>I built a k8s cluster with help of this guide: <a href="https://wiki.learnlinux.tv/index.php/How_to_build_your_own_Raspberry_Pi_Kubernetes_Cluster" rel="nofollow noreferrer">rpi+k8s</a>. I got some basic nginx service up and running and and I can curl from master node to worker node to get the nginx welcome page content using:</p>
<pre><code>k exec nginx-XXX-XXX -it -- curl localhost:80
</code></pre>
<p>I tried following suggestions in the following SO posts:</p>
<p><a href="https://stackoverflow.com/questions/62585798/k8s-how-do-i-access-my-app-with-a-service">link 1</a>
<a href="https://stackoverflow.com/questions/55605975/how-to-expose-service-outside-k8s-cluster">link 2</a></p>
<p>However, I still can't access a simple nginx service on the worker node from my local computer (linux). I used, <code>NODE IP:NODE PORT</code>. I also installed kubefwd and ran, <code>sudo kubefwd svc -n nginx-ns</code> but I don't see the expected output where it would show the port forwards. Any help would be appreciated. Thanks.</p>
<p>Output:</p>
<pre><code>NAME                TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/nginx-svc   NodePort   10.101.19.230   &lt;none&gt;        80:32749/TCP   168m

NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx   3/3     3            3           168m

NAME                               DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-54485b444f   3         3         3       168m
</code></pre>
<p>And here is the yaml file:</p>
<pre><code>kind: Namespace
apiVersion: v1
metadata:
  name: nginx-ns
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: nginx-ns
spec:
  selector:
    matchLabels:
      app: nginx 
  replicas: 3
  template:
    metadata:
      labels:
        app: nginx 
    spec:
      containers:
      - name: nginx 
        image: nginx:1.19-alpine
        ports:
        - name: nginxport
          containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
  namespace: nginx-ns
  labels:
    app: nginx
spec:
  selector:
    app: nginx
  ports:
  - protocol: TCP
    name: nginxport
    port: 80
    targetPort: 80
    nodePort: 32749
  type: NodePort
  selector:
    app: backend
</code></pre>

Spencer Trinh
<p>You need to update your service <code>nginx-svc</code> where you have used two <code>selector</code>.</p>
<p>remove below part:</p>
<pre><code>  selector:
    app: backend
</code></pre>
<p>Updated <code>service.yaml</code>:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
  namespace: nginx-ns
  labels:
    app: nginx
spec:
  selector:
    app: nginx
  ports:
  - protocol: TCP
    name: nginxport
    port: 80
    targetPort: 80
    nodePort: 32749
  type: NodePort
</code></pre>
<p>Then, Try this one for port-forwarding.</p>
<pre><code>kubectl port-forward -n nginx-ns svc/nginx-svc 8080:80
</code></pre>
<p>Template is like this:</p>
<p><code>kubectl port-forward -n &lt;namespace&gt; svc/&lt;svc_name&gt; &lt;local_port&gt;:&lt;svc_port&gt;</code></p>
<p>Then try in the browser with <code>127.0.0.1:8080</code> or <code>localhost:8080</code></p>
