In this article, we will explain how you can expose an application to the internet with the network load balancer (NLB).
There are three options to expose an application if you are using a standard classic Kubernetes cluster (the NodePort is the only option if you are using a free Kubernetes cluster):
- NodePort
- Network Load Balancer (NLB)
- Ingress (application load balancer, ALB)
Prerequisites
- IBM Cloud account
- IBM Cloud Container Registry
- IBM Cloud Kubernetes Service (you need a standard classic cluster)
Creating a network load balancer (NLB) service
Let’s deploy a sample Hello World app into a Kubernetes pod within the worker node by utilizing the commands in the steps below. You can see the full details of how you can deploy an app in “Lesson 3: Deploying single instance apps to Kubernetes clusters” in the IBM Cloud Docs:
git clone https://github.com/IBM/container-service-getting-started-wt.git
cd 'container-service-getting-started-wt/Lab 1'
ibmcloud cr build -t us.icr.io/tn_namespace/hello-world:1 .
kubectl create deployment hello-world-deployment --image=us.icr.io/tn_namespace/hello-world:1
Now you have the Deployment hello-world-deployment and the app is running on a pod:
Use the following steps to create a network load balancer (NLB) service to expose your app. The portable addresses that are assigned to the NLB are permanent and do not change, even when a worker node is recreated in the cluster. You will be able to access your app by <load-balancer-ip>:<port that your app requires>.
1. Create a network load balancer (NLB) service
You can create a NLB service by using either one of two methods: the command line or the service configuration file.
Create via the command line
Create via the service configuration file
2. Get the NLB’s external-IP address and the port
Next, you’ll need to get the NLB’s external IP address and listen port. Because you don’t specify an IP address at this time, one of remaining portable public IP addresses will be assigned to the network load balancer service:
3. Access your app by <NLB’s external-ip>:<NLB’s listen port>
Run curl or access in a web browser:
4. Create an IBM-provided subdomain for your app (optional)
You can create a subdomain for your app that registers public NLB IP addresses with a DNS entry. If you create a DNS subdomain for your NLB, users can access your app through the NLB’s subdomain instead. A DNS system service resolves the subdomain to the portable public IP address of the NLB:
5. Set up a custom domain (optional)
If you choose, you can set up a custom domain to point to the IBM-provided subdomain that you created in the previous step:
- Register a custom domain by working with your Domain Name Service (DNS) provider or by using IBM Cloud Internet Services or IBM Cloud DNS.
- Define an alias for your custom domain by specifying the IBM-provided subdomain as a Canonical Name record (CNAME).
Clean up
You can run the following commands to clean up the testing in this article:
Summary
I hope that you now understand how you can expose an application to the outside of your Kubernetes cluster with the network load balancer (NLB) so that users can access the app from the Internet.
For more details about using an NLB, see the following:
- Setting up basic load balancing with an NLB 1.0
- Components and architecture of an NLB 1.0
- Create an External Load Balancer
If you want to minimise downtime and plan high availability for your app, you can configure with the NLB in a single-zone or a multi-zone cluster. See more details in “Planning your cluster for high availability.”
For more information on other methods of exposing your application to the outside of your Kubernetes cluster, see “What is Kubernetes Ingress?“