etcd Operator

by  CoreOS

The etcd operator provisions and configures etcd on Kubernetes. Etcd is a distributed, reliable key value store that uses the Raft protocol. It gracefully handles leader elections to recover from network partitions or node unavailability.

Etcd is prominently the main datastore of Kubernetes itself, but can also be used as a key value store for your own custom applications when strong consistency is required.

TL;DR:

  • Installing, updating or removing follows Kubestack's GitOps flow.
  • Instructions assume the default repository layout.
  • Bases can be consumed as-is or customized.
  • Step-by-step instructions are framework specific but bases can be used independently.

Install

  1. Vendor the base

    # Run these commands from the root of your Kubestack infra repository
    wget https://storage.googleapis.com/catalog.kubestack.com/etcd-v0.9.4-kbst.2.zip
    unzip -d manifests/bases/ etcd-v0.9.4-kbst.2.zip
    rm etcd-v0.9.4-kbst.2.zip
  2. Include resource in apps overlay

    cd manifests/overlays/apps
    kustomize edit add resource ../../bases/etcd/clusterwide
  3. Commit and push

    cd -
    git checkout -b add-etcd
    git add manifests/bases/etcd manifests/overlays/apps/kustomization.yaml
    git commit -m "Add etcd v0.9.4-kbst.2 base"
    git push origin add-etcd
  4. Review PR and merge

    Finally, review and merge the PR into master. Once it's been successfully applied against the Ops-Cluster set a prod-deploy tag to also apply the change against the Apps-Cluster.

Update

To update the operator delete the previously vendored base and then vendor the new version.

  1. Delete the previous vendored version

    # Run these commands from the root of your Kubestack infra repository
    rm -r manifests/bases/etcd
  2. Vendor the new version

    # Run these commands from the root of your Kubestack infra repository
    wget https://storage.googleapis.com/catalog.kubestack.com/etcd-v0.9.4-kbst.2.zip
    unzip -d manifests/bases/ etcd-v0.9.4-kbst.2.zip
    rm etcd-v0.9.4-kbst.2.zip
  3. Commit and push

    git checkout -b update-etcd
    git add manifests/bases/etcd
    git commit -m "Update etcd base to v0.9.4-kbst.2"
    git push origin update-etcd

Remove

Operators often create resources based on custom objects. When removing an operator, follow a two-step process to ensure operator provisioned resources are purged properly.

  1. Remove all the operator's custom objects.
  2. Once the operator had time to de-provision all resources it created, follow the instructions below to remove the operator itself.
  1. Remove resource from apps overlay

    cd manifests/overlays/apps
    kustomize edit remove resource ../../bases/etcd/clusterwide
  2. Delete the vendored base from your repository

    cd -
    # Run these commands from the root of your Kubestack infra repository
    rm -r manifests/bases/etcd
  3. Commit and push

    git checkout -b remove-etcd
    git add manifests/bases/etcd
    git commit -m "Remove etcd base"
    git push origin remove-etcd

Usage

Once the operator has been deployed to the Kubernetes cluster, you can use it to provision and operate one or more etcd clusters by creating a custom object.

etcd Custom Object

Below is an example of a EtcdCluster resource to instruct the operator to provision a etcd cluster with three members.

To get started, put the example below into a file called etcd.yaml and add it to your application's manifests. Then apply the manifests including the etcd.yaml as usual.

apiVersion: "etcd.database.coreos.com/v1beta2"
kind: "EtcdCluster"
metadata:
name: "example-etcd-cluster"
# Adding this annotation make this cluster managed by
# clusterwide operators, namespaced operators ignore it
annotations:
etcd.database.coreos.com/scope: clusterwide
spec:
size: 3