Can a kubernetes service change IP when rolling out/restart my app

12/31/2019

I have made a docker image which contains my application. (a very basic application, without any database or file storage).

I have created an yml file which describes a service and a deployment for this image.

When i want to create or update this application, i type this commands:

kubectl apply -f myapp.yml
kubectl rollout restart deployment/myapp-deployment

Everything works fine, the image is pulled and the pod are created while previous are terminated.

But i have a question about this command:

$ kubectl get services

NAME      TYPE           CLUSTER-IP     EXTERNAL-IP                         PORT(S)        AGE
myapp     LoadBalancer   x.y.z.z        abcd.a_subdomainofmyk8sprovider     80:32146/TCP   179m

I can access to my application by typing in my browser

http://abcd.asubdomainofmyk8sprovider/

Everything works. But i am wondering if the external ip can change when i am updating my application with rollout restart ?

I have tried several times: The IP did not changed, except one time, but this time, i have changed something in myapp.yml file

Thanks

-- Bob5421
kubernetes

2 Answers

12/31/2019

ClusterIP can not be changed, but External IP can.

Depending on where is running your cluster, you might lose the external IP forever; with cloud providers, for example, if you haven't reserved it previously.

You can edit the service and change the external IP, or change the service type, in which case it will lose it automatically, and change it back to LoadBalancer type, later on, with different IP address.

But to change the ClusterIP you have to delete the service.

-- suren
Source: StackOverflow

12/31/2019

Both the Service's cluster-internal IP address and any external load balancer it creates should remain stable, even if you change the Pods behind it (update Deployments, add more Pods with matching labels, kubectl rollout restart because it hung, etc.).

If you delete and recreate the Service there aren't any guarantees (in fact you will almost definitely get different IP addresses), but repeating a kubectl apply or helm upgrade that redeclares an identical Service will leave it in place.

-- David Maze
Source: StackOverflow