Improve vagrant hostname support across cluster

This commit is contained in:
derekwaynecarr
2014-09-05 12:33:52 -04:00
parent acb3e39d49
commit 7f75aae8ab
7 changed files with 61 additions and 13 deletions

View File

@@ -23,10 +23,16 @@ NUM_MINIONS=${KUBERNETES_NUM_MINIONS-"3"}
export KUBE_MASTER_IP="10.245.1.2"
export KUBERNETES_MASTER="https://10.245.1.2"
INSTANCE_PREFIX=kubernetes
MASTER_NAME="${INSTANCE_PREFIX}-master"
MASTER_TAG="${INSTANCE_PREFIX}-master"
MINION_TAG="${INSTANCE_PREFIX}-minion"
MINION_NAMES=($(eval echo ${INSTANCE_PREFIX}-minion-{1..${NUM_MINIONS}}))
# IP LOCATIONS FOR INTERACTING WITH THE MINIONS
MINION_IP_BASE="10.245.2."
for (( i=0; i <${NUM_MINIONS}; i++)) do
KUBE_MINION_IP_ADDRESSES[$i]="${MINION_IP_BASE}$[$i+2]"
MINION_NAMES[$i]="${MINION_IP_BASE}$[$i+2]"
VAGRANT_MINION_NAMES[$i]="minion-$[$i+1]"
KUBE_MINION_IP_ADDRESSES[$i]="${MINION_IP_BASE}$[$i+2]"
MINION_IP[$i]="${MINION_IP_BASE}$[$i+2]"
VAGRANT_MINION_NAMES[$i]="minion-$[$i+1]"
done

View File

@@ -18,12 +18,24 @@
set -e
source $(dirname $0)/provision-config.sh
# Setup hosts file to support ping by hostname to each minion in the cluster from apiserver
minion_ip_array=(${MINION_IPS//,/ })
for (( i=0; i<${#MINION_NAMES[@]}; i++)); do
minion=${MINION_NAMES[$i]}
ip=${minion_ip_array[$i]}
if [ ! "$(cat /etc/hosts | grep $minion)" ]; then
echo "Adding $minion to hosts file"
echo "$ip $minion" >> /etc/hosts
fi
done
# Update salt configuration
mkdir -p /etc/salt/minion.d
echo "master: $MASTER_NAME" > /etc/salt/minion.d/master.conf
cat <<EOF >/etc/salt/minion.d/grains.conf
grains:
node_ip: $MASTER_IP
master_ip: $MASTER_IP
etcd_servers: $MASTER_IP
cloud_provider: vagrant

View File

@@ -20,12 +20,23 @@ source $(dirname $0)/provision-config.sh
MINION_IP=$4
# make sure each minion has an entry in hosts file for master
# Setup hosts file to support ping by hostname to master
if [ ! "$(cat /etc/hosts | grep $MASTER_NAME)" ]; then
echo "Adding host entry for $MASTER_NAME"
echo "Adding $MASTER_NAME to hosts file"
echo "$MASTER_IP $MASTER_NAME" >> /etc/hosts
fi
# Setup hosts file to support ping by hostname to each minion in the cluster
minion_ip_array=(${MINION_IPS//,/ })
for (( i=0; i<${#MINION_NAMES[@]}; i++)); do
minion=${MINION_NAMES[$i]}
ip=${minion_ip_array[$i]}
if [ ! "$(cat /etc/hosts | grep $minion)" ]; then
echo "Adding $minion to hosts file"
echo "$ip $minion" >> /etc/hosts
fi
done
# Let the minion know who its master is
mkdir -p /etc/salt/minion.d
echo "master: $MASTER_NAME" > /etc/salt/minion.d/master.conf
@@ -33,7 +44,7 @@ echo "master: $MASTER_NAME" > /etc/salt/minion.d/master.conf
# Our minions will have a pool role to distinguish them from the master.
cat <<EOF >/etc/salt/minion.d/grains.conf
grains:
minion_ip: $MINION_IP
node_ip: $MINION_IP
etcd_servers: $MASTER_IP
roles:
- kubernetes-pool

View File

@@ -40,6 +40,7 @@ function verify-prereqs {
# Instantiate a kubernetes cluster
function kube-up {
get-password
vagrant up
@@ -73,10 +74,11 @@ function kube-up {
done
done
done
echo
echo "Waiting for each minion to be registered with cloud provider"
for (( i=0; i<${#MINION_NAMES[@]}; i++)); do
MACHINE="${MINION_NAMES[$i]}"
COUNT="0"
until [ "$COUNT" -eq "1" ]; do
$(dirname $0)/kubecfg.sh -template '{{range.Items}}{{.ID}}:{{end}}' list minions > /tmp/minions