TryCoreOS(2)

TurnToJPG -->


Local Discovery Service

Take a look at the yaml configuration file:

  etcd2:
    # generate a new token for each unique cluster from
https://discovery.etcd.io/new?size=3
    # specify the initial size of your cluster with ?size=X
    discovery: https://discovery.etcd.io/4add2186302763c8876afd1684ca06fe

This means all of you coreos nodes should reach the internet, what if we deploy a coreos cluster offline? We need to deploy a local discovery service.

ArchLinux etcd2 Example

Download the etcd v2.3.7 and extract it to specified directory via :

$ curl -L \
https://github.com/coreos/etcd/releases/download/v2.3.7/etcd-v2.3.7-linux-amd64.tar.gz \
-o etcd-v2.3.7-linux-amd64.tar.gz
$ tar xzvf etcd-v2.3.7-linux-amd64.tar.gz

Create a customized systemd item like following, you should change the etcd executable file to your own positioni, also specify your own data-dir:

$ sudo mkdir -p /var1/Nov14/etcd/etcd-v2.3.7-linux-amd64/data
$ sudo vim /usr/lib/systemd/system/myetcd.service 
[Unit]
Description=myownetcd
After=multi-user.service

[Service]
ExecStart=/var1/Nov14/etcd/etcd-v2.3.7-linux-amd64/etcd
--data-dir=/var1/Nov14/etcd/etcd-v2.3.7-linux-amd64/data
--name=single-etcd-service  --listen-client-urls
'http://0.0.0.0:2379,http://0.0.0.0:4001' --advertise-client-urls
'http://0.0.0.0:2379,http://0.0.0.0:4001'
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=myownetcd

[Install]
WantedBy=multi-user.target

Start and enable the service:

$ sudo systemctl enable myetcd.service
$ sudo systemctl start myetcd.service

Test etcd

Very simple test:

$ ./etcdctl set mykey "this is awesome"
$ ./etcdctl get mykey
this is awesome

Create own discovery

Use uuidgen for generating a new uuid:

$ uuidgen 
557a2133-88f3-41d2-9b27-9fd4081f7b41

Use this new generated uuid for generating a 3-node cluster:

$ curl -X PUT \
http://172.17.8.1:4001/v2/keys/557a2133-88f3-41d2-9b27-9fd4081f7b41/_config/size \
-d value=3

Now you could examine the generated etcd items:

$ /var1/Nov14/etcd/etcd-v2.3.7-linux-amd64/etcdctl ls --recursive /
/mykey
/557a2133-88f3-41d2-9b27-9fd4081f7b41

Use your own discovery

Change the definition in yaml file:

    #discovery: https://discovery.etcd.io/4add2186302763c8876afd1684ca06fe
    discovery: http://172.17.8.1:4001/v2/keys/557a2133-88f3-41d2-9b27-9fd4081f7b41

Now re-create the coreOS cluster, you will see the coreOS cluster could work properly again.

Start First Docker

Enable registry-mirror in coreOS:

# echo 'DOCKER_OPTS="--registry-mirror=http://1a653205.m.daocloud.io"' >> /run/flannel_docker_opts.env
# systemctl restart docker
# docker pull busybox

Now write the hello.service definition:

# vim /etc/systemd/system/hello.service
[Unit] 
Description=Hello World 
After=docker.service 
Requires=docker.service 

[Service] 
TimeoutStartSec=0 
ExecStartPre=-/bin/docker kill busybox1 
ExecStartPre=-/bin/docker rm busybox1 
ExecStart=/bin/docker run --name busybox1 busybox /bin/sh -c "while true; do echo Hello World; sleep 1; done" 
ExecStop="/bin/docker kill busybox1"
ExecStopPost="/bin/docker rm busybox1"
 
[Install] 
WantedBy=multi-user.target

Start and enable the service via:

# systemctl start hello.service
# systemctl enable hello.service

Trouble-Shooting

Reset your etcd2 database:

$ sudo systemctl stop fleetd
$ sudo systemctl stop etcd2
$ sudo rm -rf /var/lib/etcd2/*
$ sudo rm -rf /etc/systemd/system/etcd* 
$ sudo reboot 

Then your etcd2 will be re-initialized.