Reload Kubernetes ReplicationController to get newly created Service

1/25/2016

Is there a way to reload currently running pods created by replicationcontroller to reapply newly created services?

Example:

I have a running pods created by ReplicationController config file. I have deleted a service called mongo-svc and recreated it again using different port. Is there a way for the pod's env file to be updated with the new IP and ports from the new mongo-svc?

-- mateeyow
kubernetes

3 Answers

1/25/2016

You can restart pods by simply deleting them: if they are linked to a Replication controller, the RC will take care of restarting them

kubectl delete pod <your-pod-name>

if you have a couple pods, it's easy enougth to copy/paste the pod names, but if you have many pods it can become cumbersome.

So another way to delete pods and restart them is to scale the RC down to 0 instances and back up to the number you need.

kubectl scale --replicas=0 rc <your-rc>
kubectl scale --replicas=<n> rc <your-rc>

By-the-way, you may also want to look at 'rolling-updates' to do this in a more production friendly manner, but that implies updating the RC config.

-- MrE
Source: StackOverflow

1/25/2016

If you want the same pod to have the new service, the clean answer is no. You could (I strongly suggest not to do this) run kubectl exec <pod-name> -c <containers> -- export <service env var name>=<service env var value>. But your best bet is to run kubectl delete <pod-name> and let your replication controller handle the work.

I've ran into a similar issue for services being ran outside of kubernetes, say a DB for instance, to address this I've been creating this https://github.com/cpg1111/kubongo which updates the service's endpoint without deleting the pods. That same idea can also be applied to other pods in kubernetes to automate the service update. Basically it watches a specific service, and when it's IP changes for whatever reason it updates all the pods without deleting them. This does use the same code as kubectl exec however it is automated, sanitizes input and ensures the export is executed on all pods.

-- Christian Grabowski
Source: StackOverflow

1/25/2016

What do you mean with 'reapply'?

The pods to which the services point are generally selected based on labels.In other words, you can add / remove labels from the pods to include / exclude them from a service.

Read here for more information about defining services: http://kubernetes.io/v1.1/docs/user-guide/services.html#defining-a-service

And here for more information about labels: http://kubernetes.io/v1.1/docs/user-guide/labels.html

Hope it helps!

-- virsox
Source: StackOverflow