2016-11-23 139 views
3

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

例如,我开始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节点需要配置为公开这个端口。

+0

你能澄清你的“访问是什么意思来自主机的暴露服务“?看起来你已经可以通过以下方式访问主机上的hello-minikube服务了: 'minikube service hello-minikube --url' –

+0

是的你是对的。实际上,这是配置错误,因为主机无法访问端口,我很困惑我需要更改一些防火墙设置以使其可访问。 – KarateKid

回答

14

我不确定你在问什么,因为看起来你已经知道minikube service <SERVICE_NAME> --url命令,它会给你一个你可以访问服务的URL。为了打开暴露的服务,minikube service <SERVICE_NAME>命令可用于:

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

此命令将在默认浏览器中打开指定的服务。这里是 minikube服务文档:https://github.com/kubernetes/minikube/blob/master/docs/minikube_service.md

还有一个--url选项用于打印服务的网址是什么得到在浏览器中打开:

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

在我的Linux主机上找不到端口'$ kubectl expose deployment hello-minikube --type = NodePort 错误:无法通过--port flag或introspection找到端口' – Stephane

2

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

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

更新2017年9月14日:

这里是与minikube v0.16.0工作的小例子。

1)运行下面的命令来创建对8080上运行的nginx的和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)找到由SVC使用的nodeport:

$ k 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=/ 
... 
+1

这看起来并不正确。 – macrael

+0

不能在MacOS minikube中工作 – icordoba

+0

1)kubernetes为IP地址和端口分配公开的服务 2)IP和端口在具有虚拟IP的虚拟IP上运行,您的笔记本电脑不具有本地访问权限。 – ives

相关问题