maxtacu/ecr-pull-through
Mutating webhook for ECR pull-through
ECR Pull-Through Cache Mutation Webhook ๐
A Kubernetes mutation webhook that automatically redirects container image pulls through Amazon ECR's pull-through cache, optimizing performance and reducing costs.
๐ฏ What It Does
This webhook intercepts pod creation requests in your Kubernetes cluster and automatically modifies container image references to use Amazon ECR's pull-through cache. This means:
- โก Faster image pulls through local caching
- ๐ฐ Reduced network egress costs
- ๐ Seamless integration with existing deployments
๐ฆ Prerequisites
-
ECR Pull-Through Cache Configuration
You must manually configure pull-through cache for these registries:ghcr.iodocker.ioregistry.k8s.ioquay.io
โ ๏ธ Important: Use registry-matching names for your configurations as required by this webhook. -
IAM Configuration
Check theaws-policiesfolder for:- Example lifecycle policies for Creation Templates
- ECR Registry policy examples
- Role configurations for EKS nodes
๐ For detailed ECR Pull-Through setup, see the AWS documentation.
๐ ๏ธ Installation Options
Option 1: Helm Chart (Recommended)
-
Clone the repository:
-
Install the chart:
helm install ecr-pull-through -n kube-system chart/ecr-pull-through \
--set awsAccount=123456789012 \
--set awsRegion=us-west-2๐ Prerequisites:
- cert-manager must be installed in your cluster
- The chart uses cert-manager to generate TLS certificates for the webhook
Option 2: Kyverno Policies
Note: docker.io support is limited in Kyverno configuration
- Find policies for
docker.io,quay.io,registry.k8s.io, andghcr.ioin thekyvernofolder - Update AWS account ID in policies
- Apply to your cluster
Option 3: Manual Webhook Installation
- Clone this repository
- Go to
manifestsfolder - Configure manifests/configmap.yaml
- Ensure your kubectl context points to the target cluster
- Run
./install.sh
๐ Note: By default, the webhook only processes namespaces labeled with
pull-through-enabled: "true". Modify manifests/bundle.yaml to change this behavior.
๐งช Testing
Use the sample pod manifests in the tests folder to verify the webhook's operation.
๐งน Maintenance
ECR Repository Cleanup
This might be useful if you are testing ECR Pull-through and want to occasionally cleanup pull-through registries.
Use ecr-cleanup.sh to remove pull-through generated repositories:
./ecr-cleanup.sh๐ License
This project is open-source and available under the MIT License.
