提问者:小点点

在迷你部暴露港口


在minikube中,如何使用nodeport公开服务?

例如,我使用以下命令启动一个kubernetes集群并创建和公开一个端口,如下所示:

$ 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节点也需要配置为暴露这个端口。


共3个答案

匿名用户

我不确定你在问什么,因为你似乎已经知道minikube服务

$ 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...

此命令将在您的默认浏览器中打开指定的服务。

还有一个--url选项用于打印服务的url,这是在浏览器中打开的内容:

$ minikube service hello-minikube --url
http://192.168.99.100:31167

匿名用户

由于minikube通过nodeIP: nodePort而不是localhost:nodePort公开访问,您可以通过使用kubectl的端口转发功能来实现此工作。例如,如果您正在运行mongoDB服务:

kubectl port-forward svc/mongo 27017:27017

这将在localhost:27017上公开服务,FWIW。此外,您可能想弄清楚如何在后台运行它。

匿名用户

Minikube运行在类似192.168.99.100的东西上。因此,您应该能够在您公开服务的NodePort上访问它。例如,假设您的NodePort30080,那么您的服务将作为192.168.99.100:30080访问。

要获取minikube ip,请运行命令minikube ip

2017年9月14日更新:

这是一个适用于minikubev0.16.0的小例子。

1)运行下面的命令创建一个在8080上运行的nginx和一个转发到它的NodePortsvc

$ 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)找到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)找到minikube ip:

$ minikube ip
192.168.99.100

4)用卷发与它交谈:

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

相关问题