0

I tried to send request 192.168.49.2:31083, but it did not work. I'm using Kubernetes with Docker.

kubectl expose deployment k8s-web-hello --port=3000 --type=NodePort

kubectl get service
NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
k8s-web-hello   NodePort    10.109.32.222   <none>        3000:31083/TCP   9m54s
kubernetes      ClusterIP   10.96.0.1       <none>        443/TCP          7d

minikube ip
192.168.49.2

How do I fix it?

Edited:

minikube service k8s-web-hello

|-----------|---------------|-------------|---------------------------|
| NAMESPACE |     NAME      | TARGET PORT |            URL            |
|-----------|---------------|-------------|---------------------------|
| default   | k8s-web-hello |    3000     | http://192.168.49.2:31083 |
|-----------|---------------|-------------|---------------------------|
  Starting tunnel for service k8s-web-hello.
|-----------|---------------|-------------|------------------------|
| NAMESPACE |     NAME      | TARGET PORT |          URL           |
|-----------|---------------|-------------|------------------------|
| default   | k8s-web-hello |             | http://127.0.0.1:45767 |
|-----------|---------------|-------------|------------------------|
  Opening service default/k8s-web-hello in default browser...
❗  Because you are using a Docker driver on linux, the terminal needs to be open to run it.
Opening in existing browser session.

I do not understand why i can not access via first URL with IP address of the Minikube virtual machine but the second URL with local IP can ?

1 Answers1

1

Refer to this official Doc and as per this you need to use “type: NodePort” in yaml that specifies a NodePort value and you need to do curl with this nodeport value only.

Below is the sample example :

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app.kubernetes.io/name: MyApp
  ports:
      # By default and for convenience, the `targetPort` is set to the same value as the `port` field.
    - port: 80
      targetPort: 80
      # Optional field
      # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
      nodePort: 30007

Note that As you are using minikube IP you need to tunnel into Minikube for access.

Can I know how you are sending the request either by Curl or browsing with HTTP? Can you share your yaml also so that it could be easy to answer.

Hemanth Kumar
  • 2,728
  • 1
  • 4
  • 19