Using load balancers
    • PDF

    Using load balancers

    • PDF

    Article Summary

    Available in Classic

    Integrate with Load Balancer

    If you set the service type to LoadBalancer when you create a Kubernetes service, NAVER Cloud Platform’s Ncloud Kubernetes Service automatically creates a load balancer instance.
    You can configure a load balancer, by using annotations in the service manifest.

    The following table shows annotations supported to configure load balancers.

    AnnotationDescriptionNote
    service.beta.kubernetes.io/ncloud-load-balancer-backend-protocolLoad balancer protocol. Select one of the following: tcp, http, https, and ssl.Default is tcp.
    service.beta.kubernetes.io/ncloud-load-balancer-proxy-protocolIndicates whether to enable the proxy protocol.
    Select between true and false.
    It is valid when the load balancer’s protocol is set to ssl or tcp.
    service.beta.kubernetes.io/ncloud-load-balancer-internalUsed to create a private network load balancer.
    Select between true and false.
    Default is false.
    service.beta.kubernetes.io/ncloud-load-balancer-ssl-certSSL Certificate name to configure a listener when the load balancer protocol is https or ssl.Use the certificate name registered in Certificate Manager.
    service.beta.kubernetes.io/ncloud-load-balancer-ssl-portsPorts to be additionally assigned to the instance when the load balancer protocol is https or ssl.
    Use a comma (,) as a delimiter.
    Example: "443,6443"
    service.beta.kubernetes.io/ncloud-load-balancer-l7-healthcheck-pathPath for L7 Healthcheck when the load balancer protocol is http or https.Default is "/".
    service.beta.kubernetes.io/ncloud-load-balancer-descriptionMemo about a load balancer instance to create.
    service.beta.kubernetes.io/ncloud-load-balancer-algorithm-typeLoad balancing algorithm. Select one of the following: RR (ROUND ROBIN), LC (LEAST_CONNECTION), SIPHS (Source IP Hash)Default is RR.
    service.beta.kubernetes.io/ncloud-load-balancer-termination-protectionThis option determines whether to enable load balancer termination protection when the Service whose type is LoadBalancer is removed.Default is false.
    Note

    If you need to get the client IP address, set service.beta.kubernetes.io/ncloud-load-balancer-proxy-protocol to true. For more information, refer to Ingress Tutorial.

    Create load balancer instances

    To create a load balancer instance in Kubernetes Service, specify the service manifest as follows.

    "type": "LoadBalancer"
    

    The following example shows a yaml configuration file
    in which the annotation to create a private network load balancer instance is added.

    kind: Service
    apiVersion: v1
    metadata:
      name: example-service
      annotations:
        service.beta.kubernetes.io/ncloud-load-balancer-internal: "true"
    spec:
      ports:
      - port: 8765
        targetPort: 9376
      selector:
        app: example
      type: LoadBalancer
    

    Save the above as nks-lb.yml and execute kubectl apply -f nks-lb.yml to deploy it, and a load balancer instance is automatically created.
    This may take several minutes or longer to complete.

    Execute the following command to check the private IP address of the created load balancer instance. The IP address is indicated in EXTERNAL-IP column.

    $ kubectl --kubeconfig=$KUBE_CONFIG get svc example-service
    NAME              TYPE           CLUSTER-IP       EXTERNAL-IP    PORT(S)          AGE
    example-service   LoadBalancer   172.16.101.104   10.39.10.118   8765:30365/TCP   2m11s
    

    Create a load balancer instance with kubectl expose

    Apart from the method described above, you can also use the kubectl expose command and --type=LoadBalancer flag to create a load balancer instance.

    Let’s create a deployment named my-nginx by executing the following command. You can use the deployment to run Nginx pod.

    $ kubectl --kubeconfig=$KUBE_CONFIG create deployment --image nginx my-nginx
    

    Then, execute the following command to create a load balancer instance.

    $ kubectl --kubeconfig=$KUBE_CONFIG expose deployment my-nginx --port=80 --type=LoadBalancer
    

    Delete load balancer instances

    The kubernetes service resource created with the load balancer type is integrated with NAVER Cloud Platform’s load balancer instance automatically created.
    So, if the service resource is deleted from Kubernetes Service, the integrated load balancer instance is automatically deleted as well.

    Use the following command to view the services created. The type of each service is indicated in TYPE column.

    $ kubectl --kubeconfig=$KUBE_CONFIG get service
    NAME         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
    my-nginx     LoadBalancer   172.16.188.167   slb-904582.ncloudslb.com     80:32681/TCP   21s
    

    To delete a kubernetes service resource with the load balancer type, execute the following command.

    $ kubectl --kubeconfig=$KUBE_CONFIG delete service my-nginx
    service "my-nginx" deleted
    

    As soon as the kubernetes service resource is deleted, the load balancer is automatically deleted. This may take several minutes or longer to complete.


    Was this article helpful?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.