Backport "tie minion registration to kubelet activation"

this changes moves minion registration out of the
configure-kubernetes-minion.sh script and puts it in a systemd service
unit that tracks the state of the kubelet.service and
registers/unregisters the minion as appropriate.

heat-coe-templates: I6532a9bc08bbb2351a2ae5d29bc884cb3cad3508

Change-Id: I2d6a722d63b2b465e880daff87b8307132f82a32
changes/89/192589/4
Tom Cammann 7 years ago
parent eb7abda967
commit 680a5bab0a
  1. 2
      magnum/templates/heat-kubernetes/fragments/configure-kubernetes-minion.sh
  2. 48
      magnum/templates/heat-kubernetes/fragments/kube-register.yaml

@ -32,5 +32,5 @@ cat >> /etc/environment <<EOF
KUBERNETES_MASTER=http://$KUBE_MASTER_IP:8080
EOF
/usr/local/bin/kube-register
systemctl enable kube-register

@ -13,19 +13,43 @@ write_files:
awk '$1 == "inet" {print $2}' | cut -f1 -d/)
# wait for master api
until curl -sf "${master_url}/healthz"; do
until curl -o /dev/null -sf "${master_url}/healthz"; do
echo "waiting for kubernetes master"
sleep 1
done
cpu=$(($(nproc) * 1000))
memory=$(awk '/MemTotal: /{print $2 * 1024}' /proc/meminfo)
if [ "$1" = "-u" ]; then
echo "unregistering minion $myip"
kubectl -s ${master_url} delete minion/$myip
else
echo "registering minion $myip"
cpu=$(($(nproc) * 1000))
memory=$(awk '/MemTotal: /{print $2 * 1024}' /proc/meminfo)
cat <<EOF | kubectl create -s ${master_url} -f-
apiVersion: v1beta1
id: $myip
kind: Minion
resources:
capacity:
cpu: $cpu
memory: $memory
EOF
cat <<EOF | kubectl create -s ${master_url} -f-
apiVersion: v1beta1
id: $myip
kind: Minion
resources:
capacity:
cpu: $cpu
memory: $memory
EOF
fi
- path: /etc/systemd/system/kube-register.service
permissions: "0644"
owner: root
content: |
[Unit]
Description=Register/unregister this node with the Kubernetes master
Requires=kubelet.service
After=kubelet.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/kube-register
ExecStop=/usr/local/bin/kube-register -u
[Install]
WantedBy=kubelet.service

Loading…
Cancel
Save