Skip to content

Kubernetes mutating webhook written using Python and FastAPI

Notifications You must be signed in to change notification settings

k-mitevski/kubernetes-mutating-webhook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kubernetes Mutating Webhook

A Kubernetes mutating admission webhook, written using Python and FastAPI.

I've written a blog post that explains the whole set up.

The webhook will add a nodeSelector label when a Deployment, StatefulSet, or DaemonSet is created.

The required nodeSelector is set through the NODE_POOL environment variable in the webhook deployment file.

env:
- name: NODE_POOL
  value: "kubernetes.io/hostname: docker-desktop"

Example:

kubectl apply -f tests.yaml

deployment.apps/nginx-deployment created
statefulset.apps/nginx-sts created
[2022-11-06 21:50:08,723] INFO: Applying nodeSelector for Deployment/nginx-deployment.
[2022-11-06 21:50:08,723] INFO: Got 'kubernetes.io/hostname: docker-desktop' as nodeSelector label, patching pods...
INFO:     192.168.65.3:33852 - "POST /mutate?timeout=20s HTTP/1.1" 200 OK
[2022-11-06 21:50:08,785] INFO: Applying nodeSelector for StatefulSet/nginx-sts.
[2022-11-06 21:50:08,786] INFO: Got 'kubernetes.io/hostname: docker-desktop' as nodeSelector label, patching pods...

About

Kubernetes mutating webhook written using Python and FastAPI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published