22set -euo pipefail
33
44REMOTE_HOST=$1
5+ KUBECONFIG=$2
56REMOTE_PORT=${REMOTE_PORT:- 22}
6- CLUSTER_DIR=${CLUSTER_DIR:- cluster}
77IDENT=${IDENT:- ${HOME} / .ssh/ id_rsa}
88SSH_OPTS=${SSH_OPTS:- }
99
@@ -13,41 +13,57 @@ function usage() {
1313 exit 1
1414}
1515
16+ function extract_master_endpoint (){
17+ grep ' certificate-authority-data' ${KUBECONFIG} | awk ' {print $2}' | base64 -d > /home/core/ca.crt
18+ grep ' client-certificate-data' ${KUBECONFIG} | awk ' {print $2}' | base64 -d > /home/core/client.crt
19+ grep ' client-key-data' ${KUBECONFIG} | awk ' {print $2}' | base64 -d > /home/core/client.key
20+
21+ MASTER_PUB=" $( awk ' /server:/ {print $2}' ${KUBECONFIG} | awk -F/ ' {print $3}' | awk -F: ' {print $1}' ) "
22+ # TODO (aaron): The -k was added with the gce conformance tests - figure out why it's needed here.
23+ # The certs are seemingly signed correctly, but says no SAN for MASTER_PUB
24+ MASTER_PRIV=$( curl -k https://${MASTER_PUB} :443/api/v1/namespaces/default/endpoints/kubernetes \
25+ --cacert /home/core/ca.crt --cert /home/core/client.crt --key /home/core/client.key \
26+ | jq -r ' .subsets[0].addresses[0].ip' )
27+ rm -f /home/core/ca.crt /home/core/client.crt /home/core/client.key
28+ }
29+
1630# Initialize a worker node
1731function init_worker_node() {
18- # Setup bootstrap-kubeconfig
32+ extract_master_endpoint
33+
34+ # Setup kubeconfig
1935 mkdir -p /etc/kubernetes
20- mv /home/core/bootstrap-kubeconfig /etc/kubernetes/bootstrap- kubeconfig
36+ cp ${KUBECONFIG} /etc/kubernetes/kubeconfig
2137
22- # Move kubelet service file
23- mv /home/core/kubelet.worker /etc/systemd/system/kubelet.service
38+ sed " s/{{apiserver}}/ ${MASTER_PRIV} / " /home/core/ kubelet.worker > /etc/systemd/system/kubelet.service
39+ rm /home/core/kubelet.worker
2440
2541 # Start services
2642 systemctl daemon-reload
2743 systemctl stop update-engine; systemctl mask update-engine
2844 systemctl enable kubelet; sudo systemctl start kubelet
2945}
3046
31- [ " $# " == 1 ] || usage
47+ [ " $# " == 2 ] || usage
3248
3349# This script can execute on a remote host by copying itself + kubelet service unit to remote host.
3450# After assets are available on the remote host, the script will execute itself in "local" mode.
3551if [ " ${REMOTE_HOST} " != " local" ]; then
3652
37- # Copy kubelet service file and bootstrap- kubeconfig to remote host
53+ # Copy kubelet service file and kubeconfig to remote host
3854 scp -i ${IDENT} -P ${REMOTE_PORT} ${SSH_OPTS} kubelet.worker core@${REMOTE_HOST} :/home/core/kubelet.worker
39- scp -i ${IDENT} -P ${REMOTE_PORT} ${SSH_OPTS} ${CLUSTER_DIR} /auth/bootstrap-kubeconfig core@${REMOTE_HOST} :/home/core/bootstrap- kubeconfig
55+ scp -i ${IDENT} -P ${REMOTE_PORT} ${SSH_OPTS} ${KUBECONFIG} core@${REMOTE_HOST} :/home/core/kubeconfig
4056
4157 # Copy self to remote host so script can be executed in "local" mode
4258 scp -i ${IDENT} -P ${REMOTE_PORT} ${SSH_OPTS} ${BASH_SOURCE[0]} core@${REMOTE_HOST} :/home/core/init-worker.sh
43- ssh -i ${IDENT} -p ${REMOTE_PORT} ${SSH_OPTS} core@${REMOTE_HOST} " sudo /home/core/init-worker.sh local"
59+ ssh -i ${IDENT} -p ${REMOTE_PORT} ${SSH_OPTS} core@${REMOTE_HOST} " sudo /home/core/init-worker.sh local /home/core/kubeconfig "
4460
4561 # Cleanup
4662 ssh -i ${IDENT} -p ${REMOTE_PORT} ${SSH_OPTS} core@${REMOTE_HOST} " rm /home/core/init-worker.sh"
4763
4864 echo
4965 echo " Node bootstrap complete. It may take a few minutes for the node to become ready. Access your kubernetes cluster using:"
50- echo " kubectl --kubeconfig=${CLUSTER_DIR} /auth/admin-kubeconfig get nodes"
66+ echo " kubectl --kubeconfig=${KUBECONFIG} get nodes"
5167 echo
5268
5369# Execute this script locally on the machine, assumes a kubelet.service file has already been placed on host.
0 commit comments