Files
kyverno-2026-example/03-mutation/02-sidecar/inject-fluent-bit.yaml
2026-04-08 20:22:14 +07:00

58 lines
2.0 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: inject-fluent-bit-sidecar
annotations:
policies.kyverno.io/title: "Автовнедрение Fluent Bit sidecar"
policies.kyverno.io/category: Logging
policies.kyverno.io/severity: low
policies.kyverno.io/subject: Pod
policies.kyverno.io/description: >-
Автоматически добавляет Fluent Bit sidecar контейнер ко всем подам
с аннотацией logging.company.com/enabled: "true".
Подход Opt-in: разработчик явно запрашивает injection.
ЗАМЕНИТЕ образ registry.company.com на ваш внутренний реестр.
spec:
rules:
- name: inject-fluent-bit
match:
resources:
kinds:
- Pod
preconditions:
all:
# Opt-in: только поды с явной аннотацией
- key: "{{ request.object.metadata.annotations.\"logging.company.com/enabled\" }}"
operator: Equals
value: "true"
# Не добавлять если sidecar уже есть (защита от дублирования)
- key: "fluent-bit"
operator: NotIn
value: "{{ request.object.spec.containers[].name }}"
mutate:
patchStrategicMerge:
spec:
containers:
- name: fluent-bit
image: fluent/fluent-bit:2.1 # замените на внутренний реестр
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 50m
memory: 64Mi
volumeMounts:
- name: varlog
mountPath: /var/log
readOnly: true
- name: fluent-bit-config
mountPath: /fluent-bit/etc/
volumes:
- name: varlog
hostPath:
path: /var/log
- name: fluent-bit-config
configMap:
name: fluent-bit-config