75 lines
No EOL
2.6 KiB
Bash
Executable file
75 lines
No EOL
2.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# Deploy a 3-node K3s cluster on Proxmox using Debian 12
|
|
|
|
set -e
|
|
|
|
echo "=== K3s Cluster Deployment Script ==="
|
|
echo "This will create a lightweight 3-node K3s cluster on your Proxmox servers"
|
|
echo
|
|
echo "VMs to be created:"
|
|
echo " - k3s-server (10.0.19.210) - 2 CPU, 2GB RAM, 20GB disk"
|
|
echo " - k3s-agent1 (10.0.19.211) - 2 CPU, 2GB RAM, 20GB disk"
|
|
echo " - k3s-agent2 (10.0.19.212) - 2 CPU, 2GB RAM, 20GB disk"
|
|
echo
|
|
|
|
# Check if proxmox password is set
|
|
if [ -z "$PROXMOX_PASSWORD" ]; then
|
|
echo "Please set PROXMOX_PASSWORD environment variable"
|
|
echo "export PROXMOX_PASSWORD='your-proxmox-password'"
|
|
exit 1
|
|
fi
|
|
|
|
# Install required collections if needed
|
|
if ! ansible-galaxy collection list | grep -q community.general; then
|
|
echo "Installing required Ansible collections..."
|
|
ansible-galaxy collection install community.general
|
|
fi
|
|
|
|
# Check if template exists
|
|
echo "Checking if Debian 12 template exists..."
|
|
TEMPLATE_EXISTS=$(ansible -i inventories/k3s/hosts proxmox -m shell -a "qm list | grep -q debian12-cloud-init && echo yes || echo no" -e proxmox_password="$PROXMOX_PASSWORD" | grep -o "yes\|no" | head -1)
|
|
|
|
if [ "$TEMPLATE_EXISTS" != "yes" ]; then
|
|
echo "Debian 12 template not found. Please run create-vm-template.yml first."
|
|
read -p "Create template now? (y/n) " -n 1 -r
|
|
echo
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
ansible-playbook create-vm-template.yml -e proxmox_password="$PROXMOX_PASSWORD"
|
|
else
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Deploy K3s cluster
|
|
echo
|
|
echo "Ready to deploy K3s cluster"
|
|
read -p "Continue? (y/n) " -n 1 -r
|
|
echo
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
echo "Creating VMs and installing K3s..."
|
|
ansible-playbook -i inventories/k3s/hosts k3s-cluster.yml \
|
|
-e proxmox_password="$PROXMOX_PASSWORD" \
|
|
-e vm_password="${K3S_VM_PASSWORD:-changeme}"
|
|
fi
|
|
|
|
echo
|
|
echo "=== Deployment Complete ==="
|
|
echo "To access your K3s cluster:"
|
|
echo " ssh debian@10.0.19.210"
|
|
echo " kubectl get nodes"
|
|
echo
|
|
echo "To copy kubeconfig to your local machine:"
|
|
echo " mkdir -p ~/.kube"
|
|
echo " scp debian@10.0.19.210:~/.kube/config ~/.kube/config-k3s"
|
|
echo " export KUBECONFIG=~/.kube/config-k3s"
|
|
echo
|
|
echo "K3s includes:"
|
|
echo " - Embedded SQLite (no external datastore needed)"
|
|
echo " - Flannel CNI for networking"
|
|
echo " - CoreDNS for cluster DNS"
|
|
echo " - Local-path provisioner for storage"
|
|
echo " - Metrics server"
|
|
echo
|
|
echo "To install additional components:"
|
|
echo " - Kubernetes Dashboard: kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml"
|
|
echo " - Cert-Manager: kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.3/cert-manager.yaml" |