#!/bin/bash set -e # Set verbosity if [ "${DEBUG}" = 1 ]; then set -x KUBEADM_VERBOSE="-v=8" else KUBEADM_VERBOSE="-v=3" fi BIN_DIR="/usr/local/bin" SBIN_DIR="/usr/local/sbin" SERVICE_DIR="/etc/systemd/system" COMMAND=$1 # Define global compatibility matrix declare -A versions=( ["containerd"]="v1.7.16" ["runc"]="v1.1.11" ["cni"]="v1.4.0" ["crictl"]="v1.29.0" ) # Helper function to display usage information helper() { cat < or curl -sfL https://goyaki.clastix.io | ENV=... bash -s You must be sudo to run this script. Commands: init: Deploy the first control-plane node of the Kubernetes cluster - This command initializes the Kubernetes control-plane on the first node. - Requires: JOIN_URL (optional), KUBEADM_CONFIG (optional), ADVERTISE_ADDRESS(optional), BIND_PORT (optional), KUBERNETES_VERSION (optional) - Example: KUBERNETES_VERSION=v1.30.2 yaki init - Example: JOIN_URL=: KUBERNETES_VERSION=v1.30.2 yaki init - Example: KUBEADM_CONFIG=kubeadm-config.yaml yaki init join: Join a control plane node to the cluster - This command joins the node as control plane to an existing Kubernetes cluster. - It also installs all necessary prerequisites, container runtime, CNI plugins, and Kubernetes binaries. - Requires: JOIN_URL, JOIN_TOKEN, JOIN_TOKEN_CACERT_HASH, JOIN_ASCP, KUBERNETES_VERSION (optional) - Example: JOIN_URL=: JOIN_TOKEN= JOIN_TOKEN_CERT_KEY= JOIN_TOKEN_CACERT_HASH=sha256: JOIN_ASCP=1 KUBERNETES_VERSION=v1.30.2 yaki join join: Join a node to the cluster - This command joins the node to an existing Kubernetes cluster. - Requires: JOIN_URL, JOIN_TOKEN, JOIN_TOKEN_CACERT_HASH, KUBERNETES_VERSION (optional) - Example: JOIN_URL=: JOIN_TOKEN= JOIN_TOKEN_CACERT_HASH=sha256: KUBERNETES_VERSION=v1.30.2 yaki join reset: Reset the node - This command removes all Kubernetes components and configurations from the node. - Example: yaki reset help: Print this help - Displays this help message. - Example: yaki help Environment variables: +-------------------------+-------------------------------------------------------------+------------+ | Variable | Description | Default | +-------------------------+-------------------------------------------------------------+------------+ | KUBERNETES_VERSION | Version of kubernetes to install. | v1.30.2 | | CONTAINERD_VERSION | Version of container runtime containerd. | see matrix | | RUNC_VERSION | Version of runc to install. | see matrix | | CNI_VERSION | Version of CNI plugins to install. | see matrix | | CRICTL_VERSION | Version of crictl to install. | see matrix | | KUBEADM_CONFIG | Path to the kubeadm config file to use. | Not set | | ADVERTISE_ADDRESS | Address to advertise for the api-server. | 0.0.0.0 | | BIND_PORT | Port to use for the api-server. | 6443 | | JOIN_TOKEN | Token to join the control-plane. | Not set | | JOIN_TOKEN_CACERT_HASH | Token Certificate Authority hash to join the control-plane. | Not set | | JOIN_TOKEN_CERT_KEY | Token Certificate Key to join the control-plane. | Not set | | JOIN_URL | URL to join the control-plane. | Not set | | JOIN_ASCP | Switch to join either as control plane or worker. | 0 | | DEBUG | Set to 1 for more verbosity during script execution. | 0 | +-------------------------+-------------------------------------------------------------+------------+ EOF } # Log functions info() { echo "[INFO] $@"; } warn() { echo "[WARN] $@" >&2; } fatal() { echo "[ERROR] $@" >&2; exit 1; } # Setup architecture setup_arch() { case ${ARCH:=$(uname -m)} in amd64|x86_64) ARCH=amd64 ;; arm64) ARCH=arm64 ;; *) fatal "unsupported architecture ${ARCH}" ;; esac SUFFIX=$(uname -s | tr '[:upper:]' '[:lower:]')-${ARCH} } # Function to get compatible components version get_version() { local component=$1 echo "${versions[$component]}" } setup_env() { # Check if running as root [ "$(id -u)" -eq 0 ] || fatal "You need to be root to perform this install" # Set default values KUBERNETES_VERSION=${KUBERNETES_VERSION:-v1.30.2} CONTAINERD_VERSION=${CONTAINERD_VERSION:-$(get_version "containerd")} RUNC_VERSION=${RUNC_VERSION:-$(get_version "runc")} CNI_VERSION=${CNI_VERSION:-$(get_version "cni")} CRICTL_VERSION=${CRICTL_VERSION:-$(get_version "crictl")} ADVERTISE_ADDRESS=${ADVERTISE_ADDRESS:-0.0.0.0} BIND_PORT=${BIND_PORT:-6443} } # Check if prerequisites are installed check_prerequisites() { info "Checking if prerequisites are installed" # List of required commands local required_commands=("conntrack" "socat" "ip" "iptables" "modprobe" "sysctl" "systemctl" "nsenter" "ebtables" "ethtool" "wget") for cmd in "${required_commands[@]}"; do if ! command -v $cmd &> /dev/null; then info "$cmd is not installed. Please install it before proceeding." exit 1 fi done } # Configure system settings configure_system_settings() { info "Configure system settings: " info " - disable swap" swapoff -a sed -i '/ swap / s/^/#/' /etc/fstab info " - enable required kernel modules" cat < /etc/containerd/config.toml sed -i '/\[Service\]/a EnvironmentFile='/etc/environment'' /usr/local/lib/systemd/system/containerd.service systemctl daemon-reload && systemctl enable --now containerd && systemctl restart containerd } # Install crictl install_crictl() { info "installing crictl" wget -qO- --progress=bar "https://github.com/kubernetes-sigs/cri-tools/releases/download/${CRICTL_VERSION}/crictl-${CRICTL_VERSION}-linux-${ARCH}.tar.gz" | tar -C "${BIN_DIR}" -xz rm -f crictl-${CRICTL_VERSION}-linux-${ARCH}.tar.gz # Cleanup downloaded tar.gz file cat <