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
This commit is contained in:
Tom Cammann 2015-05-24 02:34:39 -07:00
parent eb7abda967
commit 680a5bab0a
2 changed files with 37 additions and 13 deletions

View File

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

View File

@ -13,19 +13,43 @@ write_files:
awk '$1 == "inet" {print $2}' | cut -f1 -d/) awk '$1 == "inet" {print $2}' | cut -f1 -d/)
# wait for master api # 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 sleep 1
done done
cpu=$(($(nproc) * 1000)) if [ "$1" = "-u" ]; then
memory=$(awk '/MemTotal: /{print $2 * 1024}' /proc/meminfo) 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- cat <<EOF | kubectl create -s ${master_url} -f-
apiVersion: v1beta1 apiVersion: v1beta1
id: $myip id: $myip
kind: Minion kind: Minion
resources: resources:
capacity: capacity:
cpu: $cpu cpu: $cpu
memory: $memory memory: $memory
EOF 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