【发布时间】:2020-04-15 18:53:43
【问题描述】:
我使用 kops 在 AWS EC2 上创建了一个集群,该集群由一个主节点和两个工作节点组成,均分配了公共 IPv4。
现在,我想使用 NodePort 创建一个包含服务的部署,以将应用程序公开给公众。
创建服务后,我检索到以下信息,表明它正确识别了我的三个 pod:
nlykkei:~/projects/k8s-examples$ kubectl describe svc hello-svc
Name: hello-svc
Namespace: default
Labels: app=hello
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"hello"},"name":"hello-svc","namespace":"default"},"spec"...
Selector: app=hello-world
Type: NodePort
IP: 100.69.62.27
Port: <unset> 8080/TCP
TargetPort: 8080/TCP
NodePort: <unset> 30001/TCP
Endpoints: 100.96.1.5:8080,100.96.2.3:8080,100.96.2.4:8080
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
但是,当我尝试访问端口 30001 上的任何公共 IPv4 时,我没有收到来自服务器的响应。我已经创建了一个安全组,允许所有实例的所有入口流量到端口 30001。
一切都适用于 Mac 的 Docker Desktop,我注意到上面的输出中没有以下服务字段:
LoadBalancer Ingress: localhost
我已经研究过https://kubernetes.io/docs/concepts/services-networking/service/,并认为 NodePort 应该满足我的需求?
感谢任何帮助!
【问题讨论】:
-
可以通过pod所在节点的公网ip试试吗?
-
服务端口从8080改为80
-
为什么要把端口改为80?
-
将 targetPort 改为 80
-
@Elias - 你为什么要我改变它?
标签: amazon-web-services kubernetes cloud