From 83d76d5abe3b4b363f098abb5a85e9273dbbb8e9 Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Fri, 28 Aug 2020 09:19:24 -0400 Subject: [PATCH] [plex] add promtail to ship logs to loki (#337) * add startup probe to plex * bump version * add promtail sidecar * fix up probes * fix up logging paths in templates * add new line to configmap --- charts/plex/Chart.yaml | 4 +- charts/plex/templates/deployment.yaml | 53 +++++++++++++++---- charts/plex/templates/promtail-configmap.yaml | 18 +++++++ charts/plex/values.yaml | 44 +++++++++++++-- 4 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 charts/plex/templates/promtail-configmap.yaml diff --git a/charts/plex/Chart.yaml b/charts/plex/Chart.yaml index bb2565c3..f521d59f 100644 --- a/charts/plex/Chart.yaml +++ b/charts/plex/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v1 -appVersion: 1.19.1.2645-ccb6eb67e +appVersion: 1.19.5.3112-b23ab3896 description: Plex Media Server name: plex -version: 1.7.2 +version: 1.8.0 keywords: - plex home: https://plex.tv/ diff --git a/charts/plex/templates/deployment.yaml b/charts/plex/templates/deployment.yaml index b5e00d3f..c99e30ea 100644 --- a/charts/plex/templates/deployment.yaml +++ b/charts/plex/templates/deployment.yaml @@ -62,6 +62,20 @@ spec: {{- end }} {{- end }} containers: + {{- if .Values.logging.promtail.enabled -}} + - name: {{ .Chart.Name }}-promtail + image: "{{ .Values.logging.promtail.image.repository }}:{{ .Values.logging.promtail.image.tag }}" + imagePullPolicy: {{ .Values.logging.promtail.image.pullPolicy }} + args: + - -config.file=/etc/promtail/promtail.yaml + volumeMounts: + - name: promtail-config + mountPath: /etc/promtail/promtail.yaml + subPath: promtail.yaml + readOnly: true + - name: shared-logs + mountPath: /plex-logs + {{ end }} - name: {{ .Chart.Name }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} @@ -181,16 +195,21 @@ spec: httpGet: path: /identity port: 32400 - initialDelaySeconds: {{ .Values.probes.readiness.initialDelaySeconds }} failureThreshold: {{ .Values.probes.readiness.failureThreshold }} - timeoutSeconds: {{ .Values.probes.readiness.timeoutSeconds }} + periodSeconds: {{ .Values.probes.readiness.periodSeconds }} livenessProbe: httpGet: path: /identity port: 32400 - initialDelaySeconds: {{ .Values.probes.liveness.initialDelaySeconds }} failureThreshold: {{ .Values.probes.liveness.failureThreshold }} - timeoutSeconds: {{ .Values.probes.liveness.timeoutSeconds }} + periodSeconds: {{ .Values.probes.liveness.periodSeconds }} + startupProbe: + httpGet: + path: /identity + port: 32400 + initialDelaySeconds: {{ .Values.probes.startup.initialDelaySeconds }} + failureThreshold: {{ .Values.probes.startup.failureThreshold }} + periodSeconds: {{ .Values.probes.startup.periodSeconds }} volumeMounts: {{- if .Values.persistence.data.enabled }} - name: data @@ -223,6 +242,8 @@ spec: {{- end }} - name: shared mountPath: /shared + - name: shared-logs + mountPath: "/config/Library/Application Support/Plex Media Server/Logs/" {{- if .Values.plexPreferences.enabled }} - name: {{ .Values.plexPreferences.volume.name }} mountPath: {{ .Values.plexPreferences.volume.mountPath }} @@ -235,10 +256,7 @@ spec: {{- end }} resources: {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} +##### VOLUMES START ##### volumes: {{- if .Values.persistence.data.enabled }} - name: data @@ -288,6 +306,8 @@ spec: {{- end }} - name: shared emptyDir: {} + - name: shared-logs + emptyDir: {} {{- if .Values.plexPreferences.enabled }} - name: {{ .Values.plexPreferences.volume.name }} configMap: @@ -303,7 +323,22 @@ spec: secret: secretName: {{ .Values.certificate.pkcsMangler.certificateSecret.name }} {{- end }} -##### VOLUMES END ##### + {{- if .Values.logging.promtail.enabled -}} + - name: promtail-config + projected: + defaultMode: 0444 + sources: + - configMap: + name: {{ template "plex.fullname" . }}-promtail + items: + - key: promtail.yaml + path: promtail.yaml + {{- end }} +##### VOLUMES END ##### + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} {{- with .Values.affinity }} affinity: {{- toYaml . | nindent 8 }} diff --git a/charts/plex/templates/promtail-configmap.yaml b/charts/plex/templates/promtail-configmap.yaml new file mode 100644 index 00000000..2fc83ce5 --- /dev/null +++ b/charts/plex/templates/promtail-configmap.yaml @@ -0,0 +1,18 @@ +{{- if .Values.logging.promtail.enabled -}} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "plex.fullname" . }}-promtail + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/name: {{ include "plex.name" . }} + helm.sh/chart: {{ include "plex.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +data: +{{- if .Values.logging.promtail.config }} +{{ $root := . }} + promtail.yaml: | +{{ tpl (toYaml .Values.logging.promtail.config | indent 4) $root }} +{{- end }} +{{- end }} diff --git a/charts/plex/values.yaml b/charts/plex/values.yaml index 083b3e41..97593375 100644 --- a/charts/plex/values.yaml +++ b/charts/plex/values.yaml @@ -291,16 +291,52 @@ certificate: name: plex-certs mountPath: /etc/plex-certs +# Logging configuration +# Standard Plex log paths: +# - /config/Library/Application\ Support/Plex\ Media\ Server/Logs/*.log +# - /config/Library/Application\ Support/Plex\ Media\ Server/Logs/PMS Plugin Logs/*.log +logging: + promtail: + enabled: false + image: + repository: grafana/promtail + tag: 1.6.0 + pullPolicy: IfNotPresent + config: + server: + disable: true + positions: + filename: /tmp/positions.yaml + clients: + - url: http://loki.logs.svc.cluster.local:3100/loki/api/v1/push + scrape_configs: + - job_name: plex-logs + static_configs: + - targets: + - localhost + labels: + job: plex-logs + __path__: "/plex-logs/*.log" + - job_name: plex-plugin-logs + static_configs: + - targets: + - localhost + labels: + job: plex-plugin-logs + __path__: "/plex-logs/PMS Plugin Logs/*.log" + # Probes configuration probes: liveness: - initialDelaySeconds: 15 failureThreshold: 5 - timeoutSeconds: 5 + periodSeconds: 10 readiness: - initialDelaySeconds: 15 failureThreshold: 5 - timeoutSeconds: 5 + periodSeconds: 10 + startup: + initialDelaySeconds: 5 + failureThreshold: 30 + periodSeconds: 10 resources: {} # We usually recommend not to specify default resources and to leave this as a conscious