IBM Cloud Docs
Quick start for load balancers

Quick start for load balancers

Quickly expose your app to the Internet by creating a layer 4 load balancer.

First time setting up a load balancer? Check out Classic: Setting up basic load balancing with an NLB 1.0 or VPC: Exposing apps with VPC load balancers for prerequisite steps, limitations, and more details. Come back to these quick start steps for a brief refresher the next time you set up a load balancer.

Exposing an app by using an NLB in a classic cluster

  1. Expose your app by creating a version 1.0 network load balancer (NLB 1.0).

    kubectl expose deploy my-app --port=80 --target-port=8080 --type=LoadBalancer --name my-lb-svc
    
  2. Get the NLB 1.0 EXTERNAL-IP address.

    kubectl get svc my-lb-svc
    

    Example output

    NAME        TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)        AGE
    my-lb-svc   LoadBalancer   172.XX.XXX.XX   169.XX.XXX.XX   80:31224/TCP   23s
    
  3. Curl your app's IP address.

    curl <external-ip>
    
  4. Optional: Create a hostname for your app.

    ibmcloud ks nlb-dns create classic -c <cluster_name_or_id> --ip <NLB_IP>
    

    In a web browser, enter the hostname that is created. Example output

    NLB hostname was created as mycluster-35366fb2d3d90fd50548180f69e7d12a-0001.us-south.containers.appdomain.cloud
    

For more information, see:

Exposing an app by using a VPC load balancer in a VPC cluster

  1. Expose your app by creating a Kubernetes LoadBalancer service.

    kubectl expose deploy my-app --port=80 --target-port=8080 --type=LoadBalancer --name my-lb-svc
    
  2. Get the service's hostname that is listed in the EXTERNAL-IP column. The VPC load balancer that assigns the hostname takes a few minutes to provision in your VPC. You can't access your app by using the hostname of your Kubernetes LoadBalancer service until the VPC load balancer is fully provisioned.

    kubectl get svc my-lb-svc
    

    Example output

    NAME        TYPE           CLUSTER-IP      EXTERNAL-IP                            PORT(S)        AGE
    my-lb-svc   LoadBalancer   172.XX.XXX.XX   1234abcd-us-south.lb.appdomain.cloud   80:31224/TCP   23s
    
  3. In a web browser, enter the hostname that is created.

For more information, see VPC: Exposing apps with VPC load balancers.