Open port in mini cube

In a minibook, how to open a service using nodeport?

For example, I start the kubernetes cluster using the following command, and create and set the port as follows:

$ minikube start $ kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080 $ kubectl expose deployment hello-minikube --type=NodePort $ curl $(minikube service hello-minikube --url) CLIENT VALUES: client_address=192.168.99.1 command=GET real path=/ .... 

Now, how to access the open service from the host? I assume that the mini cube node should be configured to expose this port.

+22
kubernetes minikube
source share
4 answers

I'm not quite sure what you are asking, because it looks like you already know about the minikube service <SERVICE_NAME> --url , which will give you a URL where you can access the service. To open an open service, you can use the minikube service <SERVICE_NAME> command:

 $ kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080 deployment "hello-minikube" created $ kubectl expose deployment hello-minikube --type=NodePort service "hello-minikube" exposed $ kubectl get svc NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello-minikube 10.0.0.102 <nodes> 8080/TCP 7s kubernetes 10.0.0.1 <none> 443/TCP 13m $ minikube service hello-minikube Opening kubernetes service default/hello-minikube in default browser... 

This command will open the specified service in the default browser. Here's the minikube service documentation: https://github.com/kubernetes/minikube/blob/master/docs/minikube_service.md

There is also the --url option to print the service URL that opens in the browser:

 $ minikube service hello-minikube --url http://192.168.99.100:31167 
+49
source share

Minikube runs on something like 192.168.99.100 . Therefore, you must have access to it through NodePort on the NodePort you provide your services. For example, let's say your NodePort 30080 , then your service will be available as 192.168.99.100:30080 NodePort 30080 .

To get the ip minicube, run the minikube ip command.

September 14, 2017 Patch:

Here is a small example that works with minikube v0.16.0 .

1) Run the commands below to create nginx running on 8080 and redirect NodePort svc :

 $ kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080 deployment "hello-minikube" created $ kubectl expose deployment hello-minikube --type=NodePort service "hello-minikube" exposed 

2) Find the nodeport used by svc:

 $ kubectl get svc hello-minikube NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello-minikube 10.0.0.76 <nodes> 8080:30341/TCP 4m 

3) Find the ip minicub:

 $ minikube ip 192.168.99.100 

4) Talk to him using curl:

 $ curl 192.168.99.100:30341 CLIENT VALUES: client_address=172.17.0.1 command=GET real path=/ ... 
+11
source share

Since minikube provides access through nodeIP:nodePort and not through localhost:nodePort , you can achieve this using kubectl port forwarding kubectl . For example, if you use the mongodb service:

 kubectl port-forward svc/mongo 27017:27017 

This would expose the service to localhost:27017 , FWIW. In addition, you can figure out how to run this in the background.

+1
source share

Just a note for those looking for answers about connection denial: if your mini cube doesn’t work on β€œsomething like 192.168.99.100”, you are probably working with another vm driver, such as β€œnone”. In this case, delete the Minikube cluster and rebuild it using the default settings. it will work .... ish ... I can't get the tunnel to work ...

0
source share

All Articles