Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can `kubectl wait` work for secrets generated by deployment? If not, any alternative in bash?

I try to use bash script to run a few k8s commands. During the deployment, I need to wait for a secret to be generated by cert-manager or Vault before it can continue. I know there is a command called kubectl wait but it doesn't seem to work with secret resources, so I came up with this bash script:

  while [ -z "$matched" ]
  do
    echo "Waiting for ($secret_name) to be created"
    matched=$(kubectl get secret $secret_name -n $namespace -o jsonpath="{$path}" --ignore-not-found=true)
    sleep 10;
  done

But it fails on first run after waiting for a minute. It only works on second try. Do you have any suggestions?

like image 307
RedGiant Avatar asked Nov 24 '25 11:11

RedGiant


1 Answers

Poorly documented feature of kubectl wait:

kubectl wait --for=create --timeout=30s secret/$secret_name -n $namespace
like image 63
Ryan Avatar answered Nov 26 '25 17:11

Ryan