如何在两个 EKS 服务之间共享一个 AWS NLB?
How to share an AWS NLB between two EKS Services?
我们在 AWS 区域内的 EKS 集群中进行了跨可用区部署,其中每个可用区都是独立的,这意味着组件不会与不在同一可用区中的其他组件通信。
我们使用 Contour 作为我们的入口,并且有不同的守护进程集,每个 AZ 一个。因此,我们还为每个守护程序集定义了不同的服务。
将服务部署到 EKS 时,会创建两个不同的 NLB。
我们希望只有一个 NLB 将在服务之间共享。
问题是:能不能实现,如果能实现怎么办?
是的,您应该能够做到这一点,方法是在 Service
.
中使用适当的 选择器
在您使用的每个 DaemonSet
中,您已经在 Pod-template
中为 pods 设置了 标签。
例如
template:
metadata:
labels:
app: contour
az: az-1
和
template:
metadata:
labels:
app: contour
az: az-2
现在,在您的 Loadbalancer 服务中,您需要使用一个 选择器 匹配两个 DaemonSet 上的 Pods,例如app: contour
示例服务
apiVersion: v1
kind: Service
metadata:
name: my-service
annotation:
service.beta.kubernetes.io/aws-load-balancer-type: nlb
spec:
selector:
app: contour # this needs to match the Pods in all your DaemonSets
ports:
- protocol: TCP
port: 80
type: LoadBalancer
我们在 AWS 区域内的 EKS 集群中进行了跨可用区部署,其中每个可用区都是独立的,这意味着组件不会与不在同一可用区中的其他组件通信。
我们使用 Contour 作为我们的入口,并且有不同的守护进程集,每个 AZ 一个。因此,我们还为每个守护程序集定义了不同的服务。
将服务部署到 EKS 时,会创建两个不同的 NLB。
我们希望只有一个 NLB 将在服务之间共享。
问题是:能不能实现,如果能实现怎么办?
是的,您应该能够做到这一点,方法是在 Service
.
在您使用的每个 DaemonSet
中,您已经在 Pod-template
中为 pods 设置了 标签。
例如
template:
metadata:
labels:
app: contour
az: az-1
和
template:
metadata:
labels:
app: contour
az: az-2
现在,在您的 Loadbalancer 服务中,您需要使用一个 选择器 匹配两个 DaemonSet 上的 Pods,例如app: contour
示例服务
apiVersion: v1
kind: Service
metadata:
name: my-service
annotation:
service.beta.kubernetes.io/aws-load-balancer-type: nlb
spec:
selector:
app: contour # this needs to match the Pods in all your DaemonSets
ports:
- protocol: TCP
port: 80
type: LoadBalancer