Skip to content

Instantly share code, notes, and snippets.

@kriegalex
Last active March 7, 2024 16:25
Show Gist options
  • Select an option

  • Save kriegalex/3c4fd2493c19dac8388b737c47157e92 to your computer and use it in GitHub Desktop.

Select an option

Save kriegalex/3c4fd2493c19dac8388b737c47157e92 to your computer and use it in GitHub Desktop.
Openstack Kolla Ansible 17.1.0 setup scripts, tested for Ubuntu 22.04 LTS
#!/bin/bash
network_id="kube-private"
subnet_id="kube-private-subnet"
flavor="e2-standard-2"
key_name="mykey"
image_id="ubuntu-22.04-lts"
security_group="kubernetes"
volume_size="200"
# Specify the static IPs you want to assign to each port
controller_static_ips=("10.240.0.10" "10.240.0.11" "10.240.0.12")
# Specify the static IPs you want to assign to each port
worker_static_ips=("10.240.0.20" "10.240.0.21" "10.240.0.22")
# Create 3 network ports for controllers
for i in {0..2}
do
port_id=$(openstack port create --network $network_id --fixed-ip subnet=$subnet_id,ip-address=${controller_static_ips[$i]} --security-group $security_group controller$i --format value -c id)
echo "Created port $i with ID: $port_id"
# Store the port IDs in an array
port_ids[i]=$port_id
done
for i in {0..2}
do
openstack server create --image $image_id \
--flavor $flavor \
--key-name $key_name \
--security-group $security_group \
--nic port-id=${port_ids[i]} \
--boot-from-volume $volume_size --wait \
kube-controller${i}
done
# Create 3 network ports for workers
for i in {0..2}
do
port_id=$(openstack port create --network $network_id --fixed-ip subnet=$subnet_id,ip-address=${worker_static_ips[$i]} --security-group $security_group worker$i --format value -c id)
echo "Created port $i with ID: $port_id"
# Store the port IDs in an array
port_ids[i]=$port_id
done
for i in {0..2}
do
openstack server create --image $image_id \
--flavor $flavor \
--key-name $key_name \
--security-group $security_group \
--nic port-id=${port_ids[i]} \
--boot-from-volume $volume_size --wait \
kube-worker${i}
done
#!/bin/bash
# make sure we are in the right python venv
cd $HOME
source $HOME/kolla-ansible/bin/activate
kolla-ansible -i ./multinode bootstrap-servers
kolla-ansible -i ./multinode prechecks
kolla-ansible -i ./multinode deploy
#!/bin/bash
# this script is run as openstack user
cat_compute_netplan() {
echo '
network:
renderer: networkd
ethernets:
enp1s0f0:
dhcp4: false
enp1s0f1:
dhcp4: false
addresses: [10.100.0.110/24]
enp4s0:
dhcp4: false
addresses:
- 10.0.0.8/24
nameservers:
addresses:
- 1.1.1.1
routes:
- to: default
via: 10.0.0.1
version: 2
'
}
cat_controller_netplan() {
echo '
network:
renderer: networkd
ethernets:
eno1:
dhcp4: false
eno2:
dhcp4: false
eno3:
dhcp4: false
eno4:
dhcp4: false
vethint: {}
vethext: {}
bridges:
br0:
interfaces: [eno1]
dhcp4: false
addresses:
- 10.0.0.6/24
nameservers:
addresses:
- 1.1.1.1
routes:
- to: default
via: 10.0.0.1
br-ex:
interfaces: [eno2, vethint]
dhcp4: false
addresses: [10.100.0.100/24]
version: 2
'
}
cd $HOME
## setup openstack networking
echo "Compute node netplan config:"
cat_compute_netplan
echo "Controller node netplan config:"
cat_controller_netplan
echo "Update /etc/hosts"
update_etc_hosts
## python
sudo apt install python3-venv -y
mkdir $HOME/kolla-ansible
python3 -m venv $HOME/kolla-ansible
source $HOME/kolla-ansible/bin/activate
## now in python virtual env for kolla
pip install -U pip
pip install 'ansible>=6,<8'
## kolla-ansible
pip install git+https://opendev.org/openstack/kolla-ansible@stable/2023.1
sudo mkdir -p /etc/kolla
sudo chown $USER:$USER /etc/kolla
cp -r $HOME/kolla-ansible/share/kolla-ansible/etc_examples/kolla/* /etc/kolla
cp $HOME/kolla-ansible/share/kolla-ansible/ansible/inventory/multinode $HOME/
cd $HOME
echo '
[defaults]
host_key_checking=False
pipelining=True
forks=100
remote_port=2022
' > $HOME/ansible.cfg
## Ansible Galaxy requirements
kolla-ansible install-deps
# Initial config
kolla-genpwd # expects passwords.yml in /etc/kolla
echo "Edit /etc/kolla/globals.yml now"
echo "Edit $HOME/multinode now"
echo "Then, run kolla-ansible-deployment.sh"
#!/bin/bash
update_sshd_config() {
# Check if DenyUsers line exists in sshd_config
if grep -q "^DenyUsers" /etc/ssh/sshd_config; then
# Append user to existing DenyUsers line
sudo sed -i '/^DenyUsers/ s/$/ openstack/' /etc/ssh/sshd_config
else
# Add new DenyUsers line with specified user
echo "DenyUsers openstack" | sudo tee -a /etc/ssh/sshd_config > /dev/null
fi
}
update_etc_hosts() {
echo "10.0.0.6 controller01" | sudo tee -a /etc/hosts
echo "10.0.0.8 compute01" | sudo tee -a /etc/hosts
echo "10.0.0.8 storage01" | sudo tee -a /etc/hosts
}
# dependencies
sudo apt update
sudo apt install git python3-dev libffi-dev gcc libssl-dev -y
## setup openstack user
sudo adduser openstack
sudo usermod -aG sudo openstack
# multinode setup requires SSH to do the setup
#update_sshd_config
sudo -u openstack bash kolla-ansible-installer-user.sh
#!/bin/bash
# Define variables for interface names
neutron_external_interface_control="vethext"
network_interface_control="br0"
neutron_external_interface_compute="enp1s0f1"
network_interface_compute="enp4s0"
# Input and Output file names
default_config="multinode"
modified_config="multinode2"
cd $HOME
# Check if the default configuration file exists
if [ ! -f "$default_config" ]; then
echo "Error: The file $default_config does not exist in $HOME."
exit 1
fi
# Start with an empty output file
: > "$modified_config"
# Read through the default config file line by line
while IFS= read -r line || [[ -n "$line" ]]; do
# Skip control02 and control03
if [[ $line == "control02" ]] || [[ $line == "control03" ]]; then
continue
fi
# Skip network02
if [[ $line == "network02" ]]; then
continue
fi
# Process control01
if [[ $line == "control01" ]]; then
echo "controller01 ansible_connection=local neutron_external_interface=$neutron_external_interface_control" >> "$modified_config"
# Process network01
elif [[ $line == "network01" ]]; then
echo "controller01 ansible_connection=local neutron_external_interface=$neutron_external_interface_control network_interface=$network_interface_control" >> "$modified_config"
# Process compute01
elif [[ $line == "compute01" ]]; then
echo "compute01 neutron_external_interface=$neutron_external_interface_compute network_interface=$network_interface_compute" >> "$modified_config"
# Process monitoring01
elif [[ $line == "monitoring01" ]]; then
echo "controller01 ansible_connection=local neutron_external_interface=$neutron_external_interface_control" >> "$modified_config"
# Process storage01
elif [[ $line == "storage01" ]]; then
echo "compute01 neutron_external_interface=$neutron_external_interface_compute network_interface=$network_interface_compute" >> "$modified_config"
else
echo "$line" >> "$modified_config"
fi
done < "$default_config"
mv $default_config $default_config.bak
mv $modified_config $default_config
echo "Modified config has been saved to $default_config"
echo "Original config has been backed up to $default_config.bak"
#!/bin/bash
cp $HOME/kolla-ansible/share/kolla-ansible/init-runonce $HOME/init-runonce
echo "To switch image to Ubuntu, use:"
echo '
ARCH=amd64
UBUNTU_RELEASE="jammy" # Ubuntu 22.04 codename
IMAGE_PATH=/opt/cache/files/
IMAGE_URL=https://cloud-images.ubuntu.com/jammy/current/
IMAGE=jammy-server-cloudimg-${ARCH}.img
IMAGE_NAME="Ubuntu 22.04 LTS"
IMAGE_TYPE=linux
'
echo "Modify the instances quota"
echo "Modify the instances cores"
echo "Modify the ram quota"
echo "Updated flavors:"
echo '
# add default flavors, if they don't already exist
if ! $KOLLA_OPENSTACK_COMMAND flavor list | grep -q std.tiny; then
$KOLLA_OPENSTACK_COMMAND flavor create --id 1 --ram 512 --disk 10 --vcpus 1 std.micro
$KOLLA_OPENSTACK_COMMAND flavor create --id 2 --ram 1028 --disk 10 --vcpus 1 std.tiny
$KOLLA_OPENSTACK_COMMAND flavor create --id 3 --ram 2048 --disk 20 --vcpus 2 std.small
$KOLLA_OPENSTACK_COMMAND flavor create --id 4 --ram 4096 --disk 40 --vcpus 2 std.medium
$KOLLA_OPENSTACK_COMMAND flavor create --id 5 --ram 8192 --disk 80 --vcpus 4 std.large
$KOLLA_OPENSTACK_COMMAND flavor create --id 6 --ram 16384 --disk 80 --vcpus 4 std.xlarge
$KOLLA_OPENSTACK_COMMAND flavor create --id 7 --ram 32768 --disk 100 --vcpus 8 std.huge
$KOLLA_OPENSTACK_COMMAND flavor create --id 8 --ram 16384 --disk 100 --vcpus 2 mem.xlarge
$KOLLA_OPENSTACK_COMMAND flavor create --id 9 --ram 32768 --disk 100 --vcpus 4 mem.huge
fi
'
#!/bin/bash
# Configuration variables
export_dir="/mnt/glance" # NFS export directory
controller_ip="10.0.0.6" # Controller IP or network
local_network="10.0.0.0/24" # Local network CIDR
nfs_port=50001 # Standard NFS port, change if needed
rpcbind_port=111 # RPC Bind port
# Ensure the script is run as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
# Step 1: Install NFS Kernel Server
echo "Installing NFS Kernel Server..."
apt update && apt install -y nfs-kernel-server
# Step 2: Configure NFS Export
if [ ! -d "$export_dir" ]; then
echo "Creating NFS export directory: $export_dir"
mkdir -p "$export_dir"
fi
# Backup the current /etc/exports file
cp /etc/exports /etc/exports.backup
# Add the export entry
echo "$export_dir $controller_ip(rw,sync,no_subtree_check)" > /etc/exports
# Export the directory
exportfs -rav
# Restart NFS server to apply changes
systemctl restart nfs-kernel-server
# Step 3: Configure Firewall
echo "Configuring UFW to allow NFS traffic..."
ufw allow from $local_network to any port $nfs_port
ufw allow from $local_network to any port $rpcbind_port
#ufw enable
#ufw status verbose
echo "NFS Server setup is complete."
#!/bin/bash
# Check if the script is run as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Please use sudo to run this script."
exit 1
fi
# Function to check if ZFS is installed and install it if not
install_zfs_if_missing() {
if ! command -v zpool &> /dev/null; then
echo "ZFS is not installed. Attempting to install ZFS on Ubuntu."
# Update repositories and install ZFS
apt update
apt install -y zfsutils-linux
echo "ZFS has been installed."
else
echo "ZFS is already installed."
fi
}
install_zfs_if_missing
# Function to prompt for drive IDs
prompt_for_drive_ids() {
echo "Enter the IDs of the drives you wish to include in the pool, separated by spaces:"
read -a ids
# Validate IDs
for id in "${ids[@]}"; do
if [[ "$id" =~ ^/dev/disk/by-id/ ]]; then
echo "Please only input the ID, not the full path. For example, use 'ata-XXXX' instead of '/dev/disk/by-id/ata-XXXX'."
return 1 # Indicate error
fi
done
# Convert IDs to their corresponding /dev/disk/by-id paths
drive_paths=()
for id in "${ids[@]}"; do
drive_path="/dev/disk/by-id/$id"
if [[ -e "$drive_path" ]]; then
drive_paths+=("$drive_path")
else
echo "No drive found for ID $id."
return 1 # Indicate error
fi
done
echo "Using drives: ${drive_paths[*]}"
ZPOOL_DRIVE_PATHS=("${drive_paths[@]}")
return 0 # Success
}
# Proceed with the rest of the script
# List available drives and their ID
echo "Available drives and their IDs:"
ls -l /dev/disk/by-id | grep -v 'wwn-' | grep -v 'part' | awk '{print $9}' | while read -r line; do
echo "/dev/disk/by-id/$line"
done
echo
read -p "Enter the type of ZFS pool you want to create (mirror, raidz1, raidz2): " pool_type
# Validate pool type
if [[ "$pool_type" != "mirror" && "$pool_type" != "raidz1" && "$pool_type" != "raidz2" ]]; then
echo "Invalid pool type selected. Exiting."
exit 1
fi
# Attempt to read IDs with retry on failure
if ! prompt_for_drive_ids; then
echo "Let's try one more time."
if ! prompt_for_drive_ids; then
echo "Failed to read valid drive IDs. Exiting."
exit 1
fi
fi
# Prompt for pool name
echo
read -p "Enter the name for your ZFS pool: " pool_name
# Construct the zpool create command
create_cmd="zpool create $pool_name"
case $pool_type in
mirror)
create_cmd+=" mirror ${ZPOOL_DRIVE_PATHS[*]}"
;;
raidz1)
create_cmd+=" raidz1 ${ZPOOL_DRIVE_PATHS[*]}"
;;
raidz2)
create_cmd+=" raidz2 ${ZPOOL_DRIVE_PATHS[*]}"
;;
esac
# Execute the zpool create command
echo "Creating ZFS pool with command: $create_cmd"
eval $create_cmd
if [ $? -eq 0 ]; then
echo "ZFS pool $pool_name created successfully."
else
echo "Failed to create ZFS pool."
fi
#zfs set compression=lz4 $pool_name
#zfs create $pool_name/cinder-volumes
#!/bin/bash
sudo apt install zsh -y
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
sudo apt update
which zsh
# to switch shell:
# exec bash
# exec zsh
# to remove:
# sudo apt purge zsh -y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment