Below you will find pages that utilize the taxonomy term “Bash”
`kubectl get events`
NAMESPACE=test
kubectl create namespace ${NAMESPACE}
kubectl create deployment kuard \
--image=gcr.io/kuar-demo/kuard-amd64:blue \
--port=8080 \
--namespace=${NAMESPACE}
Typically, I’d then use kubectl describe pod to check the Events section for any issues:
kubectl describe pod \
--selector=app=kuard \
--namespace=test
But, from the Pod’s name (without the pod/ prefix), you can:
NAME=$(\
kubectl get pod \
--selector=app=kuard \
--namespace=test \
--output=name) && \
NAME=${NAME#pod/} && \
echo ${NAME}
kubectl get events \
--field-selector=involvedObject.name=${NAME} \
--namespace=${NAMESPACE} \
--output=jsonpath='{range .items[*]}{.message}{"\n"}{end}'
NOTE
range‘ing over the items permits adding newlines (\n) after each entry. Using{.items[*].message}yields a less manageable result.
bash loops with multi-statement conditions
I wanted to pause a script until the status of 2 Cloud Run services became ready. In this case, I wanted to check for the status condition RoutesReady to be True.
My initial attempt is ghastly:
while [[ "True"!=$(gcloud run services describe ...) && "True"!=$(gcloud run service describe ...)]]
do
...
loop
NOTE In actuality, is was worse than that because I had
--projectand--regionflags and pumped the result throughjq
I found an interesting comment by jonathan-leffler on this Stack overflow answer suggesting that the condition in bash loops could actually be an (arbitrarily?) complex sequence of commands as long as the final statement returns true. Thanks Jonathan!