flagger icon indicating copy to clipboard operation
flagger copied to clipboard

New deployments with Flagger gives 503s for a few second

Open khansuhel opened this issue 5 years ago • 8 comments

Hi,

we are facing an issue wherein every new deployment throws 503s for a few seconds before stabilising. Flagger is configured with linkerd and we are using Traefik as our Ingress controller.

Our setup looks like this

AWS EKS version: 1.18
Flagger version: 1.6.3
Linkerd version: stable-2.9.3
Traefik version: 2.1.3

We tested our setup by removing the Canary configured for our app and rollouts were normal. It is only when we configure Canary for our app that the 503s are observed.

Here is what the Canary for the app looks like

apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
  name: abc-app
  namespace: default
spec:
  provider: linkerd
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: abc-app
  progressDeadlineSeconds: 1200
  # See https://docs.flagger.app/usage/how-it-works#canary-finalizers
  # This will scale up the number of pods of the old deployment when deleting all flagger resources
  revertOnDeletion: true
  service:
    port: 80
    targetPort: 8080
    portName: http
    portDiscovery: true
  # promote the canary without analysing it
  skipAnalysis: false
  analysis:
    # schedule interval
    interval: 60s
    # max number of failed metric checks before rollback
    threshold: 5
    # max traffic percentage routed to canary
    # percentage (0-100)
    maxWeight: 100
    # canary increment step
    # percentage (0-100)
    stepWeight: 10
    # Incremental traffic percentage step for the promotion phase
    stepWeightPromotion: 10
    # Linkerd Prometheus checks
    metrics:
      - name: request-duration
        # maximum req duration P99
        # milliseconds
        thresholdRange:
          max:  90
        interval: 30s
      - name: request-success-rate
        # minimum req success rate (non 5xx responses)
        # percentage (0-100)
        thresholdRange:
          min: 500
        interval: 30s

Request your help with this issue.

khansuhel avatar Feb 23 '21 16:02 khansuhel

@khansuhel shot in the dark here, but: I had a similar issue and it was caused because I was reapplying the service resource every time with the deployments which caused the selector to be updated and then flagger updating it back. Matching your service resource selector with the one Flagger uses should fix the issue (or just not applying the service resource).

jhuliano avatar Feb 23 '21 16:02 jhuliano

@jhuliano that indeed was the problem. I ended up removing service.yaml and things went smooth after that. Although I still don't know why things were working fine with service.yaml until suddenly one day this issue came up. 🤷‍♂️ The only thing that I found in documentation is that flagger scans the deployments and creates three different artifacts (<service.name>., <service.name>.-primary, <service.name>.-canary ) for deployment automatically but how the presence of an explicit service can spoil the whole setup is probably not mentioned anywhere.

Anyways, Thanks for your help 🙂

khansuhel avatar Feb 24 '21 12:02 khansuhel

@khansuhel you can still have the explicit definitions though. In my case, I decided to have all my service resources defined explicitly (including the primary and canary), the only catch is that you need to match the Flagger configurations with the explicit definition (doing a kubectl get svc/{service} -o yaml can help you to spot the differences). But I guess indeed maybe it could be a good idea to document this behavior @stefanprodan ?

jhuliano avatar Feb 24 '21 12:02 jhuliano

@jhuliano could you share how your service.yaml looks like? Thank you!

ek-ex avatar Feb 24 '21 19:02 ek-ex

@stefanprodan im wondering what is your recommendation for this?

ek-ex avatar Feb 24 '21 19:02 ek-ex

@ek-ex this is what I have:

apiVersion: v1
kind: Service
metadata:
  name: ${SERVICE_NAME}
  labels:
    app: ${SERVICE_NAME}
    # Removes reference to canary resource to avoid services getting deleted together with canary resource
    ownerReferences: ~
spec:
  ports:
    - name: http
      port: 80
      targetPort: ${SERVICE_PORT}
      protocol: TCP
  selector:
    app: ${SERVICE_NAME}-primary

---
apiVersion: v1
kind: Service
metadata:
  name: ${SERVICE_NAME}-primary
  labels:
    app: ${SERVICE_NAME}-primary
    # Removes reference to canary resource to avoid services getting deleted together with canary resource
    ownerReferences: ~
spec:
  ports:
    - name: http
      port: 80
      targetPort: ${SERVICE_PORT}
      protocol: TCP
  selector:
    app: ${SERVICE_NAME}-primary

---
apiVersion: v1
kind: Service
metadata:
  name: ${SERVICE_NAME}-canary
  labels:
    app: ${SERVICE_NAME}-canary
    # Removes reference to canary resource to avoid services getting deleted together with canary resource
    ownerReferences: ~
spec:
  ports:
    - name: http
      port: 80
      targetPort: ${SERVICE_PORT}
      protocol: TCP
  selector:
    app: ${SERVICE_NAME}-canary

This of course might change depending on how Flagger is configured in your cluster, that is why doing a kubectl get svc/{service} -o yaml is probably your best shot.

jhuliano avatar Feb 25 '21 08:02 jhuliano

My recommendation is to delete the ClusterIP services from your charts/repos/etc and let Flagger manage them.

stefanprodan avatar Feb 25 '21 10:02 stefanprodan

@stefanprodan maybe a bit unrelated: but by any chance is there a way to create the resource without having the reference (metadata.lalbels.ownerReferences) to the canary resource? This causes the kubernetes "garbage collector" to delete all other resources If by any chance I happen to want to get rid of the canary resource. I don't want the service getting removed and causing an outage, for example, if we: recreate the canary resource or stop using Flagger.

That is one of the reasons why I chose to declare those resources, the other one is for clarity/explicitness on the codebase (being able to understand what resources the app is using to run).

jhuliano avatar Feb 25 '21 13:02 jhuliano