在一個簡單的bash腳本我想要運行多個kubectl
和helm
命令,如:
helm install \
cert-manager jetstack/cert-manager \
--namespace cert-manager \
--create-namespace \
--version v1.5.4 \
--set installCRDs=true
kubectl apply -f deploy/cert-manager/cluster-issuers.yaml
我的問題是,在helm install
命令之後我必須等到 cert-manager pod 運行,然後kubectl apply
才能使用該命令。現在腳本調用它太早了,所以它會失敗。
正如評論kubectl wait
中所述是要走的路。
示例來自kubectl wait --help
Examples:
# Wait for the pod "busybox1" to contain the status condition of type "Ready"
kubectl wait --for=condition=Ready pod/busybox1
這樣您的腳本將暫停,直到指定的 pod 正在運行,kubectl
並將輸出
<pod-name> condition met
到標準輸出。
kubectl wait
還在實驗階段。如果您想避免實驗性功能,您可以使用 bashwhile
循環實現類似的結果。按豆莢名稱:
while [[ $(kubectl get pods <pod-name> -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do
sleep 1
done
或按標籤:
while [[ $(kubectl get pods -l <label>=<label-value> -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do
sleep 1
done
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句