本文将介绍在AWS Load Balancer Controller(V2)中发布的其他几项重要功能:通过在上篇中创建好的EKS集群中实验,使用Network Load Balancer(NLB)+ IP模式实现南北向HTTP(S)流量的导入,以及演示通过引入Target Group Binding CRD来实现将EKS中的服务灵活地绑定到已有Target Group上的新功能。
操作步骤
使用NLB + IP模式实现南北向流量的导入
除了上篇中介绍的使用Application Load Balancer的基于七层的HTTP流量导入,我们很多时候也会有基于四层TCP流量的导入需求,在EKS平台我们可以使用NLB来实现这个需求。
部署示例服务nginx,并通过Classic Load Balancer(CLB)发布
运行下列命令生成样例程序nginx的K8S部署和服务,注意通过设置 type: LoadBalancer 将服务通过AWS负载均衡器(默认类型为CLB)发布到互联网:
cat <<EoF > ~/environment/nginx.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: "nginx"
spec:
selector:
app: nginx
type: LoadBalancer
ports:
- protocol: TCP
port: 80
targetPort: 80
EoF
kubectl apply -f ~/environment/nginx.yaml
上篇文章请参考:在AWS EKS上发布K8S服务(上)
返回技术博客
This article covers additional important features introduced in AWS Load Balancer Controller (V2): using Network Load Balancer (NLB) in IP mode to handle north-south HTTP(S) traffic ingress on the EKS cluster created in Part 1, and demonstrating the new Target Group Binding CRD for flexibly binding EKS services to existing Target Groups.
Steps
North-South Traffic Ingress with NLB + IP Mode
In addition to the Layer 7 HTTP traffic ingress via Application Load Balancer covered in Part 1, there are many scenarios requiring Layer 4 TCP traffic ingress. On EKS, this can be achieved using NLB.
Deploy a sample nginx service and expose it via Classic Load Balancer (CLB)
Run the following commands to create a K8S Deployment and Service for nginx. Note that setting type: LoadBalancer exposes the service to the internet via an AWS load balancer (CLB by default):
cat <<EoF > ~/environment/nginx.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: "nginx"
spec:
selector:
app: nginx
type: LoadBalancer
ports:
- protocol: TCP
port: 80
targetPort: 80
EoF
kubectl apply -f ~/environment/nginx.yaml
See also: Deploying K8S Services on AWS EKS (Part 1)
Back to Tech Blog