File tree Expand file tree Collapse file tree 4 files changed +50
-1
lines changed Expand file tree Collapse file tree 4 files changed +50
-1
lines changed Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ # Copyright 2016 The Kubernetes Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ METADATA_ENDPOINT=" http://metadata.google.internal/computeMetadata/v1/instance/attributes/kube-master-internal-ip"
18
+ METADATA_HEADER=" Metadata-Flavor: Google"
19
+ ip=$( curl -s --fail ${METADATA_ENDPOINT} -H " ${METADATA_HEADER} " )
20
+ if [ -n " $ip " ];
21
+ then
22
+ # Check if route is already set if not set it
23
+ if ! sudo ip route show table local | grep -q " $( echo " $ip " | cut -d' /' -f 1) " ;
24
+ then
25
+ sudo ip route add to local " ${ip} /32" dev " $( ip route | grep default | awk ' {print $5}' ) "
26
+ fi
27
+ fi
Original file line number Diff line number Diff line change @@ -157,6 +157,7 @@ function create-master-instance-internal() {
157
157
metadata=" ${metadata} ,gci-docker-version=${KUBE_TEMP} /gci-docker-version.txt"
158
158
metadata=" ${metadata} ,kube-master-certs=${KUBE_TEMP} /kube-master-certs.yaml"
159
159
metadata=" ${metadata} ,cluster-location=${KUBE_TEMP} /cluster-location.txt"
160
+ metadata=" ${metadata} ,kube-master-internal-route=${KUBE_ROOT} /cluster/gce/gci/kube-master-internal-route.sh"
160
161
metadata=" ${metadata} ,${MASTER_EXTRA_METADATA} "
161
162
162
163
local disk=" name=${master_name} -pd"
Original file line number Diff line number Diff line change @@ -29,6 +29,24 @@ write_files:
29
29
[Install]
30
30
WantedBy=kubernetes.target
31
31
32
+ - path : /etc/systemd/system/kube-master-internal-route.service
33
+ permissions : 0644
34
+ owner : root
35
+ content : |
36
+ [Unit]
37
+ Description=Configure kube internal route
38
+ After=kube-master-installation.service
39
+
40
+ [Service]
41
+ Type=oneshot
42
+ RemainAfterExit=yes
43
+ ExecStartPre=/usr/bin/curl --fail --retry 5 --retry-delay 3 --silent --show-error -H "X-Google-Metadata-Request: True" -o /home/kubernetes/bin/kube-master-internal-route.sh http://metadata.google.internal/computeMetadata/v1/instance/attributes/kube-master-internal-route
44
+ ExecStartPre=/bin/chmod 544 /home/kubernetes/bin/kube-master-internal-route.sh
45
+ ExecStart=/home/kubernetes/bin/kube-master-internal-route.sh
46
+
47
+ [Install]
48
+ WantedBy=kubernetes.target
49
+
32
50
- path : /etc/systemd/system/kube-master-configuration.service
33
51
permissions : 0644
34
52
owner : root
@@ -125,6 +143,7 @@ write_files:
125
143
runcmd :
126
144
- systemctl daemon-reload
127
145
- systemctl enable kube-master-installation.service
146
+ - systemctl enable kube-master-internal-route.service
128
147
- systemctl enable kube-master-configuration.service
129
148
- systemctl enable kube-container-runtime-monitor.service
130
149
- systemctl enable kubelet-monitor.service
Original file line number Diff line number Diff line change @@ -2947,7 +2947,8 @@ function attach-internal-master-ip() {
2947
2947
echo " Setting ${name} 's aliases to '${aliases} ' (added ${ip} )"
2948
2948
# Attach ${ip} to ${name}
2949
2949
gcloud compute instances network-interfaces update " ${name} " --project " ${PROJECT} " --zone " ${zone} " --aliases=" ${aliases} "
2950
- run-gcloud-command " ${name} " " ${zone} " ' sudo ip route add to local ' ${ip} ' /32 dev $(ip route | grep default | awk ' \' ' {print $5}' \' ' )' || true
2950
+ gcloud compute instances add-metadata " ${name} " --zone " ${zone} " --metadata=kube-master-internal-ip=" ${ip} "
2951
+ run-gcloud-command " ${name} " " ${zone} " ' sudo /bin/bash /home/kubernetes/bin/kube-master-internal-route.sh' || true
2951
2952
return $?
2952
2953
}
2953
2954
@@ -2965,6 +2966,7 @@ function detach-internal-master-ip() {
2965
2966
echo " Setting ${name} 's aliases to '${aliases} ' (removed ${ip} )"
2966
2967
# Detach ${MASTER_NAME}-internal-ip from ${name}
2967
2968
gcloud compute instances network-interfaces update " ${name} " --project " ${PROJECT} " --zone " ${zone} " --aliases=" ${aliases} "
2969
+ gcloud compute instances remove-metadata " ${name} " --zone " ${zone} " --keys=kube-master-internal-ip
2968
2970
run-gcloud-command " ${name} " " ${zone} " ' sudo ip route del to local ' ${ip} ' /32 dev $(ip route | grep default | awk ' \' ' {print $5}' \' ' )' || true
2969
2971
return $?
2970
2972
}
You can’t perform that action at this time.
0 commit comments