Kubernetes开发新手:如何向Kube-proxy推送代码变更?
Hey there! As someone who’s tinkered with customizing kube-proxy on ARM clusters before, I can help you streamline this workflow so you don’t have to manually swap binaries on each Raspberry Pi every time you make a change. Let’s break this down into practical, actionable steps:
First, quick context: kube-proxy is almost always deployed as a DaemonSet in the kube-system namespace, meaning it runs on every node in your cluster. Manually replacing binaries works for one-off tests, but using Kubernetes’ native tools will make your changes reproducible and easier to roll back.
1. Build a Custom ARM-Compatible Kube-proxy Image
Since Raspberry Pis use ARM architecture, you’ll need to cross-compile your modified kube-proxy binary and package it into a Docker image that your RPI nodes can run. Here’s how to do it with Kubernetes’ official build tools:
From your local dev machine (where you already cross-compile), run this command to build the ARM64 binary and image:
make WHAT=cmd/kube-proxy ARCH=arm64 REGISTRY=your-docker-username TAG=v1.28.0-customReplace
your-docker-usernamewith your Docker Hub handle (or a local private registry if you don’t want public pushes) andv1.28.0-customwith a tag that matches your cluster’s Kubernetes version plus a custom suffix.If your RPIs don’t have internet access, skip pushing to a registry and instead save/load the image locally:
docker save your-docker-username/kube-proxy:v1.28.0-custom -o kube-proxy-custom.tar # Copy to each node and load the image for node in rpi-node-1 rpi-node-2 rpi-node-3 rpi-node-4; do scp kube-proxy-custom.tar pi@$node:/tmp/ ssh pi@$node "docker load -i /tmp/kube-proxy-custom.tar" done
2. Update the Kube-proxy DaemonSet to Use Your Custom Image
Tell Kubernetes to replace the default kube-proxy with your modified version:
Edit the DaemonSet directly (fastest for quick changes):
kubectl edit daemonset kube-proxy -n kube-systemFind the
containers[0].imagefield and swap the default image with your custom one (e.g.,your-docker-username/kube-proxy:v1.28.0-custom). Save and exit—Kubernetes will automatically roll out new Pods to all nodes.For version-controlled changes, export the current config, modify it, then apply:
kubectl get daemonset kube-proxy -n kube-system -o yaml > kube-proxy-custom.yamlUpdate the
spec.template.spec.containers[0].imageline in the YAML, then apply:kubectl apply -f kube-proxy-custom.yaml -n kube-system
3. Verify Your Changes Are Working
After deployment, confirm everything’s running as expected:
- Check Pod status across all nodes:
kubectl get pods -n kube-system -l k8s-app=kube-proxy - View logs to ensure your custom logic is executing:
kubectl logs -n kube-system -l k8s-app=kube-proxy - Exec into a Pod to verify the binary version or test functionality:
kubectl exec -n kube-system $(kubectl get pods -n kube-system -l k8s-app=kube-proxy -o name | head -1) -- /usr/local/bin/kube-proxy --version
For Quick, Temporary Tests: Batch Binary Replacement
If you still want to stick with binary swaps for fast iterations (e.g., testing tiny code changes without building an image), use a script to automate the process across all 4 RPIs:
Create a shell script named update-kube-proxy.sh:
#!/bin/bash # Path to your cross-compiled kube-proxy binary LOCAL_BINARY="./build/bin/kube-proxy" # List of your RPI nodes (update with your actual hostnames/IPs) NODES=("rpi-node-1" "rpi-node-2" "rpi-node-3" "rpi-node-4") for node in "${NODES[@]}"; do echo "Updating kube-proxy on $node..." scp "$LOCAL_BINARY" pi@$node:/tmp/ ssh pi@$node "sudo systemctl stop kube-proxy && sudo cp /tmp/kube-proxy /usr/local/bin/kube-proxy && sudo systemctl start kube-proxy" done echo "All nodes updated!"
Make it executable with chmod +x update-kube-proxy.sh and run it whenever you need to push changes.
Quick Tips to Avoid Headaches
- Test changes on one node first (use node selectors in the DaemonSet) before rolling out to all 4 RPIs.
- Ensure your custom kube-proxy version matches your cluster’s Kubernetes version to avoid compatibility bugs.
- If you’re modifying kube-proxy’s configuration (not just code), don’t forget to update the
kube-proxy-configConfigMap inkube-systemif needed.
内容的提问来源于stack exchange,提问作者elia

