Home > front end >  Kubernetes wait for secret to be created
Kubernetes wait for secret to be created

Time:03-08

How can I wait in Kubernetes till a secret is created? There is kubectl wait ... which I see examples for pods and deployments, but how can I use it for secrets?

CodePudding user response:

if your workflow requires a specific secret to be present in K8s in the first place to be consumed by a K8s pod, you can achieve this in multiple ways

  1. if you are creating k8s secret at the same time as you are creating a pod where it will be consumed, you can delay the start of the pod by postStart hook

  2. you can further mount secret as volume to your K8s pod and add application logic to not start application until mounted volume have required secret as text file for you to consume

I provided above solutions based on available info in question. feel free to add more context and I can add more details/option to achieve your workflow

CodePudding user response:

How can I wait in Kubernetes till a secret is created? There is kubectl wait ...

Try:

while ! kubectl get secret <name> --namespace <if not default>; do echo "Waiting for my secret. CTRL-C to exit."; sleep 1; done

  • Related