Where should I keep service files for a CoreOS cluster, and how should I load them?

210 views Asked by At

I would like to deploy a cluster of CouchDB servers behind a load balancer, and have the services do that magical etcd discovery. After finishing the CoreOS quickstart, I am at a loss for how to actually use what I have just learned in a project of my own, and I can't tell which of the more in-depth tutorials would get me going.

In the demo, I wrote a service file inside of a running instance, and then used fleetctl to start it. What I would like to do, is have that service file under version control in my project, like the Dockerfile. How do I get the CoreOS cluster to initialize using an external service file?

I am developing locally using Vagrant, but I will deploy to AWS as soon.

1

There are 1 answers

0
Greg On BEST ANSWER

I did a quick search for coreos on aws and the first link was the amazon product. they have pretty good documentation on how to do that. from a high level, you need to use a cloud-config file. when you boot your coreos (that is, instantiate the ec2 image) you can pass a text file in the user_data. that text file lets you do a couple of things, mainly write files and then define units. Units are your services. Anything in the cloud-config file will be started automatically when you 'boot' your ec2 instance.

Or, you can use the 'write_files' directive in the cloud_config to create each individual service. For example, my cloud config has:

write_files:
  - path: /etc/systemd/system/skydns.service
    permissions: 0644
    owner: core:core
    content: |
      [Unit]
      Description=SkyDNS service discovery
      After=flanneld.service docker.service etcd.service
      Requires=flanneld.service docker.service etcd.service

      [Service]
      Restart=always
      ExecStartPre=-/usr/bin/env docker kill skydns
      ExecStartPre=-/usr/bin/env docker rm skydns
      ExecStartPre=/usr/bin/env docker pull tacodata/skydns-coreos
      ExecStart=/usr/bin/env bash -c '/usr/bin/docker run --name skydns -p 53:53/udp test/skydns-nameservers 8.8.8.8:53 -domain local
      ExecStop=-/usr/bin/docker stop skydns
  [Install]
  WantedBy = multi-user.target

There is a bit of a learning curve to the systemd init stuff. I don't know how a cloud-config file would play with the vagrant environment either. many platforms use a cloud-config, so, that is a good think to start with.

-g