From 10eb55f7962f6fa0bfc3ff5a3cea83854ee3908b Mon Sep 17 00:00:00 2001 From: Frederic Branczyk Date: Wed, 29 Apr 2020 16:50:33 +0200 Subject: [PATCH] receive: Use anti-affinity to spread across zones Signed-off-by: Frederic Branczyk --- CHANGELOG.md | 2 ++ .../all/manifests/thanos-receive-statefulSet.yaml | 11 +++++++++++ jsonnet/kube-thanos/kube-thanos-receive.libsonnet | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 319f1b73..2eaed2ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ We use *breaking* word for marking changes that are not backward compatible (rel - [#105](https://github.com/thanos-io/kube-thanos/pull/105) compactor, store: Add deduplication replica label flags and delete delay labels +- [#119](https://github.com/thanos-io/kube-thanos/pull/119) receive: Distribute receive instances across node zones via pod anti affinity (note: only available on 1.17+). + ### Fixed - diff --git a/examples/all/manifests/thanos-receive-statefulSet.yaml b/examples/all/manifests/thanos-receive-statefulSet.yaml index 1cb35baa..74c4b6ce 100644 --- a/examples/all/manifests/thanos-receive-statefulSet.yaml +++ b/examples/all/manifests/thanos-receive-statefulSet.yaml @@ -38,6 +38,17 @@ spec: - thanos topologyKey: kubernetes.io/hostname weight: 100 + - podAffinityTerm: + labelSelector: + matchExpressions: + - key: app.kubernetes.io/instance + operator: In + values: + - thanos-receive + namespaces: + - thanos + topologyKey: topology.kubernetes.io/zone + weight: 100 containers: - args: - receive diff --git a/jsonnet/kube-thanos/kube-thanos-receive.libsonnet b/jsonnet/kube-thanos/kube-thanos-receive.libsonnet index 10e0ca24..d9633ed9 100644 --- a/jsonnet/kube-thanos/kube-thanos-receive.libsonnet +++ b/jsonnet/kube-thanos/kube-thanos-receive.libsonnet @@ -119,6 +119,16 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet'; matchExpression.withOperator('In') + matchExpression.withValues([tr.statefulSet.metadata.labels['app.kubernetes.io/instance']]), ]), + affinity.new() + + affinity.withWeight(100) + + affinity.mixin.podAffinityTerm.withNamespaces(tr.config.namespace) + + affinity.mixin.podAffinityTerm.withTopologyKey('topology.kubernetes.io/zone') + + affinity.mixin.podAffinityTerm.labelSelector.withMatchExpressions([ + matchExpression.new() + + matchExpression.withKey('app.kubernetes.io/instance') + + matchExpression.withOperator('In') + + matchExpression.withValues([tr.statefulSet.metadata.labels['app.kubernetes.io/instance']]), + ]), ]) + sts.mixin.spec.selector.withMatchLabels(tr.config.podLabelSelector) + {