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.

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