带有睡眠命令的Kubernetes Pod需要时间才能删除

发布于 2025-02-03 01:59:58 字数 591 浏览 4 评论 0原文

目前,在Kubectl delete命令之后,可以终止POD需要很长时间。我感觉可能是因为睡眠命令。

如何使容器停止更快? 我应该在这里使用哪些最佳实践?

apiVersion: apps/v1
kind: Deployment
...
spec:
  template:
    spec:
      containers:
        - image: alpine
          ..
          command:
            - /bin/sh
            - -c
            - |
              trap : TERM INT 
              while true; do
                # some code to check something
                sleep 10
              done

我的方法是“陷阱:术语int”正确的方法吗?目前,我看不到任何积极的效果...

当我终止豆荚时,命令需要几秒钟才能返回。

kubectl delete pod my-pod

Currently it takes quite a long time before the pod can be terminated after a kubectl delete command. I have the feeling that it could be because of the sleep command.

How can I make the container stop faster?
What best practices should I use here?

apiVersion: apps/v1
kind: Deployment
...
spec:
  template:
    spec:
      containers:
        - image: alpine
          ..
          command:
            - /bin/sh
            - -c
            - |
              trap : TERM INT 
              while true; do
                # some code to check something
                sleep 10
              done

Is my approach with "trap: TERM INT" correct? At the moment I don't see any positive effect...

When I terminate the pod it takes several seconds for the command to come back.

kubectl delete pod my-pod

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始终不够爱げ你 2025-02-10 01:59:58

terminationgraceperiodseconds添加到您的规格中:

...
spec:
  template:
    spec:
      terminationGracePeriodSeconds: 10  # <-- default is 30, can go as low as 0 to send SIGTERM immediately.
      containers:
        - image: alpine

Add terminationGracePeriodSeconds to your spec will do:

...
spec:
  template:
    spec:
      terminationGracePeriodSeconds: 10  # <-- default is 30, can go as low as 0 to send SIGTERM immediately.
      containers:
        - image: alpine
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文