mirror of
https://github.com/jbowdre/vsphere-k8s.git
synced 2024-11-22 08:02:17 +00:00
Compare commits
6 commits
2d14363967
...
b5bbc4e7a8
Author | SHA1 | Date | |
---|---|---|---|
b5bbc4e7a8 | |||
05ab05a84a | |||
101ad08bd3 | |||
6cd9786752 | |||
3a13a5b3fa | |||
0b13e195dc |
9 changed files with 101 additions and 97 deletions
|
@ -178,7 +178,6 @@ autoinstall:
|
|||
hostname: ${ vm_guest_os_hostname }
|
||||
users:
|
||||
- name: ${ build_username }
|
||||
passwd: "${ build_password }"
|
||||
groups: [adm, cdrom, dip, plugdev, lxd, sudo]
|
||||
lock-passwd: false
|
||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||
|
|
3
packer/packer_cache/ssh_private_key_packer.example.pem
Normal file
3
packer/packer_cache/ssh_private_key_packer.example.pem
Normal file
|
@ -0,0 +1,3 @@
|
|||
-----BEGIN OPENSSH PRIVATE KEY-----
|
||||
|
||||
-----END OPENSSH PRIVATE KEY-----
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
DESCRIPTION:
|
||||
DESCRIPTION :
|
||||
Ubuntu Server 20.04 LTS Kubernetes node variables used by the Packer Plugin for VMware vSphere (vsphere-iso).
|
||||
*/
|
||||
|
||||
|
@ -77,12 +77,11 @@ communicator_port = 22
|
|||
communicator_timeout = "20m"
|
||||
common_ip_wait_timeout = "20m"
|
||||
common_shutdown_timeout = "15m"
|
||||
vm_shutdown_command = "sudo /usr/sbin/shutdown -P now"
|
||||
build_remove_keys = true
|
||||
build_username = "admin"
|
||||
build_password = "VMware1!"
|
||||
ssh_keys = [
|
||||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOpLvpxilPjpCahAQxs4RQgv+Lb5xObULXtwEoimEBpA builder"
|
||||
"ssh-ed25519 blahblahblah builder"
|
||||
]
|
||||
|
||||
// Provisioner Settings
|
||||
|
|
|
@ -34,13 +34,13 @@ locals {
|
|||
build_tool = "HashiCorp Packer ${packer.version}"
|
||||
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}"
|
||||
shutdown_command = "sudo /usr/sbin/shutdown -P now"
|
||||
iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"]
|
||||
iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}"
|
||||
data_source_content = {
|
||||
"/meta-data" = file("data/meta-data")
|
||||
"/user-data" = templatefile("data/user-data.pkrtpl.hcl", {
|
||||
build_username = var.build_username
|
||||
build_password = bcrypt(var.build_password)
|
||||
ssh_keys = concat([local.ssh_public_key], var.ssh_keys)
|
||||
vm_guest_os_language = var.vm_guest_os_language
|
||||
vm_guest_os_keyboard = var.vm_guest_os_keyboard
|
||||
|
|
|
@ -15,7 +15,6 @@ variable "vsphere_endpoint" {
|
|||
variable "vsphere_username" {
|
||||
type = string
|
||||
description = "The username to login to the vCenter Server instance. ('packer')"
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "vsphere_password" {
|
||||
|
|
|
@ -52,7 +52,7 @@ EOF
|
|||
sudo chown "$(id -u):$(id -g)" "${HOME}"/.kube/config
|
||||
|
||||
echo ">> Applying Calico networking..."
|
||||
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
|
||||
kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/master/manifests/calico.yaml
|
||||
|
||||
echo ">> Creating discovery config..."
|
||||
kubectl -n kube-public get configmap cluster-info -o jsonpath='{.data.kubeconfig}' > discovery.yaml
|
||||
|
@ -63,7 +63,7 @@ EOF
|
|||
fi
|
||||
fi
|
||||
echo ">> Waiting up to 10 minutes for all control-plane nodes to be Ready..."
|
||||
python3 -m http.server 2>/dev/null &
|
||||
python3 -m http.server &>/dev/null &
|
||||
PROC_ID=$!
|
||||
attempts_max=60
|
||||
attempt=0
|
||||
|
@ -382,20 +382,25 @@ else
|
|||
sleep 10
|
||||
done
|
||||
echo ">> Continuing after $((attempt*10)) seconds."
|
||||
echo ">> Joining cluster..."
|
||||
echo ">> Retrieving cluster discovery config..."
|
||||
attempts_max=6
|
||||
attempt=0
|
||||
until [ -f /etc/kubernetes/discovery.yaml ]; do
|
||||
wget "http://${K8S_CONTROLPLANE_VIP}:8000/discovery.yaml" 2>/dev/null
|
||||
if ! sudo install -m 600 discovery.yaml /etc/kubernetes/discovery.yaml 2>/dev/null; then
|
||||
if [ ${attempt} -eq ${attempts_max} ]; then
|
||||
echo ">> [ERROR] Timeout waiting for discovery.yaml! <<"
|
||||
exit 1
|
||||
fi
|
||||
until [ -f ~/discovery.yaml ] || [ ${attempt} -eq ${attempts_max} ]; do
|
||||
wget "http://${K8S_CONTROLPLANE_VIP}:8000/discovery.yaml"
|
||||
sleep 2
|
||||
if ! [ -f ~/discovery.yaml ]; then
|
||||
echo ">> Unable to retrieve config..."
|
||||
attempt=$((attempt+1))
|
||||
sleep 10
|
||||
sleep 8
|
||||
fi
|
||||
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!"
|
||||
cat << EOF > kubeadmjoin.yaml
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
caCertPath: /etc/kubernetes/pki/ca.crt
|
||||
|
@ -411,17 +416,8 @@ nodeRegistration:
|
|||
controlPlane:
|
||||
certificateKey: ${KUBEADM_CERTKEY}
|
||||
EOF
|
||||
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 ">> Joining cluster..."
|
||||
if sudo kubeadm join "${K8S_CONTROLPLANE_VIP}":6443 --config kubeadmjoin.yaml; then
|
||||
echo ">> Node ${HOSTNAME} successfully initialized!"
|
||||
touch .k8s-node-success
|
||||
mkdir -p "${HOME}"/.kube
|
||||
|
|
|
@ -17,7 +17,7 @@ echo ">> Continuing after $((attempt*10)) seconds."
|
|||
echo ">> Waiting up to 10 minutes for all control-plane nodes..."
|
||||
attempts_max=60
|
||||
attempt=0
|
||||
until wget "http://${K8S_CONTROLPLANE_VIP}:8000/.k8s-controlplane-success" 2>/dev/null; do
|
||||
until curl --fail "http://${K8S_CONTROLPLANE_VIP}:8000/.k8s-controlplane-success" 2>/dev/null; do
|
||||
if [ ${attempt} -eq ${attempts_max} ]; then
|
||||
echo ">> [ERROR] Timeout waiting for control-plane nodes! <<"
|
||||
exit 1
|
||||
|
@ -26,18 +26,26 @@ until wget "http://${K8S_CONTROLPLANE_VIP}:8000/.k8s-controlplane-success" 2>/de
|
|||
sleep 10
|
||||
done
|
||||
echo ">> Continuing after $((attempt*10)) seconds."
|
||||
echo ">> Joining cluster..."
|
||||
echo ">> Retrieving cluster discovery config..."
|
||||
attempts_max=6
|
||||
attempt=0
|
||||
until [ -f /etc/kubernetes/discovery.yaml ]; do
|
||||
wget "http://${K8S_CONTROLPLANE_VIP}:8000/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
|
||||
until [ -f ~/discovery.yaml ] || [ ${attempt} -eq ${attempts_max} ]; do
|
||||
wget "http://${K8S_CONTROLPLANE_VIP}:8000/discovery.yaml"
|
||||
sleep 2
|
||||
if ! [ -f ~/discovery.yaml ]; then
|
||||
echo ">> Unable to retrieve config..."
|
||||
attempt=$((attempt+1))
|
||||
sleep 10
|
||||
sleep 8
|
||||
fi
|
||||
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
|
||||
apiVersion: kubeadm.k8s.io/v1beta3
|
||||
caCertPath: /etc/kubernetes/pki/ca.crt
|
||||
|
|
Loading…
Reference in a new issue