Create Ingress With Path Based Routing¶
Path-based routing is one of the features offered by Application Load Balancer.
The Application Load Balancer forwards the requests to the specific targets based on the rules configured in the load balancer.
Overriding Health Check Configuration¶
Since each target in this case might have different health check requirements, you can override the ingress health check configurations by adding the same health check annotations in kubernetes service definition.
Docker Images¶
Here are the Docker Images used in this tutorial:
Note
All microservices (profile
, notifications
, and feed
) run on port 3000
.
- reyanshkharga/reactapp:profile is a react app that serves request on
/profile
path. - reyanshkharga/reactapp:notifications is a react app that serves request on
/notifications
path. - reyanshkharga/reactapp:feed is a react app that serves request on
/feed
path.
Objective¶
In this example we will have 3 microservices:
profile
: uses docker imagereyanshkharga/reactapp:profile
notifications
: uses docker imagereyanshkharga/reactapp:notifications
feed
: uses docker imagereyanshkharga/reactapp:feed
We'll do the following:
- Create a deployment and service for
profile
microservice. - Create a deployment and service for
notifications
microservice. - Create a deployment and service for
feed
microservice. - Create a ingress that sends traffic to one of the microservices based on the path.
- We'll also provide separate health check path for each microservice using
alb.ingress.kubernetes.io/healthcheck-path
annotation in the service definition of each microservice.
Step 1: Create Kubernetes Objects¶
Let's create the kubernetes objects as discussed above:
Observe the following:
- We've provided the health check paths for each of the microservices using the
alb.ingress.kubernetes.io/healthcheck-path
annotation. - In the ingress, we have used path-based rules to route traffic to a particular microservice based on matching path.
Assuming your folder structure looks like the one below:
Let's apply the manifests to create the kubernetes objects:
This will create the following resources:
- Deployment and service for
profile
microservice. - Deployment and service for
notifications
microservice. - Deployment and service for
feed
microservice. - Ingress with three rules.
Step 2: Verify Kubernetes Objects¶
# List pods
kubectl get pods
# List deployments
kubectl get deployments
# List services
kubectl get svc
# List ingress
kubectl get ingress
Also, go to the AWS Console and verify the resources created by the AWS Load Balancer Controller, including the load balancer, target groups, listener rules, etc.
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 3: Access App Via Load Balancer DNS¶
Copy the load balancer DNS from the ingress or AWS console and verify the following paths:
If everything is fine, the <alb-dns>/profile
, <alb-dns>/notifications
, and <alb-dns>/feed
paths should serve the profile
, notifications
, and feed
microservices, respectively.
Ordering of Load Balancer Listener Rules¶
Rules are evaluated in priority order, from the lowest value to the highest value. The default rule is evaluated last. You can change the priority of a non-default rule at any time but you cannot change the priority of the default rule.
In later sections, we'll explore how to use the IngressGroup
feature of the AWS Load Balancer Controller to specify the desired ordering of listener rules.
Clean Up¶
Assuming your folder structure looks like the one below:
Let's delete all the resources we created: