From 3dec09b69defb81e43f598eed3f8138d0507bdba Mon Sep 17 00:00:00 2001 From: Raimonds Vanags Date: Sun, 25 May 2025 11:58:56 +0200 Subject: [PATCH] container_runtime option added to settings.yaml --- Vagrantfile | 9 ++++--- scripts/common.sh | 66 ++++++++++++++++++++++++++++++++++++----------- settings.yaml | 4 +-- 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 2803482..8a4815c 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,4 +1,3 @@ - require "yaml" vagrant_root = File.dirname(File.expand_path(__FILE__)) settings = YAML.load_file "#{vagrant_root}/settings.yaml" @@ -47,7 +46,8 @@ Vagrant.configure("2") do |config| "ENVIRONMENT" => settings["environment"], "KUBERNETES_VERSION" => settings["software"]["kubernetes"], "KUBERNETES_VERSION_SHORT" => settings["software"]["kubernetes"][0..3], - "OS" => settings["software"]["os"] + "OS" => settings["software"]["os"], + "CONTAINER_RUNTIME" => settings["software"]["container_runtime"] }, path: "scripts/common.sh" controlplane.vm.provision "shell", @@ -83,7 +83,8 @@ Vagrant.configure("2") do |config| "ENVIRONMENT" => settings["environment"], "KUBERNETES_VERSION" => settings["software"]["kubernetes"], "KUBERNETES_VERSION_SHORT" => settings["software"]["kubernetes"][0..3], - "OS" => settings["software"]["os"] + "OS" => settings["software"]["os"], + "CONTAINER_RUNTIME" => settings["software"]["container_runtime"] }, path: "scripts/common.sh" node.vm.provision "shell", path: "scripts/node.sh" @@ -95,4 +96,4 @@ Vagrant.configure("2") do |config| end end -end +end diff --git a/scripts/common.sh b/scripts/common.sh index c261cc7..31926c2 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -44,24 +44,52 @@ EOF # Apply sysctl params without reboot sudo sysctl --system -## Install CRIO Runtime - +## Install Container Runtime sudo apt-get update -y apt-get install -y software-properties-common curl apt-transport-https ca-certificates -curl -fsSL https://pkgs.k8s.io/addons:/cri-o:/prerelease:/main/deb/Release.key | - gpg --dearmor -o /etc/apt/keyrings/cri-o-apt-keyring.gpg -echo "deb [signed-by=/etc/apt/keyrings/cri-o-apt-keyring.gpg] https://pkgs.k8s.io/addons:/cri-o:/prerelease:/main/deb/ /" | - tee /etc/apt/sources.list.d/cri-o.list - -sudo apt-get update -y -sudo apt-get install -y cri-o - -sudo systemctl daemon-reload -sudo systemctl enable crio --now -sudo systemctl start crio.service +if [ "${CONTAINER_RUNTIME}" == "cri-o" ]; then + echo "Installing CRI-O runtime..." + + curl -fsSL https://pkgs.k8s.io/addons:/cri-o:/prerelease:/main/deb/Release.key | + gpg --dearmor -o /etc/apt/keyrings/cri-o-apt-keyring.gpg + echo "deb [signed-by=/etc/apt/keyrings/cri-o-apt-keyring.gpg] https://pkgs.k8s.io/addons:/cri-o:/prerelease:/main/deb/ /" | + tee /etc/apt/sources.list.d/cri-o.list + + sudo apt-get update -y + sudo apt-get install -y cri-o + + sudo systemctl daemon-reload + sudo systemctl enable crio --now + sudo systemctl start crio.service + +elif [ "${CONTAINER_RUNTIME}" == "containerd" ]; then + echo "Installing containerd runtime..." + + # Install containerd + sudo mkdir -p /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + + sudo apt-get update -y + sudo apt-get install -y containerd.io + + # Configure containerd + sudo mkdir -p /etc/containerd + containerd config default | sudo tee /etc/containerd/config.toml > /dev/null + + # Enable SystemdCgroup + sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml + + sudo systemctl restart containerd + sudo systemctl enable containerd + +else + echo "Unsupported container runtime: ${CONTAINER_RUNTIME}" + exit 1 +fi -echo "CRI runtime installed successfully" +echo "Container runtime ${CONTAINER_RUNTIME} installed successfully" sudo mkdir -p /etc/apt/keyrings curl -fsSL https://pkgs.k8s.io/core:/stable:/v$KUBERNETES_VERSION_SHORT/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg @@ -74,8 +102,16 @@ sudo apt-get update -y sudo apt-get install -y jq # Disable auto-update services -sudo apt-mark hold kubelet kubectl kubeadm cri-o +sudo apt-mark hold kubelet kubectl kubeadm +if [ "${CONTAINER_RUNTIME}" == "cri-o" ]; then + sudo apt-mark hold cri-o +elif [ "${CONTAINER_RUNTIME}" == "containerd" ]; then + sudo apt-mark hold containerd +else + Something went wrong when marking the container runtime as held. + exit 1 +fi local_ip="$(ip --json a s | jq -r '.[] | if .ifname == "eth1" then .addr_info[] | if .family == "inet" then .local else empty end else empty end')" cat > /etc/default/kubelet << EOF diff --git a/settings.yaml b/settings.yaml index 2acb7f6..ab2fd68 100644 --- a/settings.yaml +++ b/settings.yaml @@ -10,7 +10,7 @@ cluster_name: Kubernetes Cluster # All IPs/CIDRs should be private and allowed in /etc/vbox/networks.conf. network: # Worker IPs are simply incremented from the control IP. - control_ip: 10.0.0.10 + control_ip: 192.168.56.101 dns_servers: - 8.8.8.8 - 1.1.1.1 @@ -32,7 +32,7 @@ nodes: software: box: bento/ubuntu-24.04 calico: 3.26.0 - # To skip the dashboard installation, set its version to an empty value or comment it out: + container_runtime: "containerd" # Options: cri-o, containerd dashboard: 2.7.0 kubernetes: 1.31.0-*