0

我正在 kubernetes 中创建服务。如何将 Classic Load Balancer 更改为 Network Load Balancer?我正在为它提供的外部客户端 IP 转向网络负载均衡器。我使用 AWS。这是我的配置:

apiVersion : apps/v1
kind: Deployment
metadata:
  name: my-web-deployment-multi-pod
  labels:
    app : my-k8s-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      project: cia
  template:
    metadata:
      labels:
        project: cia
    spec:
      containers:
        - name : my-web
          image: adv4000/k8sphp:latest
          ports:
            - containerPort: 80   # Port on Pod

        - name : not-my-web
          image: tomcat:8.5.38
          ports:
            - containerPort: 8080  # Port on Pod



apiVersion: v1
kind: Service
metadata:
  name: my-multi-pods-service
spec:
  type: LoadBalancer
  selector:
    project: cia
  ports:
    - name      : my-web-app-listener
      protocol  : TCP
      port      : 80
      targetPort: 80

    - name      : not-my-web-app-listener
      protocol  : TCP
      port      : 8888
      targetPort: 8080
4

1 回答 1

2

要在 AWS 上使用网络负载均衡器,请使用service.beta.kubernetes.io/aws-load-balancer-type值设置为的注释nlb

您的服务最终将如下所示:

apiVersion: v1
kind: Service
metadata:
  name: my-multi-pods-service
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-type: "nlb"
spec:
  type: LoadBalancer
  selector:
    project: cia
  ports:
    - name      : my-web-app-listener
      protocol  : TCP
      port      : 80
      targetPort: 80

    - name      : not-my-web-app-listener
      protocol  : TCP
      port      : 8888
      targetPort: 8080

如需进一步阅读,请查看:https ://kubernetes.io/docs/concepts/services-networking/service/#aws-nlb-support

于 2021-03-23T11:11:57.420 回答