Kubernetes operators: building custom resource status from internal container information

9/9/2021

I am implementing a kubernetes operator which should simply deploy a service whenever a specific pod is found to be in running state. The problem is that the process inside the pod container (which I cannot modify in any way) is serving the port randomly and there is no way for me to know the port number before effectively running the process itself. At that point I could write a script to gather this port info from inside the pod and serve it through a specific endpoint.

I would like to bring this information about the port inside my reconcile loop so that I can consequently spawn the service pointing to the correct targetPort, but cannot really come up with a clean kubernetes compliant solution.

The only way that I can think of is forcing my controller to query the endpoint on the pod directly pointing at its ip address.

Can you help me figure out a better or more standard way ?

-- Luca Montechiesi
kubebuilder
kubernetes
kubernetes-operator
operator-sdk
reconcile

0 Answers