In my kubernets cluster, I have custom python script in a pod which needs ovn-nbctl show command (this cmd will give all floating ips)and this results will be given to the py script which will give me number of floating ips pinging in the cluster.

Problem is Ovn-nbctl show works only inside the kube ovn cni pod. How to use or send the result of this command to the python script pod.

Kubectl ko nbctl(in host) and ovn-nbctl show (in ovn cni pod)gives the same output

What I'm expecting is:

  1. I need the python script to run (which requires the ovn-nbctl show command)
  2. The fix should work even after the pod restarts
  3. The ovn nbctl show command should be executed in intervals for the python script to be real-time.
  4. Should have minimum work to setup this

What I've tried so far.

Method 1: I tried to save the command o/p in a file inside the kube ovn cni pod and then volume mounted it to the python pod but if the cni pod restarts I'll lose the file and the shell script/cronjob for real-time interval for inside the cni pod

Method 2:

I tried to use the kube ovn image and created a pod with the python script so I can run the command but container itself not running and sceptical if the command will give me the floating ips.

Method 3: I tried running the python script inside the ovn cni so I can use the cmd with ease but the py script will removed once the pod restarts along with the cronjob/ updating ip data shell script

Any other approch which will help me with my expectations?

1

There are 1 answers

0
ABWassim On BEST ANSWER

There are ways of doing this but it would require Kubectl in Kubectl or SSH which I strongly advise you against as it will be harder and/or less secure than the methods you suggested.

From my understanding I'm thinking about two solutions (close to the ones you mentioned) :

  • Create a custom Docker image with Python + your script + ovn-nbctl, but it could become very heavy and difficult to maintain.
  • Use a CronJob with an initContainer that would execute the ovn-nbctl command, redirect the output to a file and copy the file to a shared volume. The Python container would then read the file copied in the shared volume and process it, but it wouldn't make the Python script real-time since it will be terminated when the job will be done. But from my understanding, if it's the only thing this Python script does (aka. reading the file and giving you floating IPs), then no need for it to be real time with this solution.