mirror of
https://github.com/kelseyhightower/kubernetes-the-hard-way.git
synced 2025-12-15 09:18:58 +03:00
This commit introduces a new directory structure for managing virtual machines, specifically tailored for setting up Kubernetes manually on Ubuntu. Files have been added to the `virtual-machines` directory, which includes scripts and configurations necessary for the setup. The following files have been added: - `README.md`: Documentation for the virtual machines setup. - `Vagrantfile`: Configuration for Vagrant to manage the virtual machines. - `ssh.sh`: Script to set up SSH access. - `tmux.conf`: Configuration file for tmux. - `update-dns.sh`: Script to update DNS settings. - `controlplane.sh`: Script to set up the control plane. - `setup-hosts.sh`: Script to configure the hosts file. - `vimrc`: Configuration file for Vim. This commit is part of the ongoing effort to enhance the documentation and setup instructions for manual installation of Kubernetes. Making it easier for users to get started with manual installations and configurations. With the intended purpose of making them more capabale administrators and users of Kubernetes.
53 lines
1.5 KiB
Bash
53 lines
1.5 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# Set up /etc/hosts so we can resolve all the nodes
|
|
|
|
set -e
|
|
|
|
IP_NW=$1
|
|
BUILD_MODE=$2
|
|
NUM_WORKER_NODES=$3
|
|
MASTER_IP_START=$4
|
|
NODE_IP_START=$5
|
|
|
|
if [ "$BUILD_MODE" = "BRIDGE" ]
|
|
then
|
|
# Determine machine IP from route table -
|
|
# Interface that routes to default GW that isn't on the NAT network.
|
|
sleep 5
|
|
MY_IP="$(ip route | grep default | grep -Pv '10\.\d+\.\d+\.\d+' | awk '{ print $9 }')"
|
|
|
|
# From this, determine the network (which for average broadband we assume is a /24)
|
|
MY_NETWORK=$(echo $MY_IP | awk 'BEGIN {FS="."} ; { printf("%s.%s.%s", $1, $2, $3) }')
|
|
|
|
# Create a script that will return this machine's IP to the bridge post-provisioner.
|
|
cat <<EOF > /usr/local/bin/public-ip
|
|
#!/usr/bin/env sh
|
|
echo -n $MY_IP
|
|
EOF
|
|
chmod +x /usr/local/bin/public-ip
|
|
else
|
|
# Determine machine IP from route table -
|
|
# Interface that is connected to the NAT network.
|
|
MY_IP="$(ip route | grep "^$IP_NW" | awk '{print $NF}')"
|
|
MY_NETWORK=$IP_NW
|
|
fi
|
|
|
|
# Remove unwanted entries
|
|
sed -e '/^.*ubuntu-jammy.*/d' -i /etc/hosts
|
|
sed -e "/^.*${HOSTNAME}.*/d" -i /etc/hosts
|
|
|
|
# Export PRIMARY IP as an environment variable
|
|
echo "PRIMARY_IP=${MY_IP}" >> /etc/environment
|
|
|
|
[ "$BUILD_MODE" = "BRIDGE" ] && exit 0
|
|
|
|
# Update /etc/hosts about other hosts (NAT mode)
|
|
echo "${MY_NETWORK}.${MASTER_IP_START} controlplane" >> /etc//hosts
|
|
for i in $(seq 1 $NUM_WORKER_NODES)
|
|
do
|
|
num=$(( $NODE_IP_START + $i ))
|
|
echo "${MY_NETWORK}.${num} node0${i}" >> /etc//hosts
|
|
done
|
|
|