Compare commits
No commits in common. "15aa8ad93446ea50b03252df911c053b8e6b432b" and "fe47af873cd2884cd391ad4059eb832408a6cd34" have entirely different histories.
15aa8ad934
...
fe47af873c
@ -15,7 +15,7 @@ echo "Installing dependencies..."
|
||||
apt install -y apt-transport-https openjdk-11-jre-headless uuid-runtime pwgen wget gnupg
|
||||
|
||||
check_system_requirements() {
|
||||
echo "Checking the minimum system requirements for Graylog..."
|
||||
echo "Checking the minimum system requirements for Graylog..."1
|
||||
|
||||
# Minimum required RAM (in MB)
|
||||
minimum_ram=4096
|
||||
|
@ -61,11 +61,10 @@ fi
|
||||
|
||||
echo "System meets minimum requirements. Proceeding with installation..."
|
||||
|
||||
# Download the latest version of netbox and unzip it
|
||||
echo "Downloading latest version of Netbox and moving files..."
|
||||
sudo wget https://github.com/netbox-community/netbox/archive/refs/tags/vX.Y.Z.tar.gz
|
||||
sudo tar -xzf vX.Y.Z.tar.gz -C /opt
|
||||
sudo ln -s /opt/netbox-X.Y.Z/ /opt/netbox
|
||||
# Add Netbox repository
|
||||
echo "Adding Netbox repository..."
|
||||
echo "deb https://packagecloud.io/netbox-community/netbox/ubuntu/ $(lsb_release -sc) main" | tee -a /etc/apt/sources.list.d/netbox-community.list
|
||||
curl -L https://packagecloud.io/netbox-community/netbox/gpgkey | apt-key add -
|
||||
|
||||
# Prompt user for PostgreSQL and Netbox password
|
||||
read -p "Enter PostgreSQL password for 'netbox' user: " PG_PASSWORD
|
||||
|
@ -1,114 +0,0 @@
|
||||
#!/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!"
|
@ -1,136 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# 1st Step - Ask user for no. of cluster nodes
|
||||
echo "How many nodes would you like your cluster to have?"
|
||||
read NODECOUNT
|
||||
|
||||
# 2nd Step - Ask user for node details & store in tmp files
|
||||
for ((i=0; i < $NODECOUNT; i++))
|
||||
do
|
||||
echo "Please enter the IP address of the ${i}th node: "
|
||||
read IPADDR_$i
|
||||
echo "${IPADDR_$i}" > /tmp/node${i}_ip.txt
|
||||
|
||||
echo "Please enter the username for SSH access to the ${i}th node (defaults to 'root'):"
|
||||
read USERNAME_$i
|
||||
if [ -z $USERNAME ]
|
||||
then USERNAME="root";
|
||||
fi
|
||||
echo "${USERNAME}" > /tmp/node${i}_user.txt
|
||||
|
||||
echo "Please enter the password for SSH access to the ${i}th node (defaults to 'root'):"
|
||||
read PASSWORD_$i
|
||||
if [ -z $PASSWORD ]
|
||||
then PASSWORD="root";
|
||||
fi
|
||||
echo "${PASSWORD}" > /tmp/node${i}_pass.txt
|
||||
done
|
||||
|
||||
# 3rd Step - Confirm node details with user & allow them to edit if necessary
|
||||
echo "The following IP addresses were entered by the user:"
|
||||
for ((i=0; i < $NODECOUNT; i++))
|
||||
do
|
||||
echo "${IPADDR_$i}"
|
||||
done
|
||||
read -p "Please confirm these are correct, or type 'edit' to make changes: " USERCONFIRMATION
|
||||
if [ "$USERCONFIRMATION" == "edit" ]
|
||||
then
|
||||
for ((i=0; i < $NODECOUNT; i++))
|
||||
do
|
||||
echo "Please enter the IP address of the ${i}th node: "
|
||||
read IPADDR_$i
|
||||
echo "${IPADDR_$i}" > /tmp/node${i}_ip.txt
|
||||
|
||||
echo "Please enter the username for SSH access to the ${i}th node (defaults to 'root'):"
|
||||
read USERNAME_$i
|
||||
if [ -z $USERNAME ]
|
||||
then USERNAME="root";
|
||||
fi
|
||||
echo "${USERNAME}" > /tmp/node${i}_user.txt
|
||||
|
||||
echo "Please enter the password for SSH access to the ${i}th node (defaults to 'root'):"
|
||||
read PASSWORD_$<s> i
|
||||
if [ -z $PASSWORD ]
|
||||
then PASSWORD="root";
|
||||
fi
|
||||
echo "${PASSWORD}" > /tmp/node${i}_pass.txt
|
||||
done
|
||||
fi
|
||||
|
||||
# 4th Step - Ask user to define master node & store selection in tmp files
|
||||
echo "Please enter the number of the node you would like to define as your control plane (master):"
|
||||
read MASTERNODE_SELECTION
|
||||
echo "${MASTERNODE_SELECTION}" > /tmp/master.txt
|
||||
|
||||
# 5th Step - Add K8S repo & relevant keys to each node, install K8S & restart services
|
||||
for ((i=0; i < $NODECOUNT; i++))
|
||||
do
|
||||
echo "Adding Kubernetes repo to the system sources list on ${IPADDR_$i}..."
|
||||
ssh -n $USERNAME_$i@${IPADDR_$i} 'sudo sh -c "echo deb http://apt.kubernetes.io/ kubernetes-xenial main > /etc/apt/sources.list.d/kubernetes.list"'
|
||||
|
||||
echo "Adding GPG key to the system on ${IPADDR_$i}..."
|
||||
ssh -n $USERNAME_$i@${IPADDR_$i} 'sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -'
|
||||
|
||||
echo "Updating package list on ${IPADDR_$i}..."
|
||||
ssh -n $USERNAME_$i@${IPADDR_$i} 'sudo sh -c "apt update"'
|
||||
|
||||
echo "Upgrading packages on ${IPADDR_$i}..."
|
||||
ssh -n $USERNAME_$i@${IPADDR_$i} 'sudo sh -c "apt upgrade"'
|
||||
done
|
||||
|
||||
# 6th Step - Install K8S on master node and ask for configuration options from user
|
||||
echo "Installing Kubernetes on the master node..."
|
||||
ssh -n $USERNAME_$MASTERNODE_SELECTION@${IPADDR_$MASTERNODE_SELECTION} 'sudo sh -c "apt install kubeadm; apt-get install kubelet; apt-get install kubernetes-cni"'
|
||||
|
||||
echo "Please enter your preferred port number for the control plane (master node) (defaults to 6443): "
|
||||
read PORT_SELECTION
|
||||
if [ -z $PORT_SELECTION ]
|
||||
then PORT_SELECTION="6443";
|
||||
fi
|
||||
|
||||
echo "Please enter your preferred IP address or FQDN for the control plane (master node) (defaults to '0.0.0.0'): "
|
||||
read IPADDRESS_SELECTION
|
||||
if [ -z $IPADDRESS_SELECTION ]
|
||||
then IPADDRESS_SELECTION="0.0.0.0";
|
||||
fi
|
||||
|
||||
echo "Configuring Kubernetes on the master node, using port ${PORT_SELECTION} and listening IP/domain ${IPADDRESS_SELECTION}..."
|
||||
ssh -n $USERNAME_$MASTERNODE_SELECTION@${IPADDR_$MASTERNODE_SELECTION} 'sudo sh -c "kubeadm init --apiserver-advertise-address=$IPADDRESS_SELECTION --apiserver-bind-port=$PORT_SELECTION"'
|
||||
|
||||
echo "Please enter the following options to configure the Kubernetes control plane (master node)..."
|
||||
echo "1. Pod Network CIDR: "
|
||||
read NETWORKCIDR_SELECTION
|
||||
echo "${NETWORKCIDR_SELECTION}" > /tmp/network.txt
|
||||
|
||||
echo "2. Service Subnet: "
|
||||
read SERVICESUBNET_SELECTION
|
||||
echo "${SERVICESUBNET_SELECTION}" > /tmp/servicesubnet.txt
|
||||
|
||||
echo "3. Kubernetes DNS Domain: "
|
||||
read K8SDNS_SELECTION
|
||||
echo "${K8SDNS_SELECTION}" > /tmp/kube-dns.txt
|
||||
|
||||
echo "Please enter your preferred Kubernetes version (defaults to '1.20.1'): "
|
||||
read K8SVERSION_SELECTION
|
||||
if [ -z $K8SVERSION_SELECTION ]
|
||||
then K8SVERSION_SELECTION="1.20.1";
|
||||
fi
|
||||
|
||||
echo "Please enter your preferred pod Network provider (defaults to 'calico'): "
|
||||
read NETWORKPROVIDER_SELECTION
|
||||
if [ -z $NETWORKPROVIDER_SELECT<s> ION_SELECTION ]
|
||||
then NETWORKPROVIDER_SELECTION="calico";
|
||||
fi
|
||||
|
||||
echo "Configuring Kubernetes on the master node with pod Network CIDR: ${NETWORKCIDR_SELECTION}, service subnet: ${SERVICESUBNET_SELECTION}, K8S DNS domain: ${K8SDNS_SELECTION}, K8S version: ${K8SVERSION_SELECTION}, and pod network provider: ${NETWORKPROVIDER_SELECTION}..."
|
||||
ssh -n $USERNAME_$MASTERNODE_SELECTION@${IPADDR_$MASTERNODE_SELECTION} 'sudo sh -c "kubectl apply --kubelet-extra-args '--node-ip=$IPADDRESS_SELECTION' -f https://docs.projectcalico.org/manifests/kube-flannel.yaml; kubeadm init phase addon all; kubectl apply --kubelet-extra-args '--node-ip=$IPADDRESS_SELECTION' -f https://docs.projectcalico.org/manifests/kube-flannel.yaml; kubectl create deployment nginx-deployment --image=nginx; kubectl expose deployments nginx-deployment --port 80 --type LoadBalancer"'
|
||||
|
||||
echo "Restarting Kubernetes services on the master node..."
|
||||
ssh -n $USERNAME_$MASTERNODE_SELECTION@${IPADDR_$MASTERNODE_SELECTION} 'sudo sh -c "systemctl restart kubelet.service"'
|
||||
|
||||
echo "Restarting Kubernetes services on all nodes..."
|
||||
for ((i=0; i < $NODECOUNT; i++))
|
||||
do
|
||||
echo "Restarting Kubernetes services on the ${IPADDR_$i} node..."
|
||||
ssh -n $USERNAME_$i@${IPADDR_$i} 'sudo sh -c "systemctl restart kubelet.service"'
|
||||
done
|
@ -1,21 +0,0 @@
|
||||
Please generate me a bash script to deploy a Kubernetes cluster across multiple VM's. The script should complete every step for the user. Include colour coded echo statements to make it easy to use. It needs to include the following steps:
|
||||
|
||||
1) Ask the user to input the number of nodes that are going to be part of the K8S cluster.
|
||||
|
||||
2) Ask the user to input the IP's and SSH credentials for each node. The script needs to temporarily store these credentials in the linux tmp directory to use for the rest of this process. Following the users input, the script should then list all the previously inputed IP addresses and ask the user to confirm they are correct. If the user declares they are not, the script should offer them the option to go back and edit them before proceeding with the next step.
|
||||
|
||||
3) It should then ask the user which node (by number or IP) they would like to define as the master node/control plane. All other nodes should be assumed to be worker nodes.
|
||||
|
||||
4) It should then proceed to use the previously defined SSH credentials to log in to each node sequentially and add the K8S repository and relevant keys.
|
||||
|
||||
5) Following this, it should log in to each node sequentially and run apt update and apt upgrade, followed by the rebooting of each node. Following the successful execution of this task (and while the nodes are rebooting), the script should include a time delay of 5 minutes while displaying a countdown in seconds to allow each node to reboot.
|
||||
|
||||
6) It should then proceed to use the credentials of the corresponding node to install K8S on the master node initially. The install must add the official K8S repository to the system sources list and then run apt update before proceeding with the installation.
|
||||
|
||||
7) Following the successful completion of the K8S installation, the script must then offer the user the following options in order to complete the K8S configuration. The script must parse the users choices to the relveant configuration files and then restart all K8S services.
|
||||
|
||||
1) Port number: The script must offer the user the option to define a custom port. If no choice is made the script should resort to the default.
|
||||
|
||||
2) Listening IP or domain: The script must offer the user the option to input the IP address or FQDN that K8S will listen on.
|
||||
|
||||
8) After completing the installation of Kubernetes on the master node, the script must then proceed to add the official K8S repo to all the master nodes and then install K8S on each machine.
|
Loading…
Reference in New Issue
Block a user