简体   繁体   English

在 kubernetes 中超时 pod/job

[英]Timeout a pod/job in kubernetes

Trying to use timeout and bash as entrypoint is not working as expected.尝试使用timeoutbash作为入口点没有按预期工作。 The pod keeps running even after the specified timeout.即使在指定的超时之后,pod 仍会继续运行。 Intention is to have a bash -c entry point for which I can define a timeout, after which, the pod enters an "Error" state.目的是有一个bash -c入口点,我可以为它定义超时,之后,pod 进入“错误”状态。 Once this is working, this will be used to timeout jobs like backups/cleaning that could get stuck forever otherwise.一旦它起作用,这将用于超时工作,如备份/清理,否则可能会永远卡住。

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: redis-cli
  name: redis-cli
spec:
  containers:
  - name: redis-cli
    image: xxxx/redis-cli:0.0.1
    imagePullPolicy: Always
    env:
      - name: REDIS_SERVICE
        value: redis.svc
      - name: REDIS_PORT
        value: "6666"
    command: ['/usr/bin/timeout', '20', '/bin/bash', '-c' ]
    args:
      - sleep 6000
    resources:
      limits:
        memory: "12Gi"
        cpu: "2000m"
  dnsPolicy: ClusterFirst
  restartPolicy: Never

You can achieve the timeout using spec.activeDeadlineSeconds.您可以使用 spec.activeDeadlineSeconds 实现超时。

spec:
  activeDeadlineSeconds: 10
  containers:
  - command:
    - /bin/sh
    - -c
    - sleep 6000
    image: busybox

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

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