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 @@ -23,6 +23,24 @@ write_files:
23
23
[Install]
24
24
WantedBy=kubernetes.target
25
25
26
+ - path : /etc/systemd/system/kube-master-internal-route.service
27
+ permissions : 0644
28
+ owner : root
29
+ content : |
30
+ [Unit]
31
+ Description=Configure kube internal route
32
+ After=kube-master-installation.service
33
+
34
+ [Service]
35
+ Type=oneshot
36
+ RemainAfterExit=yes
37
+ 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
38
+ ExecStartPre=/bin/chmod 544 /home/kubernetes/bin/kube-master-internal-route.sh
39
+ ExecStart=/home/kubernetes/bin/kube-master-internal-route.sh
40
+
41
+ [Install]
42
+ WantedBy=kubernetes.target
43
+
26
44
- path : /etc/systemd/system/kube-master-configuration.service
27
45
permissions : 0644
28
46
owner : root
@@ -119,6 +137,7 @@ write_files:
119
137
runcmd :
120
138
- systemctl daemon-reload
121
139
- systemctl enable kube-master-installation.service
140
+ - systemctl enable kube-master-internal-route.service
122
141
- systemctl enable kube-master-configuration.service
123
142
- systemctl enable kube-container-runtime-monitor.service
124
143
- systemctl enable kubelet-monitor.service
Original file line number Diff line number Diff line change @@ -2946,7 +2946,8 @@ function attach-internal-master-ip() {
2946
2946
echo " Setting ${name} 's aliases to '${aliases} ' (added ${ip} )"
2947
2947
# Attach ${ip} to ${name}
2948
2948
gcloud compute instances network-interfaces update " ${name} " --project " ${PROJECT} " --zone " ${zone} " --aliases=" ${aliases} "
2949
- run-gcloud-command " ${name} " " ${zone} " ' sudo ip route add to local ' ${ip} ' /32 dev $(ip route | grep default | awk ' \' ' {print $5}' \' ' )' || true
2949
+ gcloud compute instances add-metadata " ${name} " --zone " ${zone} " --metadata=kube-master-internal-ip=" ${ip} "
2950
+ run-gcloud-command " ${name} " " ${zone} " ' sudo /bin/bash /home/kubernetes/bin/kube-master-internal-route.sh' || true
2950
2951
return $?
2951
2952
}
2952
2953
@@ -2964,6 +2965,7 @@ function detach-internal-master-ip() {
2964
2965
echo " Setting ${name} 's aliases to '${aliases} ' (removed ${ip} )"
2965
2966
# Detach ${MASTER_NAME}-internal-ip from ${name}
2966
2967
gcloud compute instances network-interfaces update " ${name} " --project " ${PROJECT} " --zone " ${zone} " --aliases=" ${aliases} "
2968
+ gcloud compute instances remove-metadata " ${name} " --zone " ${zone} " --keys=kube-master-internal-ip
2967
2969
run-gcloud-command " ${name} " " ${zone} " ' sudo ip route del to local ' ${ip} ' /32 dev $(ip route | grep default | awk ' \' ' {print $5}' \' ' )' || true
2968
2970
return $?
2969
2971
}
You can’t perform that action at this time.
0 commit comments