Replace image when creating pod, aims to speed up image pulling.
Clone this project. Run dev/webhook-create-signed-cert.sh
to generate a server certificate/key pair.
./dev/webhook-create-signed-cert.sh --service k8s-image-replacer --namespace default --secret k8s-image-replacer-tls
kubectl apply -f dev/k8s-image-replacer.yaml
Create a mutating webhook with the cluster CA bundle.
# Replace the ${CA_BUNDLE} placeholder with the actual value.
cat dev/mutating-webhook-template.yaml | ./dev/webhook-patch-ca-bundle.sh > mutating-webhook.yaml
# Create the mutating webhook.
kubectl apply -f mutating-webhook.yaml
The pod with k8s-image-replacer: enabled
label will be replaced image by default. If you want to set which pod's
image to be replaced, update the dev/mutating-webhook-template.yaml
and check the Kubernetes
document here
.
Follow the README here to build your own image registry proxy with Cloudflare Workers.
- When a pod is created, the Kubernetes API server will send a request to the
k8s-image-replacer
webhook. For more information, check the Kubernetes document. - The webhook service will check if the pod's image is in the replacement map in the configuration file.
- If the image is in the replacement map, the webhook will replace the image with the replacement image.
- The pod will be created with the replacement image.
- The image will be pulled from the image registry proxy.
MIT License