简体   繁体   English

将外部 IP 分配给 Kubernetes 节点 (AWS EKS)

[英]Assign external IP to Kubernetes nodes (AWS EKS)

I have a UDP service I need to expose to the internet from an AWS EKS cluster.我有一个 UDP 服务,我需要从 AWS EKS 集群向 Internet 公开。 AWS load balancers (classic or NLB) don't do UDP, so I'd like to use a NodePort with Route53's multi-value to get UDP round robin load balancing to my nodes. AWS负载均衡器(经典或NLB)不做UDP,所以我想用一个NodePort与Route53的多值获得UDP循环赛负载平衡,以我的节点。

My nodes on AWS EKS don't have an ExternalIP assigned to them.我在 AWS EKS 上的节点没有分配给它们的ExternalIP While the EC2 instances the nodes run on have public IPs, these haven't been assigned to the nodes when the cluster was created.虽然运行节点的 EC2 实例具有公共 IP,但在创建集群时尚未将这些 IP 分配给节点。

How can I assign the EC2 public IPs to my k8s nodes?如何将 EC2 公共 IP 分配给我的 k8s 节点?

NAME                                          STATUS    ROLES     AGE       VERSION   EXTERNAL-IP   OS-IMAGE                                         KERNEL-VERSION               CONTAINER-RUNTIME
x.us-west-2.compute.internal   Ready     <none>    7d        v1.10.3   <none>        Amazon Linux 2 (2017.12) LTS Release Candidate   4.14.42-61.37.amzn2.x86_64   docker://17.6.2
x.us-west-2.compute.internal      Ready     <none>    7d        v1.10.3   <none>        Amazon Linux 2 (2017.12) LTS Release Candidate   4.14.42-61.37.amzn2.x86_64   docker://17.6.2
x.us-west-2.compute.internal   Ready     <none>    7d        v1.10.3   <none>        Amazon Linux 2 (2017.12) LTS Release Candidate   4.14.42-61.37.amzn2.x86_64   docker://17.6.2

I'm currently testing against a HTTP service for convenience, and here's what my test service looks like:为方便起见,我目前正在针对 HTTP 服务进行测试,这是我的测试服务的样子:

apiVersion: v1
kind: Service
metadata:
  name: backend-api
  labels:
    app: backend-api
spec:
  selector:
    app: backend-api
  type: NodePort
  ports:
  - name: back-http
    port: 81
    targetPort: 8000
    protocol: TCP
  externalIPs:
  - x.x.x.x
  - x.x.x.x
  - x.x.x.x

For this example, my curl requests never hit the HTTP service running on the nodes.对于此示例,我的curl请求从未命中节点上运行的 HTTP 服务。 My hunch is that is because the nodes don't have externalIP s.我的预感是因为节点没有externalIP

I haven't tried HostPort or UDP, but I've had success with public NodePorts.我还没有尝试过 HostPort 或 UDP,但我在公共 NodePorts 上取得了成功。

As long as the instance has a public IP, its security policy opens the ports, there's no OS firewall, and you don't have incompatible NetworkPolicies, then HostPort will just work.只要实例具有公共 IP,其安全策略会打开端口,没有操作系统防火墙,并且您没有不兼容的 NetworkPolicies,那么 HostPort 就可以正常工作。 NodePort forwards the OS's port into Kubernetes. NodePort 将操作系统的端口转发到 Kubernetes。 ExternalIP and other internal Kubernetes settings are irrelevant. ExternalIP 和其他内部 Kubernetes 设置无关紧要。

You can use the External IP controller for assigning IPs to the nodes. 您可以使用外部IP控制器为节点分配IP。 It is designed to work on the bare metal cluster, but I think it should work in your case also. 它设计用于裸机群集,但我认为它也适用于您的情况。

External IP Controller is a k8s application which is deployed on top of k8s cluster and which configures External IPs on k8s worker node(s) to provide IP connectivity. 外部IP控制器是一个k8s应用程序,它部署在k8s集群之上,它在k8s工作节点上配置外部IP以提供IP连接。

Description: 描述:

External IP controller kubernetes application is running on one of the nodes (replicas=1). 外部IP控制器kubernetes应用程序正在其中一个节点上运行(副本= 1)。

  • On start it pulls information about services from kube-api and brings up all External IPs on the specified interface (eth0 in our example above). 在开始时,它从kube-api中提取有关服务的信息,并在指定的接口上显示所有外部IP(在上面的示例中为eth0)。
  • It watches kube-api for updates in services with External IPs and: 它通过外部IP监视kube-api的服务更新,并且:
    • When new External IPs appear it brings them up. 当出现新的外部IP时,它会启动它们。
    • When service is removed it removes appropriate External IPs from the interface. 删除服务后,它会从界面中删除相应的外部IP。
  • Kubernetes provides fail-over for External IP controller. Kubernetes为外部IP控制器提供故障转移。 Since we have replicas set to 1, then we'll have only one instance running in a cluster to avoid IPs duplication. 由于我们将副本设置为1,因此我们将只在群集中运行一个实例以避免IP重复。 And when there's a problem with k8s node, External IP controller will be spawned on a new k8s worker node and bring External IPs up on that node. 当k8s节点出现问题时,将在新的k8s工作节点上生成外部IP控制器,并在该节点上启动外部IP。

Check out the Demo to see how it works. 查看演示以了解它是如何工作的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM