minikube : not able to connect a locally deployed nginx service
Asked Answered
G

1

8

I have installed minikube on my ubuntu 16.04 machine and have started a cluster, with a message

"Kubernetes is available at https://192.168.99.100:443"

Next, I deployed nginx service with the following command

> kubectl.sh run my-nginx --image=nginx --replicas=2 --port=80 --expose

> kubectl.sh get  pods -o wide
NAME                        READY     STATUS    RESTARTS   AGE       NODE
my-nginx-2494149703-8jnh4   1/1       Running   0          13m       127.0.0.1
my-nginx-2494149703-q09be   1/1       Running   0          13m       127.0.0.1

> kubectl.sh get  services -o wide
NAME         CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE       SELECTOR
kubernetes   10.0.0.1     <none>        443/TCP   14m       <none>
my-nginx     10.0.0.83    <none>        80/TCP    13m       run=my-nginx

> kubectl.sh get  nodes -o wide
NAME        STATUS    AGE
127.0.0.1   Ready     16m

Questions:

1) Is node 127.0.0.1 my local development machine? This has got me confused me the most.

2) Is my following understanding correct: The cluster (nodes, kubernetes API server) has internal IP addresses in 10.0.0.x and their corresponding external IP addresses are 192.168.99.x. The 2 pods will then have IPs in the range like 10.0.1.x and 10.0.2.x ?

3) Why is the external IP for the services not there? Not even, for the kubernetes service. Isn't the 192.168.99.43 an external IP here?

4) Most importantly, how do I connect to the nginx service from my laptop?

Garda answered 27/6, 2016 at 4:48 Comment(0)
P
13

1) Is node 127.0.0.1 my local development machine? This has got me confused me the most.

When a node registers, you provide the IP or name to register with. By default, the node is just registering 127.0.0.1. This is referencing your VM running linux, not your host machine.

2) Is my following understanding correct: The cluster (nodes, kubernetes API server) has internal IP addresses in 10.0.0.x and their corresponding external IP addresses are 192.168.99.x. The 2 pods will then have IPs in the range like 10.0.1.x and 10.0.2.x ?

Yup, the 10.0.0.x network is your overlay network. The 192.168.99.x are your "public" addresses which are visible outside of the cluster.

3) Why is the external IP for the services not there? Not even, for the kubernetes service. Isn't the 192.168.99.43 an external IP here?

The external IP is typically used to ingress traffic via a specific IP. The kubernetes service is using a clusterIP service type which means it's only visible to the internal cluster.

4) Most importantly, how do I connect to the nginx service from my laptop?

The easiest way to view your nginx service is to make it type NodePort, then deploy the service. After that, describe the service to get the port that was assigned (or after you create it will tell you as well). Then hit the ip of your VM and provide the auto assigned NodePort.

e.g. http://192.168.99.100:30001

Phyllida answered 27/6, 2016 at 13:26 Comment(6)
Thanks Steve! One other way to access the service (if you don't want to use a NodePort), is to use kubectl port-forward to access the underlying pod. For example, you could run: kubectl port-forward mypod 8080:8080, to make the pod available on localhost:8080Oney
Thanks Steve. Regarding your first answer, you mean to say that 127.0.0.1 is the only nw interface of the node (VM in this case) that pods inside it can communicate, right? Secondly, when I run 'kubectl exec my-nginx-yczg9 -- sh -c "ifconfig -a'' , it gives eth0 with some IP like 172.17.0.4. Now, as I understand it, my-nginx-yczg9 is a pod and a pod can have N containers. So is it fair to say that 172.17.0.4:80 is a Pod IP (virtual IP- endpoint?) , which will be proxied to appropriate nginx container running inside the pod and that container will have IP in the docker subnet within?Garda
Thanks diorec, How does the port forward command work here ? Please correct me if I am wrong: As per my understanding, my machine's(host) local host ip (i.e 127.0.0.1:8080) will act as a proxy to 192.168.99.100:30001 ? in which the command will be kubectl port-forward mypod 8080:30001Garda
The 127.0.0.1 is the name of the node (your only node). It's running all the components of your cluster. Pods inside the network get their own ip's which are only addressable inside the cluster. That's the 172.* addresses you mention. Does that help?Phyllida
See also this topic if you want to route traffic from your local environment to a Service without using a nodePort: https://mcmap.net/q/507746/-dev-machine-as-part-of-minikube-39-s-networkCordwain
On a slightly related topic, how would you then set it up so that going to an example.com from the browser would go to this 192.168.99.100:30001? I also have that related question here: #43009214Rodmun

© 2022 - 2024 — McMap. All rights reserved.