Administration
Use these standard procedures to administer etcd:
- Create Cluster: Initialize an etcd cluster
- Destroy Cluster: Destroy an etcd cluster
- CLI Environment: Configure etcd client to access server cluster
- RBAC Authentication: Use etcd RBAC auth
- Reload Config: Update etcd server member list for clients
- Add Member: Add new member to existing etcd cluster
- Remove Member: Remove member from etcd cluster
- Utility Scripts: Simplify ops with
bin/etcd-addandbin/etcd-rm
For more, refer to FAQ: ETCD.
Create Cluster
Define etcd cluster in config inventory:
Run etcd.yml playbook:
Since v3.6, etcd.yml installs clusters and adds members. It does not remove them. Use the dedicated etcd-rm.yml for all removals.
For production etcd clusters, enable the safeguard etcd_safeguard to prevent accidental deletion.
Destroy Cluster
Use the dedicated etcd-rm.yml playbook to destroy an Etcd cluster. The default etcd_rm_data: true deletes local data and configuration. First, confirm that no PostgreSQL cluster still uses it as DCS. Verify a recent backup and check the exact target name.
Or use utility script:
The removal playbook respects etcd_safeguard. If this parameter is true, the playbook aborts before any cluster-leave, deregistration, service-stop, or file-deletion operation. The default is false. The absence of an explicit override does not confirm removal.
Before you remove the etcd cluster, make sure no PostgreSQL cluster uses it as DCS. Otherwise, PostgreSQL HA will fail.
CLI Environment
Pigsty uses the etcd v3 API by default. Etcd v3.6+ removed the v2 API. Pigsty automatically configures /etc/profile.d/etcdctl.sh on etcd nodes. The shell loads this environment script at login.
Example client env config:
Since v4.0, Pigsty enables RBAC authentication for etcd by default. User authentication is still required:
After you configure the client environment, run etcd CRUD operations:
RBAC Authentication
Since v4.0, Pigsty enables etcd RBAC authentication by default. During cluster initialization, the etcd_auth task creates the root user and enables authentication.
Set the root user password with etcd_root_password. The default is Etcd.Root. Pigsty stores it in /etc/etcd/etcd.pass with 0640 permissions. Root owns the file, and the etcd group can read it.
We strongly recommend that you change the default password in production:
Client auth methods:
Patroni and etcd auth:
Patroni uses pg_etcd_password as the etcd connection password. If it is empty, Patroni uses the cluster name as the password. We do not recommend this default. In production, set a separate etcd password for each PostgreSQL cluster.
Reload Config
After you add or remove etcd members, update the service endpoint references. Update these etcd references in Pigsty:
| Config Location | Config File | Update Method |
|---|---|---|
| etcd member config | /etc/etcd/etcd.conf | ./etcd.yml -t etcd_conf |
| etcdctl env vars | /etc/profile.d/etcdctl.sh | ./etcd.yml -t etcd_config |
| Patroni DCS config | /etc/patroni/patroni.yml | ./pgsql.yml -t pg_conf |
| VIP-Manager config | /etc/default/vip-manager.yml | ./pgsql.yml -t pg_vip_config |
Refresh etcd member config:
Refresh etcdctl client env:
Update Patroni DCS endpoint config:
Update VIP-Manager endpoint config (only for PGSQL L2 VIP):
After bin/etcd-add or bin/etcd-rm completes, the script shows commands to refresh the configuration.
Add Member
ETCD Reference: Add a member
Recommended: Utility Script
Use bin/etcd-add script to add new members to existing etcd cluster:
The script attempts these operations in order:
- Validates the IP address
- Sets
etcd_init=existingautomatically and runs theetcd.ymlplaybook - Provides safety warnings and countdown
- Shows configuration refresh commands after completion
Manual: Step-by-Step
Add new member to existing etcd cluster:
- Update config inventory: Add new instance to
etcdgroup - Notify cluster: Run
etcdctl member add(optional, playbook auto-does this) - Initialize new member: Run playbook with
etcd_init=existingparameter - Promote member: Promote learner to full member (optional, required when using
etcd_learner=true) - Reload config: Update etcd endpoint references for all clients
When you add members, you must set etcd_init=existing. Otherwise, the new instance creates a new cluster instead of joining the existing cluster.
Detailed: Add member to etcd cluster
This example starts with a single-instance etcd cluster:
Add new member using utility script (recommended):
For manual addition, first run etcdctl member add. This announces the new learner instance etcd-2 to the existing etcd cluster:
Run etcdctl member list or em list. The new member appears with the unstarted state:
Run the etcd.yml playbook to initialize the new instance, etcd-2. When the playbook completes, the new member is running:
After the new member initializes and runs stably, promote it from learner to follower:
The new member is now part of the cluster. Reload the configuration so all clients can find it.
Repeat these steps to add more members. Production environments need at least 3 members.
Remove Member
Recommended: Utility Script
Use bin/etcd-rm script to remove members from etcd cluster:
The script automatically performs these operations:
- Gracefully removes members from cluster
- Stops and disables etcd service
- Cleans up data and config files
- Deregisters from monitoring system
The underlying removal role tolerates some leave and cleanup errors. After the script finishes, inspect etcdctl member list, endpoint health, and remaining quorum. Also inspect the actual service and data-directory state on the target.
Manual: Step-by-Step
Remove member instance from etcd cluster:
- Keep the member in the inventory: The removal playbook needs its
etcd_seq, cluster members, and connection endpoints - Clean up the instance: Run
etcd-rm.ymlagainst the target. It attemptsmember removeand stops the service. It then cleans up according to the removal flags. - Update the inventory: Comment out or delete the member only after the playbook succeeds
- Reload references: Follow Reload Config for the remaining etcd members and the Patroni/VIP-Manager endpoints
Do not delete the target from the inventory before you run the removal playbook. Without the target, the hosts: etcd scope in etcd-rm.yml cannot select it. The playbook also cannot get the instance identity or cluster endpoints from the inventory.
You do not need to repeat etcdctl member remove before or after the playbook.
Detailed: Remove member from etcd cluster
Example: 3-node etcd cluster, remove instance 3.
Method 1: Utility script (recommended)
The script attempts to remove the member, stop the service, and clean up data. Afterwards, still inspect the member list, quorum, and target files as described above.
Method 2: Manual
First keep the member to be removed in the inventory, then run the removal playbook:
The playbook attempts these operations in order:
- Get member list, find corresponding member ID
- Execute
etcdctl member removeto kick from cluster - Stop etcd service
- Clean up data and config files
The playbook queries the member ID and runs member remove automatically. Do this manually only when troubleshooting:
After manual member removal, keep the target in the inventory. Run ./etcd-rm.yml -l 10.10.10.12 to stop, deregister, and clean it up. The leave step skips a member that is already removed.
Confirm that the member has left the live cluster and the remaining members retain quorum. Also confirm that the target service and files have the expected state. Only then delete 10.10.10.12 from the inventory. Follow Reload Config to update the remaining etcd members and all client references.
Repeat these steps to remove more members. Combine this procedure with Add Member for rolling upgrades and migrations of the etcd cluster.
Utility Scripts
v3.6+ provides utility scripts to simplify etcd cluster scaling:
bin/etcd-add
Add new members to existing etcd cluster:
Script features:
- Validates IP addresses in config inventory
- Auto-sets
etcd_init=existingparameter - Executes
etcd.ymlplaybook to complete member addition - Shows configuration refresh commands after completion
bin/etcd-rm
Remove members or entire cluster from etcd:
Script features:
- Provides safety warnings and confirmation countdown
- Auto-executes
etcd-rm.ymlplaybook - Gracefully removes members from cluster
- Cleans up data and config files
Manage Etcd Password
The etcd_root_password parameter defines the password of the etcd root user.
To change it, use an INFRA node or ETCD node that can reach an etcd endpoint. Run this command as the admin user:
Update every reference to the etcd root password. Include the Patroni client configuration on INFRA nodes and the etcdctl client environment:
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)