Testing CoreOS on homelab servers - part 1
I've been working on some scripts to build and deploy cloud-config files in my homelab.
core01: 192.168.61
core02: 192.168.62
core03: 192.168.63
core04: 192.168.64
Create and deploy cluster configuration
From my Mac, build and deploy new cloud-config with:
$ ./create.and.deploy.sh
For each core server in the homelab, the scripts build and deploy configuration files for my coreos test cluster.
E.g for server core01
#cloud-config
#version: 20161210_203041
hostname: "core01"
ssh_authorized_keys:
- ssh-rsa ...
coreos:
etcd2:
# Static cluster
name: core01
advertise-client-urls: http://192.168.1.61:2379
initial-advertise-peer-urls: http://192.168.1.61:2380
initial-cluster: "core01=http://192.168.1.61:2380,core02=http://192.168.1.62:2380,core03=http://192.168.1.63:2380,core04=http://192.168.1.64:2380"
initial-cluster-state: new
listen-client-urls: http://0.0.0.0:2379,http://0.0.0.0:4001
listen-peer-urls: http://0.0.0.0:2380,http://0.0.0.0:7001
fleet:
public-ip: $public_ipv4
metadata: "role=services"
flannel:
interface: $public_ipv4
update:
reboot-strategy: "etcd-lock"
units:
- name: 00-eth0.network
runtime: true
content: |
[Match]
Name=eno1
[Network]
DNS=192.168.1.1
Address=192.168.1.61/24
Gateway=192.168.1.1
Domains=home.lab
- name: etcd2.service
command: start
- name: fleet.service
command: start
- name: flanneld.service
drop-ins:
- name: 50-network-config.conf
content: |
[Service]
ExecStartPre=/usr/bin/etcdctl set /coreos.com/network/config '{ "Network": "10.1.0.0/16" }'
command: start
- name: docker-tcp.socket
command: start
enable: true
content: |
[Unit]
Description=Docker Socket for the API
[Socket]
ListenStream=2375
Service=docker.service
BindIPv6Only=both
[Install]
WantedBy=sockets.target
write_files:
- path: "/etc/motd"
permissions: "0644"
owner: "root"
content: |
--- My CoreOS Cluster (core01) ---
Checking cluster status
core@core01 ~ $ etcdctl member list
4374c5ef9f2370d6: name=core03 peerURLs=http://192.168.1.63:2380 clientURLs=http://192.168.1.63:2379 isLeader=true
45337feea7d7a60f: name=core01 peerURLs=http://192.168.1.61:2380 clientURLs=http://192.168.1.61:2379 isLeader=false
6688d9448380b482: name=core02 peerURLs=http://192.168.1.62:2380 clientURLs=http://192.168.1.62:2379 isLeader=false
c9a76f89ee66e035: name=core04 peerURLs=http://192.168.1.64:2380 clientURLs=http://192.168.1.64:2379 isLeader=false
core@core01 ~ $ fleetctl list-machines
MACHINE IP METADATA
2d0e73b6... 192.168.1.64 role=services
497f6384... 192.168.1.61 role=services
9f8f9d8a... 192.168.1.62 role=services
c6d410a0... 192.168.1.63 role=services
Launching containers and testing failover
Container configuration
vi myapp.service
--- snip begin ---[Unit]
Description=MyApp
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill busybox1
ExecStartPre=-/usr/bin/docker rm busybox1
ExecStartPre=/usr/bin/docker pull busybox
ExecStart=/usr/bin/docker run --name busybox1 busybox /bin/sh -c "trap 'exit 0' INT TERM; while true; do echo Hello World; sleep 1; done"
ExecStop=/usr/bin/docker stop busybox1
--- snip end ---
vi apache@.service
--- snip begin ---
[Unit]
Description=My Apache Frontend
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill apache1
ExecStartPre=-/usr/bin/docker rm apache1
ExecStartPre=/usr/bin/docker pull coreos/apache
ExecStart=/usr/bin/docker run --rm --name apache1 -p 80:80 coreos/apache /usr/sbin/apache2ctl -D FOREGROUND
ExecStop=/usr/bin/docker stop apache1
[X-Fleet]
Conflicts=apache@*.service
--- snip end ---
Launch the containers
core@core01 ~ $ fleetctl start myapp.service
core@core01 ~ $ fleetctl start apache@1
core@core01 ~ $ fleetctl start apache@2
core@core01 ~ $ fleetctl list-units
UNIT MACHINE ACTIVE SUB
apache@1.service 2d0e73b6.../192.168.1.64 active running
apache@2.service c6d410a0.../192.168.1.63 active running
myapp.service 2d0e73b6.../192.168.1.64 active running
Testing failover
core@core04 ~ $ sudo reboot
core@core01 ~ $ fleetctl list-units
UNIT MACHINE ACTIVE SUB
apache@1.service 497f6384.../192.168.1.61 active running
apache@2.service c6d410a0.../192.168.1.63 active running
myapp.service 9f8f9d8a.../192.168.1.62 active running