Skip to content

Instantly share code, notes, and snippets.

@darth-veitcher
Last active March 10, 2020 13:19
Show Gist options
  • Save darth-veitcher/490df99baea77a044a857ea13a0b67f3 to your computer and use it in GitHub Desktop.
Save darth-veitcher/490df99baea77a044a857ea13a0b67f3 to your computer and use it in GitHub Desktop.
Kubernetes setup on Ubuntu 16.04 | k3s
#! /bin/bash
# KUBERNETES SETUP
# Quick and dirty kubernetes setup script (k3s)
#
# 1. Set the supported docker version per kubernetes
# Make sure to select the `validated` one. Also worth
# noting that k3s usually will install the latest version
# of kubernetes.
export K8S_DOCKER_VERSION=18.09
# 2. Install docker community edition
sudo apt-get update; \
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
p7zip-full \
software-properties-common; \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -; \
sudo add-apt-repository \
"deb https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable"; \
sudo apt-get update && sudo apt-get install -y docker-ce=$(apt-cache madison docker-ce | grep ${K8S_DOCKER_VERSION} | head -1 | awk '{print $3}')
# 3. Pre-flight fixes
# Setup docker daemon.
sudo tee /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
# Docker service
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo systemctl daemon-reload
sudo systemctl restart docker
# The swap should be disabled both for the current session
sudo swapoff -a
# Now edit the `/etc/fstab` file to add a comment so it persists
# across restarts
sudo sed -i.bak 's/$.*swap.*^//' /etc/fstab
# 4. Install kubernetes (k3s) and jq
# --no-deploy servicelb = don't deploy default load balancer (we'll use metallb)
# --no-deploy traefik = don't deploy ingress (we'll use nginx)
# --docker = use docker instead of containerd
sudo apt-get install -y jq; \
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="server --no-deploy=traefik --no-deploy=servicelb --docker" sh -s -
@darth-veitcher
Copy link
Author

darth-veitcher commented Mar 9, 2020

Designed to be run on a very basic Ubuntu Server base installation to get up and running with a k3s master node. Tested with 16.04 and 18.04 LTS.

NB: both the LoadBalancer and Ingress defaults have been removed as my personal preference is to use MetalLB and Nginx - comment out line 27 if you want to change this.

@darth-veitcher
Copy link
Author

darth-veitcher commented Mar 9, 2020

To use

curl -sf $(curl -sf https://bit.ly/3aU5Wnh | grep -Eo “https://(.*sh)”) | bash -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment