Kubernetes Public Image Cache Controller
Overview
Kubernetes controller for automatically backup public
images to user's registry which are used in Deployments and DaemonSets.
kube-system and controller's namespaces are ignored.
Testing On MacOS
Install & Start Minikube Cluster
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64
sudo install minikube-darwin-amd64 /usr/local/bin/minikube
# Start Cluster
minikube start
# Start Dashboard
minikube dashboard
If you're going to use local docker images for testing, use minikube for image building as follows.
- Set the environment variables with eval $(minikube docker-env)
- Build the image with the Docker daemon of Minikube (eg docker build -t my-image .)
- Set the image in the pod spec like the build tag (eg my-image)
- Set the imagePullPolicy to Never, otherwise Kubernetes will try to download the image.
Build & Push Your Own Controller
docker build -t <username>/kube-image-clone-controller:latest .
docker push <username>/kube-image-clone-controller:latest
Pull Public Image from Dockerhub
docker push testingnew123/kube-image-clone-controller:latest
Quick Start
Create the NameSpace
kubectl create namespace image-clone-namespace
Set the Target Docker Registry Credentials as a Secret
kubectl create secret --namespace=image-clone-namespace generic docker-registry-credentials \
--from-literal=docker-server=index.docker.io \
--from-literal=docker-username=testingnew123 \
--from-literal=docker-password=xxxx
Kubernetes config file is prepared with necessary RBAC config to start.
kubectl apply -f .kubenates/k8s.yaml
DEMO
Stop Controller
kubectl delete -f .kubenates/k8s.yaml
NOTE: This will remove the namespace and all data associated with image-clone-controller.
Special Notes and Assumptions
- Source Repository is properly tagged and previous tags will not be overridden.(once a tag is cloned it will not be cloned again until it remains in the target registry)
- If
latest
tag is referred in the image it will always clone to the target registry.