Created
July 20, 2020 11:16
-
-
Save nilesh93/fe90c8d2137bc24d32479e4fae64c558 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ## prerequisites-kubernetes.sh | |
| ## Generic installation on all nodes | |
| K8S_VERSION="$1" | |
| ## Enable IP Forwarding | |
| 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 | |
| ## Disable Swap | |
| swapoff -a | |
| sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab | |
| ## Setup Docker | |
| 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 | |
| ## Setup Kubeadm Kubelet Kubernetes-CNI Kubectl | |
| 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=$K8S_VERSION kubeadm=$K8S_VERSION kubectl=$K8S_VERSION -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 -y nfs-common |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment