Skip to content
Snippets Groups Projects

Kube Install

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Adphi
    Edited
    kube 2.50 KiB
    #! /usr/bin/env bash
    
    if [ "$EUID" -ne 0 ]
      then echo "Please run as root"
      exit
    fi
    echo "Installing packages: apt-transport-https ca-certificates curl software-properties-common"
    
    apt-get update -qq && apt-get install -qq -y apt-transport-https ca-certificates curl software-properties-common
    
    echo "Adding kubernetes repository"
    
    curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - &> /dev/null
    cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
    deb https://apt.kubernetes.io/ kubernetes-xenial main
    EOF
    apt-get update -qq
    
    echo "Checking version"
    
    VERSIONS=($(apt-cache show kubelet|grep -i version|sed 's/ //g'|cut -d':' -f 2))
    
    VERSION=$1
    if [[ ! " ${VERSIONS[*]} " =~ ${VERSION} ]]; then
            echo "Invalid version: $VERSION. Available Versions:"
            printf "%s\n"  "${VERSIONS[@]}"
            exit 1
    fi
    echo "Using Version: $VERSION"
    
    update-alternatives --set iptables /usr/sbin/iptables-legacy &> /dev/null
    update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy &> /dev/null
    update-alternatives --set arptables /usr/sbin/arptables-legacy &> /dev/null
    update-alternatives --set ebtables /usr/sbin/ebtables-legacy &> /dev/null
    
    echo "Pre Configuring Containerd"
    cat > /etc/modules-load.d/containerd.conf <<EOF
    overlay
    br_netfilter
    EOF
    
    modprobe overlay
    modprobe br_netfilter
    
    # Setup required sysctl params, these persist across reboots.
    cat > /etc/sysctl.d/99-kubernetes-cri.conf <<EOF
    net.bridge.bridge-nf-call-iptables  = 1
    net.ipv4.ip_forward                 = 1
    net.bridge.bridge-nf-call-ip6tables = 1
    EOF
    
    sysctl --system
    
    # Install containerd
    echo "Installing Containerd"
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key --keyring /etc/apt/trusted.gpg.d/docker.gpg add -
    add-apt-repository \
        "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
        $(lsb_release -cs) \
        stable"
    apt-get update -qq && apt-get install -y containerd.io -qq
    
    echo "Configuring Containerd"
    
    # Configure containerd
    mkdir -p /etc/containerd
    containerd config default > /etc/containerd/config.toml
    
    # Restart containerd
    systemctl restart containerd
    
    echo "Installing Kubernetes packages: kubelet kubeadm kubectl"
    apt-get install -qq -y kubelet=$VERSION kubeadm=$VERSION kubectl=$VERSION
    apt-mark hold kubelet kubeadm kubectl
    
    echo "Disabling swap"
    # Disable swap
    swapoff -a
    sed -i 's/\/swap/# \/swap/g' /etc/fstab
    
    systemctl daemon-reload
    systemctl restart kubelet
    
    echo "Create resolv.conf symlink"
    sudo rm /etc/resolv.conf
    sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
    echo "Done"
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment