Skip to content

Instantly share code, notes, and snippets.

@alexanderankin
Created December 25, 2023 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexanderankin/4e5163d57519841849f4844d2f617926 to your computer and use it in GitHub Desktop.
Save alexanderankin/4e5163d57519841849f4844d2f617926 to your computer and use it in GitHub Desktop.

create a kubernetes cluster

(a work in progress)

create droplets

curl -X POST -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer '$TOKEN'' \
    -d '{"names":["k8s-droplet"],
        "size":"s-1vcpu-1gb",
        "region":"nyc3",
        "image":"ubuntu-22-04-x64",
        "vpc_uuid":"omitted_guid"}' \
    "https://api.digitalocean.com/v2/droplets"
# fix networking config for forwarding (copied, unverified)
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

sudo modprobe -a overlay br_netfilter

# sysctl params required by setup, params persist across reboots
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF

# Apply sysctl params without reboot
sudo sysctl --system
arch=$(dpkg --print-architecture)
code=$(. /etc/os-release && echo "$VERSION_CODENAME")

curl -fSsL 'https://download.docker.com/linux/ubuntu/gpg' | gpg --dearmor | tee /etc/apt/keyrings/docker.gpg > /dev/null;
echo "deb [arch=$arch signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $code stable" | \
  tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update && apt install docker-ce -y
sed 's/^\(disabled_plugins = \["cri"\]\)$/#\1/' /etc/containerd/config.toml -i # re-enable cri plugin???
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | gpg --dearmor | tee /etc/apt/keyrings/k8s.gpg > /dev/null
echo 'deb [arch=$arch signed-by=/etc/apt/keyrings/k8s.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | \
  tee /etc/apt/sources.list.d/k8s.list > /dev/null
apt update && apt install kubeadm -y
. <(kubeadm completion bash)
. <(kubectl completion bash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment