kubernetes重新启动策略的始终失败与失败之间有什么区别? [英] What is the difference between always and on failure for kubernetes restart policy?
问题描述
我发现的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.
Always
和OnFailure
有什么区别?事情在重启之前一定不会失败吗?
What is the difference between Always
and OnFailure
? Mustn't the thing fail before it can be restarted?
推荐答案
始终表示即使容器以零退出代码(即成功退出)退出,容器也将重新启动.当您不在乎容器为何退出而只想确保其始终处于运行状态(例如网络服务器)时,这很有用.这是默认设置.
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 意味着仅当容器以非零退出代码退出(即出现问题)时,才会重新启动容器.当您要使用广告连播完成特定任务并确保它成功完成时,此功能很有用-如果没有完成,它将重新启动直到完成.
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 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 =始终":此Pod的重新启动策略.合法值[始终,OnFailure,从不].如果设置为始终",则为该容器创建一个部署;如果设置为"OnFailure",则为此容器创建一个作业;如果设置为从不",则创建一个常规容器.对于后两个--replicas必须为1.默认为始终"
--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'
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重新启动策略的始终失败与失败之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!