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

add bucket replicate component #237

Merged
merged 3 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ We use *breaking* word for marking changes that are not backward compatible (rel

### Added

-
- [#237](https://github.com/thanos-io/kube-thanos/pull/237) Add new bucket replicate component.

### Fixed

Expand Down
13 changes: 13 additions & 0 deletions all.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ local b = t.bucket(commonConfig {
// },
});

local br = t.bucketReplicate(commonConfig {
replicas: 1,
// Use the same object storage secret as an example.
// Need to use another one in real cases.
objectStorageToConfig: {
name: 'thanos-objectstorage',
key: 'thanos.yaml',
},
compactionLevels: [1, 2, 3],
resolutions: ['0s'],
});

local c = t.compact(commonConfig {
replicas: 1,
serviceMonitor: true,
Expand Down Expand Up @@ -215,6 +227,7 @@ local finalQ = t.query(q.config {
});

{ ['thanos-bucket-' + name]: b[name] for name in std.objectFields(b) if b[name] != null } +
{ ['thanos-bucket-replicate-' + name]: br[name] for name in std.objectFields(br) if br[name] != null } +
{ ['thanos-compact-' + name]: c[name] for name in std.objectFields(c) if c[name] != null } +
{
['compact-' + shard + '-' + name]: cs.shards[shard][name]
Expand Down
93 changes: 93 additions & 0 deletions examples/all/manifests/thanos-bucket-replicate-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/component: object-store-bucket-replicate
app.kubernetes.io/instance: thanos-bucket-replicate
app.kubernetes.io/name: thanos-bucket-replicate
app.kubernetes.io/version: v0.22.0
name: thanos-bucket-replicate
namespace: thanos
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/component: object-store-bucket-replicate
app.kubernetes.io/instance: thanos-bucket-replicate
app.kubernetes.io/name: thanos-bucket-replicate
template:
metadata:
labels:
app.kubernetes.io/component: object-store-bucket-replicate
app.kubernetes.io/instance: thanos-bucket-replicate
app.kubernetes.io/name: thanos-bucket-replicate
app.kubernetes.io/version: v0.22.0
spec:
containers:
- args:
- tools
- bucket
- replicate
- --log.level=info
- --log.format=logfmt
- --objstore.config=$(OBJSTORE_CONFIG)
- --objstore-to.config=$(OBJSTORE_TO_CONFIG)
- |-
--tracing.config="config":
"sampler_param": 2
"sampler_type": "ratelimiting"
"service_name": "thanos-bucket-replicate"
"type": "JAEGER"
- --compaction=1
- --compaction=2
- --compaction=3
- --resolution=0s
env:
- name: OBJSTORE_CONFIG
valueFrom:
secretKeyRef:
key: thanos.yaml
name: thanos-objectstorage
- name: OBJSTORE_TO_CONFIG
valueFrom:
secretKeyRef:
key: thanos.yaml
name: thanos-objectstorage
- name: HOST_IP_ADDRESS
valueFrom:
fieldRef:
fieldPath: status.hostIP
image: quay.io/thanos/thanos:v0.22.0
livenessProbe:
failureThreshold: 4
httpGet:
path: /-/healthy
port: 10902
scheme: HTTP
periodSeconds: 30
name: thanos-bucket-replicate
ports:
- containerPort: 10902
name: http
readinessProbe:
failureThreshold: 20
httpGet:
path: /-/ready
port: 10902
scheme: HTTP
periodSeconds: 5
resources:
limits:
cpu: 0.42
memory: 420Mi
requests:
cpu: 0.123
memory: 123Mi
terminationMessagePolicy: FallbackToLogsOnError
nodeSelector:
beta.kubernetes.io/os: linux
securityContext:
fsGroup: 65534
runAsUser: 65534
serviceAccountName: thanos-bucket-replicate
terminationGracePeriodSeconds: 120
19 changes: 19 additions & 0 deletions examples/all/manifests/thanos-bucket-replicate-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/component: object-store-bucket-replicate
app.kubernetes.io/instance: thanos-bucket-replicate
app.kubernetes.io/name: thanos-bucket-replicate
app.kubernetes.io/version: v0.22.0
name: thanos-bucket-replicate
namespace: thanos
spec:
ports:
- name: http
port: 10902
targetPort: 10902
selector:
app.kubernetes.io/component: object-store-bucket-replicate
app.kubernetes.io/instance: thanos-bucket-replicate
app.kubernetes.io/name: thanos-bucket-replicate
10 changes: 10 additions & 0 deletions examples/all/manifests/thanos-bucket-replicate-serviceAccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app.kubernetes.io/component: object-store-bucket-replicate
app.kubernetes.io/instance: thanos-bucket-replicate
app.kubernetes.io/name: thanos-bucket-replicate
app.kubernetes.io/version: v0.22.0
name: thanos-bucket-replicate
namespace: thanos
2 changes: 1 addition & 1 deletion examples/development-minio/pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: minio
namespace: thanos
kakkoyun marked this conversation as resolved.
Show resolved Hide resolved
labels:
app.kubernetes.io/name: minio
spec:
storageClassName: local-storage
accessModes:
- ReadWriteOnce
resources:
Expand Down
2 changes: 1 addition & 1 deletion examples/development-minio/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Service
metadata:
name: minio
spec:
type: ClusterIP
type: NodePort
ports:
- port: 9000
targetPort: 9000
Expand Down
185 changes: 185 additions & 0 deletions jsonnet/kube-thanos/kube-thanos-bucket-replicate.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
// These are the defaults for this components configuration.
// When calling the function to generate the component's manifest,
// you can pass an object structured like the default to overwrite default values.
local defaults = {
local defaults = self,
name: 'thanos-bucket-replicate',
namespace: error 'must provide namespace',
version: error 'must provide version',
image: error 'must provide image',
objectStorageConfig: error 'must provide objectStorageConfig',
objectStorageToConfig: error 'must provide objectStorageToConfig', // Destination object store configuration.
resources: {},
logLevel: 'info',
logFormat: 'logfmt',
ports: {
http: 10902,
},
tracing: {},
minTime: '',
maxTime: '',
compactionLevels: [],
resolutions: [],

commonLabels:: {
'app.kubernetes.io/name': 'thanos-bucket-replicate',
'app.kubernetes.io/instance': defaults.name,
'app.kubernetes.io/version': defaults.version,
'app.kubernetes.io/component': 'object-store-bucket-replicate',
},

podLabelSelector:: {
[labelName]: defaults.commonLabels[labelName]
for labelName in std.objectFields(defaults.commonLabels)
if labelName != 'app.kubernetes.io/version'
},

securityContext:: {
fsGroup: 65534,
runAsUser: 65534,
},
};

function(params) {
local tbr = self,

// Combine the defaults and the passed params to make the component's config.
config:: defaults + params,
// Safety checks for combined config of defaults and params
assert std.isNumber(tbr.config.replicas) && tbr.config.replicas >= 0 : 'thanos bucket replicate replicas has to be number >= 0',
assert std.isObject(tbr.config.resources),

service: {
apiVersion: 'v1',
kind: 'Service',
metadata: {
name: tbr.config.name,
namespace: tbr.config.namespace,
labels: tbr.config.commonLabels,
},
spec: {
ports: [
{
assert std.isString(name),
assert std.isNumber(tbr.config.ports[name]),

name: name,
port: tbr.config.ports[name],
targetPort: tbr.config.ports[name],
}
for name in std.objectFields(tbr.config.ports)
],
selector: tbr.config.podLabelSelector,
},
},

serviceAccount: {
apiVersion: 'v1',
kind: 'ServiceAccount',
metadata: {
name: tbr.config.name,
namespace: tbr.config.namespace,
labels: tbr.config.commonLabels,
},
},

deployment:
local container = {
name: 'thanos-bucket-replicate',
image: tbr.config.image,
args: [
'tools',
'bucket',
'replicate',
'--log.level=' + tbr.config.logLevel,
'--log.format=' + tbr.config.logFormat,
'--objstore.config=$(OBJSTORE_CONFIG)',
'--objstore-to.config=$(OBJSTORE_TO_CONFIG)',
] + (
if std.length(tbr.config.tracing) > 0 then [
'--tracing.config=' + std.manifestYamlDoc(
{ config+: { service_name: defaults.name } } + tbr.config.tracing
),
] else []
) + (
if std.length(tbr.config.minTime) > 0 then [
'--min-time=' + tbr.config.minTime,
] else []
) + (
if std.length(tbr.config.maxTime) > 0 then [
'--max-time=' + tbr.config.maxTime,
] else []
) + (
if std.length(tbr.config.compactionLevels) > 0 then [
'--compaction=%d' % compactionLevel
for compactionLevel in tbr.config.compactionLevels
] else []
) + (
if std.length(tbr.config.resolutions) > 0 then [
'--resolution=%s' % resolution
for resolution in tbr.config.resolutions
] else []
),
env: [
{ name: 'OBJSTORE_CONFIG', valueFrom: { secretKeyRef: {
key: tbr.config.objectStorageConfig.key,
name: tbr.config.objectStorageConfig.name,
} } },
{ name: 'OBJSTORE_TO_CONFIG', valueFrom: { secretKeyRef: {
key: tbr.config.objectStorageToConfig.key,
name: tbr.config.objectStorageToConfig.name,
} } },
{
// Inject the host IP to make configuring tracing convenient.
name: 'HOST_IP_ADDRESS',
valueFrom: {
fieldRef: {
fieldPath: 'status.hostIP',
},
},
},
],
ports: [
{ name: name, containerPort: tbr.config.ports[name] }
for name in std.objectFields(tbr.config.ports)
],
livenessProbe: { failureThreshold: 4, periodSeconds: 30, httpGet: {
scheme: 'HTTP',
port: tbr.config.ports.http,
path: '/-/healthy',
} },
readinessProbe: { failureThreshold: 20, periodSeconds: 5, httpGet: {
scheme: 'HTTP',
port: tbr.config.ports.http,
path: '/-/ready',
} },
resources: if tbr.config.resources != {} then tbr.config.resources else {},
terminationMessagePolicy: 'FallbackToLogsOnError',
};

{
apiVersion: 'apps/v1',
kind: 'Deployment',
metadata: {
name: tbr.config.name,
namespace: tbr.config.namespace,
labels: tbr.config.commonLabels,
},
spec: {
replicas: 1,
selector: { matchLabels: tbr.config.podLabelSelector },
template: {
metadata: { labels: tbr.config.commonLabels },
spec: {
serviceAccountName: tbr.serviceAccount.metadata.name,
securityContext: tbr.config.securityContext,
containers: [container],
terminationGracePeriodSeconds: 120,
nodeSelector: {
'beta.kubernetes.io/os': 'linux',
},
},
},
},
},
}
1 change: 1 addition & 0 deletions jsonnet/kube-thanos/thanos.libsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
bucket: (import 'kube-thanos-bucket.libsonnet'),
bucketReplicate: (import 'kube-thanos-bucket-replicate.libsonnet'),
compact: (import 'kube-thanos-compact.libsonnet'),
compactShards: (import 'kube-thanos-compact-shards.libsonnet'),
query: (import 'kube-thanos-query.libsonnet'),
Expand Down