Job Failure

This commit is contained in:
huanqing.shao
2019-10-28 23:12:24 +08:00
parent df1c6afe10
commit c1cbc8641e
8 changed files with 69 additions and 6 deletions

View File

@ -1,6 +1,6 @@
<template>
<div :style="$isDev ? 'background-color: #grey;' : ''" v-if="!$frontmatter.lessAds && $themeConfig.showAds">
<div class="ads">
<div class="ads" v-if="!$frontmatter.isSharing">
<div>
<a @click="clickAds" :href="random.url" target="_blank" rel="nofollow" style="text-decoration: none;">
<span class="name">

View File

@ -202,6 +202,7 @@ module.exports = {
children: [
'k8s-intermediate/workload/wl-job/',
'k8s-intermediate/workload/wl-job/spec',
'k8s-intermediate/workload/wl-job/failure',
]
}
]

View File

@ -3,7 +3,7 @@
<div class="page-nav" style="max-width: 1000px; margin-top: 56px;">
<AdSensePageTop></AdSensePageTop>
</div>
<div v-if="!$frontmatter.lessAds" class="page-nav" style="max-width: 1000px; margin: auto;">
<div v-if="!$frontmatter.isSharing" class="page-nav" style="max-width: 1000px; margin: auto;">
<div class="tip custom-block" style=" padding: 1rem; margin-top: 0;">
<div style="display: inline-block; vertical-align: top; line-height: 1.6rem;">
<li>
@ -29,6 +29,9 @@
<slot name="top" />
<Content class="theme-default-content" style="padding-top: 0; margin-top: -3rem; padding-bottom: 1rem;"/>
<div class="page-nav" style="max-width: 1000px; padding-top:0; margin-top: 1rem;" v-if="$frontmatter.isSharing">
Kuboard - 快速在 Kubernetes 上落地微服务
</div>
<JoinCommunity></JoinCommunity>
<PageEdit style="max-width: 1000px;"/>
<PageNav v-bind="{ sidebarItems }" style="max-width: 1000px;"/>
@ -50,7 +53,16 @@ import JoinCommunity from './JoinCommunity'
export default {
components: { PageEdit, PageNav, JoinCommunity },
props: ['sidebarItems']
props: ['sidebarItems'],
mounted () {
if (typeof window !== 'undefined') {
if (location.search !== undefined && location.search.indexOf('sharing') >= 0) {
this.$frontmatter.isSharing = true
document.title = this.$frontmatter.sharingTitle || this.$page.title
this.$frontmatter.title = this.$frontmatter.sharingTitle
}
}
}
}
</script>

View File

@ -80,7 +80,7 @@ module.exports = siteData => {
if (page.frontmatter.titlePrefix !== undefined) {
selfTitle = page.frontmatter.titlePrefix + '_' + selfTitle
}
if (page.path.indexOf('/learning/') === 0) {
if (page.path.indexOf('/learning/') === 0 && !page.frontmatter.isSharing) {
return selfTitle + '_Kubernetes教程_K8S教程_K8S培训'
}
if (page.path.indexOf('/install/') === 0) {

View File

@ -1,6 +1,7 @@
---
vssueId: 121
layout: LearningLayout
sharingTitle: Kubernete中经常被忽略的最重要的概念控制器模式
description: Kubernete教程_Kubernetes控制器_在机器人技术和自动化技术中控制循环是一个控制系统状态的无限循环。控制循环的例子有房间里的恒温器。在恒温器上设定好目标温度就是告诉该控制循环你想要的目标状态。房间里的实际温度是当前状态恒温器通过打卡或关闭加热装置不断地使当前状态接近于目标状态
meta:
- name: keywords

View File

@ -1,6 +1,7 @@
---
vssueId: 116
layout: LearningLayout
sharingTitle: 这篇文章终于讲清楚了Kubernetes是什么
description: Kubernete教程_Kubernetes介绍_Kubernetes是一个可以移植、可扩展的开源平台使用声明式的配置并依据配置信息自动地执行容器化应用程序的管理。
meta:
- name: keywords

View File

@ -292,7 +292,7 @@ Hit enter for command prompt
default-token-il9rc kubernetes.io/service-account-token 1 1d
nginxsecret Opaque 2 1m
```
* 修改 nginx 部署,使 nginx 使用 Secrets 中的 https 证书,修改 Service使其暴露 80 端口和 44端口。nginx-secure-app.yaml 文件如下所示:
* 修改 nginx 部署,使 nginx 使用 Secrets 中的 https 证书,修改 Service使其暴露 80 端口和 443端口。nginx-secure-app.yaml 文件如下所示:
``` yaml {10,11,14,37,45,46}
apiVersion: v1
@ -304,7 +304,7 @@ Hit enter for command prompt
spec:
type: NodePort
ports:
- port: 8080
- port: 80
targetPort: 80
protocol: TCP
name: http

View File

@ -0,0 +1,48 @@
---
vssueId: 151
layout: LearningLayout
description: Kubernetes中的Job对象将创建一个或多个Pod_并确保指定数量的Pod可以成功执行到进程正常结束_当Job创建的 Pod执行成功并正常结束时_Job将记录成功结束的Pod数量_当成功结束的Pod达到指定的数量时_Job将完成执行
meta:
- name: keywords
content: Kubernetes教程,K8S教程,K8S培训,Kubernetes Job
---
# 处理Pod和容器的失败
<AdSenseTitle>
</AdSenseTitle>
Pod 中的容器可能会因为多种原因执行失败,例如:
* 容器中的进程退出了且退出码exit code不为 0
* 容器因为超出内存限制而被 Kill
* 其他原因
如果 Pod 中的容器执行失败,且 `.spec.template.spec.restartPolicy = "OnFailure"`,则 Pod 将停留在该节点上,但是容器将被重新执行。此时,您的应用程序需要处理在原节点(失败之前的节点)上重启的情况。或者,您也可以设置为 `.spec.template.spec.restartPolicy = "Never"`。 参考 [容器组_生命周期](/learning/k8s-intermediate/workload/pod-lifecycle.html) 了解更多信息
整个 Pod 也可能因为多种原因执行失败,例如:
* Pod 从节点上被驱逐(节点升级、重启、被删除等)
* Pod 的容器执行失败,且 `.spec.template.spec.restartPolicy = "Never"`
当 Pod 执行失败时Job 控制器将创建一个新的 Pod。此时您的应用程序需要处理在一个新 Pod 中重新启动的情况。具体来说,需要处理临时文件、锁、未完成的输出信息以及前一次执行可能遗留下来的其他东西。
::: tip
* 即使您指定 `.spec.parallelism = 1``.spec.completions = 1` 以及 `.spec.template.spec.restartPolicy = "Never"`,同一个应用程序仍然可能被启动多次
* 如果指定 `.spec.parallelism``.spec.completions` 的值都大于 1将可能有多个 Pod 同时执行。此时,您的 Pod 还必须能够处理并发的情况
:::
## Pod失败重试
Pod backoff failure policy
某些情况下(例如,配置错误),您可能期望在 Job 多次重试仍然失败的情况下停止该 Job。此时可通过 `.spec.backoffLimit` 来设定 Job 最大的重试次数。该字段的默认值为 6.
Job 中的 Pod 执行失败之后Job 控制器将按照一个指数增大的时间延迟10s,20s,40s ... 最大为 6 分钟)来多次重新创建 Pod。如果没有新的 Pod 执行失败,则重试次数的计数将被重置。
::: warning Issue
Issue [#54870](https://github.com/kubernetes/kubernetes/issues/54870) 仍然存在于 Kubernetes v1.12 之前的版本中
:::
::: tip Debug
如果 `restartPolicy = "OnFailure"`,执行该 Job 的容器在 job 重试次数达到以后将被终止。这种情况使得 Job 程序的 debug 工作变得较为困难。建议在 debug 时,设置 `restartPolicy = "Never"`,或者使用日志系统确保失败的 Job 的日志不会丢失。
:::