Skip to content
This repository has been archived by the owner on Feb 9, 2022. It is now read-only.

Commit

Permalink
修复一些ansible的默认变量 (#1)
Browse files Browse the repository at this point in the history
Co-authored-by: link.ma <[email protected]>
  • Loading branch information
LinkMaq and link.ma authored Jun 5, 2021
1 parent a23bd02 commit 24c436e
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 39 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@ Loki Operator是基于[Operator-SDK](https://github.com/operator-framework/opera

Loki Operator完整的实现Loki在kubernetes环境下的生命周期和配置管理,适合在云原生场景多租户模式下的部署与管理。

> !!! Loki Operator还未经过大规模测试,目前还不建议直接用于生产环境.
> 🔔🔔🔔 Loki Operator还未经过大规模测试,目前还不建议直接用于生产环境.
最后,感谢Operator-SDK️项目 ❤️ ❤️
最后,感谢Operator-SDK️项目 🌈

## Supported System

Kubernetes: 1.18+

## Features
- [x] 支持Loki自动化部署
- [x] 单实例模式
- [x] 集群 / HA模式
- [x] Loki Architecture
- [x] Single Node
- [x] Cluster / HA [ 🔔 What is Loki Ha mode](https://github.com/grafana/loki/tree/main/production/docker)
- [x] Loki
- [x] Loki Frontent
- [x] Loki Gateway
- [ ] 集群 / 微服务模式
- [ ] Cluster / MicroService
- [x] Ring
- [x] Memberlist
- [ ] Consul
- [ ] Etcd
- [x] 支持缓存
- [x] Cached
- [x] Redis
- [x] Memcached
- [x] 日志持久化
- [x] StorageSchema
- [x] S3
- [x] boltdb-shipper
- [ ] Canssandra
- [ ] Cansandra
- [ ] GCS
- [x] 可观察性
- [x] metrics
- [x] Redis
- [x] Memcache
- [x] Loki
- [x] 更多的LokiStack产品集成
- [x] LokiStack
- [ ] Grafana
- [ ] Promtail

Expand Down Expand Up @@ -70,14 +70,15 @@ metadata:
spec:
version: 2.2.1
multitenancy: false
servicemonitor: false
service:
mode: single
single:
loki:
image: grafana/loki
schemaconfig:
index: boltdb-shipper
chunk filesystem
chunk: filesystem
storageconfig:
boltdb_shipper:
Expand Down Expand Up @@ -114,9 +115,9 @@ spec:
tag: 5.0.6
schemaconfig:
index: boltdb-shipper
chunk filesystem
chunk: filesystem
storageconfig$$:
storageconfig:
boltdb_shipper:
shared_store: filesystem
Expand Down
3 changes: 2 additions & 1 deletion roles/loki/tasks/loki-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
- name: Loki Operator | Frontend | ServiceMonitor
community.kubernetes.k8s:
state: '{{"present" if service.mode == "cluster" and servicemonitor else "absent"}}'
definition: "{{ lookup('template', 'frontend/servicemonitor.yaml') | from_yaml }}"
definition: "{{ lookup('template', 'frontend/servicemonitor.yaml') | from_yaml }}"
when: '{{servicemonitor is defined}}'
3 changes: 2 additions & 1 deletion roles/loki/tasks/loki-system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
- name: Loki Operator | Loki | ServiceMonitor
community.kubernetes.k8s:
state: '{{"present" if servicemonitor else "absent"}}'
definition: "{{ lookup('template', 'loki/servicemonitor.yaml') | from_yaml }}"
definition: "{{ lookup('template', 'loki/servicemonitor.yaml') | from_yaml }}"
when: '{{servicemonitor is defined}}'
3 changes: 1 addition & 2 deletions roles/loki/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
when: '{{service.mode == "cluster"}}'

- include_tasks: loki-system.yaml
when: '{{service.mode == "single" or service.cluster.type == "ha"}}'
when: '{{service.mode == "single" or service.cluster is defined and service.cluster.type == "ha"}}'

- name: Loki Operator | Loki | ConfigMap
community.kubernetes.k8s:
definition: "{{ lookup('template', 'loki.config.yaml') | from_yaml }}"
force: yes
merge_type: json
notify:
- Scale down single loki
Expand Down
14 changes: 8 additions & 6 deletions roles/loki/tasks/memcached.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
- name: Loki Operator | Memcached | ServiceAccount
community.kubernetes.k8s:
state: '{{"present" if cacheconfig.enabled and cacheconfig.type == "memcached" else "absent"}}'
state: '{{"present" if cacheconfig is defined and cacheconfig.enabled and cacheconfig.type == "memcached" else "absent"}}'
definition: "{{ lookup('template', 'memcached/serviceaccount.yaml') | from_yaml }}"

- name: Loki Operator | Memcached | StatefulSet
community.kubernetes.k8s:
state: '{{"present" if cacheconfig.enabled and cacheconfig.type == "memcached" else "absent"}}'
state: '{{"present" if cacheconfig is defined and cacheconfig.enabled and cacheconfig.type == "memcached" else "absent"}}'
definition: "{{ lookup('template', 'memcached/statefulset.yaml') | from_yaml }}"

- name: Loki Operator | Memcached | Service
community.kubernetes.k8s:
state: '{{"present" if cacheconfig.enabled and cacheconfig.type == "memcached" else "absent"}}'
state: '{{"present" if cacheconfig is defined and cacheconfig.enabled and cacheconfig.type == "memcached" else "absent"}}'
definition: "{{ lookup('template', 'memcached/service.yaml') | from_yaml }}"

- name: Loki Operator | Memcached | Metrics
community.kubernetes.k8s:
state: '{{"present" if cacheconfig.enabled and cacheconfig.type == "memcached" and servicemonitor else "absent"}}'
state: '{{"present" if cacheconfig is defined and cacheconfig.enabled and cacheconfig.type == "memcached" and servicemonitor else "absent"}}'
definition: "{{ lookup('template', 'memcached/metrics.yaml') | from_yaml }}"
when: '{{servicemonitor is defined}}'

- name: Loki Operator | Memcached | ServicesMonitor
ignore_errors: yes
community.kubernetes.k8s:
state: '{{"present" if cacheconfig.enabled and cacheconfig.type == "memcached" and servicemonitor else "absent"}}'
definition: "{{ lookup('template', 'memacached/servicemonitor.yaml') | from_yaml }}"
state: '{{"present" if cacheconfig is defined and cacheconfig.enabled and cacheconfig.type == "memcached" and servicemonitor else "absent"}}'
definition: "{{ lookup('template', 'memcached/servicemonitor.yaml') | from_yaml }}"
when: '{{servicemonitor is defined}}'

15 changes: 8 additions & 7 deletions roles/loki/tasks/redis.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
- name: Loki Operator | Reids Cache | PersistentVolumeClaims
community.kubernetes.k8s:
state: '{{"present" if cacheconfig.enabled and cacheconfig.type == "redis" else "absent"}}'
state: '{{"present" if cacheconfig is defined and cacheconfig.enabled and cacheconfig.type == "redis" else "absent"}}'
definition: "{{ lookup('template', 'redis/pvc.yaml') | from_yaml }}"

- name: Loki Operator | Reids Cache | ConfigMap
community.kubernetes.k8s:
state: '{{"present" if cacheconfig.enabled and cacheconfig.type == "redis" else "absent"}}'
state: '{{"present" if cacheconfig is defined and cacheconfig.enabled and cacheconfig.type == "redis" else "absent"}}'
definition: "{{ lookup('template', 'redis/configmap.yaml') | from_yaml }}"

- name: Loki Operator | Reids Cache | StatefulSet
community.kubernetes.k8s:
state: '{{"present" if cacheconfig.enabled and cacheconfig.type == "redis" else "absent"}}'
state: '{{"present" if cacheconfig is defined and cacheconfig.enabled and cacheconfig.type == "redis" else "absent"}}'
definition: "{{ lookup('template', 'redis/statefulset.yaml') | from_yaml }}"
force: yes

- name: Loki Operator | Reids Cache | Service
community.kubernetes.k8s:
state: '{{"present" if cacheconfig.enabled and cacheconfig.type == "redis" else "absent"}}'
state: '{{"present" if cacheconfig is defined and cacheconfig.enabled and cacheconfig.type == "redis" else "absent"}}'
definition: "{{ lookup('template', 'redis/service.yaml') | from_yaml }}"

- name: Loki Operator | Redis Cache | Metrics
community.kubernetes.k8s:
state: '{{"present" if cacheconfig.enabled and cacheconfig.type == "redis" and servicemonitor else "absent"}}'
state: '{{"present" if cacheconfig is defined and cacheconfig.enabled and cacheconfig.type == "redis" and servicemonitor else "absent"}}'
definition: "{{ lookup('template', 'redis/metrics.yaml') | from_yaml }}"
when: '{{servicemonitor is defined}}'

- name: Loki Operator | Redis Cache | ServicesMonitor
ignore_errors: yes
community.kubernetes.k8s:
state: '{{"present" if cacheconfig.enabled and cacheconfig.type == "redis" and servicemonitor else "absent"}}'
state: '{{"present" if cacheconfig is defined and cacheconfig.enabled and cacheconfig.type == "redis" and servicemonitor else "absent"}}'
definition: "{{ lookup('template', 'redis/servicemonitor.yaml') | from_yaml }}"
when: '{{servicemonitor is defined}}'
10 changes: 9 additions & 1 deletion roles/loki/templates/loki.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ data:
split_queries_by_interval: 24h
align_queries_with_step: true
max_retries: 5
{% if cacheconfig is defined %}
{% if cacheconfig.enabled %}
results_cache:
cache:
Expand All @@ -71,6 +72,7 @@ data:
{% endif %}
cache_results: true
{% endif %}
{% endif %}
ingester:
lifecycler:
Expand Down Expand Up @@ -147,6 +149,7 @@ data:
s3forcepathstyle: true
insecure: true
{% endif %}
{% if cacheconfig is defined %}
{% if cacheconfig.enabled %}
index_queries_cache_config:
{{cacheconfig.type}}:
Expand All @@ -167,7 +170,9 @@ data:
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% if cacheconfig is defined %}
{% if cacheconfig.enabled %}
chunk_store_config:
chunk_cache_config:
Expand Down Expand Up @@ -208,7 +213,9 @@ data:
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% if ruler is defined %}
{% if ruler.enabled %}
ruler:
storage:
Expand All @@ -232,6 +239,7 @@ data:
store: inmemory
{% endif %}
{% endif %}
{% endif %}
limits_config:
enforce_metric_name: false
Expand Down
14 changes: 11 additions & 3 deletions roles/loki/templates/loki/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ metadata:
plugins.cloudminds.com/loki: loki-system
app.kubernetes.io/name: '{{ ansible_operator_meta.name }}-loki-system'
spec:
{% if service.mode == "cluster" and service.cluster.type == "ha" %}
{% if service.mode == "cluster" %}
{% if service.cluster.type == "ha" %}
replicas: {{ service.cluster.loki.replicas }}
{% endif %}
{% else %}
replicas: 1
{% endif %}
Expand Down Expand Up @@ -41,7 +43,11 @@ spec:
nodeAffinity:
containers:
- name: loki-system
image: '{{service.cluster.loki.image}}:{{version}}'
{% if service.mode == "cluster" %}
image: '{{service.cluster.loki.image | default('grafana/loki')}}:{{version | default('2.2.1')}}'
{% elif service.mode == "single" %}
image: '{{service.single.loki.image | default('grafana/loki')}}:{{version | default('2.2.1')}}'
{% endif %}
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3100
Expand All @@ -50,11 +56,13 @@ spec:
- containerPort: 9095
name: grpc-9095
protocol: TCP
{% if service.mode == "cluster" and service.cluster.ring.type == "memberlist" %}
{% if service.mode == "cluster" %}
{% if service.cluster.ring.type == "memberlist" %}
- containerPort: 7946
name: tcp-7946
protocol: TCP
{% endif %}
{% endif %}
resources:
limits:
cpu: "8"
Expand Down
4 changes: 2 additions & 2 deletions roles/loki/templates/memcached/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ spec:
preStop:
exec:
command: ["/bin/sh", "-c", "/usr/bin/pkill -10 memcached ; sleep 60s"]
image: '{{cacheconfig.memcached.image}}:{{cacheconfig.memcached.tag}}'
image: '{{cacheconfig.memcached.image | default('docker.io/bitnami/memcached')}}:{{cacheconfig.memcached.tag | default('1.6.9-debian-10-r114')}}'
imagePullPolicy: "IfNotPresent"
args:
- /run.sh
Expand Down Expand Up @@ -77,7 +77,7 @@ spec:
mountPath: /cache-state
- name: tmp
mountPath: /tmp
{% if cacheconfig.enabled and cacheconfig.type == "memcached" %}
{% if cacheconfig is defined and cacheconfig.enabled and cacheconfig.type == "memcached" and servicemonitor %}
- name: metrics
image: docker.io/bitnami/memcached-exporter:0.8.0-debian-10-r105
imagePullPolicy: "IfNotPresent"
Expand Down
4 changes: 2 additions & 2 deletions roles/loki/templates/redis/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
spec:
containers:
- name: redis
image: '{{cacheconfig.redis.image}}:{{cacheconfig.redis.tag}}'
image: '{{cacheconfig.redis.image | default('redis')}}:{{cacheconfig.redis.tag | default('5.0.6')}}'
imagePullPolicy: IfNotPresent
args: ["/etc/redis.conf"]
ports:
Expand Down Expand Up @@ -59,7 +59,7 @@ spec:
readOnlyRootFilesystem: false
runAsNonRoot: true
runAsUser: 1001
{% if cacheconfig.enabled and cacheconfig.type == "redis" and servicemonitor %}
{% if cacheconfig is defined and cacheconfig.enabled and cacheconfig.type == "redis" and servicemonitor %}
- name: redis-exporter
image: oliver006/redis_exporter:v1.23.1-alpine
imagePullPolicy: IfNotPresent
Expand Down

0 comments on commit 24c436e

Please sign in to comment.