From 2cfac0e8bbdfb487129f544a8142aa5d93b3e49e Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Fri, 7 Jul 2017 15:44:20 +0100 Subject: [PATCH] kubernetes: Expose each node's ssh port on the host starting from 2222 Port base is configurable (via $KUBE_PORT_BASE envvar). Master uses this and nodes use subsequent ports. Check that the node number is numeric so we can add them to things, but avoid worker node 0 since the port will clash with master. Signed-off-by: Ian Campbell --- projects/kubernetes/boot.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/projects/kubernetes/boot.sh b/projects/kubernetes/boot.sh index c11643a6b..2f69fc990 100755 --- a/projects/kubernetes/boot.sh +++ b/projects/kubernetes/boot.sh @@ -1,11 +1,25 @@ #!/bin/bash -eu +: ${KUBE_PORT_BASE:=2222} if [ $# -eq 0 ] ; then img="kube-master" + port=${KUBE_PORT_BASE} data="" state="kube-master-state" elif [ $# -gt 1 ] ; then + case $1 in + ''|*[!0-9]*) + echo "Node number must be a number" + exit 1 + ;; + 0) + echo "Node number must be greater than 0" + exit 1 + ;; + *) ;; + esac img="kube-node" name="node-${1}" + port=$((${KUBE_PORT_BASE} + $1)) shift data="${*}" state="kube-${name}-state" @@ -19,4 +33,4 @@ else fi set -x rm -rf "${state}" -../../bin/linuxkit run -cpus 2 -mem 4096 -state "${state}" -disk size=4G -data "${data}" "${img}" +../../bin/linuxkit run -publish $port:22 -cpus 2 -mem 4096 -state "${state}" -disk size=4G -data "${data}" "${img}"