Skip to content

Quick provisioning of Bookworm VMs via Vagrant/Vagrantfile #916

Description

@matthewpoer

Started on the guide today and had to debate a bit on the best way to set up the prerequisite machines.

I settled on a Vagrant file that I wanted to share, although I'm not sure where it would be best inserted.

Creating a file called Vagrant file with the below contents, then executing a vagrant up should allow one to start the guide on Step 3. Generate and Distribute SSH Keys.

The (IMO annoying) steps of setting up [virtual] machines with Debian (now oldstable) Bookworm, setting up sshd to allow passwords + root access, and install kubectl is handled here, so the next reader should be able to dive straight into the Kubernetes related work.

$script = <<-'SCRIPT'
apt-get update
apt-get -y install wget curl vim openssl git bash-completion
cd /root
git clone --depth 1 https://github.com/kelseyhightower/kubernetes-the-hard-way.git
cd kubernetes-the-hard-way
wget -q --show-progress \
  --https-only \
  --timestamping \
  -P downloads \
  -i downloads-$(dpkg --print-architecture).txt
ARCH=$(dpkg --print-architecture)
mkdir -p downloads/{client,cni-plugins,controller,worker}
tar -xvf downloads/crictl-v1.32.0-linux-${ARCH}.tar.gz \
  -C downloads/worker/
tar -xvf downloads/containerd-2.1.0-beta.0-linux-${ARCH}.tar.gz \
  --strip-components 1 \
  -C downloads/worker/
tar -xvf downloads/cni-plugins-linux-${ARCH}-v1.6.2.tgz \
  -C downloads/cni-plugins/
tar -xvf downloads/etcd-v3.6.0-rc.3-linux-${ARCH}.tar.gz \
  -C downloads/ \
  --strip-components 1 \
  etcd-v3.6.0-rc.3-linux-${ARCH}/etcdctl \
  etcd-v3.6.0-rc.3-linux-${ARCH}/etcd
mv downloads/{etcdctl,kubectl} downloads/client/
mv downloads/{etcd,kube-apiserver,kube-controller-manager,kube-scheduler} \
  downloads/controller/
mv downloads/{kubelet,kube-proxy} downloads/worker/
mv downloads/runc.${ARCH} downloads/worker/runc
rm -rf downloads/*gz
chmod +x downloads/{client,cni-plugins,controller,worker}/*
cp downloads/client/kubectl /usr/local/bin/
echo "source /etc/bash_completion" >> ~/.bashrc
echo "source <(kubectl completion bash)" >> ~/.bashrc
echo "192.168.0.10 server.kubernetes.local server" > /root/machines.txt
echo "192.168.0.20 node-0.kubernetes.local node-0 192.168.0.20/24" >> /root/machines.txt
echo "192.168.0.30 node-1.kubernetes.local node-1 192.168.0.30/24" >> /root/machines.txt
SCRIPT

$sshd_script = <<-'SCRIPT'
sed -i 's/^#*PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
systemctl restart sshd
SCRIPT

Vagrant.configure("2") do |config|
  config.vm.define "jumpbox" do |jumpbox|
    jumpbox.vm.box = "debian/bookworm64"
    jumpbox.vm.hostname = "jumpbox"
    jumpbox.vm.network "private_network", ip: "192.168.10.100"
    jumpbox.vm.provision "shell", inline: $script
  end
  config.vm.define "server" do |server|
    server.vm.box = "debian/bookworm64"
    server.vm.hostname = "server"
    server.vm.network "private_network", ip: "192.168.0.10"
    server.vm.provision "shell", inline: $sshd_script
  end
  config.vm.define "node-0" do |node0|
    node0.vm.box = "debian/bookworm64"
    node0.vm.hostname = "node-0"
    node0.vm.network "private_network", ip: "192.168.0.20"
    node0.vm.provision "shell", inline: $sshd_script
  end
  config.vm.define "node1" do |node1|
    node1.vm.box = "debian/bookworm64"
    node1.vm.hostname = "node-1"
    node1.vm.network "private_network", ip: "192.168.0.30"
    node1.vm.provision "shell", inline: $sshd_script
  end
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions