84 lines
2.8 KiB
Bash
84 lines
2.8 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Common setup for all servers (Control Plane and Nodes)
|
|
|
|
set -euxo pipefail
|
|
|
|
# Variable Declaration
|
|
|
|
# DNS Setting
|
|
if [ ! -d /etc/systemd/resolved.conf.d ]; then
|
|
sudo mkdir /etc/systemd/resolved.conf.d/
|
|
fi
|
|
cat <<EOF | sudo tee /etc/systemd/resolved.conf.d/dns_servers.conf
|
|
[Resolve]
|
|
DNS=${DNS_SERVERS}
|
|
EOF
|
|
|
|
sudo systemctl restart systemd-resolved
|
|
|
|
# disable swap
|
|
sudo swapoff -a
|
|
|
|
# keeps the swap off during reboot
|
|
(crontab -l 2>/dev/null; echo "@reboot /sbin/swapoff -a") | crontab - || true
|
|
sudo apt-get update -y
|
|
# Install CRI-O Runtime
|
|
|
|
VERSION="$(echo ${KUBERNETES_VERSION} | grep -oE '[0-9]+\.[0-9]+')"
|
|
|
|
# Create the .conf file to load the modules at bootup
|
|
cat <<EOF | sudo tee /etc/modules-load.d/crio.conf
|
|
overlay
|
|
br_netfilter
|
|
EOF
|
|
|
|
sudo modprobe overlay
|
|
sudo modprobe br_netfilter
|
|
|
|
# Set up required sysctl params, these persist across reboots.
|
|
cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
|
|
net.bridge.bridge-nf-call-iptables = 1
|
|
net.ipv4.ip_forward = 1
|
|
net.bridge.bridge-nf-call-ip6tables = 1
|
|
EOF
|
|
|
|
sudo sysctl --system
|
|
|
|
cat <<EOF | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
|
|
deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ /
|
|
EOF
|
|
cat <<EOF | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.list
|
|
deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/ /
|
|
EOF
|
|
|
|
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$VERSION/$OS/Release.key | sudo apt-key --keyring /etc/apt/trusted.gpg.d/libcontainers.gpg add -
|
|
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/Release.key | sudo apt-key --keyring /etc/apt/trusted.gpg.d/libcontainers.gpg add -
|
|
|
|
sudo apt-get update
|
|
sudo apt-get install cri-o cri-o-runc -y
|
|
|
|
cat >> /etc/default/crio << EOF
|
|
${ENVIRONMENT}
|
|
EOF
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable crio --now
|
|
|
|
echo "CRI runtime installed successfully"
|
|
|
|
sudo apt-get update
|
|
sudo apt-get install -y apt-transport-https ca-certificates curl
|
|
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-archive-keyring.gpg
|
|
|
|
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
|
|
sudo apt-get update -y
|
|
sudo apt-get install -y kubelet="$KUBERNETES_VERSION" kubectl="$KUBERNETES_VERSION" kubeadm="$KUBERNETES_VERSION"
|
|
sudo apt-get update -y
|
|
sudo apt-get install -y jq
|
|
|
|
local_ip="$(ip --json a s | jq -r '.[] | if .ifname == "eth1" then .addr_info[] | if .family == "inet" then .local else empty end else empty end')"
|
|
cat > /etc/default/kubelet << EOF
|
|
KUBELET_EXTRA_ARGS=--node-ip=$local_ip
|
|
${ENVIRONMENT}
|
|
EOF
|