Update CockroachDB chart for k8s 1.5 and promote to stable (#344)

* Update CockroachDB chart to work with StatefulSets on k8s 1.5

* Update CockroachDB to use pod anti-affinity and disruption budget

* Promote CockroachDB chart from incubator to stable
This commit is contained in:
Alex Robinson
2017-01-18 15:57:02 -07:00
committed by Lachlan Evenson
parent f9e4e6edc5
commit 06df61fdec
5 changed files with 57 additions and 26 deletions
@@ -1,6 +1,6 @@
name: cockroachdb
home: https://www.cockroachlabs.com
version: 0.1.1
version: 0.2.0
description: CockroachDB Helm chart for Kubernetes.
sources:
- https://github.com/cockroachdb/cockroach
@@ -1,14 +1,14 @@
# CockroachDB Helm Chart
## Prerequisites Details
* Kubernetes 1.4 with alpha APIs enabled
* Kubernetes 1.5 (for StatefulSet support)
* PV support on the underlying infrastructure
## PetSet Details
* http://kubernetes.io/docs/user-guide/petset/
## StatefulSet Details
* http://kubernetes.io/docs/concepts/abstractions/controllers/statefulsets/
## PetSet Caveats
* http://kubernetes.io/docs/user-guide/petset/#alpha-limitations
## StatefulSet Caveats
* http://kubernetes.io/docs/concepts/abstractions/controllers/statefulsets/#limitations
## Todo
* Support setting up clusters with certificate-based authentication
@@ -16,7 +16,7 @@
## Chart Details
This chart will do the following:
* Set up a dynamically scalable CockroachDB cluster using a Kubernetes PetSet
* Set up a dynamically scalable CockroachDB cluster using a Kubernetes StatefulSet
## Installing the Chart
@@ -37,7 +37,8 @@ The following tables lists the configurable parameters of the CockroachDB chart
| `Image` | Container image name | `cockroachdb/cockroach` |
| `ImageTag` | Container image tag | `latest` |
| `ImagePullPolicy` | Container pull policy | `Always` |
| `Replicas` | k8s petset replicas | `3` |
| `Replicas` | k8s statefulset replicas | `3` |
| `MinAvailable` | k8s PodDisruptionBudget parameter | `67%` |
| `Component` | k8s selector key | `cockroachdb` |
| `GrpcPort` | CockroachDB primary serving port | `26257` |
| `HttpPort` | CockroachDB HTTP port | `8080` |
@@ -132,7 +133,7 @@ http://localhost:8080/ in your web browser.
If any CockroachDB member fails it gets restarted or recreated automatically by
the Kubernetes infrastructure, and will rejoin the cluster automatically when
it comes back up. You can test this scenario by killing any of the pets:
it comes back up. You can test this scenario by killing any of the pods:
```shell
kubectl delete pod my-release-cockroachdb-1
@@ -178,13 +179,11 @@ nodeID: 2
## Scaling
Scaling should typically be managed via the `helm upgrade` command, but PetSets
Scaling should typically be managed via the `helm upgrade` command, but StatefulSets
don't yet work with `helm upgrade`. In the meantime until `helm upgrade` works,
if you want to change the number of replicas, you can use the `kubectl patch`
command with the desired number of replicas, as shown below (or see the
[PetSet documentation](http://kubernetes.io/docs/user-guide/petset/#scaling-a-petset)
for more options):
if you want to change the number of replicas, you can use the `kubectl scale`
as shown below:
```shell
kubectl patch petset my-release-cockroachdb -p '{"spec":{"replicas":4}}'
kubectl scale statefulset my-release-cockroachdb --replicas=4
```
@@ -28,9 +28,10 @@ spec:
apiVersion: v1
kind: Service
metadata:
# This service only exists to create DNS entries for each pet in the petset such that they can resolve
# each other's IP addresses. It does not create a load-balanced ClusterIP and should not be used
# directly by clients in most circumstances.
# This service only exists to create DNS entries for each pod in the stateful
# set such that they can resolve each other's IP addresses. It does not
# create a load-balanced ClusterIP and should not be used directly by clients
# in most circumstances.
name: "{{ printf "%s-%s" .Release.Name .Values.Name | trunc 56 }}"
labels:
heritage: {{.Release.Service | quote }}
@@ -62,8 +63,23 @@ spec:
selector:
component: "{{.Release.Name}}-{{.Values.Component}}"
---
apiVersion: apps/v1alpha1
kind: PetSet
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: "{{ printf "%s-%s" .Release.Name .Values.Name | trunc 56 }}-budget"
labels:
heritage: {{.Release.Service | quote }}
release: {{.Release.Name | quote }}
chart: "{{.Chart.Name}}-{{.Chart.Version}}"
component: "{{.Release.Name}}-{{.Values.Component}}"
spec:
selector:
matchLabels:
component: "{{.Release.Name}}-{{.Values.Component}}"
minAvailable: {{.Values.MinAvailable}}
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: "{{ printf "%s-%s" .Release.Name .Values.Name | trunc 56 }}"
annotations:
@@ -80,13 +96,28 @@ spec:
component: "{{.Release.Name}}-{{.Values.Component}}"
annotations:
helm.sh/created: {{.Release.Time.Seconds | quote }}
pod.alpha.kubernetes.io/initialized: "true"
scheduler.alpha.kubernetes.io/affinity: >
{
"podAntiAffinity": {
"preferredDuringSchedulingIgnoredDuringExecution": [{
"weight": 100,
"labelSelector": {
"matchExpressions": [{
"key": "component",
"operator": "In",
"values": ["{{.Release.Name}}-{{.Values.Component}}"]
}]
},
"topologyKey": "kubernetes.io/hostname"
}]
}
}
# Init containers are run only once in the lifetime of a pod, before
# it's started up for the first time. It has to exit successfully
# before the pod's main containers are allowed to start.
# This particular init container does a DNS lookup for other pods in
# the petset to help determine whether or not a cluster already exists.
# If any other pets exist, it creates a file in the cockroach-data
# the set to help determine whether or not a cluster already exists.
# If any other pods exist, it creates a file in the cockroach-data
# directory to pass that information along to the primary container that
# has to decide what command-line flags to use when starting CockroachDB.
# This only matters when a pod's persistent volume is empty - if it has
@@ -134,7 +165,7 @@ spec:
resources:
{{ toYaml .Values.resources | indent 10 }}
env:
- name: PETSET_NAME
- name: STATEFULSET_NAME
value: "{{ printf "%s-%s" .Release.Name .Values.Name | trunc 56 }}"
livenessProbe:
httpGet:
@@ -163,10 +194,10 @@ spec:
# already exists and we should make sure not to create a new one).
# It's fine to run without --join on a restart if there aren't any
# other nodes.
if [ ! "$(hostname)" == "${PETSET_NAME}-0" ] || \
if [ ! "$(hostname)" == "${STATEFULSET_NAME}-0" ] || \
[ -e "/cockroach/cockroach-data/cluster_exists_marker" ]
then
CRARGS+=("--join" "${PETSET_NAME}-public")
CRARGS+=("--join" "${STATEFULSET_NAME}-public")
fi
exec /cockroach/cockroach ${CRARGS[*]}
# No pre-stop hook is required, a SIGTERM plus some time is all that's
@@ -10,6 +10,7 @@ ImagePullPolicy: "Always"
BootstrapImage: "cockroachdb/cockroach-k8s-init"
BootstrapImageTag: "0.1"
Replicas: 3
MinAvailable: "67%"
Component: "cockroachdb"
GrpcPort: 26257
HttpPort: 8080