diff --git a/pkg/kubectl/cmd/exec.go b/pkg/kubectl/cmd/exec.go index 7484afa219..522aec181f 100644 --- a/pkg/kubectl/cmd/exec.go +++ b/pkg/kubectl/cmd/exec.go @@ -174,6 +174,10 @@ func (p *ExecOptions) Run() error { return err } + if pod.Status.Phase == api.PodSucceeded || pod.Status.Phase == api.PodFailed { + return fmt.Errorf("cannot exec into a container in a completed pod; current phase is %s", pod.Status.Phase) + } + containerName := p.ContainerName if len(containerName) == 0 { glog.V(4).Infof("defaulting container name to %s", pod.Spec.Containers[0].Name)