Giter VIP home page Giter VIP logo

zone-aware-controllers-for-k8s's Introduction

Zone Aware Controllers for K8s

Introduction

Kubernetes controllers for zone (AZ) aware rollouts and disruptions.

Controllers

ZoneAwareUpdates (ZAU)

The ZoneAwareUpdate (ZAU) controller enables faster deployments for a StatefulSet whose pods are deployed across multiple availability zones. At each control loop, it applies zone-aware logic to check for pods in an old revision and deletes them so that they can be updated to a new revision.

Update Strategy

The controller exponentially increases the number of pods simultaneously deleted, deploying slowly at first and accelerating as confidence is gained in the new revision. For example, it will start by updating a single pod, then 2, then 4 and so on. The number of pods deleted in an iteration will never exceed the configured MaxUnavailable value.

The controller also never update pods from different zones at the same time, and when moving to subsequent zones it continues to increase the number of pods to be deleted until MaxUnavailable is reached.

After deleting pods, the controller will wait for them to transition to Ready state before updating the next set of pods.

When a rollback (or new rollout) is initiated before a deployment finishes, it is important to delete the most recently updated pods first to move away as fast as possible from a faulty revision. To achieve that, the controller always deletes pods in a specific order, using the zone ascending alphabetical order in conjunction with the pod decreasing ordinal order, as shown in the figure below:

             >>>>>----------------- Update Sequence (MaxUnavailable = 4) ------------------->

pod #   [[28], [27, 22], [19, 17, 15, 10], [8, 6, 1]], [[29, 26, 23, 20], [16, 14, 11, 7], [5, 2]], ...
        |                                           |  |                                         |
        '---------------- zone-1 -------------------'  '---------------- zone-2 -----------------'

Some applications don't necessarily need to have pods updated exponentially. For those, it's possible to disable exponential updates by setting the ExponentialFactor to zero.

          >>>>>---------- Update Sequence (MaxUnavailable = 4, ExponentialFactor = 0) -------->

pod #   [[28, 27, 22, 19], [17, 15, 10, 8], [6, 1]], [[29, 26, 23, 20], [16, 14, 11, 7], [5, 2]], ...
        |                                         |  |                                         |
        '---------------- zone-1 -----------------'  '---------------- zone-2 -----------------'

Usage

To have the rollout of a StatefulSet's pods coordinated by ZAU controller, the StatefulSet update strategy should be changed to OnDelete and a ZoneAwareUpdate resource defined into the same namespace as the StatefulSet.

apiVersion: zonecontrol.k8s.aws/v1
kind: ZoneAwareUpdate
metadata:
  name: <zau-name>
spec:
  statefulset: <sts-name>
  maxUnavailable: 2

maxUnavailable can be an absolute number or a percentage of total Pods. For example, in case your application is evenly distributed accross 3 zones, it's possible to update all pods at once in each zone by setting maxUnavailable to at leat 33% and exponentialFactor to 0:

apiVersion: zonecontrol.k8s.aws/v1
kind: ZoneAwareUpdate
metadata:
  name: <zau-name>
spec:
  statefulset: <sts-name>
  maxUnavailable: 33%
  exponentialFactor: 0

It's also possible to specify the name of a Amazon CloudWatch aggregate alarm that will pause the rollout when in alarm state. This can be used to prevent deployments from preceeding in case of canary failures, for example.

apiVersion: zonecontrol.k8s.aws/v1
kind: ZoneAwareUpdate
metadata:
  name: <zau-name>
spec:
  statefulset: <sts-name>
  maxUnavailable: 2
  pauseRolloutAlarm: <cw-aggregate-alarm-name>
  ignoreAlarm: false

ZoneDisruptionBudgets (ZDB)

The ZoneDisruptionBudget (ZDB) admission webhook controller extends the PodDisruptionBudgets (PDB) concept, allowing multiple disruptions only if the pods being disrupted are in the same zone.

Similar to the k8s' DisruptionController, the ZoneDisruptionBudget (ZDB) Controller is responsible for watching for changes to ZDBs and for keeping their status up to date, checking at each control-loop (https://kubernetes.io/docs/concepts/architecture/controller/) which pods are unavailable to calculate the number of disruptions allowed per zone at any time.

A validation admission webhook is used to intercept requests to the eviction API, accepting or rejecting them based on ZDB's status, allowing multiple pods disruptions in zone-1, while blocking evictions from other zones.

Usage

A ZoneDisruptionBudget has three fields:

  • A label selector .spec.selector to specify the set of pods to which it applies. This field is required.
  • .spec.maxUnavailable that defines the maximun number of pods in the same zone that can be unavailable after the eviction. It can be either an absolute number or a percentage.
apiVersion: zonecontrol.k8s.aws/v1
kind: ZoneDisruptionBudget
metadata:
  name: <zdb-name>
spec:
  selector: <pod-selector>
  maxUnavailable: 10%

Installation

The controllers were built using the kubebuilder framework. The kubebuilder based Makefile is available to use for development and deployment.

To build and push the controllers image to your container registry:

make docker-build docker-push IMG=<image-url>

To deploy the controllers to the K8s cluster specified in ~/.kube/config:

make deploy IMG=<image-url>

The controllers will be deployed to the zone-aware-controllers-system namespace by default. The namespace used can be changed in ./config/default/kustomization.yaml file.

Finally, to undeploy the controllers:

make undeploy 

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

zone-aware-controllers-for-k8s's People

Contributors

amazon-auto avatar dependabot[bot] avatar marianafranco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zone-aware-controllers-for-k8s's Issues

Make it possible to run only one of the controllers

Some users want to use only the ZAU controller to speed up deployments, not requiring the ZDB to be running. Today, both ZAU and the ZDB controllers will be started when the zone-aware-controllers is deployed.

Question: StatefulSet with zone-local EBS

I want to run application as StatefulSet in k8s in say 3 AZ:

pod-0 in AZ a
pod-1 in AZ b
pod-2 in AZ c

with the EBS attached to each of them, because EBS are AZ-local

Do I need to write operator for this or I can you this zone-aware controller?

Helm chart

Provide helm chart templates to make deployments easier.

Deployment support

Deployments could definitely benefit from ZoneAwareUpdate

For example:

apiVersion: zonecontrol.k8s.aws/v1
kind: ZoneAwareUpdate
metadata:
  name: <zau-name>
spec:
  deployment: <deployment-name>
  maxUnavailable: 2

Support an upper bound when updating pods

ZAU currently supports a maxUnavailable and ExponentialFactor params to set how fast we want to update our pods.

We can set maxUnavailable as int or exponential. But that could not be enough in some scenarios where pods scales.
Example: 30 pods running.
If we set the maxUnavailable as 3, when the number of pods grows this number will be obsolete and too small.
If we set the maxUnavailable as 10%, when the number of pods increase a lot (eg:2000), 200 maybe be too fast to update nodes.

It would be nice to have a upper bound limit to not allow the percentage to overcome a certain amount.
One idea is to have something similar to kubernets HPA where you can allow different policies and the behavior which they work
https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/

CI/CD - Run tests

Create github actions to run unit and integ tests on new changes.

make docker-build is failing with go 1.19

The following error is happening when calling make docker-build for the first time on an environment with go 1.19:

make docker-build
go: creating new go.mod: module tmp
Downloading sigs.k8s.io/controller-tools/cmd/[email protected]
...
/Users/myuser/workplace/zone-aware-controllers-for-k8s/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
bash: /Users/myuser/workplace/zone-aware-controllers-for-k8s/bin/controller-gen: No such file or directory
make: *** [manifests] Error 127

Looks like we need to updated the Makefile to stop using go get to install go binaries : kubernetes-sigs/kubebuilder@b0c7cd8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.