AWS EKS Service与Ingress网络流向小记

前言

K8S Service主要负责集群内访问,Ingress负责外网流量(7层)。本文主要记录网络流向,便于业务选型

Service

ClusterIP

source pod — > VIP ClusterIP(iptables规则、本机与跨主机在规则上有点区别) ----> dest pods

NodePort

client —> Node上的kube-proxy(port) —> ClusterIP(iptables规则)—> dest pods

LoadBalancer

不加annotation默认创建的是CLB(Classic Load Balancer)

client —> CLB —> Node上的kube-proxy(port) —> ClusterIP(iptables规则) —> dest pods

---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service-lb
  namespace: net-test
#There is no any annotation
spec:
  type: LoadBalancer
  selector:
    app: nginx-net
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 80

annotation为nlb则创建NLB instance模式(Network Load Balancer)

client —> NLB(instance) —> Node上的kube-proxy(port) —> ClusterIP(iptables规则) —> dest pods

---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service-lb-2
  namespace: net-test
 #There is an important annotation
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-type: nlb
spec:
  type: LoadBalancer
  selector:
    app: nginx-net
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 80

annotation为nlb-ip则创建NLB ip模式(Network Load Balancer)

client —> NLB(ip) —> dest pods
这里是直接将数据包发到pod的ip地址,而且pod也是从VPC CIDR中分配 IP 地址,直接arp获得pod对应的内网ip地址的mac,流量就直接转到承载此pod的node上

---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service-lb-3
  namespace: net-test
 #There is an important annotation
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-type: nlb-ip
spec:
  type: LoadBalancer
  selector:
    app: nginx-net
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 80

小记

本质上NLB instance模式和CLB没有本质区别,网络流量完全相同,均需要将流量先转发到Node port。但是使用NLB ip模式则可以跨过ClusterIP流量直达pod,因此可以通过此模式获取client真实ip地址。

Ingress

client —> ALB(ip) —> dest pods
ingress负责7层协议http/https的转发,通过AWS默认创建的是ALB,通过如下配置可以看到,流量是导到Service ClusterIP。但是因为其也开启了ip模式(target-type: ip ),因此其流量也是跨过Service ClusterIP 直达pod。

---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service-clusterip
  namespace: net-test
spec:
  type: ClusterIP
  selector:
    app: nginx-net
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 80
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  namespace: net-test
  name: nginx-ingress
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip
spec:
  rules:
    - http:
        paths:
          - path: /*
            backend:
              serviceName: nginx-service-clusterip
              servicePort: 8080

参考文档
https://aws.amazon.com/cn/blogs/china/in-depth-analysis-and-research-on-service-and-ingress-in-amazon-eks/?nc1=h_ls

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值