Skip to content

Commit

Permalink
libvirt-coreos: move all IP definitions in config-default.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
L3n41c committed Mar 2, 2015
1 parent 93c0052 commit 9077c23
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
28 changes: 28 additions & 0 deletions cluster/libvirt-coreos/config-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,31 @@
# Number of minions in the cluster
NUM_MINIONS=${NUM_MINIONS:-3}
export NUM_MINIONS

# The IP of the master
export MASTER_IP="192.168.10.1"

export INSTANCE_PREFIX=kubernetes
export MASTER_NAME="${INSTANCE_PREFIX}-master"

# Map out the IPs, names and container subnets of each minion
export MINION_IP_BASE="192.168.10."
MINION_CONTAINER_SUBNET_BASE="10.10"
MASTER_CONTAINER_NETMASK="255.255.255.0"
MASTER_CONTAINER_ADDR="${MINION_CONTAINER_SUBNET_BASE}.0.1"
MASTER_CONTAINER_SUBNET="${MINION_CONTAINER_SUBNET_BASE}.0.1/24"
CONTAINER_SUBNET="${MINION_CONTAINER_SUBNET_BASE}.0.0/16"
if [[ "$NUM_MINIONS" -gt 253 ]]; then
echo "ERROR: Because of how IPs are allocated in ${BASH_SOURCE}, you cannot create more than 253 minions"
exit 1
fi
for ((i=0; i < NUM_MINIONS; i++)) do
MINION_IPS[$i]="${MINION_IP_BASE}$((i+2))"
MINION_NAMES[$i]="${INSTANCE_PREFIX}-minion-$((i+1))"
MINION_CONTAINER_SUBNETS[$i]="${MINION_CONTAINER_SUBNET_BASE}.$((i+1)).1/24"
MINION_CONTAINER_ADDRS[$i]="${MINION_CONTAINER_SUBNET_BASE}.$((i+1)).1"
MINION_CONTAINER_NETMASKS[$i]="255.255.255.0"
done
MINION_CONTAINER_SUBNETS[$NUM_MINIONS]=$MASTER_CONTAINER_SUBNET

PORTAL_NET=10.11.0.0/16
12 changes: 6 additions & 6 deletions cluster/libvirt-coreos/user_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ write_files:
coreos:
etcd:
name: ${name}
addr: 192.168.10.$(($i+1)):4001
addr: ${public_ip}:4001
bind-addr: 0.0.0.0
peer-addr: 192.168.10.$(($i+1)):7001
peer-addr: ${public_ip}:7001
# peers: {etcd_peers}
discovery: ${discovery}
units:
Expand All @@ -30,7 +30,7 @@ coreos:
MACAddress=52:54:00:00:00:${i}
[Network]
Address=192.168.10.$(($i+1))/24
Address=${public_ip}/24
DNS=192.168.10.254
Gateway=192.168.10.254
- name: cbr0.netdev
Expand All @@ -46,10 +46,10 @@ coreos:
Name=cbr0
[Network]
Address=10.10.$(($i+1)).1/24
Address=${MINION_CONTAINER_SUBNETS[$i]}
[Route]
Destination=10.10.0.0/16
Destination=${CONTAINER_SUBNET}
- name: cbr0-interface.network
command: start
content: |
Expand All @@ -66,7 +66,7 @@ coreos:
Description=NAT non container traffic
[Service]
ExecStart=/usr/sbin/iptables -w -t nat -A POSTROUTING -o eth0 -j MASQUERADE ! -d 10.10.0.0/16
ExecStart=/usr/sbin/iptables -w -t nat -A POSTROUTING -o eth0 -j MASQUERADE ! -d ${CONTAINER_SUBNET}
RemainAfterExit=yes
Type=oneshot
- name: etcd.service
Expand Down
2 changes: 1 addition & 1 deletion cluster/libvirt-coreos/user_data_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ coreos:
--port=8080 \
--etcd_servers=http://127.0.0.1:4001 \
--kubelet_port=10250 \
--portal_net=10.10.254.0/24
--portal_net=${PORTAL_NET}
Restart=always
RestartSec=2
Expand Down
4 changes: 2 additions & 2 deletions cluster/libvirt-coreos/user_data_minion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ coreos:
[Service]
ExecStart=/opt/kubernetes/bin/kubelet \
--address=0.0.0.0 \
--hostname_override=192.168.10.$(($i+1)) \
--hostname_override=${MINION_IPS[$i]} \
--etcd_servers=http://127.0.0.1:4001
Restart=always
RestartSec=2
Expand All @@ -35,7 +35,7 @@ coreos:
[Service]
ExecStart=/opt/kubernetes/bin/kube-proxy \
--etcd_servers=http://127.0.0.1:4001 \
--master=http://192.168.10.1:7080
--master=http://${MASTER_IP}:7080
Restart=always
RestartSec=2
Expand Down
16 changes: 8 additions & 8 deletions cluster/libvirt-coreos/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,16 @@ function join {

# Must ensure that the following ENV vars are set
function detect-master {
KUBE_MASTER_IP=192.168.10.1
KUBE_MASTER=kubernetes-master
KUBE_MASTER_IP=$MASTER_IP
KUBE_MASTER=$MASTER_NAME
export KUBERNETES_MASTER=http://$KUBE_MASTER_IP:8080
echo "KUBE_MASTER_IP: $KUBE_MASTER_IP"
echo "KUBE_MASTER: $KUBE_MASTER"
}

# Get minion IP addresses and store in KUBE_MINION_IP_ADDRESSES[]
function detect-minions {
for (( i = 0 ; i < $NUM_MINIONS ; i++ )); do
KUBE_MINION_IP_ADDRESSES[$i]=192.168.10.$(($i+2))
done
echo "KUBE_MINION_IP_ADDRESSES=[${KUBE_MINION_IP_ADDRESSES[@]}]"
KUBE_MINION_IP_ADDRESSES=("${MINION_IPS[@]}")
}

# Verify prereqs on host machine
Expand Down Expand Up @@ -161,12 +158,15 @@ function kube-up {

local i
for (( i = 0 ; i <= $NUM_MINIONS ; i++ )); do
if [[ $i -eq 0 ]]; then
if [[ $i -eq $NUM_MINIONS ]]; then
type=master
name=$MASTER_NAME
public_ip=$MASTER_IP
else
type=minion-$(printf "%02d" $i)
name=${MINION_NAMES[$i]}
public_ip=${MINION_IPS[$i]}
fi
name=kubernetes_$type
image=$name.img
config=kubernetes_config_$type

Expand Down

0 comments on commit 9077c23

Please sign in to comment.