AWS EKS Ingress - Canary
Tags: eks, kubernetes, canary, cka
Published: 2024-03-28 20:25:49

## Dealing with Canary
In this article I will be trying to explain, on how to create a canary deployment using AWS Application LoadBalancer using canary behavior 

We need to consider below pre-requisite before we deploy our application, (using AWS Cloud shell to do this demo)

1. Preinstalled eks cluster ( Ref: https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html) 
2. Helm Command should works on your AWS Cloud Shell ( Ref: https://docs.aws.amazon.com/eks/latest/userguide/helm.html)
3. eksctl command is already installed in my case ( Ref: https://docs.aws.amazon.com/eks/latest/userguide/lbc-helm.html) 
4. AWS Load Balancer Controller Should be installed already ( Ref: https://docs.aws.amazon.com/eks/latest/userguide/lbc-helm.html) 
5. I have enabled subnet autodiscovery option by adding tags referred https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.1/deploy/subnet_discovery/ 
Below is the graphical representation of my example 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0zwzebc4o7v0gbschzuc.png)
I have deployed two applications for doing this test, one is httpd running on 80 port number and the other one is hello-openshift running on 8080, this can be deployed using below commands 

```
kubectl create deployment mydep1 --image=docker.io/httpd
kubectl expose deployment mydep1 --port=80
kubectl create deployment mydep2 --image=docker.io/openshitf/hello-openshift
kubectl expose deployment mydep2 --port=8080
```
We are using default service type called clusterIP as our ingress will point to these services, please refer the below screenshots

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jqk7m2gngglys1lj24jl.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rxh5eij3be3c9qa1xmlq.png)
below is the yaml code for our ingress.yaml file

```
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: "canary"
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/actions.blue-green: |
      {
        "type":"forward",
        "forwardConfig":{
          "targetGroups":[
            {
              "serviceName":"mydep1",
              "servicePort":"80",
              "weight":50
            },
            {
              "serviceName":"mydep2",
              "servicePort":"8080",
              "weight":50
            }
          ]
        }
      }
  labels:
    app: canary
spec:
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: blue-green
                port:
                  name: use-annotation
```
---
kubectl apply -f ingress.yaml can se used to deploy this , once deployed we will get output like below 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fn2c1hkbjxaan21ob6jm.png)
Now let's try to run the for loop to test the 50-50 percentage canary deployment

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cyajv1m5ofq4zjn1gq7q.png)

We can clearly conclude the 50-50 load is getting distributed using the canary ingress. 

Note: I was facing issues while deploying EKS Load Balancer controller, by using kubectl logs -f -n kube-system -l app.kubernetes.io/instance=aws-load-balancer-controller command was able to conclude the error was coming due to subnet tags was missing. 

Happy Learning !!!