我有 6 个 Pod 副本正在运行,我想每 5 分钟重新启动\重新创建一次。
这需要进行滚动更新——这样所有更新都不会立即终止,也不会出现停机时间。我如何实现这一目标?
我尝试使用 cron 作业,但似乎没有工作:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: scheduled-pods-recreate
spec:
schedule: "*/5 * * * *"
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
spec:
containers:
- name: ja-engine
image: app-image
imagePullPolicy: IfNotPresent
restartPolicy: OnFailure
尽管该作业已成功创建并按照以下说明进行了安排,但它似乎从未运行过:
Name: scheduled-pods-recreate
Namespace: jk-test
Labels: <none>
Annotations: <none>
Schedule: */5 * * * *
Concurrency Policy: Forbid
Suspend: False
Starting Deadline Seconds: <unset>
Selector: <unset>
Parallelism: <unset>
Completions: <unset>
Pod Template:
Labels: <none>
Containers:
ja-engine:
Image: image_url
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Last Schedule Time: Tue, 19 Feb 2019 10:10:00 +0100
Active Jobs: scheduled-pods-recreate-1550567400
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 23m cronjob-controller Created job scheduled-pods-recreate-1550567400
所以首先,我如何确保它正在运行以便重新创建 pod?
另外我怎样才能确保没有停机时间?
cronjob 的更新版本:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- kubectl patch deployment runners -p '{"spec":{"template":{"spec":{"containers":[{"name":"jp-runner","env":[{"name":"START_TIME","value":"'$(date +%s)'"}]}]}}}}' -n jp-test
restartPolicy: OnFailure
Pod 没有以消息 Back-off restarting failed container 和错误开始,如下所示:
State: Terminated
Reason: Error
Exit Code: 127