Loadbalancer

November 19, 2024
Tags:  · 
Create an Utho account to try this guide with a $100 credit.

How to Add Load Balancers to Kubernetes Clusters

The Utho Cloud Controller supports provisioning Utho Load Balancers in a cluster’s resource configuration file.

The Utho Load Balancer Service routes load balancer traffic to all worker nodes on the cluster. Only nodes configured to accept the traffic pass health checks.

Utho Application Operator is a Kubernetes Operator that is used to manage various resources required by your Kubernetes Based Application like Load Balancer, etc.

With this Operator, you can do the following:

  • Create a CRD called UthoApplication and provide networking parameters.
  • Manage your resources from the CRD
  • Hassle Free Netwokr Resource Provisioning.

Install the controller

Prerequisites

Install the Cloud Controller Helm Chart

To install the chart with the release name utho-app-operator:

Add the Utho Operator Repository to your Helm repositories:

helm repo add utho-operator https://uthoplatforms.github.io/utho-app-operator-helm/
helm repo update

Install the Utho Operator Chart:

Note: make sure to set the Utho API Key

helm install <release_name> utho-operator/utho-app-operator-chart --set API_KEY=<YOUR_API_KEY> -n <namespace> --create-namespace

Example:

helm install utho-app-operator utho-operator/utho-app-operator-chart --set API_KEY=################## -n dev --create-namespace

Create a Configuration File for Network Loadblancer

You can update the backend port that the Loadblancer will listen to

apiVersion: apps.utho.com/v1alpha1
kind: UthoApplication
metadata:
  name: nl-lb
spec:
  loadBalancer:
    name: nl-lb
    dcslug: innoida
    # Node exposed port the loadblancer will forwad request to
    backendPort: 30088
    frontend:
      name: nl-lb
      algorithm: roundrobin
      protocol: tcp
      # public port the Loadblancer wil listen to
      port: 80
    type: network

Show Network Load Balancers

Once you apply the config file to a deployment, you can see the load balancer in the Resources tab of your cluster in the control panel.

Alternatively, use kubectl get services to see its status:

kubectl get UthoApplication

NAMEPHASELOAD-BALANCER-IPLOAD-BALANCER-TYPEFRONTEND-PORTAGE
nl-lbRUNNING111.111.111.111network802h

When the load balancer creation is complete, the LOAD-BALANCER-IP column displays the external IP address instead of empty. In the PORT column.

Show Details for One Network Load Balancer

If the provisioning process for the load balancer is unsuccessful, you can access the service’s event stream to troubleshoot any errors. The event stream includes information on provisioning status and reconciliation errors.

To get detailed information about the load balancer configuration of a single load balancer, including the event stream at the bottom, use kubectl’s describe service command:

kubectl describe UthoApplication <LB-NAME>

More examples

You can find more examples at Examples

Create a Configuration File for Application Loadblancer

You can update the backend port that the Loadblancer will listen to

apiVersion: apps.utho.com/v1alpha1
kind: UthoApplication
metadata:
  name: ap-lb
  namespace: dev
spec:
  loadBalancer:
    advancedRoutingRules:
      - aclName: ap-lb
        routeCondition: true
        targetGroupNames:
          - ap-lb
    frontend:
      name: ap-lb
      algorithm: roundrobin
      protocol: tcp
      # public port the Loadblancer wil listen to
      port: 80
    type: application
    dcslug: innoida
    name: ap-lb
  targetGroups:
    - health_check_timeout: 5
      health_check_interval: 30
      health_check_path: /
      health_check_protocol: TCP
      healthy_threshold: 2
      name: ap-lb
      protocol: TCP
      unhealthy_threshold: 3
      # Node exposed port the loadblancer will forwad request to
      port: 30088

Show Application Load Balancers

Once you apply the config file to a deployment, you can see the load balancer in the Resources tab of your cluster in the control panel.

Alternatively, use kubectl get services to see its status:

kubectl get UthoApplication

NAMEPHASELOAD-BALANCER-IPLOAD-BALANCER-TYPEFRONTEND-PORTAGE
ap-lbRUNNING111.111.111.111network802h

When the load balancer creation is complete, the LOAD-BALANCER-IP column displays the external IP address instead of empty. In the PORT column.

Show Details for One Application Load Balancer

If the provisioning process for the load balancer is unsuccessful, you can access the service’s event stream to troubleshoot any errors. The event stream includes information on provisioning status and reconciliation errors.

To get detailed information about the load balancer configuration of a single load balancer, including the event stream at the bottom, use kubectl’s describe service command:

kubectl describe UthoApplication <LB-NAME>

UthoApplication CRD Reference

UthoApplicationSpec

Defines the desired state of the UthoApplication.

FIELDDESCRIPTION
apiVersionapps.utho.com/v1alpha1
kindUthoApplication
metadataRefer to Kubernetes API documentation for fields of metadata.
specUthoApplicationSpec

UthoApplicationSpec

Specifies the UthoApplication configuration.

FIELDDESCRIPTION
loadBalancerLoadBalancer
targetGroups[]TargetGroup

LoadBalancer

Specifies the load balancer configuration.

FIELDDESCRIPTIONEXAMPLE VALUES
frontendFrontend, optional
typestring, default: applicationapplication
dcslugstringinnoida
namestringmy-lb
aclRule[]ACLRule, optional

Frontend

Specifies the frontend configuration.

FIELDDESCRIPTIONEXAMPLE VALUES
namestringtest-fe
algorithmstringroundrobin or leastconn
protocolstringhttp or https
portint6480 or 443
certificateNamestring, optionaltest-name
redirectHttpsbool, optional0 for no, 1 for yes
cookiebool, optional0 for no, 1 for yes

ACLRule

Specifies an ACL rule.

FIELDDESCRIPTIONEXAMPLE VALUES
namestringtest-rule
conditionTypestringhttp_user_agent, http_referer, url_path, http_method, query_string, http_header
valueACLData

ACLData

Specifies the ACL data.

FIELDDESCRIPTIONEXAMPLE VALUES
typestringhttp_user_agent, http_referer, url_path, http_method, query_string, http_header
data[]string/

TargetGroup

Specifies a target group configuration.

FIELDDESCRIPTIONEXAMPLE VALUES
namestringtest-tg
protocolstringHTTP, TCP, HTTPS, UDP
health_check_pathstring/healthz
health_check_protocolstringHTTP, TCP, HTTPS, UDP
health_check_intervalint6430
health_check_timeoutint645
healthy_thresholdint643
unhealthy_thresholdint642
portint6480
Create an Utho account to try this guide with a $100 credit.