I've a pod with two containers. I need to pause one of them because when it's getting error whole of pod will restart and the second container start all things from beginning. I need to suspend first container till second one do it's job. Can i achieve this?
1 Answer
You can define second one container as init container. Init containers are exactly like regular containers, except they always run to completion, each init container must complete successfully before the next one starts.
Here is an example:
apiVersion: v1 kind: Pod metadata: name: example labels: app: app spec: containers: - name: app-container image: busybox:1.28 command: ['sh', '-c', 'echo The app is running! && sleep 3600'] initContainers: - name: init-example image: busybox:1.28 command: ['sh', '-c', "until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for myservice; sleep 2; done"] Take a look: init-containers.