0

I have two pods pod-a and pod-b and they belong to different applications inside an Openshift project.

Both pods expose a health check http url which I can use to check if a given pod is up and running.

I don't want both pods to be up together at any given time.

If pod-a is up, pod-b should not start and vice-versa.

How can I achieve this in Openshift?

Mandark
  • 798
  • 1
  • 12
  • 33
  • Are these from the same deployment? What is your use case? – Lev Kuznetsov Aug 02 '18 at 12:20
  • They use two separate deployment config. Application A runs in pod-a and Application B runs in pod-b. Application A manages some database data. Application B performs some backing up and clearing of the database data. Application A runs most of the time, but sometimes Application B is run to clear everything up. If both apps work at the same time data gets lost. We always turn off Application A and then run Application B. As a safety precaution we want to add a check, which stops the starting of ApplicationB is ApplicationA is already running. – Mandark Aug 02 '18 at 12:30
  • If you can modify source of B I would probably wrote code there to set replica count of A to 0 and wait against kube api. If you have to have a check like this; set node affinity to the same node and declare each to have the same host port - then kube will not be able to schedule it – Lev Kuznetsov Aug 02 '18 at 12:39

2 Answers2

0

I think you could add InitContainers to each with a check that the other service is not available. InitContainers are more commonly used to check that another service is available but you could them it to check that a service is not available provided you know the service name (which you presumably do).

Ryan Dawson
  • 11,832
  • 5
  • 38
  • 61
0

Unfortunately that is not possible in the Kubernetes (Openshift). Kubernetes features nodeAffinity or nodeSelector are used for dividing pods between the nodes so in your case with one node they will not work. In your situation and for your needs there is no technical possibility to do that by k8s native tools.

aurelius
  • 3,433
  • 1
  • 13
  • 22