iifast

- 0-PackageInstallation-containerd(plralsight).sh

Nov 15th, 2021
1,409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.85 KB | None | 0 0
  1. #Setup
  2. #   1. 4 VMs Ubuntu 18.04, 1 control plane, 3 nodes.
  3. #   2. Static IPs on individual VMs
  4. #   3. /etc/hosts hosts file includes name to IP mappings for VMs
  5. #   4. Swap is disabled
  6. #   5. Take snapshots prior to installation, this way you can install
  7. #       and revert to snapshot if needed
  8. #
  9. ssh aen@c1-cp1
  10.  
  11.  
  12. #0 - Disable swap, swapoff then edit your fstab removing any entry for swap partitions
  13. #You can recover the space with fdisk. You may want to reboot to ensure your config is ok.
  14. swapoff -a
  15. vi /etc/fstab
  16.  
  17.  
  18. ###IMPORTANT####
  19. #I expect this code to change a bit to make the installation process more streamlined.
  20. #Overall, the end result will stay the same...you'll have continerd installed
  21. #I will keep the code in the course downloads up to date with the latest method.
  22. ################
  23.  
  24.  
  25. #0 - Install Packages
  26. #containerd prerequisites, first load two modules and configure them to load on boot
  27. #https://kubernetes.io/docs/setup/production-environment/container-runtimes/
  28. sudo modprobe overlay
  29. sudo modprobe br_netfilter
  30.  
  31. cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
  32. overlay
  33. br_netfilter
  34. EOF
  35.  
  36.  
  37. #Setup required sysctl params, these persist across reboots.
  38. cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
  39. net.bridge.bridge-nf-call-iptables  = 1
  40. net.ipv4.ip_forward                 = 1
  41. net.bridge.bridge-nf-call-ip6tables = 1
  42. EOF
  43.  
  44.  
  45. #Apply sysctl params without reboot
  46. sudo sysctl --system
  47.  
  48.  
  49. #Install containerd
  50. sudo apt-get update
  51. sudo apt-get install -y containerd
  52.  
  53.  
  54. #Create a containerd configuration file
  55. sudo mkdir -p /etc/containerd
  56. sudo containerd config default | sudo tee /etc/containerd/config.toml
  57.  
  58.  
  59. #Set the cgroup driver for containerd to systemd which is required for the kubelet.
  60. #For more information on this config file see:
  61. # https://github.com/containerd/cri/blob/master/docs/config.md and also
  62. # https://github.com/containerd/containerd/blob/master/docs/ops.md
  63.  
  64. #At the end of this section
  65.         [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
  66.         ...
  67. #UPDATE: This line is now in the config.toml file
  68. #change it from SystemdCgroup = false to SystemdCgroup = true
  69.             SystemdCgroup = true
  70.  
  71. sudo vi /etc/containerd/config.toml
  72.  
  73.  
  74. #Restart containerd with the new configuration
  75. sudo systemctl restart containerd
  76.  
  77.  
  78.  
  79.  
  80. #Install Kubernetes packages - kubeadm, kubelet and kubectl
  81. #Add Google's apt repository gpg key
  82. curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
  83.  
  84.  
  85. #Add the Kubernetes apt repository
  86. sudo bash -c 'cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
  87. deb https://apt.kubernetes.io/ kubernetes-xenial main
  88. EOF'
  89.  
  90.  
  91. #Update the package list and use apt-cache policy to inspect versions available in the repository
  92. sudo apt-get update
  93. apt-cache policy kubelet | head -n 20
  94.  
  95.  
  96. #Install the required packages, if needed we can request a specific version.
  97. #Use this version because in a later course we will upgrade the cluster to a newer version.
  98. VERSION=1.21.0-00
  99. sudo apt-get install -y kubelet=$VERSION kubeadm=$VERSION kubectl=$VERSION
  100. sudo apt-mark hold kubelet kubeadm kubectl containerd
  101.  
  102. #There is a breaking change in kubernetes 1.22, I will update the course shortly for that change for now use versions less than 1.22
  103. #To install the latest, omit the version parameters
  104. #sudo apt-get install kubelet kubeadm kubectl
  105. #sudo apt-mark hold kubelet kubeadm kubectl containerd
  106.  
  107.  
  108. #1 - systemd Units
  109. #Check the status of our kubelet and our container runtime, containerd.
  110. #The kubelet will enter a crashloop until a cluster is created or the node is joined to an existing cluster.
  111. sudo systemctl status kubelet.service
  112. sudo systemctl status containerd.service
  113.  
  114.  
  115. #Ensure both are set to start when the system starts up.
  116. sudo systemctl enable kubelet.service
  117. sudo systemctl enable containerd.service
Advertisement
Add Comment
Please, Sign In to add comment