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.

374 lines
13 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. If you want to manually control the upgrade procedure, you can use the variables `upgrade_node_confirm` or `upgrade_node_pause_seconds`:
  45. `upgrade_node_confirm: true` - waiting to confirmation to upgrade next node
  46. `upgrade_node_pause_seconds: 60` - pause 60 seconds before upgrade next node
  47. ## Node-based upgrade
  48. 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).
  49. Before using `--limit` run playbook `facts.yml` without the limit to refresh facts cache for all nodes:
  50. ```ShellSession
  51. ansible-playbook facts.yml -b -i inventory/sample/hosts.ini
  52. ```
  53. After this upgrade control plane and etcd groups [#5147](https://github.com/kubernetes-sigs/kubespray/issues/5147):
  54. ```ShellSession
  55. ansible-playbook upgrade-cluster.yml -b -i inventory/sample/hosts.ini -e kube_version=v1.20.7 --limit "kube_control_plane:etcd"
  56. ```
  57. Now you can upgrade other nodes in any order and quantity:
  58. ```ShellSession
  59. ansible-playbook upgrade-cluster.yml -b -i inventory/sample/hosts.ini -e kube_version=v1.20.7 --limit "node4:node6:node7:node12"
  60. ansible-playbook upgrade-cluster.yml -b -i inventory/sample/hosts.ini -e kube_version=v1.20.7 --limit "node5*"
  61. ```
  62. ## Multiple upgrades
  63. :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:
  64. 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.
  65. 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
  66. * 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`
  67. Otherwise, the upgrade will leave your cluster at the same k8s version defined in your inventory vars.
  68. The below example shows taking a cluster that was set up for v2.6.0 up to v2.10.0
  69. ```ShellSession
  70. $ kubectl get node
  71. NAME STATUS ROLES AGE VERSION
  72. apollo Ready master,node 1h v1.10.4
  73. boomer Ready master,node 42m v1.10.4
  74. caprica Ready master,node 42m v1.10.4
  75. $ git describe --tags
  76. v2.6.0
  77. $ git tag
  78. ...
  79. v2.6.0
  80. v2.7.0
  81. v2.8.0
  82. v2.8.1
  83. v2.8.2
  84. ...
  85. $ git checkout v2.7.0
  86. Previous HEAD position was 8b3ce6e4 bump upgrade tests to v2.5.0 commit (#3087)
  87. HEAD is now at 05dabb7e Fix Bionic networking restart error #3430 (#3431)
  88. # NOTE: May need to sudo pip3 install -r requirements.txt when upgrading.
  89. ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  90. ...
  91. $ kubectl get node
  92. NAME STATUS ROLES AGE VERSION
  93. apollo Ready master,node 1h v1.11.3
  94. boomer Ready master,node 1h v1.11.3
  95. caprica Ready master,node 1h v1.11.3
  96. $ git checkout v2.8.0
  97. Previous HEAD position was 05dabb7e Fix Bionic networking restart error #3430 (#3431)
  98. HEAD is now at 9051aa52 Fix ubuntu-contiv test failed (#3808)
  99. ```
  100. :info: NOTE: Review changes between the sample inventory and your inventory when upgrading versions. :info:
  101. 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.
  102. 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.
  103. ```ShellSession
  104. $ ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  105. ...
  106. "msg": "DEPRECATION: non-kubeadm deployment is deprecated from v2.9. Will be removed in next release."
  107. ...
  108. Are you sure you want to deploy cluster using the deprecated non-kubeadm mode. (output is hidden):
  109. yes
  110. ...
  111. $ kubectl get node
  112. NAME STATUS ROLES AGE VERSION
  113. apollo Ready master,node 114m v1.12.3
  114. boomer Ready master,node 114m v1.12.3
  115. caprica Ready master,node 114m v1.12.3
  116. $ git checkout v2.8.1
  117. Previous HEAD position was 9051aa52 Fix ubuntu-contiv test failed (#3808)
  118. HEAD is now at 2ac1c756 More Feature/2.8 backports for 2.8.1 (#3911)
  119. $ ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  120. ...
  121. "msg": "DEPRECATION: non-kubeadm deployment is deprecated from v2.9. Will be removed in next release."
  122. ...
  123. Are you sure you want to deploy cluster using the deprecated non-kubeadm mode. (output is hidden):
  124. yes
  125. ...
  126. $ kubectl get node
  127. NAME STATUS ROLES AGE VERSION
  128. apollo Ready master,node 2h36m v1.12.4
  129. boomer Ready master,node 2h36m v1.12.4
  130. caprica Ready master,node 2h36m v1.12.4
  131. $ git checkout v2.8.2
  132. Previous HEAD position was 2ac1c756 More Feature/2.8 backports for 2.8.1 (#3911)
  133. HEAD is now at 4167807f Upgrade to 1.12.5 (#4066)
  134. $ ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  135. ...
  136. "msg": "DEPRECATION: non-kubeadm deployment is deprecated from v2.9. Will be removed in next release."
  137. ...
  138. Are you sure you want to deploy cluster using the deprecated non-kubeadm mode. (output is hidden):
  139. yes
  140. ...
  141. $ kubectl get node
  142. NAME STATUS ROLES AGE VERSION
  143. apollo Ready master,node 3h3m v1.12.5
  144. boomer Ready master,node 3h3m v1.12.5
  145. caprica Ready master,node 3h3m v1.12.5
  146. $ git checkout v2.8.3
  147. Previous HEAD position was 4167807f Upgrade to 1.12.5 (#4066)
  148. HEAD is now at ea41fc5e backport cve-2019-5736 to release-2.8 (#4234)
  149. $ ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  150. ...
  151. "msg": "DEPRECATION: non-kubeadm deployment is deprecated from v2.9. Will be removed in next release."
  152. ...
  153. Are you sure you want to deploy cluster using the deprecated non-kubeadm mode. (output is hidden):
  154. yes
  155. ...
  156. $ kubectl get node
  157. NAME STATUS ROLES AGE VERSION
  158. apollo Ready master,node 5h18m v1.12.5
  159. boomer Ready master,node 5h18m v1.12.5
  160. caprica Ready master,node 5h18m v1.12.5
  161. $ git checkout v2.8.4
  162. Previous HEAD position was ea41fc5e backport cve-2019-5736 to release-2.8 (#4234)
  163. HEAD is now at 3901480b go to k8s 1.12.7 (#4400)
  164. $ ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  165. ...
  166. "msg": "DEPRECATION: non-kubeadm deployment is deprecated from v2.9. Will be removed in next release."
  167. ...
  168. Are you sure you want to deploy cluster using the deprecated non-kubeadm mode. (output is hidden):
  169. yes
  170. ...
  171. $ kubectl get node
  172. NAME STATUS ROLES AGE VERSION
  173. apollo Ready master,node 5h37m v1.12.7
  174. boomer Ready master,node 5h37m v1.12.7
  175. caprica Ready master,node 5h37m v1.12.7
  176. $ git checkout v2.8.5
  177. Previous HEAD position was 3901480b go to k8s 1.12.7 (#4400)
  178. HEAD is now at 6f97687d Release 2.8 robust san handling (#4478)
  179. $ ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  180. ...
  181. "msg": "DEPRECATION: non-kubeadm deployment is deprecated from v2.9. Will be removed in next release."
  182. ...
  183. Are you sure you want to deploy cluster using the deprecated non-kubeadm mode. (output is hidden):
  184. yes
  185. ...
  186. $ kubectl get node
  187. NAME STATUS ROLES AGE VERSION
  188. apollo Ready master,node 5h45m v1.12.7
  189. boomer Ready master,node 5h45m v1.12.7
  190. caprica Ready master,node 5h45m v1.12.7
  191. $ git checkout v2.9.0
  192. Previous HEAD position was 6f97687d Release 2.8 robust san handling (#4478)
  193. HEAD is now at a4e65c7c Upgrade to Ansible >2.7.0 (#4471)
  194. ```
  195. :warning: IMPORTANT: Some of the variable formats changed in the k8s_cluster.yml between 2.8.5 and 2.9.0 :warning:
  196. 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.
  197. It is at this point the cluster was upgraded from non-kubeadm to kubeadm as per the deprecation warning.
  198. ```ShellSession
  199. ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  200. ...
  201. $ kubectl get node
  202. NAME STATUS ROLES AGE VERSION
  203. apollo Ready master,node 6h54m v1.13.5
  204. boomer Ready master,node 6h55m v1.13.5
  205. caprica Ready master,node 6h54m v1.13.5
  206. # Watch out: 2.10.0 is hiding between 2.1.2 and 2.2.0
  207. $ git tag
  208. ...
  209. v2.1.0
  210. v2.1.1
  211. v2.1.2
  212. v2.10.0
  213. v2.2.0
  214. ...
  215. $ git checkout v2.10.0
  216. Previous HEAD position was a4e65c7c Upgrade to Ansible >2.7.0 (#4471)
  217. 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)
  218. ansible-playbook -i inventory/mycluster/hosts.ini -b upgrade-cluster.yml
  219. ...
  220. $ kubectl get node
  221. NAME STATUS ROLES AGE VERSION
  222. apollo Ready master,node 7h40m v1.14.1
  223. boomer Ready master,node 7h40m v1.14.1
  224. caprica Ready master,node 7h40m v1.14.1
  225. ```
  226. ## Upgrade order
  227. As mentioned above, components are upgraded in the order in which they were
  228. installed in the Ansible playbook. The order of component installation is as
  229. follows:
  230. * Docker
  231. * Containerd
  232. * etcd
  233. * kubelet and kube-proxy
  234. * network_plugin (such as Calico or Weave)
  235. * kube-apiserver, kube-scheduler, and kube-controller-manager
  236. * Add-ons (such as KubeDNS)
  237. ### Component-based upgrades
  238. A deployer may want to upgrade specific components in order to minimize risk
  239. or save time. This strategy is not covered by CI as of this writing, so it is
  240. not guaranteed to work.
  241. These commands are useful only for upgrading fully-deployed, healthy, existing
  242. hosts. This will definitely not work for undeployed or partially deployed
  243. hosts.
  244. Upgrade docker:
  245. ```ShellSession
  246. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=docker
  247. ```
  248. Upgrade etcd:
  249. ```ShellSession
  250. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=etcd
  251. ```
  252. Upgrade etcd without rotating etcd certs:
  253. ```ShellSession
  254. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=etcd --limit=etcd --skip-tags=etcd-secrets
  255. ```
  256. Upgrade kubelet:
  257. ```ShellSession
  258. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=node --skip-tags=k8s-gen-certs,k8s-gen-tokens
  259. ```
  260. Upgrade Kubernetes master components:
  261. ```ShellSession
  262. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=master
  263. ```
  264. Upgrade network plugins:
  265. ```ShellSession
  266. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=network
  267. ```
  268. Upgrade all add-ons:
  269. ```ShellSession
  270. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=apps
  271. ```
  272. Upgrade just helm (assuming `helm_enabled` is true):
  273. ```ShellSession
  274. ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=helm
  275. ```