diff --git a/README.md b/README.md index 7396323..cb8c187 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,356 @@ -# couchdb-admin [![Build Status](https://travis-ci.org/cabify/couchdb-admin.svg?branch=master)](https://travis-ci.org/cabify/couchdb-admin) -WIP CouchDB admin tooling +# CouchDB 2 cluster admin tool [![Build Status](https://travis-ci.org/cabify/couchdb-admin.svg?branch=master)](https://travis-ci.org/cabify/couchdb-admin) + +Currently operating a CouchDB 2 clustered database is a highly manual and error prone task and that's something you definitely should avoid when it comes to databases. +`couchdb-admin` is a FOSS tool written in [Go](https://golang.org/) that operates your database via the [Oficial REST API](http://docs.couchdb.org/en/2.0.0/api/) in a command-line fashion. Performs sanity checks for you and hides all the REST communication complexities from you. --- +## Features + +`couchdb-admin` works at three levels: Cluster, Node and Database: + +* Cluster wide management: + * Describe cluster: Get an overview of your cluster's current status (nodes joined, ...) + * Add nodes: Join a node into the cluster. + * Remove nodes: Remove a node from the cluster. +* Node management: + * Set config values: Apply config values on your nodes. No need to restart. + * Disable maintenance mode: Shortcut method to remove the `maintenance_mode` flag from a node. +* Database management: + * Describe database: Get an overview of your database's shards distribution across nodes. + * Create database: Create a database, configuring shards number and replication. + * Replicate a shard: Design a new replica for a particular database's shard. + * Remove a shard's replica: Free a node from holding a replica of a particular database's shard. + +## Prerequisites + +The `couchdb-admin` tool needs to be able to reach any of the nodes of the cluster to operate on both `5984` and `5986` ports. Additionally a configured admin role is required. + +* The address where to contact the server has to be given in the `--server` argument (defaults to 127.0.0.1) +* The admin username is required into the `--admin` argument (defaults to admin) +* The admin's password is required into the `--password` argument (defaults to password) + +## Examples + +DISCLAIMER: The examples shown below will use the default values for `server`, `admin` and `password` arguments. Please update them accordingly when running your own. + +### Cluster management + +#### Describe cluster + +Get an overview of your cluster's current status, which nodes form it and so on. Uses the [_membership](http://docs.couchdb.org/en/2.0.0/api/server/common.html#get--_membership) endpoint. + +``` +$ couchdb-admin describe_cluster + +2017/06/29 13:46:26 info Describing cluster layout... server=127.0.0.1 + +couchdb_admin.Nodes{ + AllNodes: {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, + ClusterNodes: {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, +} +``` + +#### Add nodes + +Following the procedure described [in the official docs](http://docs.couchdb.org/en/2.0.0/cluster/nodes.html#adding-a-node) joins a node into the cluster. +Uses the `_nodes` endpoint + +After firing up a new node, located, for example, at `couch-3.couchdb2-replica-admin`: + +``` +$ couchdb-admin add_node --node=couch-3.couchdb2-replica-admin + +2017/06/29 15:38:39 info Adding node to the cluster... node=couch-3.couchdb2-replica-admin + +2017/06/29 15:38:40 info Successfully added node! node=couch-3.couchdb2-replica-admin +``` + +And then, describing the cluster again... + +``` +$ couchdb-admin describe_cluster + +2017/06/29 15:38:54 info Describing cluster layout... server=127.0.0.1 + +couchdb_admin.Nodes{ + AllNodes: {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin", "couchdb@couch-3.couchdb2-replica-admin"}, + ClusterNodes: {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin", "couchdb@couch-3.couchdb2-replica-admin"}, +} +``` + +#### Remove nodes + +Again, following the procedure described [in the official docs](http://docs.couchdb.org/en/2.0.0/cluster/nodes.html#removing-a-node) it removes a node from the cluster. +Uses the `_nodes` endpoint + +``` +$ couchdb-admin remove_node --node=couch-3.couchdb2-replica-admin + +2017/06/29 15:55:26 info Removing node... node=couch-3.couchdb2-replica-admin + +2017/06/29 15:55:26 info Checking that node does not own any shard... node=couchdb@couch-3.couchdb2-replica-admin + +2017/06/29 15:55:26 info Node successfully removed! node=couch-3.couchdb2-replica-admin +``` +And then, describing the cluster again... +``` +$ couchdb-admin describe_cluster + +2017/06/29 15:55:59 info Describing cluster layout... server=127.0.0.1 + +couchdb_admin.Nodes{ + AllNodes: {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, + ClusterNodes: {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, +} +``` + +### Node management + +#### Set config values + +Sets config values on a node by using the [_config](http://docs.couchdb.org/en/2.0.0/api/server/configuration.html#put--_config-section-key) endpoint. +You can check possible sections, keys and values to use on the [config reference](http://docs.couchdb.org/en/2.0.0/config-ref.html). +Changes will take effect on the fly, no need to restart! + +Here we'll set the log level to debug in a particular node. + +``` +$ couchdb-admin set_config --section=log --key=level --value=debug --node=couch-0.couchdb2-replica-admin + +2017/06/29 16:04:08 info Setting config value... key=level node=couch-0.couchdb2-replica-admin section=log value=debug + +2017/06/29 16:04:08 info New config successfully applied! key=level node=couch-0.couchdb2-replica-admin section=log value=debug +``` + +And in the logs you should see `[notice] 2017-06-29T12:42:21.558278Z couchdb@couch-0.couchdb2-replica-admin <0.89.0> -------- config: [log] level set to debug for reason nil` + +#### Disable maintenance mode + +This is a shortcut method to disable the [maintenance_mode flag](http://docs.couchdb.org/en/2.0.0/config/couchdb.html#couchdb/maintenance_mode). The reason for this method is that whenever a new node is configured to replicate a shard it is set into `maintenance_mode` to avoid unconsistent reads while it syncs. + +``` +$ couchdb-admin disasble_maintenance_mode --node=couch-1.couchdb2-replica-admin + +2017/06/29 16:28:52 info Removing maintenance flag... node=couch-1.couchdb2-replica-admin + +2017/06/29 16:28:52 info Maintenance flag successfully removed! node=couch-1.couchdb2-replica-admin +``` + +You should see something like this in the logs: `[notice] 2017-06-29T13:07:06.470213Z couchdb@couch-1.couchdb2-replica-admin <0.89.0> -------- config: [couchdb] maintenance_mode set to false for reason nil` + +### Database management + +#### Describe database + +Gets a database shards ownership from the `_dbs` endpoint + +``` +$ couchdb-admin describe_database --db=testdb + +2017/06/29 16:08:04 info Describing database... db=testdb + +&couchdb_admin.Database{ + name: "testdb", + config: couchdb_admin.Config{ + Id: "testdb", + Rev: "1-898af88337774f013e7c14fafeb79f75", + Shards: {46, 49, 52, 57, 56, 50, 48, 56, 52, 50, 51}, + Changelog: { + {"add", "00000000-1fffffff", "couchdb@couch-0.couchdb2-replica-admin"}, + {"add", "00000000-1fffffff", "couchdb@couch-1.couchdb2-replica-admin"}, + {"add", "00000000-1fffffff", "couchdb@couch-2.couchdb2-replica-admin"}, + {"add", "20000000-3fffffff", "couchdb@couch-0.couchdb2-replica-admin"}, + {"add", "20000000-3fffffff", "couchdb@couch-1.couchdb2-replica-admin"}, + {"add", "20000000-3fffffff", "couchdb@couch-2.couchdb2-replica-admin"}, + {"add", "40000000-5fffffff", "couchdb@couch-0.couchdb2-replica-admin"}, + {"add", "40000000-5fffffff", "couchdb@couch-1.couchdb2-replica-admin"}, + {"add", "40000000-5fffffff", "couchdb@couch-2.couchdb2-replica-admin"}, + {"add", "60000000-7fffffff", "couchdb@couch-0.couchdb2-replica-admin"}, + {"add", "60000000-7fffffff", "couchdb@couch-1.couchdb2-replica-admin"}, + {"add", "60000000-7fffffff", "couchdb@couch-2.couchdb2-replica-admin"}, + {"add", "80000000-9fffffff", "couchdb@couch-0.couchdb2-replica-admin"}, + {"add", "80000000-9fffffff", "couchdb@couch-1.couchdb2-replica-admin"}, + {"add", "80000000-9fffffff", "couchdb@couch-2.couchdb2-replica-admin"}, + {"add", "a0000000-bfffffff", "couchdb@couch-0.couchdb2-replica-admin"}, + {"add", "a0000000-bfffffff", "couchdb@couch-1.couchdb2-replica-admin"}, + {"add", "a0000000-bfffffff", "couchdb@couch-2.couchdb2-replica-admin"}, + {"add", "c0000000-dfffffff", "couchdb@couch-0.couchdb2-replica-admin"}, + {"add", "c0000000-dfffffff", "couchdb@couch-1.couchdb2-replica-admin"}, + {"add", "c0000000-dfffffff", "couchdb@couch-2.couchdb2-replica-admin"}, + {"add", "e0000000-ffffffff", "couchdb@couch-0.couchdb2-replica-admin"}, + {"add", "e0000000-ffffffff", "couchdb@couch-1.couchdb2-replica-admin"}, + {"add", "e0000000-ffffffff", "couchdb@couch-2.couchdb2-replica-admin"}, + }, + ByNode: { + "couchdb@couch-0.couchdb2-replica-admin": {"00000000-1fffffff", "20000000-3fffffff", "40000000-5fffffff", "60000000-7fffffff", "80000000-9fffffff", "a0000000-bfffffff", "c0000000-dfffffff", "e0000000-ffffffff"}, + "couchdb@couch-1.couchdb2-replica-admin": {"00000000-1fffffff", "20000000-3fffffff", "40000000-5fffffff", "60000000-7fffffff", "80000000-9fffffff", "a0000000-bfffffff", "c0000000-dfffffff", "e0000000-ffffffff"}, + "couchdb@couch-2.couchdb2-replica-admin": {"00000000-1fffffff", "20000000-3fffffff", "40000000-5fffffff", "60000000-7fffffff", "80000000-9fffffff", "a0000000-bfffffff", "c0000000-dfffffff", "e0000000-ffffffff"}, + }, + ByRange: { + "20000000-3fffffff": {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, + "40000000-5fffffff": {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, + "60000000-7fffffff": {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, + "80000000-9fffffff": {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, + "a0000000-bfffffff": {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, + "c0000000-dfffffff": {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, + "e0000000-ffffffff": {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, + "00000000-1fffffff": {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, + }, + }, +} +``` + +Where we can see that our database has 8 shards and 3 replicas each shard. The `ByNode` key describes which shards each node is holding whilst `ByRange` describes which nodes contain which shard. +This is a special case as we have only 3 nodes, so each node has a complete copy of all the data. + +#### Create a database + +Creates a new database using the [PUT /{db}](http://docs.couchdb.org/en/2.0.0/api/database/common.html#put--db) endpoint. + +``` +$ couchdb-admin create_db --db=mydb --shards=3 --replicas=2 + +2017/06/29 16:15:42 info Creating database... db=mydb replicas=2 shards=3 + +2017/06/29 16:15:43 info Database successfully created! db=mydb replicas=2 shards=3 +``` + +Now we can see its layout across nodes. + +``` +$ couchdb-admin describe_db --db=mytdb + +2017/06/29 16:16:43 info Describing database... db=mydb + +&couchdb_admin.Database{ + name: "mydb", + config: couchdb_admin.Config{ + Id: "mydb", + Rev: "1-73e3eedeb4a3304842633c8f695e36c0", + Shards: {46, 49, 52, 57, 56, 55, 52, 48, 56, 51, 54}, + Changelog: { + {"add", "00000000-55555554", "couchdb@couch-1.couchdb2-replica-admin"}, + {"add", "00000000-55555554", "couchdb@couch-2.couchdb2-replica-admin"}, + {"add", "55555555-aaaaaaa9", "couchdb@couch-0.couchdb2-replica-admin"}, + {"add", "55555555-aaaaaaa9", "couchdb@couch-2.couchdb2-replica-admin"}, + {"add", "aaaaaaaa-ffffffff", "couchdb@couch-0.couchdb2-replica-admin"}, + {"add", "aaaaaaaa-ffffffff", "couchdb@couch-1.couchdb2-replica-admin"}, + }, + ByNode: { + "couchdb@couch-0.couchdb2-replica-admin": {"55555555-aaaaaaa9", "aaaaaaaa-ffffffff"}, + "couchdb@couch-1.couchdb2-replica-admin": {"00000000-55555554", "aaaaaaaa-ffffffff"}, + "couchdb@couch-2.couchdb2-replica-admin": {"00000000-55555554", "55555555-aaaaaaa9"}, + }, + ByRange: { + "55555555-aaaaaaa9": {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, + "aaaaaaaa-ffffffff": {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin"}, + "00000000-55555554": {"couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, + }, + }, +} +``` + +#### Replicate a shard + +Configures a node to also be a replica for a particular shard. It follows the procedure described [in the official docs](http://docs.couchdb.org/en/2.0.0/cluster/sharding.html?highlight=scaling%20out#scaling-out). + +``` +$ couchdb-admin replicate --shard=55555555-aaaaaaa9 --db=mydb --replica=couch-1.couchdb2-replica-admin + +2017/06/29 16:21:16 info Replicating shard... db=mydb replica=couch-1.couchdb2-replica-admin shard=55555555-aaaaaaa9 + +2017/06/29 16:21:16 info Shard successfully replicated db=mydb replica=couch-1.couchdb2-replica-admin shard=55555555-aaaaaaa9 + +2017/06/29 16:21:16 warn Node was sent into maintenance!. Remember to reenable it once it catches up with changes node=couch-1.couchdb2-replica-admin +``` + +And now describing the db again we can see that the shard 555... is on all nodes and taht couch-1 node holds all three shards! + +``` +$ couchdb-admin describe_db --db=mydb + +2017/06/29 16:21:57 info Describing database... db=mydb + +&couchdb_admin.Database{ + name: "mydb", + config: couchdb_admin.Config{ + Id: "mydb", + Rev: "2-5c965ef57142374eda39b6f4718b6298", + Shards: {46, 49, 52, 57, 56, 55, 52, 48, 56, 51, 54}, + Changelog: { + {"add", "00000000-55555554", "couchdb@couch-1.couchdb2-replica-admin"}, + {"add", "00000000-55555554", "couchdb@couch-2.couchdb2-replica-admin"}, + {"add", "55555555-aaaaaaa9", "couchdb@couch-0.couchdb2-replica-admin"}, + {"add", "55555555-aaaaaaa9", "couchdb@couch-2.couchdb2-replica-admin"}, + {"add", "aaaaaaaa-ffffffff", "couchdb@couch-0.couchdb2-replica-admin"}, + {"add", "aaaaaaaa-ffffffff", "couchdb@couch-1.couchdb2-replica-admin"}, + }, + ByNode: { + "couchdb@couch-0.couchdb2-replica-admin": {"55555555-aaaaaaa9", "aaaaaaaa-ffffffff"}, + "couchdb@couch-1.couchdb2-replica-admin": {"00000000-55555554", "aaaaaaaa-ffffffff", "55555555-aaaaaaa9"}, + "couchdb@couch-2.couchdb2-replica-admin": {"00000000-55555554", "55555555-aaaaaaa9"}, + }, + ByRange: { + "55555555-aaaaaaa9": {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin"}, + "aaaaaaaa-ffffffff": {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin"}, + "00000000-55555554": {"couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, + }, + }, +} +``` + +BEWARE!!!: The node receiving the new replica is automatically set into [maintenance mode](http://docs.couchdb.org/en/2.0.0/config/couchdb.html#couchdb/maintenance_mode). You should check the logs for pending changes and once it finishes syncing [disable maintenance mode](https://github.com/cabify/couchdb-admin#disable-maintenance-mode) so that it participates in reads again. + +#### Remove a shard's replica + +Configures a node to stop being a replica for a particular shard. It follows the procedure described [in the official docs](http://docs.couchdb.org/en/2.0.0/cluster/sharding.html?highlight=scaling%20out#moving-shards). + +``` +$ couchdb-admin remove_replica --db=mydb --shard=55555555-aaaaaaa9 --from=couch-1.couchdb2-replica-admin + +2017/06/29 16:34:47 info Removing shard ownership... db=mydb replica=couch-1.couchdb2-replica-admin shard=55555555-aaaaaaa9 + +2017/06/29 16:34:47 info Replica shard successfully removed! db=mydb replica=couch-1.couchdb2-replica-admin shard=55555555-aaaaaaa9 +``` + +And describing the database layout again we see that couch-1 is no longer replicating shard 555... + +``` +$ couchdb-admin describe_db --db=mydb + +2017/06/29 16:35:48 info Describing database... db=mydb + +&couchdb_admin.Database{ + name: "mydb", + config: couchdb_admin.Config{ + Id: "mydb", + Rev: "3-64420ae508c9ad647f615d5d823ec9b8", + Shards: {46, 49, 52, 57, 56, 55, 52, 48, 56, 51, 54}, + Changelog: { + {"add", "00000000-55555554", "couchdb@couch-1.couchdb2-replica-admin"}, + {"add", "00000000-55555554", "couchdb@couch-2.couchdb2-replica-admin"}, + {"add", "55555555-aaaaaaa9", "couchdb@couch-0.couchdb2-replica-admin"}, + {"add", "55555555-aaaaaaa9", "couchdb@couch-2.couchdb2-replica-admin"}, + {"add", "aaaaaaaa-ffffffff", "couchdb@couch-0.couchdb2-replica-admin"}, + {"add", "aaaaaaaa-ffffffff", "couchdb@couch-1.couchdb2-replica-admin"}, + }, + ByNode: { + "couchdb@couch-0.couchdb2-replica-admin": {"55555555-aaaaaaa9", "aaaaaaaa-ffffffff"}, + "couchdb@couch-1.couchdb2-replica-admin": {"00000000-55555554", "aaaaaaaa-ffffffff"}, + "couchdb@couch-2.couchdb2-replica-admin": {"00000000-55555554", "55555555-aaaaaaa9"}, + }, + ByRange: { + "00000000-55555554": {"couchdb@couch-1.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, + "55555555-aaaaaaa9": {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-2.couchdb2-replica-admin"}, + "aaaaaaaa-ffffffff": {"couchdb@couch-0.couchdb2-replica-admin", "couchdb@couch-1.couchdb2-replica-admin"}, + }, + }, +} +``` + ## Vendoring `couchdb-admin` currently uses [Glide](http://glide.sh/) for vendoring. + + diff --git a/cli/couchdb-admin/main.go b/cli/couchdb-admin/main.go index f45101a..4cf2b1d 100644 --- a/cli/couchdb-admin/main.go +++ b/cli/couchdb-admin/main.go @@ -13,6 +13,11 @@ import ( func main() { app := cli.NewApp() + app.Name = "CouchDB 2 Admin tool" + app.Usage = "Easily operate a CouchDB 2 cluster" + app.UsageText = "$ couchdb-admin [COMMAND] [OPTIONS]" + app.Version = "0.0.1" + app.Authors = []cli.Author{cli.Author{Name: "Carlos Alonso", Email: "carlos.alonso@cabify.com"}} app.Flags = []cli.Flag{ cli.StringFlag{ @@ -34,7 +39,8 @@ func main() { app.Commands = []cli.Command{ { - Name: "describe_db", + Name: "describe_db", + Usage: "Get a db's shards placement info", Action: func(c *cli.Context) { db_name := c.String("db") log.WithField("db", db_name).Info("Describing database...") @@ -56,7 +62,8 @@ func main() { }, }, { - Name: "replicate", + Name: "replicate", + Usage: "Replicate a database's shard into a node not containing it already", Action: func(c *cli.Context) { db_name := c.String("db") shard := c.String("shard") @@ -79,13 +86,16 @@ func main() { }, Flags: []cli.Flag{ cli.StringFlag{ - Name: "shard", + Name: "shard", + Usage: "Shard's identifier to replicate", }, cli.StringFlag{ - Name: "replica", + Name: "replica", + Usage: "Node's address where to replicate the shard", }, cli.StringFlag{ - Name: "db", + Name: "db", + Usage: "Db to where the shard belongs to", }, }, Before: func(c *cli.Context) error { @@ -93,7 +103,8 @@ func main() { }, }, { - Name: "add_node", + Name: "add_node", + Usage: "Join a node into the cluster", Action: func(c *cli.Context) { node := c.String("node") log.WithField("node", node).Info("Adding node to the cluster...") @@ -112,7 +123,8 @@ func main() { }, Flags: []cli.Flag{ cli.StringFlag{ - Name: "node", + Name: "node", + Usage: "Node's address", }, }, Before: func(c *cli.Context) error { @@ -120,7 +132,8 @@ func main() { }, }, { - Name: "describe_cluster", + Name: "describe_cluster", + Usage: "Get information of the cluster's nodes", Action: func(c *cli.Context) { log.WithField("server", c.GlobalString("server")).Info("Describing cluster layout...") cluster, err := couchdb_admin.LoadCluster(buildAuthHttpReq(c)) @@ -132,7 +145,8 @@ func main() { }, }, { - Name: "create_db", + Name: "create_db", + Usage: "Create a new database", Action: func(c *cli.Context) { db := c.String("db") replicas, shards := c.Int("replicas"), c.Int("shards") @@ -146,14 +160,17 @@ func main() { }, Flags: []cli.Flag{ cli.StringFlag{ - Name: "db", + Name: "db", + Usage: "The database name", }, cli.IntFlag{ Name: "shards", + Usage: "Number of shards to distribute the database across", Value: 8, }, cli.IntFlag{ Name: "replicas", + Usage: "Number of replicas for each shard", Value: 3, }, }, @@ -162,7 +179,8 @@ func main() { }, }, { - Name: "remove_replica", + Name: "remove_replica", + Usage: "Remove a shard from a particular node", Action: func(c *cli.Context) { db_name := c.String("db") shard := c.String("shard") @@ -184,13 +202,16 @@ func main() { }, Flags: []cli.Flag{ cli.StringFlag{ - Name: "db", + Name: "db", + Usage: "The database to where the shard belongs to", }, cli.StringFlag{ - Name: "shard", + Name: "shard", + Usage: "Name of the shard to remove from the node", }, cli.StringFlag{ - Name: "from", + Name: "from", + Usage: "Node's address from where to remove the shard's replica", }, }, Before: func(c *cli.Context) error { @@ -198,7 +219,8 @@ func main() { }, }, { - Name: "disable_maintenance_mode", + Name: "disable_maintenance_mode", + Usage: "Disable a node's maintenance mode", Action: func(c *cli.Context) { node_name := c.String("node") log.WithField("node", node_name).Info("Removing maintenance flag...") @@ -217,7 +239,8 @@ func main() { }, Flags: []cli.Flag{ cli.StringFlag{ - Name: "node", + Name: "node", + Usage: "The node's address", }, }, Before: func(c *cli.Context) error { @@ -225,7 +248,8 @@ func main() { }, }, { - Name: "set_config", + Name: "set_config", + Usage: "Set a config value of a particular node", Action: func(c *cli.Context) { node_name := c.String("node") section := c.String("section") @@ -243,16 +267,20 @@ func main() { }, Flags: []cli.Flag{ cli.StringFlag{ - Name: "node", + Name: "node", + Usage: "The node's address", }, cli.StringFlag{ - Name: "section", + Name: "section", + Usage: "CouchDB config's section where to apply the config", }, cli.StringFlag{ - Name: "key", + Name: "key", + Usage: "Key for the config value to apply", }, cli.StringFlag{ - Name: "value", + Name: "value", + Usage: "The actual config value to apply", }, }, Before: func(c *cli.Context) error { @@ -260,7 +288,8 @@ func main() { }, }, { - Name: "remove_node", + Name: "remove_node", + Usage: "Remove a node from the cluster", Action: func(c *cli.Context) { node_name := c.String("node") log.WithField("node", node_name).Info("Removing node...") @@ -284,7 +313,8 @@ func main() { }, Flags: []cli.Flag{ cli.StringFlag{ - Name: "node", + Name: "node", + Usage: "The node's address", }, }, Before: func(c *cli.Context) error { diff --git a/k8s/cleanup.sh b/k8s/cleanup.sh deleted file mode 100755 index a59e2c9..0000000 --- a/k8s/cleanup.sh +++ /dev/null @@ -1,5 +0,0 @@ -kubectl delete -f k8s/statefulset.yml - -kubectl get pvc | awk 'NR>1 {print "pvc/"$1}' | xargs kubectl delete - -kubectl get pv | awk 'NR>1 {print "pv/"$1}' | xargs kubectl delete diff --git a/k8s/statefulset.yml b/k8s/statefulset.yml deleted file mode 100644 index 7367280..0000000 --- a/k8s/statefulset.yml +++ /dev/null @@ -1,88 +0,0 @@ -kind: StorageClass -apiVersion: storage.k8s.io/v1 -metadata: - name: slow -provisioner: kubernetes.io/gce-pd -parameters: - type: pd-standard ---- -apiVersion: v1 -kind: Service -metadata: - name: couchdb2-replica -spec: - type: LoadBalancer - selector: - app: couchdb2-replica-node - ports: - - port: 5984 - name: couchdb ---- -apiVersion: v1 -kind: Service -metadata: - name: couchdb2-replica-admin -spec: - selector: - app: couchdb2-replica-node - ports: - - port: 5984 - name: couchdb - - port: 5986 - name: backdoor - clusterIP: None ---- -apiVersion: apps/v1beta1 -kind: StatefulSet -metadata: - name: couch -spec: - replicas: 3 - serviceName: couchdb2-replica-admin - template: - metadata: - labels: - app: couchdb2-replica-node - spec: - containers: - - name: couchdb2 - image: klaemo/couchdb:2.0.0 - imagePullPolicy: IfNotPresent - ports: - - name: couchdb - containerPort: 5984 - - name: backdoor - containerPort: 5986 - - name: epmd - containerPort: 4396 - - containerPort: 9100 - env: - - name: NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: COUCHDB_USER - valueFrom: - secretKeyRef: - name: couchdb-admin-credentials - key: username - - name: COUCHDB_PASSWORD - valueFrom: - secretKeyRef: - name: couchdb-admin-credentials - key: password - - name: ERL_FLAGS - value: "-setcookie cabifycouchdbreplica -name couchdb@$(NAME).couchdb2-replica-admin" - volumeMounts: - - mountPath: /opt/couchdb/data - name: data-dir - volumeClaimTemplates: - - metadata: - name: data-dir - spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 1Gi - # storageClassName: slow