My Kubernetes cluster is running under Google Cloud. I have deployment which running with port 443 and LoadBalancer expose it to the internet.
I created it in this way:
kubectl expose deployment my-app --target-port=443 --port=443 --type=LoadBalancer
After running this command, the loadbalancer is pointing to my-app
deployment. Now I created my-app2
and I want to change the loadbalancer to point the new deployment (my-app2
).
Note: Delete and re-create the deployment is releasing the external IP address and I want to avoid it.
How to patch the existing service to point another deployment without loosing the external IP?
Finally, found the solution:
kubectl patch service old-app -p '{"spec":{"selector":{"app": "new-app"}}}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With