kube-fledged
repository·master·Indexed 23 days ago
https://github.com/senthilrch/kube-fledgedA Kubernetes operator that manages container image caches on worker nodes to enable near-instant pod startup times. It allows users to pre-pull a defined list of images onto specific nodes via the ImageCache Custom Resource, which is particularly useful for rapid scaling, serverless functions, and IoT/Edge computing.
What's inside kube-fledged
- kube-fledged is a Kubernetes operator designed to create and manage a cache of container images directly on the worker nodes of a cluster. By pre-pulling a defined list of images onto specific worker nodes, it ensures that application pods can start almost instantly without waiting for images to be pulled from a remote registry. This is particularly useful for rapid scaling, serverless functions, IoT/Edge computing with intermittent connectivity, and managing access to private registries.
How kube-fledged works with Kubernetes Custom Resources
masterkube-fledged extends the Kubernetes API by defining a Custom Resource of kind
ImageCache. The core logic is managed by a custom controller namedkubefledged-controller.Users interact with the system by using standard
kubectlcommands to create or deleteImageCacheresources. Thekubefledged-controllermanages the image lifecycle using the following mechanisms:- Image Manager Routine: Responsible for pulling and deleting images using Kubernetes Jobs.
- Refresh Worker: If enabled, periodically refreshes the image cache to ensure it remains up to date.
- Status Updates: The controller automatically updates the
statusfield of theImageCacheresource to reflect the current state of image pulls, refreshes, and deletions.
How the Cluster Image Cache works
masterKube-Fledged implements a distributed Cluster Image Cache using a Kubernetes Custom Resource Definition (CRD) of kind
ImageCache. Instead of a centralized registry mirror, images are pulled directly onto specific worker nodes.When a Pod is scheduled, if its
imagePullPolicyis set toNeverorIfNotPresent, the container runtime will use the image already present in the node's local cache, eliminating the latency of pulling from a remote registry. This is particularly useful for edge computing or scenarios requiring near-instant Pod startup.Key behaviors:
- Node Selection: Images are distributed to nodes based on
nodeSelectorlabels. - Automatic Refresh: A background controller periodically checks if images are missing (e.g., due to Kubelet's garbage collection or new nodes being added) and re-pulls them.
- On-demand Refresh: Users can trigger a manual refresh by annotating the
ImageCacheresource. - Purging: Users can delete images from the cache via the API, provided no active containers are using them.
# Concept: ImageCache resource manages distributed node caching apiVersion: kubefledged.io/v1alpha2 kind: ImageCache spec: cacheSpec: - images: ["nginx:1.15.5"] nodeSelector: zone=asia-south1-a- Node Selection: Images are distributed to nodes based on
Prerequisites for kube-fledged
masterBefore installing kube-fledged, ensure you meet the following requirements:
- A functioning Kubernetes cluster (e.g., minikube or production).
- Cluster-admin privileges for deployment.
- All master and worker nodes must have the
kubernetes.io/hostnamelabel.
For development purposes, you will also need:
- git, make, go, docker engine (>= 19.03), openssl, kubectl, helm, gpg, and gnu-sed installed on a Linux or Mac machine, with
kubectlconfigured to access your cluster.
Install kube-fledged using Helm operator
masterTo install kube-fledged using the Helm operator into the
kube-fledgednamespace:- Clone the repository:
git clone https://github.com/senthilrch/kube-fledged.git $HOME/kube-fledged cd $HOME/kube-fledged - Deploy the operator and kube-fledged:
(Note: You can deploy to a different namespace by exporting themake deploy-using-operatorKUBEFLEDGED_NAMESPACEvariable before running the make command.) - Verify the deployment:
kubectl get pods -n kube-fledged -l app.kubernetes.io/name=kube-fledged kubectl get imagecaches -n kube-fledged
git clone https://github.com/senthilrch/kube-fledged.git $HOME/kube-fledged cd $HOME/kube-fledged make deploy-using-operator kubectl get pods -n kube-fledged -l app.kubernetes.io/name=kube-fledged- Clone the repository:
Create an image cache
masterTo create an image cache, define an
imagecacheresource. You can use the sample manifest located atdeploy/kubefledged-imagecache.yamlas a template. If your images are in a private repository, ensure you addimagePullSecretsto the manifest.Example command:
kubectl create -f deploy/kubefledged-imagecache.yamlTo verify the creation:
kubectl get imagecaches -n kube-fledgedkubectl create -f deploy/kubefledged-imagecache.yaml kubectl get imagecaches -n kube-fledgedBuild and Deploy kube-fledged from source
masterTo build and deploy your own version of kube-fledged:
Build
- Clone the repository and enter the directory.
- (Optional) If behind a proxy, export
HTTP_PROXYandHTTPS_PROXY. - Set the following environment variables for your registry and version:
RELEASE_VERSION: your tagCONTROLLER_IMAGE_REPO:docker.io/<your_dockerhub_username>/kubefledged-controllerWEBHOOK_SERVER_IMAGE_REPO:docker.io/<your_dockerhub_username>/kubefledged-webhook-serverCRI_CLIENT_IMAGE_REPO:docker.io/<your_dockerhub_username>/kubefledged-cri-clientOPERATOR_IMAGE_REPO:docker.io/<your_dockerhub_username>/kubefledged-operator
- Run the build command:
docker login -u <username> -p <password> export DOCKER_CLI_EXPERIMENTAL=enabled make install-buildx && make release-amd64
Deploy
- Edit the manifests in
kube-fledged/deploy:- In
kubefledged-deployment-controller.yaml, set theimagefield to your controller image. - In
kubefledged-deployment-webhook-server.yaml, set theimagefield to your webhook server image. - If using a private registry, add
imagePullSecretstokubefledged-deployment-controller.yaml.
- In
- Deploy using:
make deploy-using-yaml
export RELEASE_VERSION=<your_tag> export CONTROLLER_IMAGE_REPO=docker.io/<your_dockerhub_username>/kubefledged-controller export WEBHOOK_SERVER_IMAGE_REPO=docker.io/<your_dockerhub_username>/kubefledged-webhook-server export CRI_CLIENT_IMAGE_REPO=docker.io/<your_dockerhub_username>/kubefledged-cri-client export OPERATOR_IMAGE_REPO=docker.io/<your_dockerhub_username>/kubefledged-operator docker login -u <username> -p <password> export DOCKER_CLI_EXPERIMENTAL=enabled make install-buildx && make release-amd64Install kube-fledged using Helm chart
masterTo install the latest version of kube-fledged using Helm:
- Create the target namespace:
export KUBEFLEDGED_NAMESPACE=kube-fledged kubectl create namespace ${KUBEFLEDGED_NAMESPACE} - Add the repository and install the chart:
helm repo add kubefledged-charts https://senthilrch.github.io/kubefledged-charts/ helm repo update helm install kube-fledged kubefledged-charts/kube-fledged -n ${KUBEFLEDGED_NAMESPACE} --wait
export KUBEFLEDGED_NAMESPACE=kube-fledged kubectl create namespace ${KUBEFLEDGED_NAMESPACE} helm repo add kubefledged-charts https://senthilrch.github.io/kubefledged-charts/ helm repo update helm install kube-fledged kubefledged-charts/kube-fledged -n ${KUBEFLEDGED_NAMESPACE} --wait- Create the target namespace:
Install kube-fledged using YAML manifests
masterTo install kube-fledged into a dedicated
kube-fledgednamespace using pre-built images from Docker Hub:- Clone the repository:
git clone https://github.com/senthilrch/kube-fledged.git $HOME/kube-fledged cd $HOME/kube-fledged - Deploy using the provided Makefile:
make deploy-using-yaml - Verify the deployment:
(Note: The second command should return 'No resources found' if the installation is successful and no caches have been created yet.)kubectl get pods -n kube-fledged -l app=kubefledged kubectl get imagecaches -n kube-fledged
git clone https://github.com/senthilrch/kube-fledged.git $HOME/kube-fledged cd $HOME/kube-fledged make deploy-using-yaml kubectl get pods -n kube-fledged -l app=kubefledged- Clone the repository:
Remove kube-fledged from the cluster
masterDepending on how you installed kube-fledged, use the corresponding command to remove it:
- If installed via YAML manifests:
make remove-kubefledged - If installed via Helm chart:
helm delete kube-fledged -n ${KUBEFLEDGED_NAMESPACE} - If installed via Helm Operator:
make remove-kubefledged-and-operator
# YAML make remove-kubefledged # Helm helm delete kube-fledged -n ${KUBEFLEDGED_NAMESPACE} # Operator make remove-kubefledged-and-operator- If installed via YAML manifests:
Manage image cache lifecycle (Add, Remove, Refresh, Delete)
masterkube-fledged provides several ways to manage the lifecycle of an existing
imagecache(e.g.,imagecache1) viakubectl:Add or Remove images
Use
kubectl editto modify the image list in the manifest. The editor will open, allowing you to add or remove image entries. Save and exit to apply changes.kubectl edit imagecaches imagecache1 -n kube-fledgedRefresh image cache
To trigger an on-demand refresh of the images in the cache, use a Kubernetes annotation:
kubectl annotate imagecaches imagecache1 -n kube-fledged kubefledged.io/refresh-imagecache=Delete image cache
Important: You must purge the images from the worker nodes before deleting the
imagecacheresource.- Purge the images using this annotation:
kubectl annotate imagecaches imagecache1 -n kube-fledged kubefledged.io/purge-imagecache= - Monitor the status via JSON to ensure purging is complete:
kubectl get imagecaches imagecache1 -n kube-fledged -o json - Delete the resource:
kubectl delete imagecaches imagecache1 -n kube-fledged
# Add/Remove kubectl edit imagecaches imagecache1 -n kube-fledged # Refresh kubectl annotate imagecaches imagecache1 -n kube-fledged kubefledged.io/refresh-imagecache= # Delete (Purge first) kubectl annotate imagecaches imagecache1 -n kube-fledged kubefledged.io/purge-imagecache= kubectl delete imagecaches imagecache1 -n kube-fledged- Purge the images using this annotation:
Install Kube-Fledged via Helm
masterTo install Kube-Fledged, first create a dedicated namespace, then add the official Helm repository and install the chart. It is recommended to use the
--waitflag to ensure all components are ready.# Create the namespace export KUBEFLEDGED_NAMESPACE=kube-fledged kubectl create namespace ${KUBEFLEDGED_NAMESPACE} # Install the latest version of the kube-fledged helm chart helm repo add kubefledged-charts https://senthilrch.github.io/kubefledged-charts/ helm repo update helm install kube-fledged kubefledged-charts/kube-fledged -n ${KUBEFLEDGED_NAMESPACE} --wait