how to stop and restart nodes in kubernetes how to stop and restart nodes in kubernetes kubernetes kubernetes

how to stop and restart nodes in kubernetes


May you are getting the wrong meaning of cordon and drain node.

Cordon node :

it means no more new container will get the scheduled on this node however existing running container will be kept on that same node.

Drain node :

The drain node will remove all the containers from that specific node and schedule all the containers to another node.

As much as I under what you want do is

I want to stop first node and again restart those nodes

if you can access the Node and do the SSH into worker nodes you can also run inside node after SSH : systemctl restart kubelet

OR

you can stop or scale down the deployment to zero mean you can pause or restart the container or pod

with node you can delete node and new will will join the Kubernetes cluster.

kubectl delete node a1

which will be similar to restarting the node in this case you must be using the node pools in GKE or AWS other cloud providers.

Note : if you are running single replicas of you application you might face the downtime if delete the node or restart the kubelet

i would suggest you to cordon and drain node before you restart.

  1. kubectl cordon a1 (stop new pod sceduling)
  2. kubectl drain a1 (remove running containers)
  3. kubectl delete node a1 (remove the node from cluster) or systemctl restart kubelet (restart the node)

Regarding the error :

There are pending nodes to be drained: a2 error: cannot deleteDaemonSet-managed Pods

You need to use the --ignore-daemonsets key when you drain Kubernetes nodes:

--ignore-daemonsets=false: Ignore DaemonSet-managed pods.

so command will be something like

kubectl drain node <node-name> --ignore-daemonsets