0

I am creating a service in kubernetes. How can I change the Classic Load Balancer to Network Load Balancer? I am turning to network load balancer for the external client ip it provides. I use AWS. Here is my configuration:

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
rock'n rolla
  • 1,883
  • 1
  • 13
  • 19
AlexWhite
  • 123
  • 2
  • 15

1 Answers1

2

To use a Network Load Balancer on AWS, use the annotation service.beta.kubernetes.io/aws-load-balancer-type with the value set to nlb.

Your service would end up looking like something below:

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

For further read, look at this: https://kubernetes.io/docs/concepts/services-networking/service/#aws-nlb-support

rock'n rolla
  • 1,883
  • 1
  • 13
  • 19
  • 2
    A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](/help/deleted-answers) – 4b0 Mar 23 '21 at 11:19
  • Yeah that makes sense. Edited it now. Cheers! – rock'n rolla Mar 23 '21 at 11:25
  • Still getting external IP like this: a1f8521595ab57-1392192552.us-west-2.elb.amazonaws.com. I thought it would help me getting ip like this: 10.212.321.21 – AlexWhite Mar 23 '21 at 12:22
  • I'm afraid that's the format AWS follows for dynamically generating LB DNS name. – rock'n rolla Mar 23 '21 at 12:37