Last active
July 5, 2023 05:08
-
-
Save ulexxander/7fbb625d62edf3d270d2ed26efd1b7a3 to your computer and use it in GitHub Desktop.
Basic Kubernetes installation snippets
This file contains 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
#cloud-config | |
users: | |
- name: alex | |
groups: sudo, docker | |
shell: /bin/bash | |
lock_passwd: false | |
# mkpasswd --method=SHA-512 --rounds=4096 | |
passwd: "$6$rounds=4096$liX9KRchDIBKuoXt$LqW34rkz2k3yB/MmSPL4SbvGmO0xg7sQKgnwkTAhTV6RjvZAOJS9G4iURlkJS63TRt.ThpE9Thy9G/1.JwXDC0" | |
ssh_authorized_keys: | |
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDQ1lu+edUae0ND7RzuYe7DnHeakq9WrwZGFgElj2vH4 | |
package_update: true | |
package_upgrade: false | |
packages: | |
- apt-transport-https | |
runcmd: | |
- | | |
tee /etc/modules-load.d/kubernetes.conf <<EOF | |
overlay | |
br_netfilter | |
EOF | |
- modprobe overlay | |
- modprobe br_netfilter | |
- | | |
tee /etc/sysctl.d/kubernetes.conf <<EOF | |
net.bridge.bridge-nf-call-ip6tables = 1 | |
net.bridge.bridge-nf-call-iptables = 1 | |
net.ipv4.ip_forward = 1 | |
EOF | |
- sysctl --system | |
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmour -o /etc/apt/trusted.gpg.d/docker.gpg | |
- apt-add-repository -y "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | |
- apt install -y containerd.io | |
- containerd config default | tee /etc/containerd/config.toml > /dev/null | |
- sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml | |
- systemctl restart containerd | |
- curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmour -o /etc/apt/trusted.gpg.d/kubernetes-xenial.gpg | |
- apt-add-repository -y "deb http://apt.kubernetes.io/ kubernetes-xenial main" | |
- apt install -y kubelet kubeadm kubectl | |
- apt-mark hold kubelet kubeadm kubectl | |
- kubeadm config images pull |
This file contains 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
# Source tutorials: | |
# https://www.linuxtechi.com/install-kubernetes-on-ubuntu-22-04/ | |
# https://computingforgeeks.com/install-kubernetes-cluster-ubuntu-jammy/?expand_article=1 | |
tee /etc/modules-load.d/kubernetes.conf <<EOF | |
overlay | |
br_netfilter | |
EOF | |
modprobe overlay | |
modprobe br_netfilter | |
tee /etc/sysctl.d/kubernetes.conf <<EOF | |
net.bridge.bridge-nf-call-ip6tables = 1 | |
net.bridge.bridge-nf-call-iptables = 1 | |
net.ipv4.ip_forward = 1 | |
EOF | |
sysctl --system | |
apt update | |
# Other packages are already installed. | |
# apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates | |
apt install -y apt-transport-https | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmour -o /etc/apt/trusted.gpg.d/docker.gpg | |
apt-add-repository -y "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | |
apt install -y containerd.io | |
containerd config default | tee /etc/containerd/config.toml > /dev/null | |
# https://kubernetes.io/docs/setup/production-environment/container-runtimes/#systemd-cgroup-driver | |
sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml | |
systemctl restart containerd | |
# systemctl status containerd | |
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmour -o /etc/apt/trusted.gpg.d/kubernetes-xenial.gpg | |
apt-add-repository -y "deb http://apt.kubernetes.io/ kubernetes-xenial main" | |
apt install -y kubelet kubeadm kubectl | |
apt-mark hold kubelet kubeadm kubectl | |
kubeadm config images pull | |
# FOR MASTER | |
kubeadm init \ | |
--service-cidr 10.114.0.0/16 \ | |
--pod-network-cidr 10.115.0.0/16 \ | |
--upload-certs | |
# FOR WORKER | |
kubeadm join 78.47.170.193:6443 --token ??? \ | |
--discovery-token-ca-cert-hash ??? | |
# LOCALLY | |
scp [email protected]:/etc/kubernetes/admin.conf kubectl-admin.conf | |
export KUBECONFIG=kubectl-admin.conf | |
wget https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml | |
sed -i 's|"Network": ".*"|"Network": "10.115.0.0/16"|' kube-flannel.yml | |
kubectl apply -f kube-flannel.yml | |
# TODO: cloud init should reboot after done? | |
# apt upgrade -y | |
# [ -f /var/run/reboot-required ] && sudo reboot -f | |
# TODO: apt update after apt-add-repository not needed, right? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ubuntu 22.04, running on Hetzner, commands executed as root user.