Reputation: 7392
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
When I run the command: kubectl get pods, I can see the pods running
kubectl get svc
I then checked the logs for webapp, I don't see any errors
I then checked the details logs by running the command: kubectl describe pod podname
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:
minikube service webapp-servicel
, it opens up the web page, but again does not connect to the IP.How can I fix this?
Upvotes: 11
Views: 25260
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
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
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
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
Reputation: 149
On Windows 11 with Ubuntu 20.04 WSL, it worked for me by using:
minikube start --driver=hyperv
Upvotes: 0
Reputation: 9222
Try these 3 options
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
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.
kubectl port-forward svc/<SERVICE_NAME> 3000:3000
and access application on localhost:3000
Upvotes: 25
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.
stop minikube
minikube stop
delete minikube (this deletes your cluster)
minikube delete
start up minikube again, but this time specify the hyperkit driver
minikube start --vm-driver=hyperkit
check status
minikube status
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
get your ip
minikube ip
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