Skip to content

Flagger on EKS App Mesh

Interactive Diagram

새 탭 ↗

Configuring a Kubernetes Object Delivery environment using Flagger on Amazon App Mesh (the Service Mesh provided by AWS) and integrating it with an FluxCD-based Amazon EKS GitOps environment.

  • App Mesh integration with Amazon EKS

    • Kubernetes custom resources: using mesh, virtual nodes, routers, services (excluding the Virtual Gateway for external exposure)
    • CRD controller: synchronization of the App Mesh control plane with custom resources
    • Admission controller: Envoy sidecar injection and assigning services (pods) to App Mesh virtual nodes
    • Telemetry service: using the Prometheus provided by App Mesh
    • Progressive delivery operator: canary release automation using a Flagger instance

See the EKS GitOps Handson https://eks.handson.flagger.dev/profile/#app-mesh-profile

  • GitOps Pipeline

    • A pre-configured Amazon EKS cluster (ver. >= 1.16)
    • A pre-configured ECR
    • A pre-configured AWS Code Pipeline (CodeCommit + CodeBuild)
    • A Pull-based Deployment environment for an FluxCD-based K8s manifest repository
  • Delivery Process

    • Install App Mesh Components and Prometheus
    • Install Flagger

See the Flagger Official Docs https://docs.flagger.app/install/flagger-install-on-eks-appmesh

  • Add the Helm repository
Terminal window
helm repo add eks https://aws.github.io/eks-charts
  • Install the App Mesh CRD and create the namespace:
Terminal window
kubectl apply -k github.com/aws/eks-charts/stable/appmesh-controller//crds?ref=master
kubectl create ns appmesh-system
  • App Mesh controller helm install
Terminal window
helm upgrade -i appmesh-controller eks/appmesh-controller \
--wait --namespace appmesh-system
  • App Mesh Prometheus helm install : Installed to collect App Mesh metrics needed for Flagger’s canary analysis
Terminal window
helm upgrade -i appmesh-prometheus eks/appmesh-prometheus \
--wait --namespace appmesh-system
  • Add the Helm repository
Terminal window
helm repo add flagger https://flagger.app
  • Install the Flagger CRD : Canary, AlertProvider, MetricTemplate, etc.
Terminal window
kubectl apply -f https://raw.githubusercontent.com/fluxcd/flagger/main/artifacts/flagger/crd.yaml
  • Flagger helm install in the App Mesh namespace
Terminal window
helm upgrade -i flagger flagger/flagger \
--namespace=appmesh-system \
--set crd.create=false \
--set meshProvider=appmesh:v1beta2 \
--set metricsServer=http://appmesh-prometheus:9090
  • Flagger Grafana helm install for monitoring
Terminal window
helm upgrade -i flagger-grafana flagger/grafana \
--set url=http://prometheus:9090

Configuration details of a Service Mesh-based Flagger Canary Release. By defining Flagger’s Canary custom resource, an Amazon App Mesh-based canary release automation process was configured.

See the Flagger Official Docs https://docs.flagger.app/tutorials/appmesh-progressive-delivery

Based on the target deployment and HPA defined in the Canary resource, Flagger not only creates the primary deployment, service, HPA, etc., but also creates the custom resources needed for the service mesh that matches the defined provider.

In the case of App Mesh, if you configure the environment manually, you have to directly define and apply K8s manifests for Mesh, VirtualNode, VirtualService, VirtualRouter, etc. However, when you define it using Flagger’s Canary resource, it automatically creates the virtual node, service, and router for the related primary and canary routes, so only the mesh (which defines the logical boundary of the global scope for App Mesh configuration) was created directly.

  • Mesh resource manifest
apiVersion: appmesh.k8s.aws/v1beta2
kind: Mesh
metadata:
name: global
spec:
namespaceSelector:
matchLabels:
appmesh.k8s.aws/sidecarInjectorWebhook: enabled
egressFilter:
type: ALLOW_ALL
  • Example of creating virtual node, router, and service directly
---
# VirtualNode: acts as a logical pointer to a k8s service
apiVersion: appmesh.k8s.aws/v1beta2
kind: VirtualNode
metadata:
name: mariadb-shop
spec:
podSelector:
matchLabels:
app: mariadb-shop
listeners:
- portMapping:
port: 3306
protocol: tcp
serviceDiscovery:
dns: # specify service
hostname: mariadb-shop.shop-infra.svc.cluster.local.
---
# VirtualRouter: routes VirtualService traffic to a VirtualNode
apiVersion: appmesh.k8s.aws/v1beta2
kind: VirtualRouter
metadata:
name: mariadb-shop
spec:
listeners:
- portMapping:
port: 3306
protocol: tcp
routes:
- name: route-to-mariadb-shop
tcpRoute:
action:
weightedTargets:
- virtualNodeRef:
name: mariadb-shop
weight: 1
---
# VirtualService: an object abstracting an actual k8s service. created with the same name as the service
apiVersion: appmesh.k8s.aws/v1beta2
kind: VirtualService
metadata:
name: mariadb-shop
spec:
awsName: mariadb-shop.shop-infra
provider:
virtualRouter:
virtualRouterRef:
name: mariadb-shop
  • App Mesh Traffic Flow example

App Mesh example: service calls through Envoy proxies and the relationship between virtual services, virtual routers and virtual nodes Source: AWS App Mesh User Guide, What is AWS App Mesh, Amazon Web Services, CC BY-SA 4.0

See the Amazon App Mesh Official Docs https://docs.aws.amazon.com/app-mesh/latest/userguide/what-is-app-mesh.html

Details of creating a Canary Resource targeting the deployment and HPA configuration that was previously deployed based on FluxCD.

  • Canary resource manifest example
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
name: <name>
spec:
provider: appmesh:v1beta2
# target deployment definition
targetRef:
apiVersion: apps/v1
kind: Deployment
name: <name>
progressDeadlineSeconds: 300
# target hpa definition
autoscalerRef:
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
name: <name>
# service definition for expose (ClusterIP)
service:
port: <port>
backends: # for App Mesh, content that must be added to allow virtual service egress
- arn:aws:appmesh:ap-northeast-2:170247361816:mesh/global/virtualService/mariadb-shop.shop-infra
- arn:aws:appmesh:ap-northeast-2:170247361816:mesh/global/virtualService/rabbitmq.shop-infra
- arn:aws:appmesh:ap-northeast-2:170247361816:mesh/global/virtualService/redis-session.shop-infra
# canary analysis definition area
skipAnalysis: false # if true, canary promotion happens immediately
analysis:
# schedule interval (default 60s)
interval: 30s
# max number of failed metric checks before rollback
threshold: 3
# define the maximum weight value to reach, percentage (0-100)
maxWeight: 80
# traffic weight increment unit, percentage (0-100)
stepWeight: 20
# metric check of App Mesh Prometheus
### flagger's service mesh metric check provides the following 2 items by default
### request success rate, duration
metrics:
- name: request-success-rate
# minimum req success rate (non 5xx responses), percentage (0-100)
thresholdRange:
min: 99
interval: 1m
- name: request-duration
# maximum req duration P99, milliseconds
thresholdRange:
max: 500
interval: 30s
# send a message to the slack channel using the created alert provider as reference
### alert provider is pre-created in the namespace based on the slack web hook url.
alerts:
- name: "dev team Slack"
severity: info
providerRef:
name: on-call
namespace: shop
# webhook-based Testing (optional)
### defined as rollout type, calls a url that invokes a curl command whenever the weight changes
### the flagger-loadtester application is pre-deployed.
webhooks:
- name: acceptance-test
type: rollout
url: http://flagger-loadtester.shop/
timeout: 60s
metadata:
type: bash
cmd: "curl -X GET http://account-canary.shop:8180/v1/accounts/events"
  • Alert Provider creation manifest example
apiVersion: flagger.app/v1beta1
kind: AlertProvider
metadata:
name: on-call
spec:
type: slack
channel: on-call-alerts
username: flagger
# webhook address (ignored if secretRef is specified)
address: <webhook address>
  • Objects generated when creating the Canary resource : the app name is account
Terminal window
# Flagger canary resource
canary.flagger.app/account
# primary object of the target deployment and hpa
deployment.apps/account-primary
horizontalpodautoscaler.autoscaling/account-primary
# canary service for the primary service and weight routing
service/account ClusterIP
service/account-canary ClusterIP
service/account-primary ClusterIP
# App Mesh resource, assigned an AWS arn.
virtualnode.appmesh.k8s.aws/account-canary arn:aws:appmesh:ap-northeast-2:170247361816:mesh/global/virtualNode/account-canary_shop
virtualnode.appmesh.k8s.aws/account-primary arn:aws:appmesh:ap-northeast-2:170247361816:mesh/global/virtualNode/account-primary_shop
virtualrouter.appmesh.k8s.aws/account arn:aws:appmesh:ap-northeast-2:170247361816:mesh/global/virtualRouter/account_shop
virtualrouter.appmesh.k8s.aws/account-canary arn:aws:appmesh:ap-northeast-2:170247361816:mesh/global/virtualRouter/account-canary_shop
virtualservice.appmesh.k8s.aws/account arn:aws:appmesh:ap-northeast-2:170247361816:mesh/global/virtualService/account.shop
virtualservice.appmesh.k8s.aws/account-canary arn:aws:appmesh:ap-northeast-2:170247361816:mesh/global/virtualService/account-canary.shop

A Canary release demo of an application that mounts the application properties of a Spring Boot Application as a configmap volume.

  1. Modify the spring boot application property in the K8s manifest git repository, then commit & push.
  2. FluxCD performs kustomize reconciliation, regenerating the K8s configmap.
  3. Flagger detects the change event on the configmap and starts the canary release process.
  4. Canary Release 4-1. Due to the changed configmap, an application error occurs and pod creation fails 4-2. A Slack message is received via the alert provider
  5. Modify the spring boot application property in the K8s manifest git repository to the correct value, then commit & push.
  6. Repeat steps 2 ~ 4 again.
  7. Canary Release 7-1. The request-success-rate metric analysis threshold check fails 7-2. A Slack message is received via the alert provider
  8. Adjust the metric threshold of the Flagger canary resource
  9. Perform a Deployment rollout restart.
  10. A Slack message is received via the alert provider.
PlantUML Diagram

Summary of test details by case.

  • Set an incorrect db connection and git commit & push.
$ git diff HEAD^ HEAD
--- a/clusters/eks/shop/prd/account/application-prd.yml
+++ b/clusters/eks/shop/prd/account/application-prd.yml
@@ -11,7 +11,7 @@ spring:
database-platform: org.hibernate.dialect.MariaDB103Dialect
datasource:
driver-class-name: org.mariadb.jdbc.Driver
- url: jdbc:mariadb://mariadb-shop.shop-infra/accounts?characterEncoding=UTF-8
+ url: jdbc:mariadb://mariadb-shop-new.shop-infra/accounts?characterEncoding=UTF-8
  • FluxCD changes only the configmap account, and as a result Flagger starts the Canary release : Due to the configmap change, an error occurs in the newly created pod, making the canary release impossible.
Terminal window
$ kubectl get cm
NAME DATA
account 2
account-primary 2
  • Received the Canary release alert Canary release alert

Canary analysis metric threshold check failure

Section titled “Canary analysis metric threshold check failure”

The success rate did not reach the 100% threshold, so the canary release failed.

  • canary describe details : This can also be checked from the controller logs, and status monitoring of the canary resource is possible as well.
$ kubectl describe canary
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Synced 50m flagger Copying account.shop template spec to account-primary.shop
Normal Synced 49m flagger Routing all traffic to primary
Normal Synced 49m flagger Promotion completed! Scaling down account.shop
Normal Synced 32m (x2 over 52m) flagger New revision detected! Scaling up account.shop
Normal Synced 31m (x2 over 51m) flagger Advance account.shop canary weight 25
Normal Synced 31m (x2 over 51m) flagger Starting canary analysis for account.shop
Normal Synced 30m (x2 over 50m) flagger Advance account.shop canary weight 50
Warning Synced 30m flagger Halt account.shop advancement success rate 99.74% < 100%
Warning Synced 29m flagger Halt account.shop advancement success rate 99.54% < 100%
Warning Synced 29m flagger Halt account.shop advancement success rate 99.58% < 100%
Warning Synced 28m flagger Halt account.shop advancement success rate 99.61% < 100%
Warning Synced 28m flagger Halt account.shop advancement success rate 99.53% < 100%
Warning Synced 27m flagger Halt account.shop advancement success rate 99.66% < 100%
Warning Synced 26m (x3 over 27m) flagger Halt account.shop advancement success rate 99.65% < 100%
Warning Synced 25m flagger Rolling back account.shop failed checks threshold reached 10
Warning Synced 25m flagger (combined from similar events): Canary failed! Scaling down account.shop
  • Monitoring through the Flagger Dashboard : Uses App Mesh’s Prometheus metrics. The same applies to Flagger.

  • AWS X-ray Monitoring : Verify whether traffic was actually distributed well between pods, and check in which pod the error occurred. : The error rate of the component below is shown in red proportionally. I checked because I was skeptical about whether the traffic distribution was really working well.

Adjusting the Canary analysis metric threshold

Section titled “Adjusting the Canary analysis metric threshold”

After adjusting the threshold, restart the Canary release. Even though the K8s canary resource was modified due to the metric threshold change, since there is no change to the Pod Spec, configmap, or secret, Flagger does not automatically perform the canary release.

Perform a rollout restart of the Deployment to start the canary release.

  • After modifying the threshold range of the Canary analysis, git commit & push : After that, restart the deployment.
@@ -59,7 +59,7 @@ spec:
# minimum req success rate (non 5xx responses)
# percentage (0-100)
thresholdRange:
- min: 100
+ min: 95
interval: 3m
  • Check Canary status : The metric threshold check completes normally, and canary promotion is performed.
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Synced 5m54s (x3 over 68m) flagger New revision detected! Scaling up account.shop
Warning Synced 5m24s flagger canary deployment account.shop not ready: waiting for rollout to finish: 1 of 2 updated replicas are available
Normal Synced 4m54s (x3 over 68m) flagger Starting canary analysis for account.shop
Normal Synced 4m54s (x3 over 68m) flagger Advance account.shop canary weight 25
Normal Synced 3m54s (x3 over 67m) flagger Advance account.shop canary weight 50
Normal Synced 3m24s (x2 over 66m) flagger Copying account.shop template spec to account-primary.shop
Normal Synced 2m54s (x2 over 66m) flagger Routing all traffic to primary
Normal Synced 2m24s (x2 over 65m) flagger Promotion completed! Scaling down account.shop
  • Received Slack message : Received a start message and a normal completion message

Canary promotion completion alert

TBD