mirror of https://github.com/k3s-io/k3s
Optionally associate master instance with AWS Elastic IP
When MASTER_RESERVED_IP is set to elastic IP from AWS, then aws/util.sh will associate it with master instance and assign it to KUBE_MASTER_IP. If no MASTER_RESERVED_IP is set, new elastic ip will be requested from amazon. This allows cluster certificates to be generated for an IP that doesn't change between stopping & starting cluster instances. The requested elastic ip is not released when kube-down.sh is run. I think it is good because user could have created DNS records and it would be bad if the IP was removed. He can reuse it next time through MASTER_RESERVED_IP when setting up cluster again.pull/6/head
parent
ec19d41b63
commit
d4d02a9028
|
@ -43,7 +43,9 @@ MINION_SCOPES=""
|
|||
POLL_SLEEP_INTERVAL=3
|
||||
PORTAL_NET="10.0.0.0/16"
|
||||
MASTER_IP_RANGE="${MASTER_IP_RANGE:-10.246.0.0/24}"
|
||||
|
||||
# If set to Elastic IP, master instance will be associated with this IP.
|
||||
# Otherwise new Elastic IP will be aquired
|
||||
MASTER_RESERVED_IP="${MASTER_RESERVED_IP:-}"
|
||||
|
||||
# When set to true, Docker Cache is enabled by default as part of the cluster bring up.
|
||||
ENABLE_DOCKER_REGISTRY_CACHE=true
|
||||
|
|
|
@ -365,6 +365,34 @@ function wait-for-instance-running {
|
|||
done
|
||||
}
|
||||
|
||||
function allocate-elastic-ip {
|
||||
$AWS_CMD allocate-address --domain vpc --output text | cut -f3
|
||||
}
|
||||
|
||||
function assign-ip-to-instance {
|
||||
local ip_address=$1
|
||||
local instance_id=$2
|
||||
local elastic_ip_allocation_id=$($AWS_CMD describe-addresses --public-ips $ip_address --output text | cut -f2)
|
||||
$AWS_CMD associate-address --instance-id $master_instance_id --allocation-id $elastic_ip_allocation_id > /dev/null
|
||||
local association_result=$?
|
||||
|
||||
if [[ $association_result -eq 0 ]]; then
|
||||
echo $ip_address
|
||||
fi
|
||||
}
|
||||
|
||||
function assign-elastic-ip {
|
||||
local assigned_public_ip=$1
|
||||
local master_instance_id=$2
|
||||
|
||||
if [[ -n $MASTER_RESERVED_IP ]]; then
|
||||
assign-ip-to-instance $MASTER_RESERVED_IP $master_instance_id
|
||||
else
|
||||
assign-ip-to-instance $(allocate-elastic-ip) $master_instance_id
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function kube-up {
|
||||
find-release-tars
|
||||
upload-server-tars
|
||||
|
@ -505,7 +533,7 @@ function kube-up {
|
|||
fi
|
||||
else
|
||||
KUBE_MASTER=${MASTER_NAME}
|
||||
KUBE_MASTER_IP=${ip}
|
||||
KUBE_MASTER_IP=$(assign-elastic-ip $ip $master_id)
|
||||
echo -e " ${color_green}[master running @${KUBE_MASTER_IP}]${color_norm}"
|
||||
|
||||
# We are not able to add a route to the instance until that instance is in "running" state.
|
||||
|
|
Loading…
Reference in New Issue