I tried starting minikube using virtualbox, docker and hyperkit. For each case, I cannot access the nodeport.
My pods and services look good
NAME READY STATUS RESTARTS AGE
dbpostgresql-655654d6dd-mmgxk 1/1 Running 0 40m
tern-559c74bfb7-tqs96 1/1 Running 0 27m
test-pod 1/1 Running 0 11m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
dbpostgresql ClusterIP 10.102.194.214 <none> 5432/TCP 40m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 44m
tern NodePort 10.102.162.15 <none> 8080:31905/TCP 19m
my minikube ip is 192.168.59.103
but when typing http://192.168.59.103:31905/ I am having site cannot be reached
here my deployment file
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: tern
name: tern
spec:
replicas: 1
selector:
matchLabels:
app: tern
template:
metadata:
labels:
app: tern
spec:
containers:
- image: tern:6
name: tern
ports:
- containerPort: 8080
here my service file
apiVersion: v1
kind: Service
metadata:
name: tern
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
selector:
app.kubernetes.io/name: tern
The service is wrong, selector should be the same as matchLabels, change it to this:
After updating the service definition, perform a service describe to verify if the pod IP has been added to the endpoints. Next, validate from another pod whether the service is reachable. Additionally, on the same VM, check if the NodePort is accessible using either 'localhost' or the node's IP. Finally, from your localhost, add a port forward from the VM to your local machine, and then confirm if the service is accessible.