The Etcd Cookbook is a library cookbook that provides custom resources for use in recipes.
This cookbook is concerned with the Etcd distributed key/value store as distributed by CoreOS, Inc.
This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit sous-chefs.org or come chat with us on the Chef Community Slack in #sous-chefs.
- Chef Infra Client 16+
- Network accessible web server hosting the etcd binary.
The following platforms have been tested with Test Kitchen. It will most likely work on other platforms as well
|---------------+--------+
| | 3.2.15 |
|---------------+--------+
| amazonlinux 2 | X |
|---------------+--------+
| centos-7 | X |
|---------------+--------+
| debian-9 | X |
|---------------+--------+
| debian-10 | X |
|---------------+--------+
| fedora | X |
|---------------+--------+
| ubuntu-16.04 | X |
|---------------+--------+
| ubuntu-18.04 | X |
|---------------+--------+
| ubuntu-20.04 | X |
|---------------+--------+
| opensuse-leap | X |
|---------------+--------+
- Add
depends 'etcd'to your cookbook's metadata.rb - Use the resources shipped in cookbook in a recipe, the same way you'd use core Chef resources (file, template, directory, package, etc).
etcd_service 'etcd0' do
advertise_client_urls 'http://127.0.0.1:2379'
listen_client_urls 'http://0.0.0.0:2379'
initial_advertise_peer_urls 'http://127.0.0.1:2380'
listen_peer_urls 'http://0.0.0.0:2380'
initial_cluster_token 'etcd-cluster-1'
initial_cluster 'etcd0=http://127.0.0.1:2380,etcd1=http://127.0.0.1:3380,etcd2=http://127.0.0.1:4380'
initial_cluster_state 'new'
action :start
ignore_failure true # required for the first cluster build
end
etcd_service 'etcd1' do
advertise_client_urls 'http://127.0.0.1:3379'
listen_client_urls 'http://0.0.0.0:3379'
initial_advertise_peer_urls 'http://127.0.0.1:3380'
listen_peer_urls 'http://0.0.0.0:3380'
initial_cluster_token 'etcd-cluster-1'
initial_cluster 'etcd0=http://127.0.0.1:2380,etcd1=http://127.0.0.1:3380,etcd2=http://127.0.0.1:4380'
initial_cluster_state 'new'
action :start
ignore_failure true
end
etcd_service 'etcd2' do
advertise_client_urls 'http://127.0.0.1:4379'
listen_client_urls 'http://0.0.0.0:4379'
initial_advertise_peer_urls 'http://127.0.0.1:4380'
listen_peer_urls 'http://0.0.0.0:4380'
initial_cluster_token 'etcd-cluster-1'
initial_cluster 'etcd0=http://127.0.0.1:2380,etcd1=http://127.0.0.1:3380,etcd2=http://127.0.0.1:4380'
initial_cluster_state 'new'
action :start
ignore_failure true
endBy default reosource creates etcd-NODE_NAME unit file name. Sometimes it's not comfortable.
If you don't run multi etcd service in node, you can change this action to default service name.
etcd_service 'etcd' do
action :start
default_service_name true
...
endThe cookbooks ran under test-kitchen make excellent usage examples.
The test recipes are found at:
test/cookbooks/etcd_test/etcd_service: composite resource that uses etcd_installation and etcd_service_manageretcd_installation: automatically selects an installation methodetcd_service_manager: automatically selects a service manageretcd_key: manages keys in etcdetcd_installation_binary: copies a pre-compiled etcd binary onto disketcd_installation_docker: pulls a docker image to the DOCKER_HOSTetcd_service_manager_systemd: manage etcd daemon with systemd unit filesetcd_service_manager_docker: starts a docker process on the DOCKER_HOST
The etcd_installation resource auto-selects one of the below resources with the provider resolution system. Defaults to binary installation.
etcd_installation 'default' do
action :create
endThe etcd_installation_binary resource copies the precompiled Go binary onto the disk.
etcd_installation_binary 'default' do
version '3.2.6'
source 'https://my.computers.biz/dist/etcd'
checksum '90aff7364caa43932fd46974825af20e0ecb70fe7e01981e2d3a496106f147e7'
action :create
endThe etcd_installation_docker resource uses the docker_image resource to pull an image to the DOCKER_HOST.
repo- The image name to pull. Defaults to 'quay.io/coreos/etcd'tag- The image tag to pull.version- String used to calculate tag string when tag is omitted. Defaults to '2.3.7'
The etcd_service_manager resource auto-selects one of the below resources with the provider resolution system. The etcd_service family all share a common set of properties, which are listed under the etcd_service composite resource.
etcd startup behavior is a bit quirky. etcd loops indefinitely on startup until quorum can be established. Due to this the first nodes service start will fail unless all nodes come up at the same time. Due to this there is an ignore_failure property for the systemd service managers which allows you to continue on in the chef run if the service fails to start. systemd will automatically keep restarting the service until all nodes are up and the cluster is healthy. For sys-v init you're on your own.
etcd_service_manager 'default' do
action :start
end- ignore_failure - Ignore failures starting the etcd service. Before quorum is established nodes will loop indefinitely and never successfully start. This can help ensure all instances are up when init systems can handle restart on failure. Default: false
etcd_service_manager_systemd 'default' do
action :start
end- service_timeout - The time in seconds before the service start fails. Default: 120
- ignore_failure - Ignore failures starting the etcd service. Before quorum is established nodes will loop indefinitely and never successfully start. This can help ensure all instances are up when init systems can handle restart on failure. Default: false
etcd_service_manager_docker 'default' do
action :start
end- repo - defaults to 'quay.io/coreos/etcd'
- tag - default calculated from version
- version - defaults to '3.2.15',
- container_name - defaults to resource name
- port - defaults to ['2379/tcp4:2379', '2380/tcp4:2380']
- host_data_path - Path to store data locally on the host, which will be mounted into the container
The etcd_service: resource is a composite resource that uses etcd_installation and etcd_service_manager resources to install and manage the etcd service.
- The
:createaction uses anetcd_installation - The
:deleteaction uses anetcd_installation - The
:startaction uses anetcd_service_manager - The
:stopaction uses anetcd_service_manager
The service management strategy for the host platform is dynamically chosen based on platform, but can be overridden.
The etcd_service resource property list corresponds to the options found in
Etcd Configuration Flags documentation
sourcenode_namedata_dirwal_dirsnapshot_countsnapshot to disk.heartbeat_intervalelection_timeoutlisten_peer_urlslisten_client_urlsmax_snapshotsmax_walscorsquota_backend_bytes
initialinitial_advertise_peer_urlsinitial_clusterinitial_cluster_stateinitial_cluster_tokenadvertise_client_urlsdiscoverydiscovery_srvdiscovery_fallback(removed in v3.6)discovery_proxy(removed in v3.6)strict_reconfig_checkauto_compaction_retentionenable_v2(removed in v3.6)
discovery_tokendiscovery_endpointsdiscovery_dial_timeoutdiscovery_request_timeoutdiscovery_keepalive_timediscovery_keepalive_timeoutdiscovery_insecure_transportdiscovery_insecure_skip_tls_verifydiscovery_certdiscovery_keydiscovery_cacertdiscovery_userdiscovery_password
proxyproxy_failure_waitproxy_refresh_intervalproxy_dial_timeoutproxy_write_timeoutproxy_read_timeout
cert_filekey_fileclient_cert_authtrusted_ca_fileauto_tlspeer_cert_filepeer_key_filepeer_client_cert_authpeer_trusted_ca_filepeer_cert_allowed_cnpeer_auto_tlsetcdctl_client_cert_fileetcdctl_client_key_fileexperimental_peer_skip_client_san_verification(deprecated in v3.6, usepeer_skip_client_san_verification)peer_skip_client_san_verification(v3.6+, replacesexperimental_peer_skip_client_san_verification)
debuglog_package_levelslog_format(v3.6+)
enable_pprofmetricslisten-metrics-urls
auth_token
feature_gates
force_new_cluster
http_proxyhttps_proxyno_proxyauto_restartconfig_file
The etcd_key resource sets, watches and deletes keys in etcd.
- The
:setaction sets a key - The
:deleteaction deletes a key - The
:watchaction waits for a key to update
key- The key namevalue- The desired valuettl- The ttl for the key (optional)host- The hostname of the etcd server, defaults to127.0.0.1port- The port that etcd is listening on, defaults to2379
etcd_key "/test" do
value "a_test_value"
action :set
endThis project exists thanks to all the people who contribute.
Thank you to all our backers!
Support this project by becoming a sponsor. Your logo will show up here with a link to your website.