Connecting to etcd2
etcdv2 is being deprecated
With the release of etcd3 from beta, Compose will soon no longer support etcd2 on the platform. The deprecation schedule is:
November 1st, 2017 - No more etcd2 provisions.
February 1st, 2018 - Official EOL
May 1st, 2018 - Start spinning down deployments.Please plan on upgrading or deprovisioning your etcd2 deployments accordingly.
Compose etcd deployments use Let's Encrypt certificates to secure traffic to and from your deployment.
To connect using the https connection strings found on the Overview page under Connection info you will need to have the Let's Encrypt certificate as part of the certificate store for your OS or runtime environment.
You can test that you can connect from your current machine by entering the HTTPS connection string with the admin user and password in a browser window.
Command-line Utilities
curl
To use command-line utilities pass the path and filename of that certificate to the utility.
Let's start with simple HTTP requests. You can use a utility such as curl
to issue such requests from the command line. For example:
curl -L https://user:[email protected]:port/v2/keys/
This command, with appropriate username, password and host would request the keys
at the top of the etcd hierarchy.
etcdctl
The etcdctl
command, which provides a more etcd-centric command set, which includes ls
, set
, get
, mk
, mkdir
, update
and so on.
Getting etcdctl
The
etcdctl
command is available in the etcd distribution which can be downloaded from the coreos/etcd repository. If you are a Mac user, you may find it easier to install Homebrew and then runbrew install etcd
. Either method should give you a binaryetcdctl
command.
etcdctl --no-sync --endpoints https://host1:port1,https://host2:post2 -u user:pass ls /
This command has the same effect as the previous curl command. Further information on etcdctl can be found in its README file.
Applications - Go
Here's an extract of code for Go using the etcd Go driver. In this example we import the CoreOS etcd client for Go like so:
import (
"io/ioutil"
"net/http"
...
"github.com/coreos/etcd/client"
...
)
The next block of code performs the actual connection. Note that endpointlist
, username
and password
are strings being passed in from the command-line.
endpoints := strings.Split(*endpointlist, ",")
// When we create the etcd client configuration, use that transport
cfg := client.Config{
Endpoints: endpoints,
HeaderTimeoutPerRequest: time.Minute,
Username: *username,
Password: *password,
}
// And create your client as normal.
etcdclient, err := client.New(cfg)
A full example using this code is available in the examplco3 repository - that's the final example from our Essentially Etcd series (part 1, part 2 and part 3 where we explore, with code, working with etcd and Go).
Still Need Help?
If this article didn't solve things, summon a human and get some help!
Updated almost 3 years ago