Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 1569770

Browse files
authored
Merge pull request #350 from pbx0/script-updates
support self-hosted etcd in quickstart scripts
2 parents a1bcf5f + d1a45d8 commit 1569770

File tree

5 files changed

+33
-31
lines changed

5 files changed

+33
-31
lines changed

hack/quickstart/init-master.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ REMOTE_PORT=${REMOTE_PORT:-22}
66
CLUSTER_DIR=${CLUSTER_DIR:-cluster}
77
IDENT=${IDENT:-${HOME}/.ssh/id_rsa}
88
SSH_OPTS=${SSH_OPTS:-}
9+
SELF_HOST_ETCD=${SELF_HOST_ETCD:-false}
910

1011
BOOTKUBE_REPO=${BOOTKUBE_REPO:-quay.io/coreos/bootkube}
1112
BOOTKUBE_VERSION=${BOOTKUBE_VERSION:-v0.3.9}
@@ -37,16 +38,25 @@ function init_master_node() {
3738
systemctl daemon-reload
3839
systemctl stop update-engine; systemctl mask update-engine
3940

41+
etcd_render_flags=""
42+
etcd_start_flags=""
43+
4044
# Start etcd.
41-
configure_etcd
42-
systemctl enable etcd-member; sudo systemctl start etcd-member
45+
if [ "$SELF_HOST_ETCD" = true ] ; then
46+
echo "WARNING: THIS IS NOT YET FULLY WORKING - merely here to make ongoing testing easier"
47+
etcd_render_flags="--etcd-servers=http://10.3.0.15:2379 --experimental-self-hosted-etcd"
48+
etcd_start_flags="--etcd-server=http://${COREOS_PRIVATE_IPV4}:12379 --experimental-self-hosted-etcd"
49+
else
50+
configure_etcd
51+
systemctl enable etcd-member; sudo systemctl start etcd-member
52+
fi
4353

4454
# Render cluster assets
4555
/usr/bin/rkt run \
4656
--volume home,kind=host,source=/home/core \
4757
--mount volume=home,target=/core \
4858
--trust-keys-from-https --net=host ${BOOTKUBE_REPO}:${BOOTKUBE_VERSION} --exec \
49-
/bootkube -- render --asset-dir=/core/assets --api-servers=https://${COREOS_PUBLIC_IPV4}:443,https://${COREOS_PRIVATE_IPV4}:443
59+
/bootkube -- render --asset-dir=/core/assets --api-servers=https://${COREOS_PUBLIC_IPV4}:443,https://${COREOS_PRIVATE_IPV4}:443 ${etcd_render_flags}
5060

5161
# Move the local kubeconfig into expected location
5262
chown -R core:core /home/core/assets
@@ -61,8 +71,10 @@ function init_master_node() {
6171
/usr/bin/rkt run \
6272
--volume home,kind=host,source=/home/core \
6373
--mount volume=home,target=/core \
74+
--volume manifests,kind=host,source=/etc/kubernetes/manifests \
75+
--mount volume=manifests,target=/etc/kubernetes/manifests \
6476
--net=host ${BOOTKUBE_REPO}:${BOOTKUBE_VERSION} --exec \
65-
/bootkube -- start --asset-dir=/core/assets
77+
/bootkube -- start --asset-dir=/core/assets ${etcd_start_flags}
6678
}
6779

6880
[ "$#" == 1 ] || usage
@@ -81,7 +93,7 @@ if [ "${REMOTE_HOST}" != "local" ]; then
8193

8294
# Copy self to remote host so script can be executed in "local" mode
8395
scp -i ${IDENT} -P ${REMOTE_PORT} ${SSH_OPTS} ${BASH_SOURCE[0]} core@${REMOTE_HOST}:/home/core/init-master.sh
84-
ssh -i ${IDENT} -p ${REMOTE_PORT} ${SSH_OPTS} core@${REMOTE_HOST} "sudo BOOTKUBE_REPO=${BOOTKUBE_REPO} BOOTKUBE_VERSION=${BOOTKUBE_VERSION} /home/core/init-master.sh local"
96+
ssh -i ${IDENT} -p ${REMOTE_PORT} ${SSH_OPTS} core@${REMOTE_HOST} "sudo BOOTKUBE_REPO=${BOOTKUBE_REPO} BOOTKUBE_VERSION=${BOOTKUBE_VERSION} SELF_HOST_ETCD=${SELF_HOST_ETCD} /home/core/init-master.sh local"
8597

8698
# Copy assets from remote host to a local directory. These can be used to launch additional nodes & contain TLS assets
8799
mkdir ${CLUSTER_DIR}

hack/quickstart/init-worker.sh

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,17 @@ 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/client.crt /home/core/client.key
28-
}
29-
3016
# Initialize a worker node
3117
function init_worker_node() {
32-
extract_master_endpoint
3318

3419
# Setup kubeconfig
3520
mkdir -p /etc/kubernetes
3621
cp ${KUBECONFIG} /etc/kubernetes/kubeconfig
37-
# Pulled out of the kubeconfig in extract_master_endpoint. Other installations should
38-
# place the root CA here manually.
39-
mv /home/core/ca.crt /etc/kubernetes/ca.crt
22+
# Pulled out of the kubeconfig. Other installations should place the root
23+
# CA here manually.
24+
grep 'certificate-authority-data' ${KUBECONFIG} | awk '{print $2}' | base64 -d > /etc/kubernetes/ca.crt
4025

41-
sed "s/{{apiserver}}/${MASTER_PRIV}/" /home/core/kubelet.worker > /etc/systemd/system/kubelet.service
42-
rm /home/core/kubelet.worker
26+
mv /home/core/kubelet.worker /etc/systemd/system/kubelet.service
4327

4428
# Start services
4529
systemctl daemon-reload

hack/quickstart/kubelet.master

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ ExecStartPre=/bin/mkdir -p /srv/kubernetes/manifests
1313
ExecStartPre=/bin/mkdir -p /var/lib/cni
1414
ExecStartPre=-/usr/bin/rkt rm --uuid-file=/var/run/kubelet-pod.uuid
1515
ExecStart=/usr/lib/coreos/kubelet-wrapper \
16-
--api-servers=https://${COREOS_PRIVATE_IPV4}:443 \
1716
--kubeconfig=/etc/kubernetes/kubeconfig \
17+
--require-kubeconfig \
1818
--client-ca-file=/etc/kubernetes/ca.crt \
1919
--anonymous-auth=false \
2020
--cni-conf-dir=/etc/kubernetes/cni/net.d \

hack/quickstart/kubelet.worker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ ExecStartPre=/bin/mkdir -p /etc/kubernetes/cni/net.d
1111
ExecStartPre=/bin/mkdir -p /var/lib/cni
1212
ExecStartPre=-/usr/bin/rkt rm --uuid-file=/var/run/kubelet-pod.uuid
1313
ExecStart=/usr/lib/coreos/kubelet-wrapper \
14-
--api-servers=https://{{apiserver}}:443 \
1514
--kubeconfig=/etc/kubernetes/kubeconfig \
15+
--require-kubeconfig \
1616
--client-ca-file=/etc/kubernetes/ca.crt \
1717
--anonymous-auth=false \
1818
--cni-conf-dir=/etc/kubernetes/cni/net.d \

hack/tests/conformance-gce.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ BOOTKUBE_REPO=${BOOTKUBE_REPO:-}
3131
BOOTKUBE_VERSION=${BOOTKUBE_VERSION:-}
3232
COREOS_CHANNEL=${COREOS_CHANNEL:-'coreos-stable'}
3333
WORKER_COUNT=4
34+
SELF_HOST_ETCD=${SELF_HOST_ETCD:-false}
35+
3436
GCE_PREFIX=${GCE_PREFIX:-'bootkube-ci'}
37+
GCE_SERVICE_ACCOUNT=${GCE_SERVICE_ACCOUNT:-'bootkube-ci'}
38+
GCE_PROJECT=${GCE_PROJECT:-coreos-gce-testing}
3539

3640
function cleanup {
3741
gcloud compute instances delete --quiet --zone us-central1-a ${GCE_PREFIX}-m1 || true
@@ -45,8 +49,8 @@ function cleanup {
4549
function init {
4650
curl https://sdk.cloud.google.com | bash
4751
source ~/.bashrc
48-
gcloud config set project coreos-gce-testing
49-
gcloud auth activate-service-account ${GCE_PREFIX}@coreos-gce-testing.iam.gserviceaccount.com --key-file=/build/keyfile
52+
gcloud config set project ${GCE_PROJECT}
53+
gcloud auth activate-service-account ${GCE_SERVICE_ACCOUNT}@${GCE_PROJECT}.iam.gserviceaccount.com --key-file=/build/keyfile
5054
apt-get update && apt-get install -y jq
5155

5256
ssh-keygen -t rsa -f /root/.ssh/id_rsa -N ""
@@ -64,7 +68,7 @@ function add_master {
6468

6569
MASTER_IP=$(gcloud compute instances list ${GCE_PREFIX}-m1 --format=json | jq --raw-output '.[].networkInterfaces[].accessConfigs[].natIP')
6670
cd /build/bootkube/hack/quickstart && SSH_OPTS="-o StrictHostKeyChecking=no" \
67-
CLUSTER_DIR=/build/cluster BOOTKUBE_REPO=${BOOTKUBE_REPO} BOOTKUBE_VERSION=${BOOTKUBE_VERSION} ./init-master.sh ${MASTER_IP}
71+
CLUSTER_DIR=/build/cluster BOOTKUBE_REPO=${BOOTKUBE_REPO} BOOTKUBE_VERSION=${BOOTKUBE_VERSION} SELF_HOST_ETCD=${SELF_HOST_ETCD} ./init-master.sh ${MASTER_IP}
6872
}
6973

7074
function add_workers {
@@ -111,6 +115,8 @@ else
111115
"--mount volume=keyfile,target=/build/keyfile " \
112116
)
113117

118+
#TODO(pb): See if there is a way to make the --inherit-env option replace
119+
#passing all the variables manually.
114120
sudo rkt run --insecure-options=image ${RKT_OPTS} docker://golang:1.7.4 --exec /bin/bash -- -c \
115-
"IN_CONTAINER=true BOOTKUBE_REPO=${BOOTKUBE_REPO} BOOTKUBE_VERSION=${BOOTKUBE_VERSION} COREOS_CHANNEL=${COREOS_CHANNEL} /build/bootkube/hack/tests/$(basename $0)"
121+
"IN_CONTAINER=true BOOTKUBE_REPO=${BOOTKUBE_REPO} BOOTKUBE_VERSION=${BOOTKUBE_VERSION} COREOS_CHANNEL=${COREOS_CHANNEL} GCE_PREFIX=${GCE_PREFIX} GCE_SERVICE_ACCOUNT=${GCE_SERVICE_ACCOUNT} GCE_PROJECT=${GCE_PROJECT} SELF_HOST_ETCD=${SELF_HOST_ETCD} /build/bootkube/hack/tests/$(basename $0)"
116122
fi

0 commit comments

Comments
 (0)