Relevant Documentation:
Always
restart policy that completes after a few seconds.vi always-pod.yml
apiVersion: v1
kind: Pod
metadata:
name: always-pod
spec:
restartPolicy: Always
containers:
- name: busybox
image: busybox
command: ['sh', '-c', 'sleep 10']
Run the following command to create the pod:
kubectl create -f always-pod.yml
kubectl get pod always-pod
OnFailure
restart policy.vi onfailure-pod.yml
apiVersion: v1
kind: Pod
metadata:
name: onfailure-pod
spec:
restartPolicy: OnFailure
containers:
- name: busybox
image: busybox
command: ['sh', '-c', 'sleep 10']
Run the following command to create the pod:
kubectl create -f onfailure-pod.yml
kubectl get pod onfailure-pod
vi onfailure-pod.yml
apiVersion: v1
kind: Pod
metadata:
name: onfailure-pod
spec:
restartPolicy: OnFailure
containers:
- name: busybox
image: busybox
command: ['sh', '-c', 'sleep 10; this is a bad command that will fail']
Run the following command to create the pod:
kubectl create -f onfailure-pod.yml