@@ -1892,8 +1892,11 @@ function make-gcloud-network-argument() {
1892
1892
if [[ " ${enable_ip_alias} " == ' true' ]]; then
1893
1893
ret=" --network-interface"
1894
1894
ret=" ${ret} network=${networkURL} "
1895
- # If address is omitted, instance will not receive an external IP.
1896
- ret=" ${ret} ,address=${address:- } "
1895
+ if [[ " ${address:- } " == " no-address" ]]; then
1896
+ ret=" ${ret} ,no-address"
1897
+ else
1898
+ ret=" ${ret} ,address=${address:- } "
1899
+ fi
1897
1900
ret=" ${ret} ,subnet=${subnetURL} "
1898
1901
ret=" ${ret} ,aliases=pods-default:${alias_size} "
1899
1902
ret=" ${ret} --no-can-ip-forward"
@@ -1905,7 +1908,7 @@ function make-gcloud-network-argument() {
1905
1908
fi
1906
1909
1907
1910
ret=" ${ret} --can-ip-forward"
1908
- if [[ -n ${address:- } ]]; then
1911
+ if [[ -n ${address:- } ]] && [[ " $address " != " no-address " ]] ; then
1909
1912
ret=" ${ret} --address ${address} "
1910
1913
fi
1911
1914
fi
@@ -2010,13 +2013,17 @@ function create-node-template() {
2010
2013
fi
2011
2014
fi
2012
2015
2016
+ local address=" "
2017
+ if [[ ${GCE_PRIVATE_CLUSTER:- } == " true" ]]; then
2018
+ address=" no-address"
2019
+ fi
2013
2020
2014
2021
local network=$( make-gcloud-network-argument \
2015
2022
" ${NETWORK_PROJECT} " \
2016
2023
" ${REGION} " \
2017
2024
" ${NETWORK} " \
2018
2025
" ${SUBNETWORK:- } " \
2019
- " " \
2026
+ " ${address} " \
2020
2027
" ${ENABLE_IP_ALIASES:- } " \
2021
2028
" ${IP_ALIAS_SIZE:- } " )
2022
2029
@@ -2113,6 +2120,7 @@ function kube-up() {
2113
2120
create-network
2114
2121
create-subnetworks
2115
2122
detect-subnetworks
2123
+ create-cloud-nat-router
2116
2124
write-cluster-location
2117
2125
write-cluster-name
2118
2126
create-autoscaler-config
@@ -2302,6 +2310,26 @@ function detect-subnetworks() {
2302
2310
echo " ${color_red} Could not find subnetwork with region ${REGION} , network ${NETWORK} , and project ${NETWORK_PROJECT} "
2303
2311
}
2304
2312
2313
+ # Sets up Cloud NAT for the network.
2314
+ # Assumed vars:
2315
+ # NETWORK_PROJECT
2316
+ # REGION
2317
+ # NETWORK
2318
+ function create-cloud-nat-router() {
2319
+ if [[ ${GCE_PRIVATE_CLUSTER:- } == " true" ]]; then
2320
+ gcloud compute routers create " $NETWORK -nat-router" \
2321
+ --project $NETWORK_PROJECT \
2322
+ --region $REGION \
2323
+ --network $NETWORK
2324
+ gcloud compute routers nats create " $NETWORK -nat-config" \
2325
+ --project $NETWORK_PROJECT \
2326
+ --router-region $REGION \
2327
+ --router " $NETWORK -nat-router" \
2328
+ --nat-all-subnet-ip-ranges \
2329
+ --auto-allocate-nat-external-ips
2330
+ fi
2331
+ }
2332
+
2305
2333
function delete-all-firewall-rules() {
2306
2334
if fws=$( gcloud compute firewall-rules list --project " ${NETWORK_PROJECT} " --filter=" network=${NETWORK} " --format=" value(name)" ) ; then
2307
2335
echo " Deleting firewall rules remaining in network ${NETWORK} : ${fws} "
@@ -2333,6 +2361,15 @@ function delete-network() {
2333
2361
fi
2334
2362
}
2335
2363
2364
+ function delete-cloud-nat-router() {
2365
+ if [[ ${GCE_PRIVATE_CLUSTER:- } == " true" ]]; then
2366
+ if [[ -n $( gcloud compute routers describe --project " ${NETWORK_PROJECT} " --region " ${REGION} " " ${NETWORK} -nat-router" --format=' value(name)' 2> /dev/null || true) ]]; then
2367
+ echo " Deleting Cloud NAT router..."
2368
+ gcloud compute routers delete --project " ${NETWORK_PROJECT} " --region " ${REGION} " --quiet " ${NETWORK} -nat-router"
2369
+ fi
2370
+ fi
2371
+ }
2372
+
2336
2373
function delete-subnetworks() {
2337
2374
# If running in custom mode network we need to delete subnets manually.
2338
2375
mode=" $( check-network-mode) "
@@ -3209,6 +3246,7 @@ function kube-down() {
3209
3246
" ${NETWORK} -default-internal" # Pre-1.5 clusters
3210
3247
3211
3248
if [[ " ${KUBE_DELETE_NETWORK} " == " true" ]]; then
3249
+ delete-cloud-nat-router
3212
3250
# Delete all remaining firewall rules in the network.
3213
3251
delete-all-firewall-rules || true
3214
3252
delete-subnetworks || true
@@ -3404,6 +3442,13 @@ function check-resources() {
3404
3442
return 1
3405
3443
fi
3406
3444
3445
+ if [[ ${GCE_PRIVATE_CLUSTER:- } == " true" ]]; then
3446
+ if gcloud compute routers describe --project " ${NETWORK_PROJECT} " --region " ${REGION} " " ${NETWORK} -nat-router" & > /dev/null; then
3447
+ KUBE_RESOURCE_FOUND=" Cloud NAT router"
3448
+ return 1
3449
+ fi
3450
+ fi
3451
+
3407
3452
# No resources found.
3408
3453
return 0
3409
3454
}
0 commit comments