Tanmay
Tanmay

Reputation: 404

How to change the cloud-config to specify a specific version of etcd

I am using core-os and configuring it with cloud-config files. I need to use a etcd-service for my application.

This is the relevant part of the cloud-config file.

- name: etcd.service
  command: start
  content: |
    [Unit]
    Description=etcd
    Requires=setup-network-environment.service
    After=setup-network-environment.service

    [Service]
    EnvironmentFile=/etc/network-environment
    User=etcd
    PermissionsStartOnly=true
    ExecStart=/usr/bin/etcd \
    --name ${DEFAULT_IPV4} \
    --addr ${DEFAULT_IPV4}:4001 \
    --bind-addr 0.0.0.0 \
    --discovery https://discovery.etcd.io/SOMEKEY \
    --data-dir /var/lib/etcd \
    --http-read-timeout 86400 \
    --peer-addr ${DEFAULT_IPV4}:7001 \
    --snapshot true
    Restart=always
    RestartSec=10s

I am not sure how to update the version of etcd.

Upvotes: 1

Views: 2088

Answers (3)

Rob
Rob

Reputation: 2456

The cloud-config parser has built in support for etcd2 and the new configuration parameters: https://coreos.com/docs/cluster-management/setup/cloudinit-cloud-config/#etcd2

An example:

#cloud-config

coreos:
  etcd2:
    # generate a new token for each unique cluster from https://discovery.etcd.io/new?size=3
    discovery: https://discovery.etcd.io/<token>
    # multi-region and multi-cloud deployments need to use $public_ipv4
    advertise-client-urls: http://$public_ipv4:2379
    initial-advertise-peer-urls: http://$private_ipv4:2380
    # listen on both the official ports and the legacy ports
    # legacy ports can be omitted if your application doesn't depend on them
    listen-client-urls: http://0.0.0.0:2379,http://0.0.0.0:4001
    listen-peer-urls: http://$private_ipv4:2380,http://$private_ipv4:7001

Upvotes: 0

Tanmay
Tanmay

Reputation: 404

Turns out etcd2 is already installed on coreos. It is currently shipped in the coreos-alpha 653 release, alongside etcd. To change it in the cloud-config, you just have to change

ExecStart=/usr/bin/etcd

to

ExecStart=/usr/bin/etcd2

and remove some flags which are deprecated in etcd2.

Upvotes: 1

Greg
Greg

Reputation: 6759

I have a template generator and I can tell it to switch between etcd and etcd2 by setting a single environment variable. One thing I did was use the etcd2.service name or etcd.service (I didn't just put the etcd2 configuration in the etcd unit section). That could work, but, you might think about changing all etcd.service references in your file to etcd2.service. Anyway, here is the ExecStart section for etcd2:

    ExecStart=/usr/bin/etcd2 \
    --name ${d['etcd']['name']} \
    --advertise-client-urls ${d['etcd']['advertise-client-urls']} \
    --discovery ${d['etcd']['discovery']} \
    --data-dir /var/lib/etcd \
    --initial-advertise-peer-urls ${d['etcd']['initial-advertise-peer-urls']} \
    --listen-client-urls ${d['etcd']['listen-client-urls']} \
    --listen-peer-urls ${d['etcd']['listen-peer-urls']}

Here are my env variables for d['etcd']:

"etcd": {
    "mver":"etcd2.service",
    "discovery":"http://discovery.etcd.io/SOMEKEY",
    "addr":"$private_ipv4:4001",
    "name":"$private_ipv4",
    "peer-addr":"$private_ipv4:7001",
    "advertise-client-urls":"http://$private_ipv4:2379",
    "initial-advertise-peer-urls":"http://$private_ipv4:2380",
    "listen-client-urls":"http://0.0.0.0:2379,http://0.0.0.0:4001",
    "listen-peer-urls":"http://$private_ipv4:2380,http://$private_ipv4:7001"
}

Somewhere I remember reading that $public_ipv4 was needed for one of these variables, put, I just went with the private ip for all of them. My environment here is digital ocean. Be sure to use coreos-alpha (at least I think that is still required at the time of this writing).

Upvotes: 0

Related Questions