Skip to content

Commit

Permalink
Merge pull request kubernetes#89543 from bartekzurawski/fix-kube-up-g…
Browse files Browse the repository at this point in the history
…ce-private-restart

Set ip alias route on kubernetes-master during booting
  • Loading branch information
k8s-ci-robot authored Apr 24, 2020
2 parents 47daccb + 3e4744c commit e494b07
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
27 changes: 27 additions & 0 deletions cluster/gce/gci/kube-master-internal-route.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

METADATA_ENDPOINT="http://metadata.google.internal/computeMetadata/v1/instance/attributes/kube-master-internal-ip"
METADATA_HEADER="Metadata-Flavor: Google"
ip=$(curl -s --fail ${METADATA_ENDPOINT} -H "${METADATA_HEADER}")
if [ -n "$ip" ];
then
# Check if route is already set if not set it
if ! sudo ip route show table local | grep -q "$(echo "$ip" | cut -d'/' -f 1)";
then
sudo ip route add to local "${ip}/32" dev "$(ip route | grep default | awk '{print $5}')"
fi
fi
1 change: 1 addition & 0 deletions cluster/gce/gci/master-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ function create-master-instance-internal() {
metadata="${metadata},gci-docker-version=${KUBE_TEMP}/gci-docker-version.txt"
metadata="${metadata},kube-master-certs=${KUBE_TEMP}/kube-master-certs.yaml"
metadata="${metadata},cluster-location=${KUBE_TEMP}/cluster-location.txt"
metadata="${metadata},kube-master-internal-route=${KUBE_ROOT}/cluster/gce/gci/kube-master-internal-route.sh"
metadata="${metadata},${MASTER_EXTRA_METADATA}"

local disk="name=${master_name}-pd"
Expand Down
19 changes: 19 additions & 0 deletions cluster/gce/gci/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ write_files:
[Install]
WantedBy=kubernetes.target
- path: /etc/systemd/system/kube-master-internal-route.service
permissions: 0644
owner: root
content: |
[Unit]
Description=Configure kube internal route
After=kube-master-installation.service
[Service]
Type=oneshot
RemainAfterExit=yes
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
ExecStartPre=/bin/chmod 544 /home/kubernetes/bin/kube-master-internal-route.sh
ExecStart=/home/kubernetes/bin/kube-master-internal-route.sh
[Install]
WantedBy=kubernetes.target
- path: /etc/systemd/system/kube-master-configuration.service
permissions: 0644
owner: root
Expand Down Expand Up @@ -125,6 +143,7 @@ write_files:
runcmd:
- systemctl daemon-reload
- systemctl enable kube-master-installation.service
- systemctl enable kube-master-internal-route.service
- systemctl enable kube-master-configuration.service
- systemctl enable kube-container-runtime-monitor.service
- systemctl enable kubelet-monitor.service
Expand Down
4 changes: 3 additions & 1 deletion cluster/gce/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2947,7 +2947,8 @@ function attach-internal-master-ip() {
echo "Setting ${name}'s aliases to '${aliases}' (added ${ip})"
# Attach ${ip} to ${name}
gcloud compute instances network-interfaces update "${name}" --project "${PROJECT}" --zone "${zone}" --aliases="${aliases}"
run-gcloud-command "${name}" "${zone}" 'sudo ip route add to local '${ip}'/32 dev $(ip route | grep default | awk '\''{print $5}'\'')' || true
gcloud compute instances add-metadata "${name}" --zone "${zone}" --metadata=kube-master-internal-ip="${ip}"
run-gcloud-command "${name}" "${zone}" 'sudo /bin/bash /home/kubernetes/bin/kube-master-internal-route.sh' || true
return $?
}

Expand All @@ -2965,6 +2966,7 @@ function detach-internal-master-ip() {
echo "Setting ${name}'s aliases to '${aliases}' (removed ${ip})"
# Detach ${MASTER_NAME}-internal-ip from ${name}
gcloud compute instances network-interfaces update "${name}" --project "${PROJECT}" --zone "${zone}" --aliases="${aliases}"
gcloud compute instances remove-metadata "${name}" --zone "${zone}" --keys=kube-master-internal-ip
run-gcloud-command "${name}" "${zone}" 'sudo ip route del to local '${ip}'/32 dev $(ip route | grep default | awk '\''{print $5}'\'')' || true
return $?
}
Expand Down

0 comments on commit e494b07

Please sign in to comment.