我在Kubernetes集群上访问NodePort服务时遇到困难 .
Goal
设置ALB Ingress控制器,以便我可以使用websockets和http / 2
根据该控制器的要求设置NodePort服务
Steps taken
以前在AWS eu-west-1上创建了Kops(版本1.6.2)集群 . 添加了nginx入口的kops插件以及Kube-lego . ELB入口工作正常 .
使用该项目指定的IAM配置文件,使用自定义AWS密钥设置ALB Ingress Controller .
使用kubectl replace --force将服务类型从LoadBalancer更改为NodePort
> kubectl describe svc my-nodeport-service
Name: my-node-port-service
Namespace: default
Labels: <none>
Selector: service=my-selector
Type: NodePort
IP: 100.71.211.249
Port: <unset> 80/TCP
NodePort: <unset> 30176/TCP
Endpoints: 100.96.2.11:3000
Session Affinity: None
Events: <none>
> kubectl describe pods my-nodeport-pod
Name: my-nodeport-pod
Node: <ip>.eu-west-1.compute.internal/<ip>
Labels: service=my-selector
Status: Running
IP: 100.96.2.11
Containers:
update-center:
Port: 3000/TCP
Ready: True
Restart Count: 0
(ssh into node)
$ sudo netstat -nap | grep 30176
tcp6 0 0 :::30176 :::* LISTEN 2093/kube-proxy
Results
来自ALB的卷曲挂起
来自 <public ip address of all nodes>:<node port for service>
的卷曲挂起
Expected
从ALB和直接到节点:node-port的卷曲应返回200“Ok”(服务对根的http响应)
更新:在上面引用的github上创建的问题,在某些情况下还有一些进一步的细节:
1 回答
默认情况下,Kops不会将EC2实例配置为允许来自外部的NodePort流量 .
为了使群集外部的流量能够到达NodePort,您必须编辑EC2实例的配置,这些实例是AWS上EC2控制台中的Kubernetes节点 .
进入EC2控制台后,单击"Security groups." Kops应注释为集群创建的原始安全组为
nodes.<your cluster name>
和master.<your cluster name>
我们需要修改这些安全组以将流量从NodePorts的默认端口范围转发到实例 .
单击安全组,单击规则并添加以下规则 .
Port range to open on the nodes and master :30000-32767
这将允许互联网上的任何人访问群集上的NodePort,因此请确保您希望这些暴露 .
或者,不是从任何原点允许它,而是只允许来自alb-ingress-controller为ALB创建的安全组 . 但是,由于可以重新创建这些,因此可能需要修改对kubernetes服务的修改规则 . 我建议明确地指定NodePort它是一个预定的已知NodePort而不是一个随机分配的NodePort .