kubernetes 重启策略的always 和on failure 之间有什么区别? [英] What is the difference between always and on failure for kubernetes restart policy?

查看:65
本文介绍了kubernetes 重启策略的always 和on failure 之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现的 Kubernetes 中重启策略的最佳来源是:

The best source for restart policies in Kubernetes I have found is this:

http://kubernetes.io/docs/user-guide/pods/multi-container/#restartpolicy

但它只列出了可能的 restartPolicy 值,并没有解释它们.

But it only lists the possible restartPolicy values and does not explain them.

AlwaysOnFailure 有什么区别?东西在重新启动之前不是必须失败吗?

What is the difference between Always and OnFailure? Mustn't the thing fail before it can be restarted?

推荐答案

Always 意味着即使容器以零退出代码(即成功)退出,也会重新启动.当您不关心容器退出的原因时,这很有用,您只想确保它始终在运行(例如 Web 服务器).这是默认设置.

Always means that the container will be restarted even if it exited with a zero exit code (i.e. successfully). This is useful when you don't care why the container exited, you just want to make sure that it is always running (e.g. a web server). This is the default.

OnFailure 意味着容器只有在以非零退出代码退出时才会重新启动(即出现问题).当您想使用 pod 完成某个任务并确保它成功完成时,这很有用 - 如果没有成功,它将重新启动,直到它完成.

OnFailure means that the container will only be restarted if it exited with a non-zero exit code (i.e. something went wrong). This is useful when you want accomplish a certain task with the pod, and ensure that it completes successfully - if it doesn't it will be restarted until it does.

Never 表示容器无论退出的原因都不会重新启动.

Never means that the container will not be restarted regardless of why it exited.

kubectl run --help可以看出,这些不同的重启策略基本上映射到不同的控制器类型:

These different restart policies basically map to the different controller types as you can see from kubectl run --help:

--restart="Always":此 Pod 的重启策略.合法值 [Always、OnFailure、Never].如果设置为Always",则为此 pod 创建部署,如果设置为OnFailure",则为此 pod 创建作业,如果设置为Never",则创建常规 pod.对于后两个 --replicas 必须为 1.默认 'Always'

--restart="Always": The restart policy for this Pod. Legal values [Always, OnFailure, Never]. If set to 'Always' a deployment is created for this pod, if set to 'OnFailure', a job is created for this pod, if set to 'Never', a regular pod is created. For the latter two --replicas must be 1. Default 'Always'

以及 pod 用户指南:

ReplicationController 仅适用于 RestartPolicy = Always 的 Pod.作业仅适用于 RestartPolicy 等于 OnFailure 或 Never 的 Pod.

ReplicationController is only appropriate for pods with RestartPolicy = Always. Job is only appropriate for pods with RestartPolicy equal to OnFailure or Never.

这篇关于kubernetes 重启策略的always 和on failure 之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆