kubernetes-bootstrapping/00-provisioning/README.md
2023-12-18 18:28:22 -07:00

73 lines
2.5 KiB
Markdown

# 00-Provisioning
Adding new nodes
1. Call lighter and pass the new node's name to generate ignition files for the node, see below snippet.
2. Commit and check the resulting ignition/*.json files into version control at deadbeef.codes, they need to be present before booting the node.
```bash
# Be sure to run from 00-provisioning directory
cd 00-provisioning
# Templating for Butane files to replace hostname with name passed
# to lighter, then it calls butane to generate ignition files
lighter() {
if [ -z "$1" ]; then
echo "error: lighter() called without specifying a VM name"
echo "Usage: lighter() <name>"
return
fi
# Create temporary working copies
cp butane/boot.yaml butane/boot~.yaml
cp butane/full.yaml butane/full~.yaml
# Replace hostname token with name provided
hostnameToken="{{HOSTNAME}}"
sed -i -e "s/$hostnameToken/$1/g" butane/boot~.yaml
sed -i -e "s/$hostnameToken/$1/g" butane/full~.yaml
# Butane transpile to ignition files
butane butane/boot~.yaml > ignition/$1-boot.json
butane butane/full~.yaml > ignition/$1-full.json
# Cleanup mess
rm -f butane/*~.yaml
}
lighter kube-control01
lighter kube-control02
lighter kube-node01
lighter kube-node02
lighter kube-node03
```
After you've checked the ignition files into version control, provision the server, either on baremetal or VM - example with virtualbox. Use a method to point it to the boot ignition file, in virtual box guest properties can be used.
```bash
# Stop git bash being stupid
export MSYS_NO_PATHCONV=1
# Function to create VirtualBox VM, accepts name of VM as argument
create_vm() {
if [ -z "$1" ]; then
echo "error: create_vm() called without specifying a VM name"
echo "Usage: create_vm <name>"
return
fi
"C:/Program Files/Oracle/VirtualBox/vboxmanage.exe" import --vsys 0 --vmname "$1" "D:/VirtualBox/OVA/fedora-coreos-39.20231119.3.0-virtualbox.x86_64.ova"
"C:/Program Files/Oracle/VirtualBox/vboxmanage.exe" modifyvm $1 --nic1 bridged
"C:/Program Files/Oracle/VirtualBox/vboxmanage.exe" modifyvm $1 --bridge-adapter1 "Intel(R) Ethernet Controller I225-V"
"C:/Program Files/Oracle/VirtualBox/vboxmanage.exe" guestproperty set $1 "/Ignition/Config" "$(cat ignition/$1-boot.json)"
"C:/Program Files/Oracle/VirtualBox/vboxmanage.exe" startvm $1 --type headless
}
create_vm kube-control01
create_vm kube-control02
create_vm kube-node01
create_vm kube-node02
create_vm kube-node03
```