Configuring routes
In this section we will show how to use Amazon VPC Lattice for advanced traffic management with weighted routing for blue/green and canary-style deployments.
Let's deploy a modified version of the checkout
microservice with an added prefix "Lattice" in the shipping options. Let's deploy this new version in a new namespace (checkoutv2
) using Kustomize.
The checkoutv2
namespace now contains a second version of the application, while using the same redis
instance in the checkout
namespace.
NAME READY STATUS RESTARTS AGE
checkout-854cd7cd66-s2blp 1/1 Running 0 26s
Now let's demonstrate how weighted routing works by creating HTTPRoute
resources. First we'll create a TargetGroupPolicy
that tells Lattice how to properly perform health checks on our checkout service:
apiVersion: application-networking.k8s.aws/v1alpha1
kind: TargetGroupPolicy
metadata:
name: checkout-policy
namespace: checkout
spec:
targetRef:
group: ""
kind: Service
name: checkout
protocol: HTTP
protocolVersion: HTTP1
healthCheck:
enabled: true
intervalSeconds: 10
timeoutSeconds: 1
healthyThresholdCount: 3
unhealthyThresholdCount: 2
path: "/health"
port: 8080
protocol: HTTP
protocolVersion: HTTP1
statusMatch: "200"
Apply this resource:
Now create the Kubernetes HTTPRoute
route that distributes 75% traffic to checkoutv2
and remaining 25% traffic to checkout
:
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: checkoutroute
namespace: checkout
spec:
parentRefs:
- name: ${EKS_CLUSTER_NAME}
sectionName: http
rules:
- backendRefs:
- name: checkout
namespace: checkout
kind: Service
port: 80
weight: 25
- name: checkout
namespace: checkoutv2
kind: Service
port: 80
weight: 75
Apply this resource:
This creation of the associated resources may take 2-3 minutes, run the following command to wait for it to complete:
Once completed you will find the HTTPRoute
's DNS name from HTTPRoute
annotation application-networking.k8s.aws/lattice-assigned-domain-name
:
Name: checkoutroute
Namespace: checkout
Labels: <none>
Annotations: application-networking.k8s.aws/lattice-assigned-domain-name:
checkoutroute-checkout-0d8e3f4604a069e36.7d67968.vpc-lattice-svcs.us-east-2.on.aws
API Version: gateway.networking.k8s.io/v1beta1
Kind: HTTPRoute
...
Now you can see the associated Service created in the VPC Lattice console under the Lattice resources.
Amazon VPC Lattice can now automatically redirect traffic to this service from any source, including different VPCs! You can also take full advantage of other VPC Lattice features.