Skip to content

Instantly share code, notes, and snippets.

@saschagrunert
Last active March 2, 2022 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saschagrunert/fee54ce00944f2526b915d90667bef9c to your computer and use it in GitHub Desktop.
Save saschagrunert/fee54ce00944f2526b915d90667bef9c to your computer and use it in GitHub Desktop.
Rocky Linux 8 - Kubernetes
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "generic/rocky8"
memory = 6144
cpus = 4
config.vm.provider :virtualbox do |v|
v.memory = memory
v.cpus = cpus
end
config.vm.provider :libvirt do |v|
v.memory = memory
v.cpus = cpus
end
config.vm.provision "install-dependencies", type: "shell", run: "once" do |sh|
sh.inline = <<~SHELL
set -euxo pipefail
# Install Kubernetes and CRI-O
cat << 'EOF' > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF
export CRIO_OS=CentOS_8_Stream
export CRIO_VERSION=1.23
curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable.repo \
https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$CRIO_OS/devel:kubic:libcontainers:stable.repo
curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable:cri-o:$CRIO_VERSION.repo \
https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:$CRIO_VERSION/$CRIO_OS/devel:kubic:libcontainers:stable:cri-o:$CRIO_VERSION.repo
dnf upgrade -y
dnf install -y \
cri-o \
cri-tools \
iproute-tc \
kubeadm \
kubectl \
kubelet \
--disableexcludes=kubernetes
cat << 'EOF' > /etc/cni/net.d/100-crio-bridge.conf
{
"cniVersion": "0.3.1",
"name": "crio",
"type": "bridge",
"bridge": "cni0",
"isGateway": true,
"ipMasq": true,
"hairpinMode": true,
"ipam": {
"type": "host-local",
"routes": [{ "dst": "0.0.0.0/0" }],
"ranges": [[{ "subnet": "10.85.0.0/16" }]]
}
}
EOF
systemctl enable --now crio kubelet
# Configure system
swapoff -a
systemctl disable --now firewalld
modprobe br_netfilter
sysctl -w net.ipv4.ip_forward=1
# Bootstrap cluster
kubeadm init
# Setup credentials
USER=vagrant
USERDIR=/home/$USER
mkdir $USERDIR/.kube
cp /etc/kubernetes/admin.conf $USERDIR/.kube/config
chown -R $USER:$USER $USERDIR/.kube
echo "alias k=kubectl" >> $USERDIR/.bashrc
export KUBECONFIG=/etc/kubernetes/admin.conf
kubectl taint nodes --all node-role.kubernetes.io/master-
SHELL
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment