以下是一些常见的Kubernetes Pod重启策略示例
一、Always
无论何时容器退出,Kubernetes都会自动重启该容器。
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
restartPolicy: Always
containers:
- name: my-container
image: my-image
command: ["my-command"]
二、OnFailure
当容器以非零状态退出时,Kubernetes将重启该容器
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
restartPolicy: OnFailure
containers:
- name: my-container
image: my-image
command: ["my-command"]
三、Never
当容器退出时,Kubernetes将不会自动重启该容器
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
restartPolicy: Never
containers:
- name: my-container
image: my-image
command: ["my-command"]
四、在deployment文件指定容器的重启策略
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
restartPolicy: Always
containers:
- name: my-container
image: my-image
command: ["my-command"]
[...]Kubernetes 概念 Kubernetes(v1.21)工作负载 Kubernetes(v1.21)配置和存储Kubernetes(v1.21)网络Kubernetes(v1.21)调度原理Kubernetes(v1.21)安全K8s - Ingress 限流K8s-Pod重启策略Kubernetes滚动更新解决Mac/Windows版Desktop Docker中自带的K8s无法访问pod[...]