https://github.com/mikkeloscar/pdb-controller
Controller for adding default Pod Disruption Budgets to Kubernetes Deployments and StatefulSets
https://github.com/mikkeloscar/pdb-controller
budget controller disruption golang kubernetes pod
Last synced: 3 months ago
JSON representation
Controller for adding default Pod Disruption Budgets to Kubernetes Deployments and StatefulSets
- Host: GitHub
- URL: https://github.com/mikkeloscar/pdb-controller
- Owner: mikkeloscar
- License: apache-2.0
- Created: 2017-09-16T22:40:34.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2025-02-06T10:34:32.000Z (5 months ago)
- Last Synced: 2025-04-12T05:13:01.145Z (3 months ago)
- Topics: budget, controller, disruption, golang, kubernetes, pod
- Language: Go
- Homepage:
- Size: 188 KB
- Stars: 50
- Watchers: 7
- Forks: 12
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Pod Disruption Budget Controller
[](https://github.com/mikkeloscar/pdb-controller/actions?query=branch:master)
[](https://coveralls.io/github/mikkeloscar/pdb-controller)This is a simple Kubernetes controller for adding default [Pod Disruption
Budgets (PDBs)][pdb] for Deployments and StatefulSets in case none are defined. This
is inspired by the dicussion in
[kubernetes/kubernetes#35318](https://github.com/kubernetes/kubernetes/issues/35318)
and was created for lack of an alternative.## How it works
The controller simply gets all Pod Disruption Budgets for each namespace and
compares them to Deployments and StatefulSets. For any resource with more than
1 replica and no matching Pod Disruption Budget, a default PDB will be created:```yaml
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: my-app
namespace: kube-system
labels:
application: my-app
heritage: pdb-controller
version: v1.0.0
spec:
maxUnavailable: 1
selector:
matchLabels:
application: my-app
```The selector and labels are based on those from the related Deployment or
StatefulSet. The special `heritage=pdb-controller` label is set by the
controller and is used to find owned PDBs. Owned PDBs are removed in case
replicas of the related resource is scaled to 1 or less. This
is done to prevent deadlocking for clients depending on the PDBs e.g. cluster
upgrade tools.Additionally you can run the controller with the flag `--non-ready-ttl=15m`
which means it will remove owned PDBs in case the pods of a targeted deployment
or statefulset are non-ready for more than the specified ttl. This is another
way to ensure broken deployments doesn't block cluster operations.This global value can also be overriden by specifying the annotation
`pdb-controller.zalando.org/non-ready-ttl` on a deployment or statefulset.## Building
This project uses [Go modules](https://github.com/golang/go/wiki/Modules) as
introduced in Go 1.11 therefore you need Go >=1.11 installed in order to build.
If using Go 1.11 you also need to [activate Module
support](https://github.com/golang/go/wiki/Modules#installing-and-activating-module-support).Assuming Go has been setup with module support it can be built simply by running:
```sh
$ make
```## Setup
The `pdb-controller` can be run as a deployment in the cluster. See
[deployment.yaml](docs/deployment.yaml) for an example.Deploy it by running:
```bash
$ kubectl apply -f docs/deployment.yaml
```## TODO
* [ ] Instead of long polling, add a Watch feature.
## LICENSE
See [LICENSE](LICENSE) file.
[pdb]: https://kubernetes.io/docs/tasks/run-application/configure-pdb/