[英]Kubernetes Service not being assigned an (external) IP address
There are various answers for very similar questions around SO that all show what I expect my deployment to look like, however mine does not.对于围绕 SO 的非常相似的问题,有各种答案,它们都显示了我希望我的部署看起来像什么,但我的却没有。
I am deploying a service with a YAML file, but the service is never assigned an external IP - the result is the same if I happen to use kubectl expose
.我正在使用 YAML 文件部署服务,但从未为该服务分配外部 IP - 如果我碰巧使用
kubectl expose
,结果是一样的。
The YAML file that I am using:我正在使用的 YAML 文件:
kind: Service
apiVersion: v1
metadata:
name: hello-service
spec:
type: NodePort
selector:
app: hello-world
ports:
- protocol: TCP
port: 8080
I can also use the YAML file to assign an external IP - I assign it the same value as the node IP address.我还可以使用 YAML 文件来分配外部 IP - 我为其分配与节点 IP 地址相同的值。 Either way results in no possible connection to the service.
无论哪种方式,都无法连接到服务。 I should also point out that the 10 replicated pods all match the selector.
我还应该指出,10 个复制的 pod 都与选择器匹配。
The result of running kubectl get svc
for the default, and after updating the external IP are below:默认运行
kubectl get svc
,更新外部IP后的结果如下:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-service NodePort 10.108.61.233 <none> 8080:32406/TCP 1m
hello-service NodePort 10.108.61.233 10.49.106.251 8080:32406/TCP 1m
The tutorial I have been following, and the other answers on SO show a result similar to:我一直在关注的教程,以及关于 SO 的其他答案显示的结果类似于:
hello-service NodePort 10.108.61.233 <nodes> 8080:32406/TCP 1m
Where the difference is that the external IP is set to <nodes>不同之处在于外部IP设置为<nodes>
I have encountered a number of issues when running locally - is this just another case of doing so, or has someone else identified a way to get around the external IP assignment issue?我在本地运行时遇到了许多问题 - 这只是另一种情况,还是其他人找到了解决外部 IP 分配问题的方法?
Using NodePort means it will open a port on all nodes of your cluster. 使用NodePort意味着它将在群集的所有节点上打开一个端口。 In your example above, the port exposed to the outside world is 32406. In order to access hello-service (if it is http) it will be http://[ the node ip]:32406/.
在上面的示例中,暴露给外部世界的端口是32406.为了访问hello-service(如果它是http),它将是http:// [节点ip]:32406 /。 This will hit your minikube and the the request will be routed to your pod in roundrobin fashion.
这将打到你的minikube,请求将以roundrobin方式路由到你的pod。
same problem when trying to deploy a simple helloworld image locally with Kubernetes v1.9.2尝试使用Kubernetes v1.9.2在本地部署一个简单的 helloworld 镜像时出现同样的问题
After two weeks of attempts , It seems that Kubernetes expose all nginx web server applications internally in port 80
not 8080
经过两周的尝试,似乎 Kubernetes 在内部公开了所有nginx web 服务器应用程序在端口
80
而不是8080
So this should work kubectl expose deployment hello-service --type=NodePort --port=80
所以这应该工作
kubectl expose deployment hello-service --type=NodePort --port=80
For local development purpose, I have also met with the problem of exposing a 'public IP' for my local development cluster.出于本地开发目的,我还遇到了为本地开发集群公开“公共 IP”的问题。 Fortunately, I have found one of the kubectl command which can help:
幸运的是,我找到了 kubectl 命令之一,它可以提供帮助:
kubectl port-forward service/service-name 9092
Where 9092 is the container port to expose, so that I can access applications inside the cluster, on my local development environment.其中 9092 是要公开的容器端口,以便我可以在本地开发环境中访问集群内的应用程序。
The important note is that it is not a 'production' grade solution.重要的一点是,它不是“生产”级解决方案。 Works well as a temporary hack to get to the cluster insides.
可以很好地作为临时黑客进入集群内部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.