1{ 2 local k = import 'ksonnet-util/kausal.libsonnet', 3 local pvc = k.core.v1.persistentVolumeClaim, 4 local volumeMount = k.core.v1.volumeMount, 5 local container = k.core.v1.container, 6 local statefulSet = k.apps.v1.statefulSet, 7 local service = k.core.v1.service, 8 local containerPort = k.core.v1.containerPort, 9 10 _config+:: { 11 // run ingesters and queriers as statefulsets when using boltdb-shipper to avoid using node disk for storing the index. 12 stateful_ingesters: if self.using_boltdb_shipper then true else super.stateful_ingesters, 13 stateful_queriers: if self.using_boltdb_shipper && !self.use_index_gateway then true else super.stateful_queriers, 14 15 boltdb_shipper_shared_store: error 'must define boltdb_shipper_shared_store when using_boltdb_shipper=true. If this is not intentional, consider disabling it. boltdb_shipper_shared_store is a backend key from the storage_config, such as (gcs) or (s3)', 16 compactor_pvc_size: '10Gi', 17 compactor_pvc_class: 'fast', 18 index_period_hours: if self.using_boltdb_shipper then 24 else super.index_period_hours, 19 loki+: if self.using_boltdb_shipper then { 20 chunk_store_config+: { 21 write_dedupe_cache_config:: {}, 22 }, 23 storage_config+: { 24 boltdb_shipper+: { 25 shared_store: $._config.boltdb_shipper_shared_store, 26 active_index_directory: '/data/index', 27 cache_location: '/data/boltdb-cache', 28 }, 29 }, 30 } else {}, 31 }, 32 33 // we don't dedupe index writes when using boltdb-shipper so don't deploy a cache for it. 34 memcached_index_writes: if $._config.using_boltdb_shipper then {} else super.memcached_index_writes, 35 36 // Use PVC for compactor instead of node disk. 37 compactor_data_pvc:: if $._config.using_boltdb_shipper then 38 pvc.new('compactor-data') + 39 pvc.mixin.spec.resources.withRequests({ storage: $._config.compactor_pvc_size }) + 40 pvc.mixin.spec.withAccessModes(['ReadWriteOnce']) + 41 pvc.mixin.spec.withStorageClassName($._config.compactor_pvc_class) 42 else {}, 43 44 compactor_args:: if $._config.using_boltdb_shipper then { 45 'config.file': '/etc/loki/config/config.yaml', 46 'boltdb.shipper.compactor.working-directory': '/data/compactor', 47 'boltdb.shipper.compactor.shared-store': $._config.boltdb_shipper_shared_store, 48 target: 'compactor', 49 } else {}, 50 51 local compactor_ports = 52 [ 53 containerPort.new(name='http-metrics', port=$._config.http_listen_port), 54 ], 55 56 compactor_container:: if $._config.using_boltdb_shipper then 57 container.new('compactor', $._images.compactor) + 58 container.withPorts(compactor_ports) + 59 container.withArgsMixin(k.util.mapToFlags($.compactor_args)) + 60 container.withVolumeMountsMixin([volumeMount.new('compactor-data', '/data')]) + 61 container.mixin.readinessProbe.httpGet.withPath('/ready') + 62 container.mixin.readinessProbe.httpGet.withPort($._config.http_listen_port) + 63 container.mixin.readinessProbe.withTimeoutSeconds(1) + 64 k.util.resourcesRequests('4', '2Gi') 65 else {}, 66 67 compactor_statefulset: if $._config.using_boltdb_shipper then 68 statefulSet.new('compactor', 1, [$.compactor_container], $.compactor_data_pvc) + 69 statefulSet.mixin.spec.withServiceName('compactor') + 70 $.config_hash_mixin + 71 k.util.configVolumeMount('loki', '/etc/loki/config') + 72 statefulSet.mixin.spec.updateStrategy.withType('RollingUpdate') + 73 statefulSet.mixin.spec.template.spec.securityContext.withFsGroup(10001) // 10001 is the group ID assigned to Loki in the Dockerfile 74 else {}, 75} 76