1. Yes. Run two instances on different ports (say 3001 and 3002), nginx proxies to whichever is live. In nginx:
upstream app {
include /etc/nginx/conf.d/app-upstream.inc;
}
Deploy: start the new version on the idle port, wait for its health check, switch the include, reload nginx:
#!/usr/bin/env bash
set -euo pipefail
NEW_PORT="$1"
for i in $(seq 1 30); do
if curl -fsS "http://127.0.0.1:${NEW_PORT}/healthz" > /dev/null; then
break
fi
if [ "$i" -eq 30 ]; then
echo "new instance is not healthy, staying on the old one" >&2
exit 1
fi
sleep 1
done
echo "server 127.0.0.1:${NEW_PORT};" > /etc/nginx/conf.d/app-upstream.inc
nginx -t
nginx -s reload
Rollback is the same script with the old port, as long as you keep the old instance running for a while. nginx -s reload lets current connections finish on the old workers.
2. No Kubernetes needed. Two servers in the upstream with weights is already a canary:
upstream app {
server 127.0.0.1:3001 weight=9;
server 127.0.0.1:3002 weight=1;
}
For sticky users (same person always gets the same version) look at split_clients in the nginx docs.