diff --git a/pkg/kubelet/container/helpers.go b/pkg/kubelet/container/helpers.go index b8d841894bd..f64aeec72e2 100644 --- a/pkg/kubelet/container/helpers.go +++ b/pkg/kubelet/container/helpers.go @@ -72,8 +72,8 @@ func ShouldContainerBeRestarted(container *v1.Container, pod *v1.Pod, podStatus if status.State == ContainerStateRunning { return false } - // Always restart container in unknown state now - if status.State == ContainerStateUnknown { + // Always restart container in the unknown, or in the created state. + if status.State == ContainerStateUnknown || status.State == ContainerStateCreated { return true } // Check RestartPolicy for dead container diff --git a/pkg/kubelet/kubelet_pods.go b/pkg/kubelet/kubelet_pods.go index c662f1a2ce0..0fc4fe9106b 100644 --- a/pkg/kubelet/kubelet_pods.go +++ b/pkg/kubelet/kubelet_pods.go @@ -1210,6 +1210,13 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon switch cs.State { case kubecontainer.ContainerStateRunning: status.State.Running = &v1.ContainerStateRunning{StartedAt: metav1.NewTime(cs.StartedAt)} + case kubecontainer.ContainerStateCreated: + // Treat containers in the "created" state as if they are exited. + // The pod workers are supposed start all containers it creates in + // one sync (syncPod) iteration. There should not be any normal + // "created" containers when the pod worker generates the status at + // the beginning of a sync iteration. + fallthrough case kubecontainer.ContainerStateExited: status.State.Terminated = &v1.ContainerStateTerminated{ ExitCode: int32(cs.ExitCode),