Libin Joseph
Libin Joseph

Reputation: 7392

Unable to access minikube IP address

I am an absolute beginner to Kubernetes, and I was following this tutorial to get started. I have managed writing the yaml files. However once I deploy it, I am not able to access the web app.

This is my webapp yaml file

apiVersion: apps/v1
kind: Deployment
metadata:
 name: webapp-deployment
 labels:
  app: webapp
spec:
 replicas: 1
 selector:
  matchLabels:
   app: webapp
 template:
  metadata:
   labels:
    app: webapp
spec:
  containers:
  - name: webapp
    image: nanajanashia/k8s-demo-app:v1.0
    ports:
    - containerPort: 3000
    env:
    - name: USER_NAME
      valueFrom:
        secretKeyRef:
          name: mongo-secret
          key: mongo-user
    - name: USER_PWD
      valueFrom:
        secretKeyRef:
          name: mongo-secret
          key: mongo-password
    - name: DB_URL
      valueFrom:
        configMapKeyRef:
          name: mongo-config
          key: mongo-url

apiVersion: v1
kind: Service
metadata:
  name: webapp-servicel
spec:
  type: NodePort
  selector:
    app: webapp
  ports:
    - protocol: TCP
      port: 3000
      targetPort: 3000
      nodePort: 30200

When I run the command : kubectl get node

> Blockquote

When I run the command: kubectl get pods, I can see the pods running

enter image description here

kubectl get svc

enter image description here

I then checked the logs for webapp, I don't see any errors

enter image description here

I then checked the details logs by running the command: kubectl describe pod podname

enter image description here

I don't see any obvious errors in the result above, but again I am not experienced enough to check if there is any config that's not set properly.

Other things I have done as troubleshooting:

  1. Ran the following command for the minikube to open up the app : minikube service webapp-servicel, it opens up the web page, but again does not connect to the IP.
  2. Uninstalled minikube, kubectl and all relevant folders, and run everything again.
  3. pinged the ip address directly from command line, and cannot reach.

How can I fix this?

Upvotes: 11

Views: 25260

Answers (7)

R3qUi3M
R3qUi3M

Reputation: 85

The problem is that on Win11 (or perhaps other OS) your minikube IP:PORT does not get forwarded for some reason.

The solution that I discovered is tied to Docker Desktop - just install the docker on Win11 via installer.

There is a settings option in top right corner (the gear icon) - in settings -> enable kubernetes.

Use kubectl as you normally would to attach your yaml files. Once the pods start you can access your front-end through: localhost:exposed_port

Upvotes: 3

hamza
hamza

Reputation: 133

Not sure if this still relevent or not, but maybe for future reference If you're using minikube, and you cannot access your minikube ip (maybe because of some firewall or else) You can use miniKube service and porvide the name of your service

minikube service webapp-service

minikube will then create a tunnel between your service and your localhost, and will open it in the default browser

Upvotes: 13

m19v
m19v

Reputation: 2190

On Windows 10 with Docker-Desktop one can even do not need to use minikube. Just enable Kubernetes in Docker-Desktop settings and use kubectl. Check the link for further information.

Using Kubernetes of Docker-Desktop I could simply reach webapp with localhost:30100. In my case, for some reason I had to pull mongo docker image manually with docker pull mongo:5.0.

Upvotes: 0

Paul Finol
Paul Finol

Reputation: 19

Ran the following command for the minikube to open up the app : minikube service webapp-servicel, it opens up the web page, but again does not connect to the IP. Uninstalled minikube, kubectl and .kube and run everything again. pinged the ip address directly from command line, and cannot reach.

I suggest you to try port forwarding

https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/

kubectl port-forward svc/x-service NodePort:Port

Upvotes: 1

heroesch
heroesch

Reputation: 149

On Windows 11 with Ubuntu 20.04 WSL, it worked for me by using:

minikube start --driver=hyperv

Upvotes: 0

Dashrath Mundkar
Dashrath Mundkar

Reputation: 9222

Try these 3 options

  1. can you do the kubectl get node -o wide and get the ip address of node and then open in web browser NODE_IP_ADDRESS:30200

  2. Alternative you can run this command minikube service <SERVICE_NAME> --url which will give you direct url to access application and access the url in web browser.

  3. kubectl port-forward svc/<SERVICE_NAME> 3000:3000 and access application on localhost:3000

Upvotes: 25

Jared Gabaldon
Jared Gabaldon

Reputation: 41

I got stuck here as well. After looking through some of the gitlab issues, I found a helpful tip about the minikube driver. The instructions for starting minikub are incorrect in the video if you used

minikube start -driver docker

Here's how to fix your problem.

  1. stop minikube

    minikube stop

  2. delete minikube (this deletes your cluster)

    minikube delete

  3. start up minikube again, but this time specify the hyperkit driver

    minikube start --vm-driver=hyperkit

  4. check status

    minikube status

  5. reapply your components in this order by.

    kubectl apply -f mongo-config.yaml kubectl apply -f mongo-secret.yaml kubectl apply -f mongo.yaml kubectl aplly -f webapp.yaml

  6. get your ip

    minikube ip

  7. open a browser, go to ip address:30200 (or whatever the port you defined was, mine was 30100). You should see an image of a dog and a form.

Some information in this SO post is useful too.

Upvotes: -1

Related Questions