I'm implementing a function which can make a node offline/online from kubernetes cluster.
When I run kubectl delete node $nodename
, how can I read this node to the cluster?
It's said that if use API POST /api/v1/nodes
will cause the node state Not ready
. Is there a way to read the deleted node to cluster?
Seams that kubectl delete node only delete resource yaml file.
kubectl apply -f node.yaml
--- node.yaml ---
{
"kind": "Node",
"apiVersion": "v1",
"metadata": {
"name": "minion-0",
"labels": {
"name": "fixed"
}
}
}
The way to (re)create a node depends on your cluster setup and Kubernetes version.
kubeadm reset
and kubeadm join ...
again on the node (you might need to create a new token if the original one was short-lived, see the linked doc)To add a previously deleted node on kubernetes > 1.8x for me it works restarting kubelet service on the node. It is registering then again in the cluster. But kubernetes has a possibility to make a node "online/offlilne":
> kubectl cordon -h
Mark node as unschedulable.
Examples:
# Mark node "foo" as unschedulable.
kubectl cordon foo
Usage:
kubectl cordon NODE [options]
and
> kubectl uncordon -h
Mark node as schedulable.
Examples:
# Mark node "foo" as schedulable.
$ kubectl uncordon foo
Usage:
kubectl uncordon NODE [options]