skip to Main Content

I am running my minikube as docker image.
I am trying to expose my service to outside world using Nodeport.

This is my yaml file.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: docker-hello-world
  labels:
    app: docker-hello-world
spec:
  selector:
    matchLabels:
      app: docker-hello-world
  replicas: 3
  template:
    metadata:
      labels:
        app: docker-hello-world
    spec:
      containers:
      - name: docker-hello-world
        image: scottsbaldwin/docker-hello-world:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: docker-hello-world-svc
spec:
  selector:
    app: docker-hello-world
  ports:
    - port: 8088
      targetPort: 80
  type: NodePort

Searched a lot about nodePort that we require node ip to access the service.
I am able to access my service using minikube service docker-hello-world-svc –url
which gives me url to access the service http://127.0.0.1:52526 but here port number is different then the nodePort.

My service is successful running .

NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
docker-hello-world-svc   NodePort    10.109.146.181   <none>        8088:30934/TCP   65m

i want to access my service from outside the cluster using Nodeport but my nodes does not have any external ip

kubectl get nodes -o wide                                                                                                                                             
NAME       STATUS   ROLES           AGE    VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION      CONTAINER-RUNTIME
minikube   Ready    control-plane   5h9m   v1.24.3   192.168.49.2   <none>        Ubuntu 20.04.4 LTS   5.10.104-linuxkit   docker://20.10.17

already read out that i need ingress controller to access service but i wanna test it using nodePort .

Any work around so i can access my service using only nodePort running inside the minikube which is running as docker image?

Status of minikube does not show kubectl

>>minikube status                                                                                                                                                                             
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

2

Answers


  1. You don’t need an external IP when using NodePort, you can use minikube ip to get the minikube node address, and then connect to the respective nodePort:

    $ kubectl svc
    NAME                     TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
    docker-hello-world-svc   NodePort    10.108.66.235   <none>        8088:31550/TCP   2m15s
    
    $ minikube ip
    192.168.49.2
    
    $ curl 192.168.49.2:31550
    <h1>Hello webhook world from: docker-hello-world-cc79bf486-k4lm8</h1>
    
    

    Another alternative is to use a LoadBalancer service, and use minikube tunnel to connect to it using the internal port:

    $ kubectl  svc
    NAME                     TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)          AGE
    docker-hello-world-svc   LoadBalancer   172.16.58.95   172.16.58.95   8088:32624/TCP   10s
    
    $ curl 172.16.58.95:8088
    <h1>Hello webhook world from: docker-hello-world-cc79bf486-dg5s9</h1>
    

    Notes:

    • You will only get an EXTERNAL-IP after running minikube tunnel in a separate terminal (it’s a foreground process)
    • I recommend that you run Minikube using a less common IP range for the services, preventing conflicts with other network routes:
    minikube start --service-cluster-ip-range=172.16.0.0/16
    
    Login or Signup to reply.
  2. You can use port forwarding with kubeclt. kubectl port-forward allows using resource name, such as a pod name, to select a matching pod to port forward to.

    kubectl port-forward svc/resource-name 4000:5000
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search