Upgrading kubernetes

Upgrading kubernetes is very easy with kops, as long as you are using a compatible version of kops.The kops 1.8.x series (for example) supports the kubernetes 1.6, 1.7 and 1.8 series,as per the kubernetes deprecation policy. Older versions of kubernetes will likely still work, but theseare on a best-effort basis and will have little if any testing. kops 1.8 will not support the kubernetes1.9 series, and for full support of kubernetes 1.9 it is best to wait for the kops 1.9 series release.We aim to release the next major version of kops within a few weeks of the equivalent major release of kubernetes,so kops 1.9.0 will be released within a few weeks of kubernetes 1.9.0. We try to ensure that a 1.9 pre-release(alpha or beta) is available at the kubernetes release, for early adopters.

Upgrading kubernetes is similar to changing the image on an InstanceGroup, except that the kubernetes version iscontrolled at the cluster level. So instead of kops edit ig <name>, we kops edit cluster, and change thekubernetesVersion field. kops edit cluster will open your editor with the cluster, similar to:

  1. # Please edit the object below. Lines beginning with a '#' will be ignored,
  2. # and an empty file will abort the edit. If an error occurs while saving this file will be
  3. # reopened with the relevant failures.
  4. #
  5. apiVersion: kops/v1alpha2
  6. kind: Cluster
  7. metadata:
  8. creationTimestamp: 2017-10-04T03:52:25Z
  9. name: simple.k8s.local
  10. spec:
  11. api:
  12. loadBalancer:
  13. type: Public
  14. authorization:
  15. alwaysAllow: {}
  16. channel: stable
  17. cloudProvider: gce
  18. configBase: gs://kubernetes-clusters/simple.k8s.local
  19. etcdClusters:
  20. - etcdMembers:
  21. - instanceGroup: master-us-central1-a
  22. name: a
  23. name: main
  24. - etcdMembers:
  25. - instanceGroup: master-us-central1-a
  26. name: a
  27. name: events
  28. iam:
  29. legacy: false
  30. kubernetesApiAccess:
  31. - 0.0.0.0/0
  32. kubernetesVersion: 1.7.2
  33. masterInternalName: api.internal.simple.k8s.local
  34. masterPublicName: api.simple.k8s.local
  35. networking:
  36. kubenet: {}
  37. nonMasqueradeCIDR: 100.64.0.0/10
  38. project: gce-project
  39. sshAccess:
  40. - 0.0.0.0/0
  41. subnets:
  42. - name: us-central1
  43. region: us-central1
  44. type: Public
  45. topology:
  46. dns:
  47. type: Public
  48. masters: public
  49. nodes: public

Edit kubernetesVersion, changing it to 1.7.7 for example.

Apply the changes to the cloud infrastructure using kops update cluster and kops update cluster --yes:

  1. Will create resources:
  2. InstanceTemplate/master-us-central1-a-simple-k8s-local
  3. Network name:default id:default
  4. Tags [simple-k8s-local-k8s-io-role-master]
  5. Preemptible false
  6. BootDiskImage cos-cloud/cos-stable-57-9202-64-0
  7. BootDiskSizeGB 64
  8. BootDiskType pd-standard
  9. CanIPForward true
  10. Scopes [compute-rw, monitoring, logging-write, storage-ro, https://www.googleapis.com/auth/ndev.clouddns.readwrite]
  11. Metadata {cluster-name: <resource>, startup-script: <resource>}
  12. MachineType n1-standard-1
  13. InstanceTemplate/nodes-simple-k8s-local
  14. Network name:default id:default
  15. Tags [simple-k8s-local-k8s-io-role-node]
  16. Preemptible false
  17. BootDiskImage debian-cloud/debian-9-stretch-v20170918
  18. BootDiskSizeGB 128
  19. BootDiskType pd-standard
  20. CanIPForward true
  21. Scopes [compute-rw, monitoring, logging-write, storage-ro]
  22. Metadata {startup-script: <resource>, cluster-name: <resource>}
  23. MachineType n1-standard-2
  24. Will modify resources:
  25. InstanceGroupManager/us-central1-a-master-us-central1-a-simple-k8s-local
  26. InstanceTemplate id:master-us-central1-a-simple-k8s-local-1507089163 -> name:master-us-central1-a-simple-k8s-local
  27. InstanceGroupManager/us-central1-a-nodes-simple-k8s-local
  28. InstanceTemplate id:nodes-simple-k8s-local-1507089694 -> name:nodes-simple-k8s-local

kops rolling-update cluster will show that all nodes need to be restarted.

  1. NAME STATUS NEEDUPDATE READY MIN MAX NODES
  2. master-us-central1-a NeedsUpdate 1 0 1 1 1
  3. nodes NeedsUpdate 3 0 3 3 3

Restart the instances with kops rolling-update cluster --yes.

  1. > kubectl get nodes -owide
  2. NAME STATUS AGE VERSION EXTERNAL-IP OS-IMAGE KERNEL-VERSION
  3. master-us-central1-a-8fcc Ready 26m v1.7.7 35.194.56.129 Container-Optimized OS from Google 4.4.35+
  4. nodes-9cml Ready 16m v1.7.7 35.193.12.73 Ubuntu 16.04.3 LTS 4.10.0-35-generic
  5. nodes-km98 Ready 10m v1.7.7 35.194.25.144 Ubuntu 16.04.3 LTS 4.10.0-35-generic
  6. nodes-wbb2 Ready 2m v1.7.7 35.188.177.16 Ubuntu 16.04.3 LTS 4.10.0-35-generic