如何根据容器中的PID量终止POD?

发布于 2025-02-05 02:51:01 字数 202 浏览 2 评论 0原文

设置:多服务器K8S群集

我想终止容器/POD时,当来自特定用户中的容器中运行的PID数量低于一定计数。例如:如果“用户”在容器中运行的PID少于15个,则我希望容器和POD终止,以便旋转新副本。理想情况下,我将在群集中运行一个cronjob,该群集查询用户运行的PID数量,如果低于15的PID终止POD。我不知道该如何查询从外部的容器内奔跑的PID。有什么想法可能有效吗?

Setup: Multi-server K8s cluster

I want to terminate a container/pod when the number of PIDs running in the container from a specific user is below a certain count. For example: If "user" has less than 15 PIDs running in the container, I want the container and pod to terminate so that it spins up a new copy. Ideally I would have a cronjob run in the cluster that queries the number of PIDs that user has running, and if it is below 15, terminate the pod. I don't know how to query the PIDs running inside a container from the outside. Any ideas that might work?

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

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

发布评论

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

评论(1

梦里泪两行 2025-02-12 02:51:01

您的意思是您需要重新启动POD吗?

您可以使用此处描述的LivicesProbe尝试: https://kubernetes.io/docs/tasks/configure-pod-container/configure-lives-lives-lices-lices-startup-probes/

示例:

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: liveness
    image: k8s.gcr.io/busybox
    args:
    - /bin/sh
    - -c
    - touch /tmp/healthy; sleep 30; rm -f /tmp/healthy; sleep 600
    livenessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5

您可以在命令中实现逻辑以计算进程

Did you mean you need a pod restart?

You can try this with livenessProbe as described here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/

Example:

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: liveness
    image: k8s.gcr.io/busybox
    args:
    - /bin/sh
    - -c
    - touch /tmp/healthy; sleep 30; rm -f /tmp/healthy; sleep 600
    livenessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5

You can implement your logic in command for counting processes

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文