简体   繁体   中英

Multiple containers in 1 pod with delay

I am still in the initial phase of understanding k8, so please forgive if you feel this lame. But I wanted to know if there is a way to have some kind of delay or ordered the execution of the containers in 1 single pod. Let's say we have 1 Pod A and has 2 containers. For example, a kafka container exposing port 9092 and port 8081 and another container say a Kafka connect image which hits both of these ports. I wanted to know if there is a way to execute the Kafka container first and then execute Kafka connect container so that it won't get killed.

1) Can we have some delay or a sleep between 2 container creation?

2) Can we have some kind of priority of execution of containers within pods so that we can accomplish the above-mentioned situation?

PS: I have considered creating 2 pods and currently working on that. But also wanted to try to do this and also learn something new at the same time.Thanks.

No you can't, but you could change the startup command for the second image to poll the availability of the ports of the first container through localhost . When both ports accept connections, then you know you can continue with starting up the application in the second image.

If you cannot modify the second image yourself, what you can do is create a config map which contains your own startup script using whatever scripting language you might have in the image. Mount the config map into the container at some path and then override the command run for the container in the pod definition (where depends on how you are deploying it), to invoke your script mounted in from the config map.

Your script can then do the polling, and when happy that first container is running okay, then it will execute the original command the container used to start the application.

If you were to use two pods instead, then you can still use the same idea, but rather than localhost use the hostname for the service of the first pod. In the two pod case, you could run the script in an init container instead of hijacking the original startup command of the actual image.

截至2018年初,您想要的东西本身在Kubernetes中并不存在,但是您可以使用init容器来解决用例的某些部分。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM