繁体   English   中英

Kubernetes 杀死 pod 内的进程

[英]Kubernetes kill process inside pod

我正在使用以下代码随机终止 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

脚本运行但没有输出显示,因为它进入了一些无限循环。 有人可以帮助我出错的地方吗?

两件事: -o 'jsonpath={.items[*].metadata.name}'应该在kubectl get pods ,否则 kubectl 将返回帮助信息。 此外,将 -t 添加到kubectl exec以查看终端中容器的输出。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM