Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes kubectl update service selector

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?

like image 648
No1Lives4Ever Avatar asked Feb 17 '19 16:02

No1Lives4Ever


Video Answer


1 Answers

Finally, found the solution:

kubectl patch service old-app -p '{"spec":{"selector":{"app": "new-app"}}}'
like image 88
No1Lives4Ever Avatar answered Nov 14 '22 15:11

No1Lives4Ever