mirror of https://github.com/k3s-io/k3s
Use existing subnet when launching AWS cluster in existing VPC
parent
cf824ae5e0
commit
645d6d1f26
|
@ -29,7 +29,9 @@ export AWS_DEFAULT_REGION=${AWS_REGION}
|
|||
AWS_CMD="aws --output json ec2"
|
||||
AWS_ELB_CMD="aws --output json elb"
|
||||
|
||||
MASTER_INTERNAL_IP=172.20.0.9
|
||||
INTERNAL_IP_BASE=172.20.0
|
||||
MASTER_IP_SUFFIX=.9
|
||||
MASTER_INTERNAL_IP=${INTERNAL_IP_BASE}${MASTER_IP_SUFFIX}
|
||||
|
||||
function json_val {
|
||||
python -c 'import json,sys;obj=json.load(sys.stdin);print obj'$1''
|
||||
|
@ -46,7 +48,11 @@ function get_vpc_id {
|
|||
}
|
||||
|
||||
function get_subnet_id {
|
||||
python -c "import json,sys; lst = [str(subnet['SubnetId']) for subnet in json.load(sys.stdin)['Subnets'] if subnet['VpcId'] == '$1']; print ''.join(lst)"
|
||||
python -c "import json,sys; lst = [str(subnet['SubnetId']) for subnet in json.load(sys.stdin)['Subnets'] if subnet['VpcId'] == '$1' and subnet['AvailabilityZone'] == '$2']; print ''.join(lst)"
|
||||
}
|
||||
|
||||
function get_cidr {
|
||||
python -c "import json,sys; lst = [str(subnet['CidrBlock']) for subnet in json.load(sys.stdin)['Subnets'] if subnet['VpcId'] == '$1' and subnet['AvailabilityZone'] == '$2']; print ''.join(lst)"
|
||||
}
|
||||
|
||||
function get_igw_id {
|
||||
|
@ -372,7 +378,7 @@ function kube-up {
|
|||
|
||||
if [[ -z "$VPC_ID" ]]; then
|
||||
echo "Creating vpc."
|
||||
VPC_ID=$($AWS_CMD create-vpc --cidr-block 172.20.0.0/16 | json_val '["Vpc"]["VpcId"]')
|
||||
VPC_ID=$($AWS_CMD create-vpc --cidr-block $INTERNAL_IP_BASE.0/16 | json_val '["Vpc"]["VpcId"]')
|
||||
$AWS_CMD modify-vpc-attribute --vpc-id $VPC_ID --enable-dns-support '{"Value": true}' > $LOG
|
||||
$AWS_CMD modify-vpc-attribute --vpc-id $VPC_ID --enable-dns-hostnames '{"Value": true}' > $LOG
|
||||
add-tag $VPC_ID Name kubernetes-vpc
|
||||
|
@ -381,10 +387,15 @@ function kube-up {
|
|||
|
||||
echo "Using VPC $VPC_ID"
|
||||
|
||||
SUBNET_ID=$($AWS_CMD describe-subnets | get_subnet_id $VPC_ID)
|
||||
SUBNET_ID=$($AWS_CMD describe-subnets | get_subnet_id $VPC_ID $ZONE)
|
||||
if [[ -z "$SUBNET_ID" ]]; then
|
||||
echo "Creating subnet."
|
||||
SUBNET_ID=$($AWS_CMD create-subnet --cidr-block 172.20.0.0/24 --vpc-id $VPC_ID --availability-zone ${ZONE} | json_val '["Subnet"]["SubnetId"]')
|
||||
echo "Creating subnet."
|
||||
SUBNET_ID=$($AWS_CMD create-subnet --cidr-block $INTERNAL_IP_BASE.0/24 --vpc-id $VPC_ID --availability-zone ${ZONE} | json_val '["Subnet"]["SubnetId"]')
|
||||
else
|
||||
EXISTING_CIDR=$($AWS_CMD describe-subnets | get_cidr $VPC_ID $ZONE)
|
||||
echo "Using existing CIDR $EXISTING_CIDR"
|
||||
INTERNAL_IP_BASE=${EXISTING_CIDR%.*}
|
||||
MASTER_INTERNAL_IP=${INTERNAL_IP_BASE}${MASTER_IP_SUFFIX}
|
||||
fi
|
||||
|
||||
echo "Using subnet $SUBNET_ID"
|
||||
|
@ -458,7 +469,7 @@ function kube-up {
|
|||
--iam-instance-profile Name=$IAM_PROFILE_MASTER \
|
||||
--instance-type $MASTER_SIZE \
|
||||
--subnet-id $SUBNET_ID \
|
||||
--private-ip-address 172.20.0.9 \
|
||||
--private-ip-address $MASTER_INTERNAL_IP \
|
||||
--key-name kubernetes \
|
||||
--security-group-ids $SEC_GROUP_ID \
|
||||
--associate-public-ip-address \
|
||||
|
@ -539,7 +550,7 @@ function kube-up {
|
|||
--iam-instance-profile Name=$IAM_PROFILE_MINION \
|
||||
--instance-type $MINION_SIZE \
|
||||
--subnet-id $SUBNET_ID \
|
||||
--private-ip-address 172.20.0.1${i} \
|
||||
--private-ip-address $INTERNAL_IP_BASE.1${i} \
|
||||
--key-name kubernetes \
|
||||
--security-group-ids $SEC_GROUP_ID \
|
||||
--associate-public-ip-address \
|
||||
|
|
Loading…
Reference in New Issue