Created
November 27, 2023 04:44
-
-
Save crazygit/fe4ad930c82e881083b8a866334b7f4f to your computer and use it in GitHub Desktop.
Revisions
-
crazygit created this gist
Nov 27, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ # -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure("2") do |config| # common config for master and node config.vm.provision "shell", path: "init.sh" config.vm.box = "gyptazy/ubuntu22.04-arm64" config.vm.box_check_update = false # master config.vm.define "master" do |master| master.vm.network "private_network", ip: "10.0.0.101" master.vm.hostname = "master.k8s.local" master.vm.provider "vmware_desktop" do |v| v.vmx["memsize"] = "4096" v.vmx["numvcpus"] = "2" end end # node (1..2).each do |i| config.vm.define "node#{i}" do |node| node.vm.network "private_network", ip: "10.0.0.20#{i}" node.vm.hostname = "node#{i}.k8s.local" node.vm.provider "vmware_desktop" do |v| v.vmx["memsize"] = "2048" v.vmx["numvcpus"] = "2" end end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,94 @@ set -eux # 目前写死的是ubuntu 22.04 arm架构的源 function use_tsinghua_mirror() { cat >/etc/apt/sources.list <<EOF # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse deb http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse # deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse # 预发布软件源,不建议启用 # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse # # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse EOF } # 安装常用软件 function install_software() { apt-get update && apt-get install -y vim net-tools } function install_containerd() { apt-get update && apt-get install -y ca-certificates curl gnupg install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg chmod a+r /etc/apt/keyrings/docker.gpg # Add the repository to Apt sources: echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null apt-get update apt-get install -y containerd.io apt-mark hold containerd.io } function install_kubeadm() { apt-get update apt-get install -y apt-transport-https ca-certificates curl curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg # This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list apt-get update && apt-get install -y kubelet kubeadm kubectl apt-mark hold kubelet kubeadm kubectl } function disable_swap() { swapoff -a rm /swap.img sed -i '/swap/s/^\(.*\)$/# \1/g' /etc/fstab } function config_system() { modprobe br_netfilter echo 1 | tee /proc/sys/net/ipv4/ip_forward echo 1 | tee /proc/sys/net/bridge/bridge-nf-call-iptables # 默认的containerd的配置(通过Docker安装的默认配置)是没有enable cri服务的,需要更新配置文件 containerd config default | sudo tee /etc/containerd/config.toml # 设置containerd使用正确的cgroup, 不然创建集群后,会看到k8s的系统组件的容器一直在重启 sed -i 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml # 配置crictl模式使用的runtime,生成的配置文件在/etc/crictl.yaml,可以随时修改。 crictl config runtime-endpoint unix:///var/run/containerd/containerd.sock systemctl enable containerd.service systemctl enable kubelet.service systemctl restart containerd.service systemctl restart kubelet.service } function main() { export DEBIAN_FRONTEND=noninteractive disable_swap use_tsinghua_mirror install_software # k8s 1.24版本开始不再使用docker,而是默认使用containerd install_containerd install_kubeadm config_system } main