Is there a command that can be executed in between this two instructions (which fails if the pod does not exist yet), and will wait for the pod to be created in the api-server within a specified timeout?
kubectl run mypod --image=nginx
# Add a command which qait for 'kubectl get pod' to return mypod,
# so that 'kubectl wait' command will not fail
<wanted command>
kubectl wait pod/mypod --for=condition=Ready -l olm.catalogSource=argocd-catalog --timeout=120s
2
Answers
You can create combined commands using
&&
(and) and||
(or) between commands to implement how to run according to the different conditions.The following combined command tries to run/create mypod. If it is created in a specific timeout, mypod will be created. After
||
, thedelete
command doesn’t run, because the previous command works properly.Output:
Worst case scenario: The following command tries to run nginx2 (it won’t work, due to the
ImagePullBackOff
). It first created the pod, but the pod is not ready, so it’ll run thedelete
command after||
.Output:
You can create a similar combination with
get pods
instead of creating a pod.As per the Github link, you can use the below command as a workaround.
kubectl wait
timeout
argument is poorly documented and ill-suited to waiting on multiple resources.You can usetimeout
before thekubectl wait
oroc wait
. For example with a timeout of max. 305s (the timeout of the timeout command should be a little larger than the timeout of the kubectl command)