kubernetes: support auto-init via metadata

Set KUBE_MASTER_AUTOINIT when using boot.sh to enable. User will need to pick
up the token for other nodes using `kubeadm token list`.

Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
Ian Campbell 2017-09-20 12:03:42 +01:00
parent 3ce260cb9a
commit 5c4c25cac6
3 changed files with 19 additions and 4 deletions

View File

@ -23,7 +23,14 @@ suffix=".iso"
if [ $# -eq 0 ] ; then
img="kube-master"
data=""
# If $KUBE_MASTER_AUTOINIT is set, including if it is set to ""
# then we configure for auto init. If it is completely unset then
# we do not.
if [ -n "${KUBE_MASTER_AUTOINIT+x}" ] ; then
data="{\"kubeadm\": {\"init\": \"${KUBE_MASTER_AUTOINIT}\"} }"
else
data=""
fi
state="kube-master-state"
: ${KUBE_VCPUS:=$KUBE_MASTER_VCPUS}
@ -44,7 +51,7 @@ elif [ $# -gt 1 ] || [ $# -eq 1 -a -n "${KUBE_PRESERVE_STATE}" ] ; then
img="kube-node"
name="node-${1}"
shift
data="${*}"
data="{\"kubeadm\": {\"join\": \"${*}\"} }"
state="kube-${name}-state"
: ${KUBE_VCPUS:=$KUBE_NODE_VCPUS}

View File

@ -1,6 +1,6 @@
#!/bin/sh
set -e
kubeadm init --skip-preflight-checks --kubernetes-version @KUBERNETES_VERSION@
kubeadm init --skip-preflight-checks --kubernetes-version @KUBERNETES_VERSION@ $@
for i in /etc/kubeadm/kube-system.init/*.yaml ; do
if [ -e "$i" ] ; then
echo "Applying "$(basename "$i")

View File

@ -10,7 +10,15 @@ fi
if [ -e /etc/kubelet.conf ] ; then
. /etc/kubelet.conf
fi
if [ -e /var/config/userdata ] ; then
if [ -e /var/config/kubeadm/init ] ; then
echo "kubelet.sh: init cluster with metadata \"$(cat /var/config/kubeadm/init)\""
# This needs to be in the background since it waits for kubelet to start.
# We skip printing the token so it is not persisted in the log.
kubeadm-init.sh --skip-token-print $(cat /var/config/kubeadm/init) &
elif [ -e /var/config/kubeadm/join ] ; then
echo "kubelet.sh: joining cluster with metadata \"$(cat /var/config/kubeadm/join)\""
kubeadm join --skip-preflight-checks $(cat /var/config/kubeadm/join)
elif [ -e /var/config/userdata ] ; then
echo "kubelet.sh: joining cluster with metadata \"$(cat /var/config/userdata)\""
kubeadm join --skip-preflight-checks $(cat /var/config/userdata)
fi