9

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 dont 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 dont see any obvious errors in the result above, but again I am not experienced enough to check if there is any config thats 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.

I would appreciate if someone can help me fix this.

Libin Joseph
  • 7,070
  • 5
  • 29
  • 52
  • Could you please paste your service yaml file ? – Madhan Mar 19 '22 at 11:14
  • @Libin did you find a solution to this? cause i have the same problem right now, when i try to ssh into the minkube then curl the ip:port i get a response but not from external sources. Thanks – Tahtoh Apr 17 '22 at 19:29
  • @Tahtoh : I ended up moving to docker for kubernetes. – Libin Joseph Apr 19 '22 at 01:48
  • 1
    I am not sure how to fix this exactly, but after failing on the same tutorial, I believe the problem in my case is the netmask. I'm on a typical home network with a netmask of 255.255.255.0, so, all my actual machines are on 192.168.1.x. However, the minikube node address is 192.168.49.2. That's not in the same subnet, making it unreachable from a different host on my network, though it is available from the machine that's hosting it. That, or there is a firewall blocking it, as I've changed my router subnet mask to 255.255.192.0 with no luck... (but I may need to reboot the host) – Jim May 04 '22 at 20:58
  • Specifically, the routing looks like x~ ❯ route jim@ubuntu 17:03:19 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default _gateway 0.0.0.0 UG 100 0 0 enp6s0 link-local 0.0.0.0 255.255.0.0 U 1000 0 0 enp6s0 192.168.0.0 0.0.0.0 255.255.192.0 U 100 0 0 enp6s0 192.168.49.0 0.0.0.0 255.255.255.0 U 0 0 0 br-ee3b5f11d53e – Jim May 04 '22 at 21:11
  • The mask for the 192.198.49.0 address that minikube uses is 255.255.255.0, which I think makes it unreachable, though I now have my pcs adapted with a wider mask... Not sure, but it seems like the problem if not the answer. – Jim May 04 '22 at 21:14
  • @Jim, man, I face the same question as yours. my minikube has ip: 192.168.49.2. so need to make some configurations to my local network to directly access it. – Tony Lucas Mar 20 '23 at 01:37

7 Answers7

18

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

navule
  • 3,212
  • 2
  • 36
  • 54
Dashrath Mundkar
  • 7,956
  • 2
  • 28
  • 42
  • Tried, all 3 options. First 2 does the same, cannot connect to the web app. When the run the third command, I get an error. "error: Service webapp-servicel does not have a service port 30200" – Libin Joseph Mar 19 '22 at 09:34
  • @LibinJoseph could you paste your service yaml file here – Dashrath Mundkar Mar 19 '22 at 09:41
  • @LibinJoseph can you try this ```kubectl port-forward svc/ 3000:3000``` and access on browser ```localhost:3000``` or access pod directly using ```kubectl port-forward pod/POD_NAME_OF_WEB_APP 3000:3000``` and access ```localhost:3000``` – Dashrath Mundkar Mar 19 '22 at 09:44
  • 3
    Both of those commands gives a blank page. The first command gives the error in console `E0319 20:46:13.845282 6660 portforward.go:400] an error occurred forwarding 3000 -> 3000: error forwarding port 3000 to pod c3cc7b66ddf40acb868a8f54161408a9cf2261c98ed94353b2304c8635208804, uid : exit status 1: 2022/03/19 08:21:26 socat[29438] E connect(5, AF=2 127.0.0.1:3000, 16): Connection refused` – Libin Joseph Mar 19 '22 at 09:50
  • I had the same issue, as per my experience, most of the time this happens when you are on windows and used docker as minicube's VM driver, therefore 1st option didn't work. But 2nd and 3rd options worked. thanks – Githendra McShane Nov 19 '22 at 15:08
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. 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
Aladin
  • 586
  • 3
  • 15
Paul Finol
  • 11
  • 3
1

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.

m19v
  • 1,800
  • 4
  • 11
  • 26
1

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

hamza
  • 13
  • 5
1

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

R3qUi3M
  • 65
  • 4
0

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

minikube start --driver=hyperv

heroesch
  • 150
  • 1
  • 1
  • 8
-1

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.