You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
6.2 KiB

  1. # Adding/replacing a node
  2. Modified from [comments in #3471](https://github.com/kubernetes-sigs/kubespray/issues/3471#issuecomment-530036084)
  3. ## Limitation: Removal of first kube_control_plane and etcd-master
  4. Currently you can't remove the first node in your kube_control_plane and etcd-master list. If you still want to remove this node you have to:
  5. ### 1) Change order of current control planes
  6. Modify the order of your control plane list by pushing your first entry to any other position. E.g. if you want to remove `node-1` of the following example:
  7. ```yaml
  8. children:
  9. kube_control_plane:
  10. hosts:
  11. node-1:
  12. node-2:
  13. node-3:
  14. kube_node:
  15. hosts:
  16. node-1:
  17. node-2:
  18. node-3:
  19. etcd:
  20. hosts:
  21. node-1:
  22. node-2:
  23. node-3:
  24. ```
  25. change your inventory to:
  26. ```yaml
  27. children:
  28. kube_control_plane:
  29. hosts:
  30. node-2:
  31. node-3:
  32. node-1:
  33. kube_node:
  34. hosts:
  35. node-2:
  36. node-3:
  37. node-1:
  38. etcd:
  39. hosts:
  40. node-2:
  41. node-3:
  42. node-1:
  43. ```
  44. ## 2) Upgrade the cluster
  45. run `upgrade-cluster.yml` or `cluster.yml`. Now you are good to go on with the removal.
  46. ## Adding/replacing a worker node
  47. This should be the easiest.
  48. ### 1) Add new node to the inventory
  49. ### 2) Run `scale.yml`
  50. You can use `--limit=NODE_NAME` to limit Kubespray to avoid disturbing other nodes in the cluster.
  51. Before using `--limit` run playbook `facts.yml` without the limit to refresh facts cache for all nodes.
  52. ### 3) Remove an old node with remove-node.yml
  53. With the old node still in the inventory, run `remove-node.yml`. You need to pass `-e node=NODE_NAME` to the playbook to limit the execution to the node being removed.
  54. If the node you want to remove is not online, you should add `reset_nodes=false` and `allow_ungraceful_removal=true` to your extra-vars: `-e node=NODE_NAME -e reset_nodes=false -e allow_ungraceful_removal=true`.
  55. Use this flag even when you remove other types of nodes like a control plane or etcd nodes.
  56. ### 4) Remove the node from the inventory
  57. That's it.
  58. ## Adding/replacing a control plane node
  59. ### 1) Run `cluster.yml`
  60. Append the new host to the inventory and run `cluster.yml`. You can NOT use `scale.yml` for that.
  61. ### 2) Restart kube-system/nginx-proxy
  62. In all hosts, restart nginx-proxy pod. This pod is a local proxy for the apiserver. Kubespray will update its static config, but it needs to be restarted in order to reload.
  63. ```sh
  64. # run in every host
  65. docker ps | grep k8s_nginx-proxy_nginx-proxy | awk '{print $1}' | xargs docker restart
  66. ```
  67. ### 3) Remove old control plane nodes
  68. With the old node still in the inventory, run `remove-node.yml`. You need to pass `-e node=NODE_NAME` to the playbook to limit the execution to the node being removed.
  69. If the node you want to remove is not online, you should add `reset_nodes=false` and `allow_ungraceful_removal=true` to your extra-vars.
  70. ## Replacing a first control plane node
  71. ### 1) Change control plane nodes order in inventory
  72. from
  73. ```ini
  74. [kube_control_plane]
  75. node-1
  76. node-2
  77. node-3
  78. ```
  79. to
  80. ```ini
  81. [kube_control_plane]
  82. node-2
  83. node-3
  84. node-1
  85. ```
  86. ### 2) Remove old first control plane node from cluster
  87. With the old node still in the inventory, run `remove-node.yml`. You need to pass `-e node=node-1` to the playbook to limit the execution to the node being removed.
  88. If the node you want to remove is not online, you should add `reset_nodes=false` and `allow_ungraceful_removal=true` to your extra-vars.
  89. ### 3) Edit cluster-info configmap in kube-system namespace
  90. `kubectl edit cm -n kube-public cluster-info`
  91. Change ip of old kube_control_plane node with ip of live kube_control_plane node (`server` field). Also, update `certificate-authority-data` field if you changed certs.
  92. ### 4) Add new control plane node
  93. Update inventory (if needed)
  94. Run `cluster.yml` with `--limit=kube_control_plane`
  95. ## Adding an etcd node
  96. You need to make sure there are always an odd number of etcd nodes in the cluster. In such a way, this is always a replace or scale up operation. Either add two new nodes or remove an old one.
  97. ### 1) Add the new node running cluster.yml
  98. Update the inventory and run `cluster.yml` passing `--limit=etcd,kube_control_plane -e ignore_assert_errors=yes`.
  99. If the node you want to add as an etcd node is already a worker or control plane node in your cluster, you have to remove him first using `remove-node.yml`.
  100. Run `upgrade-cluster.yml` also passing `--limit=etcd,kube_control_plane -e ignore_assert_errors=yes`. This is necessary to update all etcd configuration in the cluster.
  101. At this point, you will have an even number of nodes.
  102. Everything should still be working, and you should only have problems if the cluster decides to elect a new etcd leader before you remove a node.
  103. Even so, running applications should continue to be available.
  104. If you add multiple ectd nodes with one run, you might want to append `-e etcd_retries=10` to increase the amount of retries between each ectd node join.
  105. Otherwise the etcd cluster might still be processing the first join and fail on subsequent nodes. `etcd_retries=10` might work to join 3 new nodes.
  106. ### 2) Add the new node to apiserver config
  107. In every control plane node, edit `/etc/kubernetes/manifests/kube-apiserver.yaml`. Make sure the new etcd nodes are present in the apiserver command line parameter `--etcd-servers=...`.
  108. ## Removing an etcd node
  109. ### 1) Remove an old etcd node
  110. With the node still in the inventory, run `remove-node.yml` passing `-e node=NODE_NAME` as the name of the node that should be removed.
  111. If the node you want to remove is not online, you should add `reset_nodes=false` and `allow_ungraceful_removal=true` to your extra-vars.
  112. ### 2) Make sure only remaining nodes are in your inventory
  113. Remove `NODE_NAME` from your inventory file.
  114. ### 3) Update kubernetes and network configuration files with the valid list of etcd members
  115. Run `cluster.yml` to regenerate the configuration files on all remaining nodes.
  116. ### 4) Remove the old etcd node from apiserver config
  117. In every control plane node, edit `/etc/kubernetes/manifests/kube-apiserver.yaml`. Make sure only active etcd nodes are still present in the apiserver command line parameter `--etcd-servers=...`.
  118. ### 5) Shutdown the old instance
  119. That's it.