All Projects → nikhita → custom-database-controller

nikhita / custom-database-controller

Licence: Apache-2.0 license
No description, website, or topics provided.

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects

custom-database-controller

Example respository for the blog post Kubernetes Custom Resources Grow Up in v1.10.

This repository implements a simple custom database controller which scales mysql deployments as per the Database custom resources.

This follows the same pattern as that of the Kuberentes sample-controller.

Installation

export GOPATH=~/go
go get github.com/nikhita/custom-database-controller

Prerequisites

Custom Resources support /status and /scale subresources as an alpha feature in v1.10. You will need a Kubernetes cluster with version of at least 1.10. Enable this feature using the CustomResourceSubresources feature gate on the kube-apiserver for v1.10. This feature is enabled by default for versions >v1.10.

--feature-gates=CustomResourceSubresources=true

Running

# assumes you have a working kubeconfig, not required if operating in-cluster
$ go run *.go -kubeconfig=$HOME/.kube/config

# create a CustomResourceDefinition
$ kubectl create -f artifacts/databases-crd.yaml

# create a custom resource of type Database
$ kubectl create -f artifacts/mysql-database.yaml

# check deployments created through the Databse custom resource
$ kubectl get deployments

You can scale the Database custom resource, which can automatically scale the mysql deployments as well.

$ kubectl get deployments
NAME    DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
my-user 1         1         1            1           4s

# scaling
$ kubectl scale --replicas=3 databases/mysql
database.example.com "mysql" scaled

# after scaling
$ kubectl get deployments
NAME    DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
my-user 3         3         3            3           1m
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].