Reputation: 10953
I run a certain software in OpenShift which consists of two pods. The software has a license limit that only allows for two instances. In addition to this the two pods have to be based on the same image because this is an in(t/f)ernal design rule I have to follow.
The problem is that the two pods communicate over a shared path and each pod has its own data location. Think of this as these paths:
How can I make sure that a certain config file I place in pod1 always is configured to use /data/instance1
and pod2 always is configured to use /data/instance2
even if either of the two pods is removed and deleted again ?
I already tried to do this based on the hostname but because this changes regularly and doesn't follow a reproducible logic (softwarename-tzyjkd
for example) this approach failed.
Ideally I would gain access to a kind of "instance counter" provided by openshift.
Upvotes: 0
Views: 254
Reputation: 58523
Look at creating separate deployment configurations for each instance and set environment variables passed in to denote path differently for each. Have application use environment variable to know which path to use.
If need to load balance traffic across both instances, then set up the route to direct traffic to both in the required ratio.
For example:
oc new-build getwarped/s2i-httpd-server~https://github.com/getwarped/httpd-parked-domain.git --name mysite
oc new-app mysite --name mysite1 --env DATA=instance1
oc new-app mysite --name mysite2 --env DATA=instance2
oc expose svc/mysite1 --name mysite
oc set route-backends mysite mysite1=50 mysite2=50
This would leave you with:
$ oc get all -o name
buildconfig/mysite
build/mysite-1
imagestream/mysite
imagestream/s2i-httpd-server
deploymentconfig/mysite1
deploymentconfig/mysite2
replicationcontroller/mysite1-1
replicationcontroller/mysite2-1
route/mysite
service/mysite1
service/mysite2
pod/mysite-1-build
pod/mysite1-1-64c6a
pod/mysite2-1-v3lf4
$ oc get routes
NAME HOST/PORT PATH SERVICES PORT TERMINATION
mysite mysite-book.127.0.0.1.xip.io mysite1(50%),mysite2(50%) 8080-tcp
BTW, if you software will not even start up if it thinks something is already using the licence, you will want to change the deployment strategy from Rolling to Recreate. This will mean existing instance will be shutdown before starting a new instance. Because though you have two, you could always adjust the ratio of where traffic is routed over to the other before restarting one. That way you will not have requests fail when instance is done. You can rebalance traffic after restart of one, or switch all traffic to it and restart the other.
Upvotes: 1