'unable to access nodeIP:port, serviceIP:port or podIP:port in minikube k8s

I am using k8s in minikube under Ubuntu and deployed nginx server. Which i want to access from different level eg from serviceip, nodeip or pod ip and none of them is reachable.Not sure why?? I am running my curl command to access ip:port from the ubuntu host machine where minikube node is installed. below is the log

/home/ravi/k8s>kgp
NAMESPACE     NAME                                READY   STATUS    RESTARTS   AGE     IP             NODE       NOMINATED NODE   READINESS GATES
default       nginx-deployment-775bf4d7fb-jqxxv   1/1     Running   0          13m     172.17.0.3     minikube   <none>           <none>
kube-system   coredns-66bff467f8-gtsl7            1/1     Running   0          9h      172.17.0.2     minikube   <none>           <none>
kube-system   etcd-minikube                       1/1     Running   0          9h      192.168.49.2   minikube   <none>           <none>
kube-system   kube-apiserver-minikube             1/1     Running   0          9h      192.168.49.2   minikube   <none>           <none>
kube-system   kube-controller-manager-minikube    1/1     Running   0          9h      192.168.49.2   minikube   <none>           <none>
kube-system   kube-proxy-nphlc                    1/1     Running   0          7h28m   192.168.49.2   minikube   <none>           <none>
kube-system   kube-scheduler-minikube             1/1     Running   0          9h      192.168.49.2   minikube   <none>           <none>
kube-system   storage-provisioner                 1/1     Running   21         9h      192.168.49.2   minikube   <none>           <none>
/home/ravi/k8s>
/home/ravi/k8s>
/home/ravi/k8s>
/home/ravi/k8s>kgs
NAMESPACE     NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                  AGE   SELECTOR
default       kubernetes      ClusterIP   10.96.0.1       <none>        443/TCP                  9h    <none>
default       nginx-service   NodePort    10.101.107.62   <none>        80:31000/TCP             13m   app=nginx-app
kube-system   kube-dns        ClusterIP   10.96.0.10      <none>        53/UDP,53/TCP,9153/TCP   9h    k8s-app=kube-dns
/home/ravi/k8s>
/home/ravi/k8s>
/home/ravi/k8s>kubectl describe service nginx-service
Name:                     nginx-service
Namespace:                default
Labels:                   <none>
Annotations:              Selector:  app=nginx-app
Type:                     NodePort
IP:                       10.101.107.62
Port:                     <unset>  80/TCP
TargetPort:               8000/TCP
NodePort:                 <unset>  31000/TCP
Endpoints:                172.17.0.3:8000
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>
/home/ravi/k8s>
/home/ravi/k8s>
/home/ravi/k8s>
/home/ravi/k8s>curl 172.17.0.3:8000
curl: (7) Failed to connect to 172.17.0.3 port 8000: No route to host
/home/ravi/k8s>
/home/ravi/k8s>
/home/ravi/k8s>curl 192.168.1.52:31000
curl: (7) Failed to connect to 192.168.1.52 port 31000: Connection refused
/home/ravi/k8s>
/home/ravi/k8s>
/home/ravi/k8s>curl 10.101.107.62:80    ---> also hangs
......
......

/home/ravi/k8s>
/home/ravi/k8s>kubectl get node -o wide
NAME       STATUS   ROLES    AGE   VERSION    INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION      CONTAINER-RUNTIME
minikube   Ready    master   9h    v1.18.20   192.168.49.2   <none>        Ubuntu 20.04.1 LTS   5.13.0-40-generic   docker://20.10.3
/home/ravi/k8s>
/home/ravi/k8s>
/home/ravi/k8s>curl 192.168.49.2:31000
curl: (7) Failed to connect to 192.168.49.2 port 31000: Connection refused
/home/ravi/k8s>


/home/ravi/k8s> kubectl logs nginx-deployment-775bf4d7fb-jqxxv   ---> no log shown


/home/ravi/k8s>cat 2_nginx_nodeport.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-app
  template:
    metadata:
      labels:
        app: nginx-app
    spec:
      containers:
      - name: nginx-container
        image: nginx:1.16
        ports:
        - containerPort: 8000
---        
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: NodePort
  selector:
    app: nginx-app
  ports:
    - protocol: TCP           
      nodePort: 31000
      port: 80
      targetPort: 8000         
/home/ravi/k8s>

root@nginx-deployment-775bf4d7fb-jqxxv:~# curl 172.17.0.3:80  ---> working on port 80 instead of 8000 as set in yaml
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
</body>
</html>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source