Skip to content

Instantly share code, notes, and snippets.

@SarasaGunawardhana
Last active October 25, 2020 22:21
Show Gist options
  • Save SarasaGunawardhana/398e16e359eded8bf66a54d0862803e9 to your computer and use it in GitHub Desktop.
Save SarasaGunawardhana/398e16e359eded8bf66a54d0862803e9 to your computer and use it in GitHub Desktop.
Prerequisites for Setup Kubenetes Cluster. You should install these things on each server.
#!/bin/bash
## Generic installation on all nodes
sysctl -w net.ipv4.ip_forward=1
sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g' /etc/sysctl.conf
sudo sysctl -p /etc/sysctl.conf
swapoff -a
sed -i '2s/^/#/' /etc/fstab
apt-get update
apt-get update && apt-get install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update && apt-get install -y docker-ce
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
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
apt-get update && apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt install kubernetes-cni -y # not in documentation needed for updates
apt-get install kubelet kubeadm kubectl -y
apt-mark hold kubelet kubeadm kubectl
systemctl daemon-reload
systemctl restart kubelet
## Create Default Audit Policy
mkdir -p /etc/kubernetes
cat > /etc/kubernetes/audit-policy.yaml <<EOF
apiVersion: audit.k8s.io/v1beta1
kind: Policy
rules:
- level: Metadata
EOF
# folder to save audit logs
mkdir -p /var/log/kubernetes/audit
## Install NFS Client Drivers
sudo apt-get update
sudo apt-get install nfs-common
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment