install-scripts/proxmox-k8s/Qwen2.5-Coder-7B-.sh

115 lines
4.0 KiB
Bash
Raw Permalink Normal View History

2024-11-23 19:45:16 +00:00
#!/bin/bash
# Color codes for echo statements
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
# Function to display colored messages
echo_colored() {
local color=$1
shift
echo -e "${color}$@$NC"
}
# Step 1: Ask for the number of nodes
read -p "Enter the number of nodes in your K8S cluster: " num_nodes
# Step 2: Gather node details and store them
node_details=()
for ((i=1; i<=num_nodes; i++)); do
read -p "Enter IP address for node $i: " ip
read -p "Enter SSH username for node $i: " user
read -s -p "Enter SSH password for node $i: " password
echo ""
node_details+=("$ip:$user:$password")
done
# Step 3: Display stored IP addresses and ask for confirmation
echo_colored "$GREEN" "Stored Node Details:"
for detail in "${node_details[@]}"; do
IFS=':' read -r -a split <<< "$detail"
echo_colored "$YELLOW" "IP: ${split[0]}, User: ${split[1]}"
done
read -p "Are the above details correct? (yes/no): " confirm
if [ "$confirm" != "yes" ]; then
echo_colored "$RED" "Please edit your node details and run this script again."
exit 1
fi
# Step 4: Ask for the master node
read -p "Enter the IP address of the master node (control plane): " master_ip
# Function to execute commands on a remote node using SSH
ssh_cmd() {
local ip=$1
local user=$2
local password=$3
shift 3
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$user@$ip" "$@"
}
# Step 5: Update and upgrade all nodes, then reboot them
echo_colored "$GREEN" "Updating and upgrading all nodes..."
for detail in "${node_details[@]}"; do
IFS=':' read -r -a split <<< "$detail"
ssh_cmd "${split[0]}" "${split[1]}" "${split[2]}" "sudo apt update && sudo apt upgrade -y"
ssh_cmd "${split[0]}" "${split[1]}" "${split[2]}" "sudo reboot"
done
# Step 6: Install K8S on the master node
echo_colored "$GREEN" "Installing Kubernetes on the master node..."
master_ip_split=(${master_ip//:/ })
sshpass -p "${master_ip_split[2]}" ssh -o StrictHostKeyChecking=no "${master_ip_split[1]}@${master_ip_split[0]}" << 'EOF'
sudo apt update
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt update
sudo apt install -y kubelet=1.24.0-00 kubeadm=1.24.0-00 kubectl=1.24.0-00
sudo systemctl enable --now kubelet
EOF
# Step 7: Configure and restart Kubernetes services on the master node
echo_colored "$GREEN" "Configuring Kubernetes services on the master node..."
read -p "Do you want to customize the port number? (yes/no): " custom_port
if [ "$custom_port" == "yes" ]; then
read -p "Enter a custom port number: " k8s_port
else
k8s_port=6443
fi
read -p "Do you want to specify a listening IP or domain? (yes/no): " listen_ip
if [ "$listen_ip" == "yes" ]; then
read -p "Enter the listening IP address or FQDN: " k8s_address
else
k8s_address=0.0.0.0
fi
sshpass -p "${master_ip_split[2]}" ssh -o StrictHostKeyChecking=no "${master_ip_split[1]}@${master_ip_split[0]}" <<EOF
sudo sed -i "s/advertiseAddress: .*/advertiseAddress: $k8s_address/" /etc/kubernetes/manifests/kube-apiserver.yaml
sudo sed -i "s/nodePort: 6443/nodePort: $k8s_port/" /etc/kubernetes/manifests/kube-apiserver.yaml
sudo systemctl restart kubelet
EOF
# Step 8: Install K8S on all nodes
echo_colored "$GREEN" "Installing Kubernetes on all nodes..."
for detail in "${node_details[@]}"; do
IFS=':' read -r -a split <<< "$detail"
sshpass -p "${split[2]}" ssh -o StrictHostKeyChecking=no "${split[1]}@${split[0]}" << 'EOF'
sudo apt update
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt update
sudo apt install -y kubelet=1.24.0-00 kubeadm=1.24.0-00 kubectl=1.24.0-00
sudo systemctl enable --now kubelet
EOF
done
echo_colored "$GREEN" "Kubernetes cluster deployment completed successfully!"