From 049993fc3de9f06823538c84aa22a1cc5718d1d6 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Tue, 11 Apr 2017 18:47:39 +0100 Subject: [PATCH] demo: Switch etcd to use metadata Also add more services. Signed-off-by: Rolf Neugebauer --- projects/demo/etcd/README.md | 10 +++---- projects/demo/etcd/etcd.sh | 15 +++++----- projects/demo/etcd/etcd.yml | 41 ++++++++++++++++++++-------- projects/demo/etcd/infrakit-gcp.json | 19 +++++++++++-- projects/demo/etcd/infrakit.json | 12 ++++++++ 5 files changed, 71 insertions(+), 26 deletions(-) diff --git a/projects/demo/etcd/README.md b/projects/demo/etcd/README.md index c4b5ade77..0d759d824 100644 --- a/projects/demo/etcd/README.md +++ b/projects/demo/etcd/README.md @@ -22,9 +22,7 @@ This should create a HyperKit based, InfraKit managed `etcd` cluster with 5 `etc Start InfraKit: ``` -infrakit-flavor-vanilla & -infrakit-group-default & -../../../bin/infrakit-instance-hyperkit +./start-infrakit ``` Note: The HyperKit InfraKit plugin must be started from the directory @@ -35,10 +33,10 @@ Now, commit the new config: infrakit group commit infrakit.json ``` -To check if everything is fine, note down the IP address from one of -the nodes and then: +To check if everything is fine, we created (above) a local `etcd.local` docker image which already has the environment set up to contact the cluster: ``` -docker run --rm -t quay.io/coreos/etcd:v3.1.5 etcdctl --endpoints http://192.168.65.200:2379 member list +docker run --rm -ti etcd.local etcdctl member list +docker run --rm -ti etcd.local etcdctl cluster-health ``` You can perform rolling updates, by for example, switching the kernel version in `etcd.yml`, build a new moby, e.g., `moby build -name etcd-4.10 etcd`, update `infrakit.json`, and then commit the new configuration to InfraKit: `infrakit group commit infrakit.json`. diff --git a/projects/demo/etcd/etcd.sh b/projects/demo/etcd/etcd.sh index a812a16e0..a1224116d 100755 --- a/projects/demo/etcd/etcd.sh +++ b/projects/demo/etcd/etcd.sh @@ -4,7 +4,9 @@ set -x set -v -DATADIR=/var/lib/etcd +# Get initial cluster data from metadata +NAME_PREFIX="$(cat /etc/etcd/name_prefix)" +INIT_CLUSTER="$(cat /etc/etcd/init_cluster)" # Wait till we have an IP address IP="" @@ -13,13 +15,12 @@ while [ -z "$IP" ]; do sleep 1 done -# Name is infra+last octet of IP address -NUM=$(echo ${IP} | cut -d . -f 4) -PREFIX=$(echo ${IP} | cut -d . -f 1,2,3) -NAME=infra${NUM} +# Where to store data +DATADIR=/var/lib/etcd -# This should come from Metadata -INIT_CLUSTER="infra200=http://${PREFIX}.200:2380,infra201=http://${PREFIX}.201:2380,infra202=http://${PREFIX}.202:2380,infra203=http://${PREFIX}.203:2380,infra204=http://${PREFIX}.204:2380" +# Name is NAME_PREFIX+last octet of IP address +NUM=$(echo ${IP} | cut -d . -f 4) +NAME=${NAME_PREFIX}${NUM} # We currently have no easy way to determine if we join a cluster for # the first time or if we got restarted and need to join an existing diff --git a/projects/demo/etcd/etcd.yml b/projects/demo/etcd/etcd.yml index 957807766..82b81006a 100644 --- a/projects/demo/etcd/etcd.yml +++ b/projects/demo/etcd/etcd.yml @@ -31,13 +31,6 @@ onboot: - CAP_SYS_ADMIN rootfsPropagation: shared command: ["/mount.sh", "/var/lib/etcd"] -services: - - name: rngd - image: "mobylinux/rngd:3dad6dd43270fa632ac031e99d1947f20b22eec9@sha256:1c93c1db7196f6f71f8e300bc1d15f0376dd18e8891c8789d77c8ff19f3a9a92" - capabilities: - - CAP_SYS_ADMIN - oomScoreAdj: -800 - readonly: true - name: dhcpcd image: "mobylinux/dhcpcd:0d4012269cb142972fed8542fbdc3ff5a7b695cd" binds: @@ -48,7 +41,32 @@ services: - CAP_NET_BIND_SERVICE - CAP_NET_RAW net: host + command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] + - name: metadata + image: mobylinux/metadata:960e6c371c9a07cf512dfcfa9734a5e0db427e96 + net: host + binds: + - /dev:/dev + - /var:/var + - /etc/resolv.conf:/etc/resolv.conf + capabilities: + - all +services: + - name: rngd + image: "mobylinux/rngd:3dad6dd43270fa632ac031e99d1947f20b22eec9" + capabilities: + - CAP_SYS_ADMIN oomScoreAdj: -800 + readonly: true + - name: ntpd + image: "mobylinux/openntpd:a570316d7fc49ca1daa29bd945499f4963d227af" + capabilities: + - CAP_SYS_TIME + - CAP_SYS_NICE + - CAP_SYS_CHROOT + - CAP_SETUID + - CAP_SETGID + net: host - name: etcd image: "mobylinux/etcd" capabilities: @@ -61,10 +79,11 @@ services: net: host binds: - /var/lib/etcd:/var/lib/etcd + - /var/config/etcd:/etc/etcd outputs: - format: kernel+initrd -# - format: gcp -# project: docker4x -# bucket: rolf -# replace: true + - format: gcp + project: docker4x + bucket: rolf + replace: true diff --git a/projects/demo/etcd/infrakit-gcp.json b/projects/demo/etcd/infrakit-gcp.json index 7a952e298..339347f03 100644 --- a/projects/demo/etcd/infrakit-gcp.json +++ b/projects/demo/etcd/infrakit-gcp.json @@ -18,16 +18,31 @@ "Network": "rneugeba-demo", "Connect" : true, "MachineType": "n1-standard-1", + "DiskType": "pd-standard", "DiskSizeMb": 60, "DiskImage": "https://www.googleapis.com/compute/v1/projects/docker4x/global/images/etcd", - "DiskType": "pd-standard", + "AutoDeleteDisk": true, + "ReuseExistingDisk": false, "Scopes": [ ] } }, "Flavor": { "Plugin": "flavor-vanilla", "Properties": { - "Init": [ ], + "Init": [ + "{", + " \"etcd\": {", + " \"name_prefix\": {", + " \"perm\": \"0644\",", + " \"content\": \"server\"", + "},", + " \"init_cluster\": {", + " \"perm\": \"0644\",", + " \"content\": \"server200=http://10.132.0.200:2380,server201=http://10.132.0.201:2380,server202=http://10.132.0.202:2380,server203=http://10.132.0.203:2380,server204=http://10.132.0.204:2380\"", + "}", + "}", + "}" + ], "Tags": { "tier": "etcd-cluster", "project": "infrakit" diff --git a/projects/demo/etcd/infrakit.json b/projects/demo/etcd/infrakit.json index b9b83e274..c562fc5ef 100644 --- a/projects/demo/etcd/infrakit.json +++ b/projects/demo/etcd/infrakit.json @@ -23,6 +23,18 @@ "Plugin": "flavor-vanilla", "Properties": { "Init": [ + "{", + " \"etcd\": {", + " \"name_prefix\": {", + " \"perm\": \"0644\",", + " \"content\": \"server\"", + "},", + " \"init_cluster\": {", + " \"perm\": \"0644\",", + " \"content\": \"server200=http://192.168.65.200:2380,server201=http://192.168.65.201:2380,server202=http://192.168.65.202:2380,server203=http://192.168.65.203:2380,server204=http://192.168.65.204:2380\"", + "}", + "}", + "}" ], "Tags": { "tier": "etcd-cluster",