Advertisement
konstest

Kubernetes installation HowTo

Jun 28th, 2022
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.49 KB | None | 0 0
  1. 0. Перед началом установки необходимо выполнить Kubernetes requrements checks https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#before-you-begin что соответсвующее кол-во CPU/RAM/HDD выделено, а так же соответсвующие типы дисков
  2. 1. cat <<EOF | tee /etc/modules-load.d/k8s.conf
  3. overlay
  4. br_netfilter
  5. EOF
  6.  
  7. sudo modprobe overlay
  8. sudo modprobe br_netfilter
  9.  
  10. # sysctl params required by setup, params persist across reboots
  11. cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
  12. net.bridge.bridge-nf-call-iptables = 1
  13. net.bridge.bridge-nf-call-ip6tables = 1
  14. net.ipv4.ip_forward = 1
  15. EOF
  16.  
  17. # Apply sysctl params without reboot
  18. $ sudo sysctl --system
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. 2. Install container runtime https://github.com/containerd/containerd/blob/main/docs/getting-started.md
  26. Step 1: Installing containerd
  27.  
  28. curl https://github.com/containerd/containerd/releases/download/v1.6.6/containerd-1.6.6-linux-amd64.tar.gz | tar Cxzv /usr/local
  29.  
  30. mkdir -p /usr/local/lib/systemd/system/ && curl https://raw.githubusercontent.com/containerd/containerd/main/containerd.service -O /usr/local/lib/systemd/system/containerd.service
  31. OR using this template of config file:
  32. # Copyright The containerd Authors.
  33. #
  34. # Licensed under the Apache License, Version 2.0 (the "License");
  35. # you may not use this file except in compliance with the License.
  36. # You may obtain a copy of the License at
  37. #
  38. # http://www.apache.org/licenses/LICENSE-2.0
  39. #
  40. # Unless required by applicable law or agreed to in writing, software
  41. # distributed under the License is distributed on an "AS IS" BASIS,
  42. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  43. # See the License for the specific language governing permissions and
  44. # limitations under the License.
  45.  
  46. [Unit]
  47. Description=containerd container runtime
  48. Documentation=https://containerd.io
  49. After=network.target local-fs.target
  50.  
  51. [Service]
  52. ExecStartPre=-/sbin/modprobe overlay
  53. ExecStart=/usr/local/bin/containerd
  54.  
  55. Type=notify
  56. Delegate=yes
  57. KillMode=process
  58. Restart=always
  59. RestartSec=5
  60. # Having non-zero Limit*s causes performance problems due to accounting overhead
  61. # in the kernel. We recommend using cgroups to do container-local accounting.
  62. LimitNPROC=infinity
  63. LimitCORE=infinity
  64. LimitNOFILE=infinity
  65. # Comment TasksMax if your systemd version does not supports it.
  66. # Only systemd 226 and above support this version.
  67. TasksMax=infinity
  68. OOMScoreAdjust=-999
  69.  
  70. [Install]
  71. WantedBy=multi-user.target
  72.  
  73. Save this systemd config to /usr/local/lib/systemd/system/containerd.service
  74. systemctl daemon-reload
  75. systemctl enable --now containerd
  76.  
  77.  
  78. Step 2: Installing runc
  79. curl https://github.com/opencontainers/runc/releases/download/v1.1.3/runc.amd64 -o /usr/local/sbin/runc && chmod 755 /usr/local/sbin/runc
  80.  
  81. Step 3: Installing CNI plugins
  82. mkdir -p /opt/cni/bin && curl https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz | tar Cxzv /opt/cni/bin/
  83.  
  84. Step 4: Configure containerd for Kubernetes https://kubernetes.io/docs/setup/production-environment/container-runtimes/#containerd
  85. On Linux the default CRI socket for containerd is /run/containerd/containerd.sock. On Windows the default CRI endpoint is npipe://./pipe/containerd-containerd.
  86.  
  87. mkdir /etc/containerd && containerd config default > /etc/containerd/config.toml
  88. sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
  89. sed -ie 's#sandbox_image = .*#sandbox_image = "k8s.gcr.io/pause:3.7"#' /etc/containerd/config.toml
  90. chmod -R 755 /etc/cni/
  91. sudo systemctl restart containerd
  92.  
  93. Step 5: configure the cgroup driver for kubelet
  94. https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/configure-cgroup-driver/#configuring-the-kubelet-cgroup-driver
  95.  
  96. # cat <<EOF | tee kubeadm-config.yaml
  97. kind: ClusterConfiguration
  98. apiVersion: kubeadm.k8s.io/v1beta3
  99. ---
  100. kind: KubeletConfiguration
  101. apiVersion: kubelet.config.k8s.io/v1beta1
  102. cgroupDriver: systemd
  103. EOF
  104.  
  105.  
  106.  
  107.  
  108.  
  109. 3. Installing kubeadm, kubelet and kubectl https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#installing-kubeadm-kubelet-and-kubectl
  110.  
  111.  
  112.  
  113. 4. kubeadm init --config kubeadm-config.yaml
  114.  
  115.  
  116. Если у нас выполняется установка на ноде без интернета то предварительно нужно скачать соответствующие docker образы, список которых можно получить на ПК с установленным kubeadm и с доступом в интернет:
  117. $ kubeadm config images list
  118. $ kubeadm config images pull
  119. $ kubeadm config images list
  120. $ ctr -n=k8s.io images list
  121. $ ctr -n=k8s.io image export k8s_images.tar $(ctr -n=k8s.io images list -q | grep -vE sha256 | xargs)
  122.  
  123.  
  124. cat <<EOF | tee kube-images-list
  125. k8s.gcr.io/kube-apiserver:v1.24.2
  126. k8s.gcr.io/kube-controller-manager:v1.24.2
  127. k8s.gcr.io/kube-scheduler:v1.24.2
  128. k8s.gcr.io/kube-proxy:v1.24.2
  129. k8s.gcr.io/pause:3.7
  130. k8s.gcr.io/etcd:3.5.3-0
  131. k8s.gcr.io/coredns/coredns:v1.8.6
  132. EOF
  133. cat kube-images-list | while read IMAGE; do docker pull $IMAGE; done
  134. cat kube-images-list | while read IMAGE; do ctr -n=k8s.io images pull $IMAGE; done
  135. ctr -n=k8s.io image export k8s-docker-images.tar $(ctr -n=k8s.io images list -q | grep -vE sha256 | xargs)
  136.  
  137. # on another host import downloaded images:
  138. ctr -n=k8s.io images import k8s-docker-images.tar
  139.  
  140. kubeadm init --config kubeadm-config.yaml
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement