在 minikube 中暴露端口 [英] Expose port in minikube
问题描述
在 minikube 中,如何使用 nodeport 公开服务?
In minikube, how to expose a service using nodeport ?
例如,我使用以下命令启动一个 kubernetes 集群,并创建和公开这样的端口:
For example, I start a kubernetes cluster using the following command and create and expose a port like this:
$ 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=/ ....
现在如何从主机访问暴露的服务?我想 minikube 节点也需要配置为公开这个端口.
Now how to access the exposed service from the host? I guess the minikube node needs to be configured to expose this port as well.
推荐答案
我不太确定您要问什么,因为您似乎已经了解 minikube 服务
命令,它将为您提供一个可以访问该服务的网址.为了打开暴露的服务,可以使用minikube service
命令:
I am not exactly sure what you are asking as it seems you already know about the minikube service <SERVICE_NAME> --url
command which will give you a url where you can access the service. In order to open the exposed service, the minikube service <SERVICE_NAME>
command can be used:
$ 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 your default browser.
还有一个 --url
选项,用于打印在浏览器中打开的服务的 url:
There is also a --url
option for printing the url of the service which is what gets opened in the browser:
$ minikube service hello-minikube --url
http://192.168.99.100:31167
这篇关于在 minikube 中暴露端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!