Home > Enterprise >  Kubernetes Cluster - Containers do not restart after reboot
Kubernetes Cluster - Containers do not restart after reboot

Time:04-21

I have a kubernetes cluster setup at home on two bare metal machines. I used kubespray to install both and it uses kubeadm behind the scenes.

The problem I encounter is that all containers within the cluster have a restartPolicy: no which makes my cluster break when I restart the main node.

I have to manually run "docker container start" for all containers in "kube-system" namespace to make it work after reboot.

Does anyone have an idea where the problem might be coming from ?

CodePudding user response:

Docker provides restart policies to control whether your containers start automatically when they exit, or when Docker restarts. Here your containers have the restart policy - no which means this policy will never automatically start the container under any circumstance.

You need to change the restart policy to Always which restarts the container if it stops. If it is manually stopped, it is restarted only when Docker daemon restarts or the container itself is manually restarted.

You can change the restart policy of an existing container using docker update. Pass the name of the container to the command. You can find container names by running docker ps -a.

docker update --restart=always <CONTAINER NAME>

Restart policy details:

Keep the following in mind when using restart policies:

  • A restart policy only takes effect after a container starts successfully. In this case, starting successfully means that the container is up for at least 10 seconds and Docker has started monitoring it. This prevents a container which does not start at all from going into a restart loop.

  • If you manually stop a container, its restart policy is ignored until the Docker daemon restarts or the container is manually restarted. This is another attempt to prevent a restart loop.

CodePudding user response:

I am answering my question:

It wasn't probably very clear but I was talking about the kube-system pods that manage the whole cluster and that should automatically start when the machine restarts.

It turns out those pods (ex: code-dns, kube-proxy, etc) have a restart policy of "no" intentionally and it is the kubelet service on the node that spins up the whole cluster when you restart your node. https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/

In my case kubelet could not start due to missing cri-dockerd process. Check the issue I opened at kubespray:

Verifying the kubelet logs is done like so:

journalctl -u kubelet -f
  • Related