Create Ingress With Internal Load Balancer¶
You can create an internal load balancer to distribute traffic to your EC2 instances from clients with access to the VPC for the load balancer.
An internal load balancer routes requests to targets using private IP addresses.
You can set alb.ingress.kubernetes.io/scheme
to internal
to instruct AWS Load Balancer Controller to create an internal application load balancer.
Let's see this in action!
Docker Images¶
Here is the Docker Image used in this tutorial: reyanshkharga/nodeapp:v1
Note
reyanshkharga/nodeapp:v1 runs on port 5000
and has the following routes:
GET /
Returns host info and app versionGET /health
Returns health status of the appGET /random
Returns a randomly generated number between 1 and 10
Step 1: Create a Deployment¶
First, let's create a deployment as follows:
Apply the manifest to create the deployment:
Verify deployment and pods:
Step 2: Create a Service¶
Next, let's create a service as follows:
Apply the manifest to create the service:
Verify service:
Step 3: Create Ingress¶
Now that we have the service ready, let's create an Ingress object that creates an internal load balancer:
Note that we have set the value of alb.ingress.kubernetes.io/scheme
to internal
so that the Load Balancer Controller creates an internal load balancer.
Apply the manifest to create ingress:
Verify ingress:
Step 4: Verify AWS Resources in AWS Console¶
Visit the AWS console and verify the resources created by AWS Load Balancer Controller.
Pay close attention to the type of load balancer. It should be internal
.
Also, verify that the ALB was created by AWS Load Balancer Controller
. You can check the events in the logs as follows:
kubectl logs -f deploy/aws-load-balancer-controller -n aws-load-balancer-controller --all-containers=true
Step 5: Access App Using Internal Load Balancer DNS¶
Because the load balancer is internal, access to our app from outside the VPC is restricted. To overcome this, let's create a pod that we can use to access the load balancer and, in turn, our app. Since the pod will reside within the same VPC, we will be able to access our app.
First, let's create a pod as follows:
Apply the manifest to create the pod:
Now, let's start a shell session inside the nginx container and hit the internal load balancer url:
# Start a shell session inside the nginx container
kubectl exec -it nginx -- bash
# Hit the load balancer url using CURL
curl <internal-alb-dns>
You'll see the response from the app.
Clean Up¶
Assuming your folder structure looks like the one below:
Let's delete all the resources we created: