'Unable to access a NodePort service on Minikube
I have minikube running. Minikube status results into:
kubectl: Correctly Configured: pointing to minikube-vm at 192.168.99.100
And I defined a Service, with the following port configuration:
type: NodePort
ports:
- protocol: TCP
port: 8082
targetPort: 8082
nodePort: 30082
But when I try to access the service on the following URLs, it is not reachable:
http://192.168.99.100:30082
http://192.168.99.100:8082
Is it a must to have an Ingress defined in addition? Could I do without an Ingress? Which port?
Thanks - Christian
Below the full yaml of the service:
apiVersion: v1
kind: Service
metadata:
annotations:
description: LAC 51 Service
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{"description":"LAC 51 Service"},"labels":{"name":"lac51","service":"lac51-svc"},"name":"lac51-svc","namespace":"default"},"spec":{"ports":[{"name":"lac51-http-port","nodePort":30082,"port":8082,"protocol":"TCP","targetPort":8082}],"selector":{"app":"lac51"},"type":"NodePort"}}
creationTimestamp: null
labels:
name: lac51
service: lac51-svc
name: lac51-svc
selfLink: /api/v1/namespaces/default/services/lac51-svc
spec:
externalTrafficPolicy: Cluster
ports:
- name: lac51-http-port
port: 8082
protocol: TCP
targetPort: 8082
selector:
app: lac51
sessionAffinity: None
type: NodePort
status:
loadBalancer: {}
Solution 1:[1]
It seems that is related to the default docker driver used when you start the minikube.
To avoid these problems you can force a specific driver (e.g. "virtualbox"). To do so, follow the next steps:
- Remove old minikube with:
minikube delete
- Start minikube with virtualbox driver:
minikube start --memory=4096 --driver=virtualbox
- Run
minikube ip. You'll see an output like192.168.99.100. - Then, create again the Pods and the service and it should work properly.
I've found this info in this issue: https://github.com/kubernetes/minikube/issues/7344#issuecomment-703225254
Solution 2:[2]
In this case ingress is not necessary, Minikube should expose the service by itself. However if you want to give it a try here's a tutorial.
You can run minikube service list to get list of all available services with their corresponding URL's. Also make sure the service points to correct pod by using correct selector.
Solution 3:[3]
for m1 users, when starting minikube run this command
minikube start --ports=<port-target>:<node-port>
for eg;
minikube start --ports=30000:30000
and for exposing multiple ports, separate them by comma, eg;
minikube start --ports=30000:30000,32000:32000
and now you access the pod via: http://localhost:30000
Solution 4:[4]
If you do not want to go through the "virutalbox" route, then "port-forwarding" is an additional step you may need , like so :
kubectl port-forward <podname> <hostport>:<podport> -n <namespace-name>
podport: output from: kubectl get pod <podname> --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}' -n <namespace-name>
hostport: your desired port , say port 8080.
once forwarding starts then http://localhost:8080 on your browser should load your app.
For Mac OS users , hyperkit should do the job , like
minikube start --driver=hyperkit
Solution 5:[5]
Mac OS has networking limitations, --vm=true downloads VM image: https://github.com/kubernetes/minikube/issues/7332
minikube stop
minikube delete
minikube start --vm=true
Solution 6:[6]
Run command
minikube service serviceName
, It will open a tunnel and link will be opened in default browser.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | xserrat |
| Solution 2 | |
| Solution 3 | |
| Solution 4 | |
| Solution 5 | Song |
| Solution 6 | Rishab |
