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.

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