Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding networkpolicy for thanos components #315

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ We use *breaking* word for marking changes that are not backward compatible (rel
- [#308](https://github.com/thanos-io/kube-thanos/pull/308) Recive: add store limits flags
- [#310](https://github.com/thanos-io/kube-thanos/pull/310) Ruler: Add host anti-affinity to ruler
- [#313](https://github.com/thanos-io/kube-thanos/pull/313) Add per-container SecurityContext
- [#315](https://github.com/thanos-io/kube-thanos/pull/315) adding networkpolicy for thanos components

### Fixed

Expand Down
32 changes: 32 additions & 0 deletions jsonnet/kube-thanos/kube-thanos-bucket.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,38 @@ function(params) {
assert std.isNumber(tb.config.replicas) && tb.config.replicas >= 0 : 'thanos bucket replicas has to be number >= 0',
assert std.isObject(tb.config.resources),

networkPolicy: {
kind: 'NetworkPolicy',
apiVersion: 'networking.k8s.io/v1',
metadata: {
name: 'thanos-bucket',
namespace: cfg.namespace,
},
spec: {
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-bucket',
},
},
egress: [{}], // Allow all outside egress to connect to object storage
ingress: [{
from: [{
namespaceSelector: {
matchLabels: {
'kubernetes.io/metadata.name': cfg.namespace,
},
},
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-query',
},
},
}],
}],
policyTypes: ['Egress'],
},
},

service: {
apiVersion: 'v1',
kind: 'Service',
Expand Down
32 changes: 32 additions & 0 deletions jsonnet/kube-thanos/kube-thanos-compact.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,38 @@ function(params) {
assert std.isBoolean(tc.config.serviceMonitor),
assert std.isArray(tc.config.deduplicationReplicaLabels),

networkPolicy: {
kind: 'NetworkPolicy',
apiVersion: 'networking.k8s.io/v1',
metadata: {
name: 'thanos-compact',
namespace: cfg.namespace,
},
spec: {
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-compact',
},
},
egress: [{}], // Allow all outside egress to connect to object storage
ingress: [{
from: [{
namespaceSelector: {
matchLabels: {
'kubernetes.io/metadata.name': cfg.namespace,
},
},
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-query',
},
},
}],
}],
policyTypes: ['Egress'],
},
},

service: {
apiVersion: 'v1',
kind: 'Service',
Expand Down
32 changes: 32 additions & 0 deletions jsonnet/kube-thanos/kube-thanos-query-frontend.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,38 @@ function(params) {
assert std.isBoolean(tqf.config.serviceMonitor),
assert std.isNumber(tqf.config.maxRetries) && tqf.config.maxRetries >= 0 : 'thanos query frontend maxRetries has to be number >= 0',

networkPolicy: {
kind: 'NetworkPolicy',
apiVersion: 'networking.k8s.io/v1',
metadata: {
name: 'thanos-query-frontend',
namespace: cfg.namespace,
},
spec: {
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-query-frontend',
},
},
egress: [{}], // Allow all outside egress to connect
ingress: [{
from: [{
namespaceSelector: {
matchLabels: {
'kubernetes.io/metadata.name': cfg.namespace,
},
},
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-query',
},
},
}],
}],
policyTypes: ['Egress'],
},
},

service: {
apiVersion: 'v1',
kind: 'Service',
Expand Down
32 changes: 32 additions & 0 deletions jsonnet/kube-thanos/kube-thanos-query.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,38 @@ function(params) {
assert std.isBoolean(tq.config.autoDownsampling),
assert std.isBoolean(tq.config.useThanosEngine),

networkPolicy: {
kind: 'NetworkPolicy',
apiVersion: 'networking.k8s.io/v1',
metadata: {
name: 'thanos-query',
namespace: cfg.namespace,
},
spec: {
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-store',
},
},
egress: [{}], // Allow all outside egress to connect to object storage
ingress: [{
from: [{
namespaceSelector: {
matchLabels: {
'kubernetes.io/metadata.name': cfg.namespace,
},
},
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-store',
},
},
}],
}],
policyTypes: ['Egress'],
},
},

service: {
apiVersion: 'v1',
kind: 'Service',
Expand Down
32 changes: 32 additions & 0 deletions jsonnet/kube-thanos/kube-thanos-receive.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,38 @@ function(params) {
assert std.isObject(tr.config.receiveLimitsConfigFile),
assert std.isObject(tr.config.storeLimits),

networkPolicy: {
kind: 'NetworkPolicy',
apiVersion: 'networking.k8s.io/v1',
metadata: {
name: 'thanos-receive',
namespace: cfg.namespace,
},
spec: {
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-receive',
},
},
egress: [{}], // Allow all outside egress to connect
ingress: [{
from: [{
namespaceSelector: {
matchLabels: {
'kubernetes.io/metadata.name': cfg.namespace,
},
},
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-query',
},
},
}],
}],
policyTypes: ['Egress'],
},
},

service: {
apiVersion: 'v1',
kind: 'Service',
Expand Down
31 changes: 31 additions & 0 deletions jsonnet/kube-thanos/kube-thanos-rule.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,37 @@ function(params) {
assert std.isObject(tr.config.volumeClaimTemplate),
assert !std.objectHas(tr.config.volumeClaimTemplate, 'spec') || std.assertEqual(tr.config.volumeClaimTemplate.spec.accessModes, ['ReadWriteOnce']) : 'thanos rule PVC accessMode can only be ReadWriteOnce',

networkPolicy: {
kind: 'NetworkPolicy',
apiVersion: 'networking.k8s.io/v1',
metadata: {
name: 'thanos-rule',
namespace: cfg.namespace,
},
spec: {
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-rule',
},
},
egress: [{}], // Allow all outside egress to connect
ingress: [{
from: [{
namespaceSelector: {
matchLabels: {
'kubernetes.io/metadata.name': cfg.namespace,
},
},
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-query',
},
},
}],
}],
policyTypes: ['Egress'],
},
},

service: {
apiVersion: 'v1',
Expand Down
32 changes: 32 additions & 0 deletions jsonnet/kube-thanos/kube-thanos-sidecar.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,38 @@ function(params) {
local tsc = self,
config:: defaults + params,

networkPolicy: {
kind: 'NetworkPolicy',
apiVersion: 'networking.k8s.io/v1',
metadata: {
name: 'thanos-sidecar',
namespace: cfg.namespace,
},
spec: {
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-sidecar',
},
},
egress: [{}], // Allow all outside egress to connect
ingress: [{
from: [{
namespaceSelector: {
matchLabels: {
'kubernetes.io/metadata.name': cfg.namespace,
},
},
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-query',
},
},
}],
}],
policyTypes: ['Egress'],
},
},

service: {
apiVersion: 'v1',
kind: 'Service',
Expand Down
32 changes: 32 additions & 0 deletions jsonnet/kube-thanos/kube-thanos-store.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,38 @@ function(params) {
assert std.isObject(ts.config.volumeClaimTemplate),
assert !std.objectHas(ts.config.volumeClaimTemplate, 'spec') || std.assertEqual(ts.config.volumeClaimTemplate.spec.accessModes, ['ReadWriteOnce']) : 'thanos store PVC accessMode can only be ReadWriteOnce',

networkPolicy: {
kind: 'NetworkPolicy',
apiVersion: 'networking.k8s.io/v1',
metadata: {
name: 'thanos-store',
namespace: cfg.namespace,
},
spec: {
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-store',
},
},
egress: [{}], // Allow all outside egress to connect to object storage
ingress: [{
from: [{
namespaceSelector: {
matchLabels: {
'kubernetes.io/metadata.name': cfg.namespace,
},
},
podSelector: {
matchLabels: {
'app.kubernetes.io/name': 'thanos-query',
},
},
}],
}],
policyTypes: ['Egress'],
},
},

service: {
apiVersion: 'v1',
kind: 'Service',
Expand Down