[英]Kubernetes kill process inside pod
I was using the following code to randomly kill processes inside the pods我正在使用以下代码随机终止 pod 内的进程
: ${DELAY:=30}
if [ "$#" -ne 1 ]; then
echo "One argument expected specifying the time in seconds to run"
else
end=$((SECONDS+$1))
while [ $SECONDS -lt $end ]; do
kubectl \
-o 'jsonpath={.items[*].metadata.name}' \
get pods | \
tr " " "\n" | \
shuf | \
head -n 1 |
#xargs -t --no-run-if-empty \
kubectl exec $(head -n 1) -- kill -9 9
#if [ $((SECONDS+${DELAY})) -lt $end ];then #break loop if (seconds completed + delay) is greater than time specified in argument
# sleep "${DELAY}" #sleep so that pod gets completely deleted and a terminating pod not selecte
#else
# break
#fi
done
fi
The script runs but no output is shown as in it goes into some infinite loop.脚本运行但没有输出显示,因为它进入了一些无限循环。 Can someone help where I am going wrong?有人可以帮助我出错的地方吗?
Two things: -o 'jsonpath={.items[*].metadata.name}'
should go after kubectl get pods
, otherwise kubectl will return help message.两件事: -o 'jsonpath={.items[*].metadata.name}'
应该在kubectl get pods
,否则 kubectl 将返回帮助信息。 Also, add -t to kubectl exec
in order to see output from the container in your terminal.此外,将 -t 添加到kubectl exec
以查看终端中容器的输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.