Skip to content

Instantly share code, notes, and snippets.

@nitrag nitrag/kube-install.sh

Last active Mar 31, 2020
Embed
What would you like to do?
Ubuntu 18.04 - K8s install and join cluster
# Enable bridged traffic - https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
# Enable IP Forward
echo "1" > /proc/sys/net/ipv4/ip_forward
# Disable Swap
swapoff -a
# Remove swap entry from /etc/fstab
# Install Docker
curl -fsSL get.docker.com | sh
# Change from using cGroup to daemon.
cat > /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
mkdir -p /etc/systemd/system/docker.service.d
# Restart docker.
systemctl daemon-reload
systemctl restart docker
#REBOOT
# Add k8s APT repo
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
# List k8s versions
curl -s https://packages.cloud.google.com/apt/dists/kubernetes-xenial/main/binary-amd64/Packages | grep Version | awk '{print $2}'
# Install specific kubernetes version
sudo apt-get update -q && sudo apt-get install -qy kubelet=1.17.4-00 kubectl=1.17.4-00 kubeadm=1.17.4-00 --allow-downgrades
# On master, generate join command then run the output on the client node
kubeadm token generate
kubeadm token create <generated-token> --print-join-command
# TOKEN=$(kubeadm token generate); kubeadm token create $TOKEN --print-join-command
#### KUBECTL Client Setup
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: asdfasdfasdfasdfasdfasdfasdf
server: https://1.2.3.4:6443
name: k8s-home
contexts:
- context:
cluster: k8s-home
namespace: default
user: ryan
name: k8s-home-context
current-context: k8s-home-context
kind: Config
preferences: {}
users:
- name: ryan
user:
client-certificate: /.../.certs/ryan.crt
client-key: /.../.certs/ryan.key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.