This container's job is to stall a deployment from running any containers until some network conditions are met.
This image checks for and matches the conditions listed below (in order) before allowing the other containers in the deployment to run.
1 WAIT_FOR_IT
-
form:
"true"
or"false"
-
must equal
"true"
or the init container will be ignored -
examples:
WAIT_FOR_IT="true"
WAIT_FOR_IT="false"
2 WAIT_FOR_PODS
-
Waits for other service's pods to be running before containers can start
-
form:
<service-name>.<namespace>;<service-name-2>.<namespace-2>
-
examples:
WAIT_FOR_PODS="mysql.test"
WAIT_FOR_PODS="mysql.test;kube-dns.kube-system"
WAIT_FOR_EXTERNAL_IPS
-
Waits for a k8s service to have an exposed external IP (not
<pending>
orClusterIP
) -
form:
<service-name>.<namespace>;<service-name-2>.<namespace-2>
-
examples:
WAIT_FOR_EXTERNAL_IPS="nginx.test"
WAIT_FOR_EXTERNAL_IPS="nginx.test;otherservice.default"
WAIT_FOR_DNS_MATCHES
-
Waits for a domain name to match a specific IP before continuing
-
form:
<domain-name>=<ip-address>;<domain-name-2>=<ip-address-2>
-
examples:
WAIT_FOR_DNS_MATCHES="drone.grinsides.com=35.237.17.14;grinsides.com=35.237.17.15"
If you need to make sure a database is running before starting a GUI pod, this is the init container for you.
To wait for:
mysql
pod to start indatabases
namespacemongo
pod to start inothernamespace
namespaceredis
pod to start inanothernamespace
namespace
Configure an init container in your deployment like this:
initContainers:
- name: "wait-for-services"
image: stevenaldinger/docker-k8s-wait-for-it
imagePullPolicy: Always
env:
- name: WAIT_FOR_IT
value: "true"
- name: WAIT_FOR_PODS
value: "mysql.databases;mongo.othernamespace;redis.anothernamespace"
- name: WAIT_FOR_EXTERNAL_IPS
value: "nginx.proxy"
- name: WAIT_FOR_DNS_MATCHES
value: "drone.grinsides.com=35.237.17.14;grinsides.com=35.237.17.15"
Run this to view init logs:
kubectl logs -f $(kubectl get po -l app=redis -o jsonpath='{.items[0].metadata.name}') -c redis-init
Run this to bash into init container:
kubectl exec -it $(kubectl get po -l app=redis -o jsonpath='{.items[0].metadata.name}') -c redis-init bash