From ff2ddbf208ffa6d7e3b69cf43af418bcd2af980c Mon Sep 17 00:00:00 2001 From: Alex Robinson Date: Wed, 21 Dec 2016 16:02:30 -0500 Subject: [PATCH] Add pod anti-affinity and a disruption budget to cockroachdb example --- examples/cockroachdb/README.md | 2 +- .../cockroachdb/cockroachdb-statefulset.yaml | 29 +++++++++++++++++++ examples/cockroachdb/minikube.sh | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/examples/cockroachdb/README.md b/examples/cockroachdb/README.md index 5662ae102c6..785af8b4f3c 100644 --- a/examples/cockroachdb/README.md +++ b/examples/cockroachdb/README.md @@ -116,7 +116,7 @@ Because all of the resources in this example have been tagged with the label `ap we can clean up everything that we created in one quick command using a selector on that label: ```shell -kubectl delete statefulsets,pods,persistentvolumes,persistentvolumeclaims,services -l app=cockroachdb +kubectl delete statefulsets,persistentvolumes,persistentvolumeclaims,services,poddisruptionbudget -l app=cockroachdb ``` diff --git a/examples/cockroachdb/cockroachdb-statefulset.yaml b/examples/cockroachdb/cockroachdb-statefulset.yaml index 3f2e5f8050b..8115c6d7e16 100644 --- a/examples/cockroachdb/cockroachdb-statefulset.yaml +++ b/examples/cockroachdb/cockroachdb-statefulset.yaml @@ -54,6 +54,18 @@ spec: selector: app: cockroachdb --- +apiVersion: policy/v1beta1 +kind: PodDisruptionBudget +metadata: + name: cockroachdb-budget + labels: + app: cockroachdb +spec: + selector: + matchLabels: + app: cockroachdb + minAvailable: 67% +--- apiVersion: apps/v1beta1 kind: StatefulSet metadata: @@ -66,6 +78,22 @@ spec: labels: app: cockroachdb annotations: + scheduler.alpha.kubernetes.io/affinity: > + { + "podAntiAffinity": { + "preferredDuringSchedulingIgnoredDuringExecution": [{ + "weight": 100, + "labelSelector": { + "matchExpressions": [{ + "key": "app", + "operator": "In", + "values": ["cockroachdb"] + }] + }, + "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. @@ -80,6 +108,7 @@ spec: { "name": "bootstrap", "image": "cockroachdb/cockroach-k8s-init:0.1", + "imagePullPolicy": "IfNotPresent", "args": [ "-on-start=/on-start.sh", "-service=cockroachdb" diff --git a/examples/cockroachdb/minikube.sh b/examples/cockroachdb/minikube.sh index 1256db6080e..8c1ee41b1cd 100755 --- a/examples/cockroachdb/minikube.sh +++ b/examples/cockroachdb/minikube.sh @@ -29,7 +29,7 @@ set -exuo pipefail # Clean up anything from a prior run: -kubectl delete statefulsets,pods,persistentvolumes,persistentvolumeclaims,services -l app=cockroachdb +kubectl delete statefulsets,persistentvolumes,persistentvolumeclaims,services,poddisruptionbudget -l app=cockroachdb # Make persistent volumes and (correctly named) claims. We must create the # claims here manually even though that sounds counter-intuitive. For details