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.

401 lines
16 KiB

  1. # Upgrading Kubernetes in Kubespray
  2. Kubespray handles upgrades the same way it handles initial deployment. That is to
  3. say that each component is laid down in a fixed order.
  4. You can also individually control versions of components by explicitly defining their
  5. versions. Here are all version vars for each component:
  6. * docker_version
  7. * docker_containerd_version (relevant when `container_manager` == `docker`)
  8. * containerd_version (relevant when `container_manager` == `containerd`)
  9. * kube_version
  10. * etcd_version
  11. * calico_version
  12. * calico_cni_version
  13. * weave_version
  14. * flannel_version
  15. * kubedns_version
  16. :warning: [Attempting to upgrade from an older release straight to the latest release is unsupported and likely to break something](https://github.com/kubernetes-sigs/kubespray/issues/3849#issuecomment-451386515) :warning:
  17. See [Multiple Upgrades](#multiple-upgrades) for how to upgrade from older Kubespray release to the latest release
  18. ## Unsafe upgrade example
  19. If you wanted to upgrade just kube_version from v1.18.10 to v1.19.7, you could
  20. deploy the following way:
  21. ```ShellSession
  22. ansible-playbook cluster.yml -i inventory/sample/hosts.ini -e kube_version=v1.18.10 -e upgrade_cluster_setup=true
  23. ```
  24. And then repeat with v1.19.7 as kube_version:
  25. ```ShellSession
  26. ansible-playbook cluster.yml -i inventory/sample/hosts.ini -e kube_version=v1.19.7 -e upgrade_cluster_setup=true
  27. ```
  28. The var ```-e upgrade_cluster_setup=true``` is needed to be set in order to migrate the deploys of e.g kube-apiserver inside the cluster immediately which is usually only done in the graceful upgrade. (Refer to [#4139](https://github.com/kubernetes-sigs/kubespray/issues/4139) and [#4736](https://github.com/kubernetes-sigs/kubespray/issues/4736))
  29. ## Graceful upgrade
  30. Kubespray also supports cordon, drain and uncordoning of nodes when performing
  31. a cluster upgrade. There is a separate playbook used for this purpose. It is
  32. important to note that upgrade-cluster.yml can only be used for upgrading an
  33. existing cluster. That means there must be at least 1 kube_control_plane already
  34. deployed.
  35. ```ShellSession
  36. ansible-playbook upgrade-cluster.yml -b -i inventory/sample/hosts.ini -e kube_version=v1.19.7
  37. ```
  38. After a successful upgrade, the Server Version should be updated:
  39. ```ShellSession
  40. $ kubectl version
  41. Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.7", GitCommit:"1dd5338295409edcfff11505e7bb246f0d325d15", GitTreeState:"clean", BuildDate:"2021-01-13T13:23:52Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}
  42. Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.7", GitCommit:"1dd5338295409edcfff11505e7bb246f0d325d15", GitTreeState:"clean", BuildDate:"2021-01-13T13:15:20Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}
  43. ```
  44. ### Pausing the upgrade
  45. If you want to manually control the upgrade procedure, you can set some variables to pause the upgrade playbook. Pausing *before* upgrading each upgrade may be useful for inspecting pods running on that node, or performing manual actions on the node:
  46. * `upgrade_node_confirm: true` - This will pause the playbook execution prior to upgrading each node. The play will resume when manually approved by typing "yes" at the terminal.
  47. * `upgrade_node_pause_seconds: 60` - This will pause the playbook execution for 60 seconds prior to upgrading each node. The play will resume automatically after 60 seconds.
  48. Pausing *after* upgrading each node may be useful for rebooting the node to apply kernel updates, or testing the still-cordoned node:
  49. * `upgrade_node_post_upgrade_confirm: true` - This will pause the playbook execution after upgrading each node, but before the node is uncordoned. The play will resume when manually approved by typing "yes" at the terminal.
  50. * `upgrade_node_post_upgrade_pause_seconds: 60` - This will pause the playbook execution for 60 seconds after upgrading each node, but before the node is uncordoned. The play will resume automatically after 60 seconds.
  51. ## Node-based upgrade
  52. If you don't want to upgrade all nodes in one run, you can use `--limit` [patterns](https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html#patterns-and-ansible-playbook-flags).
  53. Before using `--limit` run playbook `facts.yml` without the limit to refresh facts cache for all nodes:
  54. ```ShellSession
  55. ansible-playbook facts.yml -b -i inventory/sample/hosts.ini
  56. ```
  57. After this upgrade control plane and etcd groups [#5147](https://github.com/kubernetes-sigs/kubespray/issues/5147):
  58. ```ShellSession
  59. ansible-playbook upgrade-cluster.yml -b -i inventory/sample/hosts.ini -e kube_version=v1.20.7 --limit "kube_control_plane:etcd"
  60. ```
  61. Now you can upgrade other nodes in any order and quantity:
  62. ```ShellSession
  63. ansible-playbook upgrade-cluster.yml -b -i inventory/sample/hosts.ini -e kube_version=v1.20.7 --limit "node4:node6:node7:node12"
  64. ansible-playbook upgrade-cluster.yml -b -i inventory/sample/hosts.ini -e kube_version=v1.20.7 --limit "node5*"
  65. ```
  66. ## Multiple upgrades
  67. :warning: [Do not skip releases when upgrading--upgrade by one tag at a time.](https://github.com/kubernetes-sigs/kubespray/issues/3849#issuecomment-451386515) :warning:
  68. For instance, if you're on v2.6.0, then check out v2.7.0, run the upgrade, check out the next tag, and run the next upgrade, etc.
  69. Assuming you don't explicitly define a kubernetes version in your k8s_cluster.yml, you simply check out the next tag and run the upgrade-cluster.yml playbook
  70. * If you do define kubernetes version in your inventory (e.g. group_vars/k8s_cluster.yml) then either make sure to update it before running upgrade-cluster, or specify the new version you're upgrading to: `ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml -e kube_version=v1.11.3`
  71. Otherwise, the upgrade will leave your cluster at the same k8s version defined in your inventory vars.
  72. The below example shows taking a cluster that was set up for v2.6.0 up to v2.10.0
  73. ```ShellSession
  74. $ kubectl get node
  75. NAME STATUS ROLES AGE VERSION
  76. apollo Ready master,node 1h v1.10.4
  77. boomer Ready master,node 42m v1.10.4
  78. caprica Ready master,node 42m v1.10.4
  79. $ git describe --tags
  80. v2.6.0
  81. $ git tag
  82. ...
  83. v2.6.0
  84. v2.7.0
  85. v2.8.0
  86. v2.8.1
  87. v2.8.2
  88. ...
  89. $ git checkout v2.7.0
  90. Previous HEAD position was 8b3ce6e4 bump upgrade tests to v2.5.0 commit (#3087)
  91. HEAD is now at 05dabb7e Fix Bionic networking restart error #3430 (#3431)
  92. # NOTE: May need to sudo pip3 install -r requirements.txt when upgrading.
  93. ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  94. ...
  95. $ kubectl get node
  96. NAME STATUS ROLES AGE VERSION
  97. apollo Ready master,node 1h v1.11.3
  98. boomer Ready master,node 1h v1.11.3
  99. caprica Ready master,node 1h v1.11.3
  100. $ git checkout v2.8.0
  101. Previous HEAD position was 05dabb7e Fix Bionic networking restart error #3430 (#3431)
  102. HEAD is now at 9051aa52 Fix ubuntu-contiv test failed (#3808)
  103. ```
  104. :info: NOTE: Review changes between the sample inventory and your inventory when upgrading versions. :info:
  105. Some deprecations between versions that mean you can't just upgrade straight from 2.7.0 to 2.8.0 if you started with the sample inventory.
  106. In this case, I set "kubeadm_enabled" to false, knowing that it is deprecated and removed by 2.9.0, to delay converting the cluster to kubeadm as long as I could.
  107. ```ShellSession
  108. $ ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  109. ...
  110. "msg": "DEPRECATION: non-kubeadm deployment is deprecated from v2.9. Will be removed in next release."
  111. ...
  112. Are you sure you want to deploy cluster using the deprecated non-kubeadm mode. (output is hidden):
  113. yes
  114. ...
  115. $ kubectl get node
  116. NAME STATUS ROLES AGE VERSION
  117. apollo Ready master,node 114m v1.12.3
  118. boomer Ready master,node 114m v1.12.3
  119. caprica Ready master,node 114m v1.12.3
  120. $ git checkout v2.8.1
  121. Previous HEAD position was 9051aa52 Fix ubuntu-contiv test failed (#3808)
  122. HEAD is now at 2ac1c756 More Feature/2.8 backports for 2.8.1 (#3911)
  123. $ ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  124. ...
  125. "msg": "DEPRECATION: non-kubeadm deployment is deprecated from v2.9. Will be removed in next release."
  126. ...
  127. Are you sure you want to deploy cluster using the deprecated non-kubeadm mode. (output is hidden):
  128. yes
  129. ...
  130. $ kubectl get node
  131. NAME STATUS ROLES AGE VERSION
  132. apollo Ready master,node 2h36m v1.12.4
  133. boomer Ready master,node 2h36m v1.12.4
  134. caprica Ready master,node 2h36m v1.12.4
  135. $ git checkout v2.8.2
  136. Previous HEAD position was 2ac1c756 More Feature/2.8 backports for 2.8.1 (#3911)
  137. HEAD is now at 4167807f Upgrade to 1.12.5 (#4066)
  138. $ ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  139. ...
  140. "msg": "DEPRECATION: non-kubeadm deployment is deprecated from v2.9. Will be removed in next release."
  141. ...
  142. Are you sure you want to deploy cluster using the deprecated non-kubeadm mode. (output is hidden):
  143. yes
  144. ...
  145. $ kubectl get node
  146. NAME STATUS ROLES AGE VERSION
  147. apollo Ready master,node 3h3m v1.12.5
  148. boomer Ready master,node 3h3m v1.12.5
  149. caprica Ready master,node 3h3m v1.12.5
  150. $ git checkout v2.8.3
  151. Previous HEAD position was 4167807f Upgrade to 1.12.5 (#4066)
  152. HEAD is now at ea41fc5e backport cve-2019-5736 to release-2.8 (#4234)
  153. $ ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  154. ...
  155. "msg": "DEPRECATION: non-kubeadm deployment is deprecated from v2.9. Will be removed in next release."
  156. ...
  157. Are you sure you want to deploy cluster using the deprecated non-kubeadm mode. (output is hidden):
  158. yes
  159. ...
  160. $ kubectl get node
  161. NAME STATUS ROLES AGE VERSION
  162. apollo Ready master,node 5h18m v1.12.5
  163. boomer Ready master,node 5h18m v1.12.5
  164. caprica Ready master,node 5h18m v1.12.5
  165. $ git checkout v2.8.4
  166. Previous HEAD position was ea41fc5e backport cve-2019-5736 to release-2.8 (#4234)
  167. HEAD is now at 3901480b go to k8s 1.12.7 (#4400)
  168. $ ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  169. ...
  170. "msg": "DEPRECATION: non-kubeadm deployment is deprecated from v2.9. Will be removed in next release."
  171. ...
  172. Are you sure you want to deploy cluster using the deprecated non-kubeadm mode. (output is hidden):
  173. yes
  174. ...
  175. $ kubectl get node
  176. NAME STATUS ROLES AGE VERSION
  177. apollo Ready master,node 5h37m v1.12.7
  178. boomer Ready master,node 5h37m v1.12.7
  179. caprica Ready master,node 5h37m v1.12.7
  180. $ git checkout v2.8.5
  181. Previous HEAD position was 3901480b go to k8s 1.12.7 (#4400)
  182. HEAD is now at 6f97687d Release 2.8 robust san handling (#4478)
  183. $ ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  184. ...
  185. "msg": "DEPRECATION: non-kubeadm deployment is deprecated from v2.9. Will be removed in next release."
  186. ...
  187. Are you sure you want to deploy cluster using the deprecated non-kubeadm mode. (output is hidden):
  188. yes
  189. ...
  190. $ kubectl get node
  191. NAME STATUS ROLES AGE VERSION
  192. apollo Ready master,node 5h45m v1.12.7
  193. boomer Ready master,node 5h45m v1.12.7
  194. caprica Ready master,node 5h45m v1.12.7
  195. $ git checkout v2.9.0
  196. Previous HEAD position was 6f97687d Release 2.8 robust san handling (#4478)
  197. HEAD is now at a4e65c7c Upgrade to Ansible >2.7.0 (#4471)
  198. ```
  199. :warning: IMPORTANT: Some of the variable formats changed in the k8s_cluster.yml between 2.8.5 and 2.9.0 :warning:
  200. If you do not keep your inventory copy up to date, **your upgrade will fail** and your first master will be left non-functional until fixed and re-run.
  201. It is at this point the cluster was upgraded from non-kubeadm to kubeadm as per the deprecation warning.
  202. ```ShellSession
  203. ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  204. ...
  205. $ kubectl get node
  206. NAME STATUS ROLES AGE VERSION
  207. apollo Ready master,node 6h54m v1.13.5
  208. boomer Ready master,node 6h55m v1.13.5
  209. caprica Ready master,node 6h54m v1.13.5
  210. # Watch out: 2.10.0 is hiding between 2.1.2 and 2.2.0
  211. $ git tag
  212. ...
  213. v2.1.0
  214. v2.1.1
  215. v2.1.2
  216. v2.10.0
  217. v2.2.0
  218. ...
  219. $ git checkout v2.10.0
  220. Previous HEAD position was a4e65c7c Upgrade to Ansible >2.7.0 (#4471)
  221. HEAD is now at dcd9c950 Add etcd role dependency on kube user to avoid etcd role failure when running scale.yml with a fresh node. (#3240) (#4479)
  222. ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  223. ...
  224. $ kubectl get node
  225. NAME STATUS ROLES AGE VERSION
  226. apollo Ready master,node 7h40m v1.14.1
  227. boomer Ready master,node 7h40m v1.14.1
  228. caprica Ready master,node 7h40m v1.14.1
  229. ```
  230. ## Upgrading to v2.19
  231. `etcd_kubeadm_enabled` is being deprecated at v2.19. The same functionality is achievable by setting `etcd_deployment_type` to `kubeadm`.
  232. Deploying etcd using kubeadm is experimental and is only available for either new or deployments where `etcd_kubeadm_enabled` was set to `true` while deploying the cluster.
  233. From 2.19 and onward `etcd_deployment_type` variable will be placed in `group_vars/all/etcd.yml` instead of `group_vars/etcd.yml`, due to scope issues.
  234. The placement of the variable is only important for `etcd_deployment_type: kubeadm` right now. However, since this might change in future updates, it is recommended to move the variable.
  235. Upgrading is straightforward; no changes are required if `etcd_kubeadm_enabled` was not set to `true` when deploying.
  236. If you have a cluster where `etcd` was deployed using `kubeadm`, you will need to remove `etcd_kubeadm_enabled` the variable. Then move `etcd_deployment_type` variable from `group_vars/etcd.yml` to `group_vars/all/etcd.yml` due to scope issues and set `etcd_deployment_type` to `kubeadm`.
  237. ## Upgrade order
  238. As mentioned above, components are upgraded in the order in which they were
  239. installed in the Ansible playbook. The order of component installation is as
  240. follows:
  241. * Docker
  242. * Containerd
  243. * etcd
  244. * kubelet and kube-proxy
  245. * network_plugin (such as Calico or Weave)
  246. * kube-apiserver, kube-scheduler, and kube-controller-manager
  247. * Add-ons (such as KubeDNS)
  248. ### Component-based upgrades
  249. A deployer may want to upgrade specific components in order to minimize risk
  250. or save time. This strategy is not covered by CI as of this writing, so it is
  251. not guaranteed to work.
  252. These commands are useful only for upgrading fully-deployed, healthy, existing
  253. hosts. This will definitely not work for undeployed or partially deployed
  254. hosts.
  255. Upgrade docker:
  256. ```ShellSession
  257. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=docker
  258. ```
  259. Upgrade etcd:
  260. ```ShellSession
  261. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=etcd
  262. ```
  263. Upgrade etcd without rotating etcd certs:
  264. ```ShellSession
  265. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=etcd --limit=etcd --skip-tags=etcd-secrets
  266. ```
  267. Upgrade kubelet:
  268. ```ShellSession
  269. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=node --skip-tags=k8s-gen-certs,k8s-gen-tokens
  270. ```
  271. Upgrade Kubernetes master components:
  272. ```ShellSession
  273. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=master
  274. ```
  275. Upgrade network plugins:
  276. ```ShellSession
  277. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=network
  278. ```
  279. Upgrade all add-ons:
  280. ```ShellSession
  281. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=apps
  282. ```
  283. Upgrade just helm (assuming `helm_enabled` is true):
  284. ```ShellSession
  285. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=helm
  286. ```
  287. ## Migrate from Docker to Containerd
  288. Please note that **migrating container engines is not officially supported by Kubespray**. While this procedure can be used to migrate your cluster, it applies to one particular scenario and will likely evolve over time. At the moment, they are intended as an additional resource to provide insight into how these steps can be officially integrated into the Kubespray playbooks.
  289. As of Kubespray 2.18.0, containerd is already the default container engine. If you have the chance, it is advisable and safer to reset and redeploy the entire cluster with a new container engine.
  290. * [Migrating from Docker do Containerd](upgrades/migrate_docker2containerd.md)