@@ -386,9 +386,8 @@ function detect-master () {
386
386
detect-project
387
387
KUBE_MASTER=${MASTER_NAME}
388
388
if [[ -z " ${KUBE_MASTER_IP-} " ]]; then
389
- local REGION=${ZONE% -* }
390
- KUBE_MASTER_IP=$( gcloud compute addresses describe " ${MASTER_NAME} -ip" \
391
- --project " ${PROJECT} " --region " ${REGION} " -q --format=' value(address)' )
389
+ KUBE_MASTER_IP=$( gcloud compute instances describe --project " ${PROJECT} " --zone " ${ZONE} " \
390
+ " ${MASTER_NAME} " --format=' value(networkInterfaces[0].accessConfigs[0].natIP)' )
392
391
fi
393
392
if [[ -z " ${KUBE_MASTER_IP-} " ]]; then
394
393
echo " Could not detect Kubernetes master node. Make sure you've launched a cluster with 'kube-up.sh'" >&2
@@ -610,9 +609,6 @@ function kube-up {
610
609
if [[ ${KUBE_USE_EXISTING_MASTER:- } == " true" ]]; then
611
610
parse-master-env
612
611
create-nodes
613
- elif [[ ${KUBE_REPLICATE_EXISTING_MASTER:- } == " true" ]]; then
614
- create-loadbalancer
615
- # TODO: Add logic for copying an existing master.
616
612
else
617
613
check-existing
618
614
create-network
@@ -743,74 +739,6 @@ function create-master() {
743
739
create-master-instance " ${MASTER_RESERVED_IP} " &
744
740
}
745
741
746
- # Detaches old and ataches new external IP to a VM.
747
- #
748
- # Arguments:
749
- # $1 - VM name
750
- # $2 - VM zone
751
- # $3 - external static IP; if empty will use an ephemeral IP address.
752
- function attach-external-ip() {
753
- local NAME=${1}
754
- local ZONE=${2}
755
- local IP_ADDR=${3:- }
756
- local ACCESS_CONFIG_NAME=$( gcloud compute instances describe " ${NAME} " \
757
- --project " ${PROJECT} " --zone " ${ZONE} " \
758
- --format=" value(networkInterfaces[0].accessConfigs[0].name)" )
759
- gcloud compute instances delete-access-config " ${NAME} " \
760
- --project " ${PROJECT} " --zone " ${ZONE} " \
761
- --access-config-name " ${ACCESS_CONFIG_NAME} "
762
- if [[ -z ${IP_ADDR} ]]; then
763
- gcloud compute instances add-access-config " ${NAME} " \
764
- --project " ${PROJECT} " --zone " ${ZONE} " \
765
- --access-config-name " ${ACCESS_CONFIG_NAME} "
766
- else
767
- gcloud compute instances add-access-config " ${NAME} " \
768
- --project " ${PROJECT} " --zone " ${ZONE} " \
769
- --access-config-name " ${ACCESS_CONFIG_NAME} " \
770
- --address " ${IP_ADDR} "
771
- fi
772
- }
773
-
774
- # Creates load balancer in front of apiserver if it doesn't exists already. Assumes there's only one
775
- # existing master replica.
776
- #
777
- # Assumes:
778
- # PROJECT
779
- # MASTER_NAME
780
- # ZONE
781
- function create-loadbalancer() {
782
- detect-master
783
- local REGION=${ZONE% -* }
784
-
785
- # Step 0: Return early if LB is already configured.
786
- if gcloud compute forwarding-rules describe ${MASTER_NAME} \
787
- --project " ${PROJECT} " --region ${REGION} > /dev/null 2>&1 ; then
788
- echo " Load balancer already exists"
789
- return
790
- fi
791
- local EXISTING_MASTER_ZONE=$( gcloud compute instances list " ${MASTER_NAME} " \
792
- --project " ${PROJECT} " --format=" value(zone)" )
793
- echo " Creating load balancer in front of an already existing master in ${EXISTING_MASTER_ZONE} "
794
-
795
- # Step 1: Detach master IP address and attach ephemeral address to the existing master
796
- attach-external-ip ${MASTER_NAME} ${EXISTING_MASTER_ZONE}
797
-
798
- # Step 2: Create target pool.
799
- gcloud compute target-pools create " ${MASTER_NAME} " --region " ${REGION} "
800
- # TODO: We should also add master instances with suffixes
801
- gcloud compute target-pools add-instances ${MASTER_NAME} --instances ${MASTER_NAME} --zone ${EXISTING_MASTER_ZONE}
802
-
803
- # Step 3: Create forwarding rule.
804
- # TODO: This step can take up to 20 min. We need to speed this up...
805
- gcloud compute forwarding-rules create ${MASTER_NAME} \
806
- --project " ${PROJECT} " --region ${REGION} \
807
- --target-pool ${MASTER_NAME} --address=${KUBE_MASTER_IP} --ports=443
808
-
809
- echo -n " Waiting for the load balancer configuration to propagate..."
810
- until $( curl -k -m1 https://${KUBE_MASTER_IP} > /dev/null 2>&1 ) ; do echo -n . ; done
811
- echo " DONE"
812
- }
813
-
814
742
function create-nodes-firewall() {
815
743
# Create a single firewall rule for all minions.
816
744
create-firewall-rule " ${NODE_TAG} -all" " ${CLUSTER_IP_RANGE} " " ${NODE_TAG} " &
@@ -1101,53 +1029,6 @@ function kube-down {
1101
1029
fi
1102
1030
fi
1103
1031
1104
- # Check if this are any remaining master replicas.
1105
- local REMAINING_MASTER_COUNT=$( gcloud compute instances list \
1106
- --project " ${PROJECT} " \
1107
- --regexp " ${MASTER_NAME} (-...)?" \
1108
- --format " value(zone)" | wc -l)
1109
-
1110
- # In the replicated scenario, if there's only a single master left, we should also delete load balancer in front of it.
1111
- if [[ " ${REMAINING_MASTER_COUNT} " == " 1" ]]; then
1112
- local REGION=${ZONE% -* }
1113
- if gcloud compute forwarding-rules describe " ${MASTER_NAME} " --region " ${REGION} " --project " ${PROJECT} " & > /dev/null; then
1114
- detect-master
1115
- local REGION=${ZONE% -* }
1116
- local EXISTING_MASTER_ZONE=$( gcloud compute instances list " ${MASTER_NAME} " \
1117
- --project " ${PROJECT} " --format=" value(zone)" )
1118
- gcloud compute forwarding-rules delete \
1119
- --project " ${PROJECT} " \
1120
- --region " ${REGION} " \
1121
- --quiet \
1122
- " ${MASTER_NAME} "
1123
- attach-external-ip " ${MASTER_NAME} " " ${EXISTING_MASTER_ZONE} " " ${KUBE_MASTER_IP} "
1124
- gcloud compute target-pools delete \
1125
- --project " ${PROJECT} " \
1126
- --region " ${REGION} " \
1127
- --quiet \
1128
- " ${MASTER_NAME} "
1129
- fi
1130
- fi
1131
-
1132
- # If there are no more remaining master replicas, we should delete all remaining network resources.
1133
- if [[ " ${REMAINING_MASTER_COUNT} " == " 0" ]]; then
1134
- # Delete firewall rule for the master.
1135
- if gcloud compute firewall-rules describe --project " ${PROJECT} " " ${MASTER_NAME} -https" & > /dev/null; then
1136
- gcloud compute firewall-rules delete \
1137
- --project " ${PROJECT} " \
1138
- --quiet \
1139
- " ${MASTER_NAME} -https"
1140
- fi
1141
- # Delete the master's reserved IP
1142
- if gcloud compute addresses describe " ${MASTER_NAME} -ip" --region " ${REGION} " --project " ${PROJECT} " & > /dev/null; then
1143
- gcloud compute addresses delete \
1144
- --project " ${PROJECT} " \
1145
- --region " ${REGION} " \
1146
- --quiet \
1147
- " ${MASTER_NAME} -ip"
1148
- fi
1149
- fi
1150
-
1151
1032
# Find out what minions are running.
1152
1033
local -a minions
1153
1034
minions=( $( gcloud compute instances list \
@@ -1166,6 +1047,14 @@ function kube-down {
1166
1047
minions=( " ${minions[@]: ${batch} } " )
1167
1048
done
1168
1049
1050
+ # Delete firewall rule for the master.
1051
+ if gcloud compute firewall-rules describe --project " ${PROJECT} " " ${MASTER_NAME} -https" & > /dev/null; then
1052
+ gcloud compute firewall-rules delete \
1053
+ --project " ${PROJECT} " \
1054
+ --quiet \
1055
+ " ${MASTER_NAME} -https"
1056
+ fi
1057
+
1169
1058
# Delete firewall rule for minions.
1170
1059
if gcloud compute firewall-rules describe --project " ${PROJECT} " " ${NODE_TAG} -all" & > /dev/null; then
1171
1060
gcloud compute firewall-rules delete \
@@ -1194,6 +1083,16 @@ function kube-down {
1194
1083
routes=( " ${routes[@]: ${batch} } " )
1195
1084
done
1196
1085
1086
+ # Delete the master's reserved IP
1087
+ local REGION=${ZONE% -* }
1088
+ if gcloud compute addresses describe " ${MASTER_NAME} -ip" --region " ${REGION} " --project " ${PROJECT} " & > /dev/null; then
1089
+ gcloud compute addresses delete \
1090
+ --project " ${PROJECT} " \
1091
+ --region " ${REGION} " \
1092
+ --quiet \
1093
+ " ${MASTER_NAME} -ip"
1094
+ fi
1095
+
1197
1096
# Delete persistent disk for influx-db.
1198
1097
if gcloud compute disks describe " ${INSTANCE_PREFIX} " -influxdb-pd --zone " ${ZONE} " --project " ${PROJECT} " & > /dev/null; then
1199
1098
gcloud compute disks delete \
0 commit comments