Compare commits

..

3 commits

Author SHA1 Message Date
2d14363967 bump VM specs 2022-12-20 08:27:12 -06:00
8d228f9ba0 wait for network timeout 2022-12-20 08:26:48 -06:00
17a27d0570 update script logic 2022-12-20 08:26:06 -06:00
4 changed files with 35 additions and 21 deletions

View file

@ -79,6 +79,7 @@ resource "vsphere_virtual_machine" "control" {
firmware = data.vsphere_virtual_machine.template.firmware firmware = data.vsphere_virtual_machine.template.firmware
hardware_version = data.vsphere_virtual_machine.template.hardware_version hardware_version = data.vsphere_virtual_machine.template.hardware_version
scsi_type = data.vsphere_virtual_machine.template.scsi_type scsi_type = data.vsphere_virtual_machine.template.scsi_type
wait_for_guest_net_timeout = 10
extra_config = { extra_config = {
"disk.EnableUUID" = "TRUE" "disk.EnableUUID" = "TRUE"
@ -163,6 +164,7 @@ resource "vsphere_virtual_machine" "worker" {
firmware = data.vsphere_virtual_machine.template.firmware firmware = data.vsphere_virtual_machine.template.firmware
hardware_version = data.vsphere_virtual_machine.template.hardware_version hardware_version = data.vsphere_virtual_machine.template.hardware_version
scsi_type = data.vsphere_virtual_machine.template.scsi_type scsi_type = data.vsphere_virtual_machine.template.scsi_type
wait_for_guest_net_timeout = 10
network_interface { network_interface {
network_id = data.vsphere_network.network.id network_id = data.vsphere_network.network.id

View file

@ -1,7 +1,8 @@
#!/bin/bash -eu #!/bin/bash -eu
source ./env.txt source ./env.txt
if [ ! -f /etc/kubernetes/manifests/kube-vip.yaml ]; then if [ "${HOSTNAME}" == "${K8S_INITIAL_NODE}" ]; then
if [ ! -f /etc/kubernetes/manifests/kube-vip.yaml ]; then
echo ">> Configuring kube-vip..." echo ">> Configuring kube-vip..."
sudo ctr image pull ghcr.io/kube-vip/kube-vip:"${KUBEVIP_VER}" sudo ctr image pull ghcr.io/kube-vip/kube-vip:"${KUBEVIP_VER}"
sudo ctr run --rm --net-host ghcr.io/kube-vip/kube-vip:"${KUBEVIP_VER}" vip /kube-vip manifest pod \ sudo ctr run --rm --net-host ghcr.io/kube-vip/kube-vip:"${KUBEVIP_VER}" vip /kube-vip manifest pod \
@ -10,9 +11,7 @@ if [ ! -f /etc/kubernetes/manifests/kube-vip.yaml ]; then
--controlplane \ --controlplane \
--arp \ --arp \
--leaderElection | sudo tee /etc/kubernetes/manifests/kube-vip.yaml --leaderElection | sudo tee /etc/kubernetes/manifests/kube-vip.yaml
fi fi
if [ "${HOSTNAME}" == "${K8S_INITIAL_NODE}" ]; then
if ! kubectl get nodes 2>/dev/null; then if ! kubectl get nodes 2>/dev/null; then
echo ">> Bootstrapping first controlplane node..." echo ">> Bootstrapping first controlplane node..."
cat << EOF > kubeadminit.yaml cat << EOF > kubeadminit.yaml
@ -57,14 +56,14 @@ EOF
echo ">> Creating discovery config..." echo ">> Creating discovery config..."
kubectl -n kube-public get configmap cluster-info -o jsonpath='{.data.kubeconfig}' > discovery.yaml kubectl -n kube-public get configmap cluster-info -o jsonpath='{.data.kubeconfig}' > discovery.yaml
sudo install -o root -g root -m 600 discovery.yaml /etc/kubernetes/discovery.yaml sudo install -m 600 discovery.yaml /etc/kubernetes/discovery.yaml
else else
echo ">> [ERROR] Cluster initialization unsuccessful on ${HOSTNAME}! <<" echo ">> [ERROR] Cluster initialization unsuccessful on ${HOSTNAME}! <<"
exit 1 exit 1
fi fi
fi fi
echo ">> Waiting up to 10 minutes for all control-plane nodes to be Ready..." echo ">> Waiting up to 10 minutes for all control-plane nodes to be Ready..."
python3 -m http.server & python3 -m http.server 2>/dev/null &
PROC_ID=$! PROC_ID=$!
attempts_max=60 attempts_max=60
attempt=0 attempt=0
@ -388,8 +387,11 @@ else
attempt=0 attempt=0
until [ -f /etc/kubernetes/discovery.yaml ]; do until [ -f /etc/kubernetes/discovery.yaml ]; do
wget "http://${K8S_CONTROLPLANE_VIP}:8000/discovery.yaml" 2>/dev/null wget "http://${K8S_CONTROLPLANE_VIP}:8000/discovery.yaml" 2>/dev/null
sudo install -o root -g root -m 600 discovery.yaml /etc/kubernetes/discovery.yaml 2>/dev/null if ! sudo install -m 600 discovery.yaml /etc/kubernetes/discovery.yaml 2>/dev/null; then
if [ ! -f /etc/kubernetes/discovery.yaml ]; then if [ ${attempt} -eq ${attempts_max} ]; then
echo ">> [ERROR] Timeout waiting for discovery.yaml! <<"
exit 1
fi
attempt=$((attempt+1)) attempt=$((attempt+1))
sleep 10 sleep 10
fi fi
@ -409,7 +411,17 @@ nodeRegistration:
controlPlane: controlPlane:
certificateKey: ${KUBEADM_CERTKEY} certificateKey: ${KUBEADM_CERTKEY}
EOF EOF
if sudo kubeadm join "${K8S_CONTROLPLANE_VIP}":6443 --config kubeadmjoin.yaml; then if sudo kubeadm join "${K8S_CONTROLPLANE_VIP}:6443" --config kubeadmjoin.yaml; then
if [ ! -f /etc/kubernetes/manifests/kube-vip.yaml ]; then
echo ">> Configuring kube-vip..."
sudo ctr image pull ghcr.io/kube-vip/kube-vip:"${KUBEVIP_VER}"
sudo ctr run --rm --net-host ghcr.io/kube-vip/kube-vip:"${KUBEVIP_VER}" vip /kube-vip manifest pod \
--interface ens192 \
--vip "${K8S_CONTROLPLANE_VIP}" \
--controlplane \
--arp \
--leaderElection | sudo tee /etc/kubernetes/manifests/kube-vip.yaml
fi
echo ">> Node ${HOSTNAME} successfully initialized!" echo ">> Node ${HOSTNAME} successfully initialized!"
touch .k8s-node-success touch .k8s-node-success
mkdir -p "${HOME}"/.kube mkdir -p "${HOME}"/.kube

View file

@ -17,7 +17,7 @@ echo ">> Continuing after $((attempt*10)) seconds."
echo ">> Waiting up to 10 minutes for all control-plane nodes..." echo ">> Waiting up to 10 minutes for all control-plane nodes..."
attempts_max=60 attempts_max=60
attempt=0 attempt=0
until "$(wget http://${K8S_CONTROLPLANE_VIP}:8000/.k8s-controlplane-success)" 2>/dev/null; do until wget "http://${K8S_CONTROLPLANE_VIP}:8000/.k8s-controlplane-success" 2>/dev/null; do
if [ ${attempt} -eq ${attempts_max} ]; then if [ ${attempt} -eq ${attempts_max} ]; then
echo ">> [ERROR] Timeout waiting for control-plane nodes! <<" echo ">> [ERROR] Timeout waiting for control-plane nodes! <<"
exit 1 exit 1
@ -31,7 +31,7 @@ attempts_max=6
attempt=0 attempt=0
until [ -f /etc/kubernetes/discovery.yaml ]; do until [ -f /etc/kubernetes/discovery.yaml ]; do
wget "http://${K8S_CONTROLPLANE_VIP}:8000/discovery.yaml" 2>/dev/null wget "http://${K8S_CONTROLPLANE_VIP}:8000/discovery.yaml" 2>/dev/null
sudo install -o root -g root -m 600 discovery.yaml /etc/kubernetes/discovery.yaml 2>/dev/null sudo install -m 600 discovery.yaml /etc/kubernetes/discovery.yaml 2>/dev/null
if [ ! -f /etc/kubernetes/discovery.yaml ]; then if [ ! -f /etc/kubernetes/discovery.yaml ]; then
attempt=$((attempt+1)) attempt=$((attempt+1))
sleep 10 sleep 10

View file

@ -20,15 +20,15 @@ vm-domain = "lab.local"
# Control plane specs # Control plane specs
vm-control-count = "3" vm-control-count = "3"
vm-control-cpu = "2" vm-control-cpu = "2"
vm-control-ram = "2048" vm-control-ram = "4096"
vm-control-disk-size = "30" vm-control-disk-size = "30"
vm-control-ip-address-start = "60" vm-control-ip-address-start = "60"
vm-control-name = "k8s-control" vm-control-name = "k8s-control"
# Worker specs # Worker specs
vm-worker-count = "3" vm-worker-count = "3"
vm-worker-cpu = "1" vm-worker-cpu = "4"
vm-worker-ram = "1024" vm-worker-ram = "8192"
vm-worker-disk-size = "30" vm-worker-disk-size = "30"
vm-worker-ip-address-start = "64" vm-worker-ip-address-start = "64"
vm-worker-name = "k8s-worker" vm-worker-name = "k8s-worker"