Use docker build → docker push → kubectl set image fixed workflow to publish the new image to the Kubernetes environment and wait for the rolling update to complete.
Quick Start
- Confirm that the local machine is configured with:
docker, and is alreadydocker loginthe corresponding image registry;kubectl, and the target cluster is configuredkubeconfig - Required information: image registry (without tag), K8s
context/namespace/deployment/container, tag (optional) - Prefer to use the script:
bash scripts/build_push_kubectl.sh --help
Workflow (recommended)
- Select image reference:
<image-repo>:<tag>(tag is automatically generated by default) - Build:
docker build -t <image-repo>:<tag> ... - Push:
docker push <image-repo>:<tag> - Deploy:
kubectl set image deployment/<deployment> <container>=<image-repo>:<tag> -n <namespace> - Verify:
kubectl rollout status deployment/<deployment> -n <namespace>
Common commands (when not using the script)
docker build -t IMAGE_REPO:TAG -f Dockerfile .
docker push IMAGE_REPO:TAG
kubectl -n NAMESPACE set image deployment/DEPLOYMENT CONTAINER=IMAGE_REPO:TAG
kubectl -n NAMESPACE rollout status deployment/DEPLOYMENT --timeout=120s
Safety Checks
- Before deployment, verify the target environment first:
kubectl config current-context、kubectl -n <ns> get deploy <name> - Production environment changes: first confirm with the user
kube-context/namespace/image/tag, then execute
Scripts
scripts/build_push_kubectl.sh
Build the image, push it to the registry, then use kubectl set image to update the Deployment and wait for the rollout to complete.