I have 2 services. One containing 2 pod replicas for a web application which is dependent on another backend service having pod (2 replicas) for MySQL containers.
The we
Having the same problem and as what they recommend, using the k8s initContainers solved my problem.
Added sample code.
kind: Service
apiVersion: v1
metadata:
name: postgres-service
spec:
# ...
---
apiVersion: apps/v1
kind: Deployment
# ...
spec:
# ...
template:
# ...
spec:
# wait for postgres-service to run first
initContainers:
- name: init-wait-for-db
image: alpine
command: ["/bin/sh", "-c", "for i in $(seq 1 300); do nc -zvw1 postgres-service 5432 && exit 0 || sleep 3; done; exit 1"]
containers:
- name: my-django-app
image: dockerhubuser/my-django-app
command: ["/bin/sh", "-c", "python /root/django/manage.py migrate && python /root/django/manage.py runserver 0.0.0.0:8000 --noreload"]
ports:
- containerPort: 8000
env:
# ...