Skip to content

Commit ac26133

Browse files
authored
Add Pod anti-affinity to Thanos Rule (#310)
Signed-off-by: Philip Gough <philip.p.gough@gmail.com>
1 parent 4c73418 commit ac26133

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ We use *breaking* word for marking changes that are not backward compatible (rel
3131
- [#301](https://github.com/thanos-io/kube-thanos/pull/301) Receive: allow configuration of `minReadySeconds` for StatefulSet
3232
- [#305](https://github.com/thanos-io/kube-thanos/pull/305) Receive: allow configuration of limits-config-file
3333
- [#308](https://github.com/thanos-io/kube-thanos/pull/308) Recive: add store limits flags
34+
- [#310](https://github.com/thanos-io/kube-thanos/pull/310) Ruler: Add host anti-affinity to ruler
3435

3536
### Fixed
3637

examples/all/manifests/thanos-rule-statefulSet.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ spec:
2424
app.kubernetes.io/name: thanos-rule
2525
app.kubernetes.io/version: v0.30.2
2626
spec:
27+
affinity:
28+
podAntiAffinity:
29+
preferredDuringSchedulingIgnoredDuringExecution:
30+
- podAffinityTerm:
31+
labelSelector:
32+
matchExpressions:
33+
- key: app.kubernetes.io/name
34+
operator: In
35+
values:
36+
- thanos-rule
37+
- key: app.kubernetes.io/instance
38+
operator: In
39+
values:
40+
- thanos-rule
41+
namespaces:
42+
- thanos
43+
topologyKey: kubernetes.io/hostname
44+
weight: 100
2745
containers:
2846
- args:
2947
- rule

jsonnet/kube-thanos/kube-thanos-rule.libsonnet

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,27 @@ function(params) {
328328
nodeSelector: {
329329
'kubernetes.io/os': 'linux',
330330
},
331+
affinity: { podAntiAffinity: {
332+
local labelSelector = { matchExpressions: [{
333+
key: 'app.kubernetes.io/name',
334+
operator: 'In',
335+
values: [tr.statefulSet.metadata.labels['app.kubernetes.io/name']],
336+
}, {
337+
key: 'app.kubernetes.io/instance',
338+
operator: 'In',
339+
values: [tr.statefulSet.metadata.labels['app.kubernetes.io/instance']],
340+
}] },
341+
preferredDuringSchedulingIgnoredDuringExecution: [
342+
{
343+
podAffinityTerm: {
344+
namespaces: [tr.config.namespace],
345+
topologyKey: 'kubernetes.io/hostname',
346+
labelSelector: labelSelector,
347+
},
348+
weight: 100,
349+
},
350+
],
351+
} },
331352
},
332353
},
333354
volumeClaimTemplates: if std.length(tr.config.volumeClaimTemplate) > 0 then [tr.config.volumeClaimTemplate {

0 commit comments

Comments
 (0)