1
votes

Background:

Let's say I have a replication controller with some pods. When these pods were first deployed they were configured to expose port 8080. A service (of type LoadBalancer) was also create to expose port 8080 publicly. Later we decide that we want to export an additional port from the pods (port 8081). We change the pod definition and do a rolling-update with no downtime, great! But we want this port to be publicly accessible as well.

Question:

Is there a good way to update a service without downtime (for example by adding a an additional port to expose)? If I just do:

kubectl replace -f my-service-with-an-additional-port.json

I get the following error message:

Replace failedspec.clusterIP: invalid value '': field is immutable
3
If you use the v1.2.0-alpha.3 version or above version, you can try the kubectl edit command to edit your Service object. Otherwise, you may need to remove immutable fields from your json file.Yu-Ju Hong

3 Answers

2
votes

If you name the ports in the pods, you can specify the target ports by name in the service rather than by number, and then the same service can direct target to pods using different port numbers.

Or, as Yu-Ju suggested, you can do a read-modify-write of the live state of the service, such as via kubectl edit. The error message was due to not specifying the clusterIP that had already been set.

1
votes

In such case you can create a second service to expose the second port, it won't conflict with the other one and you'll have no downtime.

1
votes

If you have more that one pod running for the same service you may use the Kubernetes Engine within the Google Cloud Console as follows:

Under "Workloads", select your Replication Controller. Within that screen, click "EDIT" then update and save your replication controller details.

Under "Discover & Load Balancing", select your Service. Within that screen, click "EDIT" then update and save your service details. If you changed ports you should see those reflecting under the column "Endpoints" when you've finished editing the details.

Assuming you have at least two pods running on a machine (and a restart policy of Always), if you wanted to update the pods with the new configuration or container image:

Under "Workloads", select your Replication Controller. Within that screen, scroll down to "Managed pods". Select a pod, then in that screen click "KUBECTL" -> "Delete". Note, you can do the same with the command line: kubectl delete pod <podname>. This would delete and restart it with the newly downloaded configuration and container image. Delete each pod one at a time, making sure to wait until a pod has fully restarted and working (i.e. check logs, debug) etc, before deleting the next.