4

I am following a very simple tutorial where it spawns a simple pod with an http endpoint and a service to expose that app using kubernetes.

The setup is very simple:

app-pod.yml

apiVersion: v1
kind: Pod
metadata:
  name: hello-pod
  labels:
    app: web
spec:
  containers:
    - name: web-ctr
      image: nigelpoulton/getting-started-k8s:1.0
      ports:
        - containerPort: 8080

And the nodeport service:

apiVersion: v1
kind: Service
metadata:
  name: ps-nodeport
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 8080
    nodePort: 31111
    protocol: TCP
  selector:
    app: web

The service and pod seem to be healthy:

enter image description here

But I can't reach the running app:

locahost:31111

Give " This site can't be reached message"

I am new to this stuff so any help will be appreciated.

groo
  • 4,213
  • 6
  • 45
  • 69

2 Answers2

4

In Kubernetes Kind cluster, by default, NodePort may not be bound to localhost. Please check the following resources:

Rafał Leszko
  • 4,939
  • 10
  • 19
  • 3
    Yes, exactly what I was looking for. Thanks. I created this gist with a quick start so others can quickly start instead of going around all the BS complexity around -> https://gist.github.com/mmaia/ff49117b110702a314aabd5b294cc951 – groo Dec 16 '21 at 21:03
  • 1
    Nice, happy that it worked! – Rafał Leszko Dec 17 '21 at 08:13
0

The simplest way to access the service from localhost (like you are trying to do) would be to use

kubectl port-forward

e.g. the following command would work in your case - which forwards traffic from localhost -> ps-nodeport service

kubectl port-forward service/ps-nodeport 31111: 31111
D Grewal
  • 26
  • 2