Compare commits

..

No commits in common. "b5bbc4e7a8d8ce1b78e0bfc272b2f63163aa9e1a" and "2d14363967050033fbf067f718c4e2d076719411" have entirely different histories.

9 changed files with 97 additions and 101 deletions

View file

@ -178,6 +178,7 @@ autoinstall:
hostname: ${ vm_guest_os_hostname } hostname: ${ vm_guest_os_hostname }
users: users:
- name: ${ build_username } - name: ${ build_username }
passwd: "${ build_password }"
groups: [adm, cdrom, dip, plugdev, lxd, sudo] groups: [adm, cdrom, dip, plugdev, lxd, sudo]
lock-passwd: false lock-passwd: false
sudo: ALL=(ALL) NOPASSWD:ALL sudo: ALL=(ALL) NOPASSWD:ALL

View file

@ -1,3 +0,0 @@
-----BEGIN OPENSSH PRIVATE KEY-----
-----END OPENSSH PRIVATE KEY-----

View file

@ -77,11 +77,12 @@ communicator_port = 22
communicator_timeout = "20m" communicator_timeout = "20m"
common_ip_wait_timeout = "20m" common_ip_wait_timeout = "20m"
common_shutdown_timeout = "15m" common_shutdown_timeout = "15m"
vm_shutdown_command = "sudo /usr/sbin/shutdown -P now"
build_remove_keys = true build_remove_keys = true
build_username = "admin" build_username = "admin"
build_password = "VMware1!" build_password = "VMware1!"
ssh_keys = [ ssh_keys = [
"ssh-ed25519 blahblahblah builder" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOpLvpxilPjpCahAQxs4RQgv+Lb5xObULXtwEoimEBpA builder"
] ]
// Provisioner Settings // Provisioner Settings

View file

@ -34,13 +34,13 @@ locals {
build_tool = "HashiCorp Packer ${packer.version}" build_tool = "HashiCorp Packer ${packer.version}"
build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp())
build_description = "Kubernetes Ubuntu 20.04 Node template\nBuild date: ${local.build_date}\nBuild tool: ${local.build_tool}" build_description = "Kubernetes Ubuntu 20.04 Node template\nBuild date: ${local.build_date}\nBuild tool: ${local.build_tool}"
shutdown_command = "sudo /usr/sbin/shutdown -P now"
iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"]
iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}"
data_source_content = { data_source_content = {
"/meta-data" = file("data/meta-data") "/meta-data" = file("data/meta-data")
"/user-data" = templatefile("data/user-data.pkrtpl.hcl", { "/user-data" = templatefile("data/user-data.pkrtpl.hcl", {
build_username = var.build_username build_username = var.build_username
build_password = bcrypt(var.build_password)
ssh_keys = concat([local.ssh_public_key], var.ssh_keys) ssh_keys = concat([local.ssh_public_key], var.ssh_keys)
vm_guest_os_language = var.vm_guest_os_language vm_guest_os_language = var.vm_guest_os_language
vm_guest_os_keyboard = var.vm_guest_os_keyboard vm_guest_os_keyboard = var.vm_guest_os_keyboard

View file

@ -15,6 +15,7 @@ variable "vsphere_endpoint" {
variable "vsphere_username" { variable "vsphere_username" {
type = string type = string
description = "The username to login to the vCenter Server instance. ('packer')" description = "The username to login to the vCenter Server instance. ('packer')"
sensitive = true
} }
variable "vsphere_password" { variable "vsphere_password" {

View file

@ -52,7 +52,7 @@ EOF
sudo chown "$(id -u):$(id -g)" "${HOME}"/.kube/config sudo chown "$(id -u):$(id -g)" "${HOME}"/.kube/config
echo ">> Applying Calico networking..." echo ">> Applying Calico networking..."
kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/master/manifests/calico.yaml kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
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
@ -63,7 +63,7 @@ EOF
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 &>/dev/null & python3 -m http.server 2>/dev/null &
PROC_ID=$! PROC_ID=$!
attempts_max=60 attempts_max=60
attempt=0 attempt=0
@ -382,25 +382,20 @@ else
sleep 10 sleep 10
done done
echo ">> Continuing after $((attempt*10)) seconds." echo ">> Continuing after $((attempt*10)) seconds."
echo ">> Retrieving cluster discovery config..." echo ">> Joining cluster..."
attempts_max=6 attempts_max=6
attempt=0 attempt=0
until [ -f ~/discovery.yaml ] || [ ${attempt} -eq ${attempts_max} ]; do until [ -f /etc/kubernetes/discovery.yaml ]; do
wget "http://${K8S_CONTROLPLANE_VIP}:8000/discovery.yaml" wget "http://${K8S_CONTROLPLANE_VIP}:8000/discovery.yaml" 2>/dev/null
sleep 2 if ! sudo install -m 600 discovery.yaml /etc/kubernetes/discovery.yaml 2>/dev/null; then
if ! [ -f ~/discovery.yaml ]; then if [ ${attempt} -eq ${attempts_max} ]; then
echo ">> Unable to retrieve config..." echo ">> [ERROR] Timeout waiting for discovery.yaml! <<"
attempt=$((attempt+1))
sleep 8
fi
done
if ! [ -f ~/discovery.yaml ]; then
echo ">> Timeout reached while retrieving config!"
echo "Exiting."
exit 1 exit 1
fi fi
sudo install -o root -g root -m 600 discovery.yaml /etc/kubernetes/discovery.yaml attempt=$((attempt+1))
echo ">> Successfully discovered cluster!" sleep 10
fi
done
cat << EOF > kubeadmjoin.yaml cat << EOF > kubeadmjoin.yaml
apiVersion: kubeadm.k8s.io/v1beta3 apiVersion: kubeadm.k8s.io/v1beta3
caCertPath: /etc/kubernetes/pki/ca.crt caCertPath: /etc/kubernetes/pki/ca.crt
@ -416,8 +411,17 @@ nodeRegistration:
controlPlane: controlPlane:
certificateKey: ${KUBEADM_CERTKEY} certificateKey: ${KUBEADM_CERTKEY}
EOF EOF
echo ">> Joining cluster..." 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 curl --fail "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
@ -26,26 +26,18 @@ until curl --fail "http://${K8S_CONTROLPLANE_VIP}:8000/.k8s-controlplane-success
sleep 10 sleep 10
done done
echo ">> Continuing after $((attempt*10)) seconds." echo ">> Continuing after $((attempt*10)) seconds."
echo ">> Retrieving cluster discovery config..." echo ">> Joining cluster..."
attempts_max=6 attempts_max=6
attempt=0 attempt=0
until [ -f ~/discovery.yaml ] || [ ${attempt} -eq ${attempts_max} ]; do until [ -f /etc/kubernetes/discovery.yaml ]; do
wget "http://${K8S_CONTROLPLANE_VIP}:8000/discovery.yaml" wget "http://${K8S_CONTROLPLANE_VIP}:8000/discovery.yaml" 2>/dev/null
sleep 2 sudo install -m 600 discovery.yaml /etc/kubernetes/discovery.yaml 2>/dev/null
if ! [ -f ~/discovery.yaml ]; then if [ ! -f /etc/kubernetes/discovery.yaml ]; then
echo ">> Unable to retrieve config..."
attempt=$((attempt+1)) attempt=$((attempt+1))
sleep 8 sleep 10
fi fi
done done
if ! [ -f ~/discovery.yaml ]; then
echo ">> Timeout reached while retrieving config!"
echo "Exiting."
exit 1
fi
sudo install -o root -g root -m 600 discovery.yaml /etc/kubernetes/discovery.yaml
echo ">> Successfully discovered cluster!"
echo ">> Discovered cluster!"
cat << EOF > kubeadmjoin.yaml cat << EOF > kubeadmjoin.yaml
apiVersion: kubeadm.k8s.io/v1beta3 apiVersion: kubeadm.k8s.io/v1beta3
caCertPath: /etc/kubernetes/pki/ca.crt caCertPath: /etc/kubernetes/pki/ca.crt