kubeadm-install.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env -S bash +e
  2. KUBE_VERSION=${1:-"v1.15.12"}
  3. null_str=
  4. KUBE_INSTALL_VERSION="${KUBE_VERSION/v/$null_str}"-00
  5. # Kubelet cannot run with swap enabled: https://github.com/kubernetes/kubernetes/issues/34726
  6. # Disabling swap when installing k8s via kubeadm
  7. which systemctl >/dev/null && sudo systemctl stop swap.target
  8. sudo swapoff -a
  9. wait_for_dpkg_unlock() {
  10. #wait for dpkg lock to disappear.
  11. retry=0
  12. maxRetries=100
  13. retryInterval=10
  14. until [ ${retry} -ge ${maxRetries} ]
  15. do
  16. if [[ $(sudo lsof /var/lib/dpkg/lock|wc -l) -le 0 ]]; then
  17. break
  18. fi
  19. ((++retry))
  20. echo "."
  21. sleep ${retryInterval}
  22. done
  23. if [ "${retry}" -ge ${maxRetries} ]; then
  24. echo "Failed after ${maxRetries} attempts! - cannot install kubeadm"
  25. exit 1
  26. fi
  27. }
  28. sudo apt-get update
  29. wait_for_dpkg_unlock
  30. sleep 5
  31. wait_for_dpkg_unlock
  32. sudo apt-get install -y apt-transport-https
  33. sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
  34. echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
  35. sudo apt-get update
  36. wait_for_dpkg_unlock
  37. sleep 5
  38. wait_for_dpkg_unlock
  39. # We install the specific version of kubernetes-cni for aws_1.11.x test.
  40. # kubelet in this test requires the version. If the newer versions are
  41. # necessary in the tests of other Kubernetes versions, kubernetes-cni is
  42. # updated in the kubelet installation.
  43. sudo apt-get install -y kubernetes-cni="0.7.5-00"
  44. sudo apt-get install -y kubelet="${KUBE_INSTALL_VERSION}" kubeadm="${KUBE_INSTALL_VERSION}" nfs-common