0

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?

  • why you want to wait while creating secret ? what actually you are trying to setup ? – Harsh Manvar Mar 07 '22 at 17:16
  • I bootstrap a k8s cluster using ArgoCD and need the secret to configure something. Therefore, my script starts the setup and then should continue when the secret is accessible. ArgoCD is set up using Kustomize and the pod generates the secrets, which makes it a bit tricky. –  Mar 08 '22 at 09:32

2 Answers2

2

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

gohm'c
  • 13,492
  • 1
  • 9
  • 16
0

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

vipin
  • 45
  • 2
  • 6
  • Sadly, both are no option here as I use a “predefined” Kustomize script from ArgoCD –  Mar 08 '22 at 09:33