diff --git a/charts/fluentd/README.md b/charts/fluentd/README.md index ab103a32..37c287be 100644 --- a/charts/fluentd/README.md +++ b/charts/fluentd/README.md @@ -174,6 +174,24 @@ The `fileConfigs` section is organized by sources -> filters -> destinations. Fl ``` +## Headless Service + +The chart supports deploying a headless service, which is useful for StatefulSet deployments where you need direct pod DNS resolution (e.g., `pod-0.fluentd-headless.namespace.svc.cluster.local`). + +To enable the headless service, configure the following values: + +```yaml +headlessService: + enabled: true + annotations: {} + ports: + - name: "forwarder" + protocol: TCP + containerPort: 24224 +``` + +The headless service will be created with the name `-fluentd-headless` and will expose the metrics port (24231) by default, plus any additional ports specified in `headlessService.ports`. + ## Backwards Compatibility - v0.1.x The old fluentd chart used the ENV variables and the default fluentd container definitions to set-up automatically many aspects of fluentd. It is still possible to trigger this behaviour by removing this charts current `.Values.env` configuration and replace by: diff --git a/charts/fluentd/templates/headless-service.yaml b/charts/fluentd/templates/headless-service.yaml new file mode 100644 index 00000000..1e785dba --- /dev/null +++ b/charts/fluentd/templates/headless-service.yaml @@ -0,0 +1,30 @@ +{{- if .Values.headlessService.enabled -}} +apiVersion: v1 +kind: Service +metadata: + name: {{ include "fluentd.fullname" . }}-headless + labels: + {{- include "fluentd.labels" . | nindent 4 }} + {{- with .Values.headlessService.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + type: ClusterIP + clusterIP: None + ports: + - port: 24231 + targetPort: metrics + protocol: TCP + name: metrics + {{- if .Values.headlessService.ports }} + {{- range $port := .Values.headlessService.ports }} + - name: {{ $port.name }} + port: {{ $port.containerPort }} + targetPort: {{ $port.containerPort }} + protocol: {{ $port.protocol }} + {{- end }} + {{- end }} + selector: + {{- include "fluentd.selectorLabels" . | nindent 4 }} +{{- end -}} diff --git a/charts/fluentd/templates/hpa.yaml b/charts/fluentd/templates/hpa.yaml index f4785662..6ad5b476 100644 --- a/charts/fluentd/templates/hpa.yaml +++ b/charts/fluentd/templates/hpa.yaml @@ -1,4 +1,4 @@ -{{- if and ( eq .Values.kind "Deployment" ) .Values.autoscaling.enabled }} +{{- if .Values.autoscaling.enabled }} apiVersion: {{ include "fluentd.hpa.apiVersion" . }} kind: HorizontalPodAutoscaler metadata: @@ -12,7 +12,7 @@ spec: {{- end }} scaleTargetRef: apiVersion: apps/v1 - kind: Deployment + kind: {{ .Values.kind }} name: {{ include "fluentd.fullname" . }} minReplicas: {{ .Values.autoscaling.minReplicas }} maxReplicas: {{ .Values.autoscaling.maxReplicas }} @@ -36,4 +36,4 @@ spec: {{- if .Values.autoscaling.customRules -}} {{- toYaml .Values.autoscaling.customRules | nindent 4}} {{- end -}} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/charts/fluentd/templates/pdb.yaml b/charts/fluentd/templates/pdb.yaml new file mode 100644 index 00000000..5c8e4408 --- /dev/null +++ b/charts/fluentd/templates/pdb.yaml @@ -0,0 +1,18 @@ +{{- if .Values.podDisruptionBudget.enabled }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "fluentd.fullname" . }} + labels: + {{- include "fluentd.labels" . | nindent 4 }} +spec: + {{- if .Values.podDisruptionBudget.minAvailable }} + minAvailable: {{ .Values.podDisruptionBudget.minAvailable }} + {{- end }} + {{- if .Values.podDisruptionBudget.maxUnavailable }} + maxUnavailable: {{ .Values.podDisruptionBudget.maxUnavailable }} + {{- end }} + selector: + matchLabels: + {{- include "fluentd.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/charts/fluentd/templates/statefulset.yaml b/charts/fluentd/templates/statefulset.yaml index 5bc22481..5d1e01f2 100644 --- a/charts/fluentd/templates/statefulset.yaml +++ b/charts/fluentd/templates/statefulset.yaml @@ -13,7 +13,9 @@ metadata: {{- toYaml . | nindent 4 }} {{- end }} spec: + {{- if not .Values.autoscaling.enabled }} replicas: {{ .Values.replicaCount }} + {{- end }} serviceName: {{ include "fluentd.fullname" . }} {{- with .Values.updateStrategy }} updateStrategy: @@ -25,6 +27,10 @@ spec: {{- with .Values.minReadySeconds }} minReadySeconds: {{ . }} {{- end }} + {{- with .Values.persistentVolumeClaimRetentionPolicy }} + persistentVolumeClaimRetentionPolicy: + {{- toYaml . | nindent 4 }} + {{- end }} template: metadata: annotations: diff --git a/charts/fluentd/values.yaml b/charts/fluentd/values.yaml index ac05f8b2..b440e592 100644 --- a/charts/fluentd/values.yaml +++ b/charts/fluentd/values.yaml @@ -161,6 +161,15 @@ updateStrategy: {} # rollingUpdate: # maxUnavailable: 1 +persistentVolumeClaimRetentionPolicy: {} +# whenDeleted: Delete +# whenScaled: Delete + +podDisruptionBudget: + enabled: false +# minAvailable: 1 +# maxUnavailable: 1 + ## Additional environment variables to set for fluentd pods env: [] # - name: "FLUENTD_CONF" @@ -210,6 +219,16 @@ service: # protocol: TCP # containerPort: 24224 +## Headless service for StatefulSet +## +headlessService: + enabled: false + annotations: {} + ports: [] + # - name: "forwarder" + # protocol: TCP + # containerPort: 24224 + ## Prometheus Monitoring ## metrics: