Skip to content

Instantly share code, notes, and snippets.

@oscar60310
Last active December 3, 2020 03:01
Show Gist options
  • Save oscar60310/77e6adaf3062276fb0f9197220056f06 to your computer and use it in GitHub Desktop.
Save oscar60310/77e6adaf3062276fb0f9197220056f06 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Ubuntu 18.05
set -e
NODE_ADDRESS=${NODE_ADDRESS:-$(hostname --ip-address)}
KUBE_VERSION="1.16.15"
KUBE_PACAKGE_VERSION="1.16.15-00"
DOCKER_VERSION="18.06.3~ce~3-0~ubuntu"
echo "K8S API Addr: $NODE_ADDRESS"
### Update packages
sudo apt-get update
### Tools
sudo apt-get install -y \
curl \
apt-transport-https \
jq \
ca-certificates \
gnupg-agent \
software-properties-common
### Install Docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install -y docker-ce=$DOCKER_VERSION containerd.io
### Disable swap
sudo swapoff -a
sudo sed -i '/ swap / s/^/#/' /etc/fstab
### Kubeadm
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
sudo apt-get install -y kubelet=$KUBE_PACAKGE_VERSION kubeadm=$KUBE_PACAKGE_VERSION kubectl=$KUBE_PACAKGE_VERSION
sudo apt-mark hold kubelet kubeadm kubectl
### Init control plane ( pod network cidr is required for flannel)
sudo kubeadm init \
--apiserver-cert-extra-sans $NODE_ADDRESS \
--pod-network-cidr=10.244.0.0/16 \
--kubernetes-version $KUBE_VERSION
### Copy kube config for this user
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
### Deploy CNI
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
### Remove taint
kubectl taint nodes $(kubectl get node -o json | jq -r '.items[0].metadata.name') node-role.kubernetes.io/master:NoSchedule-
### Create volume folder
sudo mkdir -p /mount
sudo mkdir -p /mount/redis-pv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment