Commit 753e183b authored by Waqar Ahmed's avatar Waqar Ahmed

Add upstream plex chart

parent 66c3d0d0
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
# OWNERS file for Kubernetes
OWNERS
apiVersion: v2
appVersion: 1.20.2.3402
description: Plex Media Server
name: plex
version: 2.1.0
keywords:
- plex
home: https://plex.tv/
icon: https://www.plex.tv/wp-content/uploads/2018/01/pmp-icon-1.png
sources:
- https://github.com/k8s-at-home/charts/tree/master/charts/plex
- https://hub.docker.com/r/plexinc/pms-docker/
maintainers:
- name: billimek
email: jeff@billimek.com
approvers:
- billimek
reviewers:
- billimek
\ No newline at end of file
# Plex Media Server helm chart
This is an opinionated helm chart for Plex Media Center based on the [official container image](https://hub.docker.com/r/plexinc/pms-docker/).
This chart is 'forked' from the excellent [munnerz/kube-plex](https://github.com/munnerz/kube-plex) repo in order to allow for more timely updates and publishing to a helm registry. **NOTE:** This chart is not compatible as an upgrade from the `kube-plex` chart.
## TL;DR
```shell
helm repo add k8s-at-home https://k8s-at-home.com/charts/
helm install k8s-at-home/plex
```
## Installing the Chart
To install the chart with the release name `plex`:
```console
helm install plex k8s-at-home/plex
```
## Uninstalling the Chart
To uninstall/delete the `plex` deployment:
```console
helm delete plex
```
The command removes all the Kubernetes components associated with the chart and deletes the release.
## Configuration
Read through the [values.yaml](https://github.com/k8s-at-home/charts/blob/master/charts/plex/values.yaml) file. It has several commented out suggested values.
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,
```console
helm install plex \
--set timezone="America/New York" \
k8s-at-home/plex
```
Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example,
```console
helm install plex -f values.yaml k8s-at-home/plex
```
#!/usr/bin/with-contenv bash
# This file is based off of the official 40-plex-first-run
# Here: https://github.com/plexinc/pms-docker/blob/master/root/etc/cont-init.d/40-plex-first-run
# It should live in /etc/cont-init.d/
# If we are debugging, enable trace
if [ "${DEBUG,,}" = "true" ]; then
set -x
fi
function getPref {
local key="$1"
xmlstarlet sel -T -t -m "/Preferences" -v "@${key}" -n "${prefFile}"
}
function setPref {
local key="$1"
local value="$2"
count="$(xmlstarlet sel -t -v "count(/Preferences/@${key})" "${prefFile}")"
count=$(($count + 0))
if [[ $count > 0 ]]; then
xmlstarlet ed --inplace --update "/Preferences/@${key}" -v "${value}" "${prefFile}"
else
xmlstarlet ed --inplace --insert "/Preferences" --type attr -n "${key}" -v "${value}" "${prefFile}"
fi
}
home="$(echo ~plex)"
pmsApplicationSupportDir="${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR:-${home}/Library/Application Support}"
prefFile="${pmsApplicationSupportDir}/Plex Media Server/Preferences.xml"
if [ ! -z "${ADVERTISE_IP}" ]; then
setPref "customConnections" "${ADVERTISE_IP}"
fi
if [ ! -z "${ALLOWED_NETWORKS}" ]; then
setPref "allowedNetworks" "${ALLOWED_NETWORKS}"
fi
# Set transcoder temp if not yet set
if [ -z "$(getPref "TranscoderTempDirectory")" ]; then
setPref "TranscoderTempDirectory" "/transcode"
fi
# Parse list of all exported variables that start with PLEX_PREFERENCE_
# The format of which is PLEX_PREFERENCE_<SOMETHING>="Key=Value"
# Where Key is the EXACT key to use in the Plex Preference file
# And Value is the EXACT value to use in the Plex Preference file for that key.
# Please note it looks like many of the key's are camelCase in some fashion.
# Additionally there are likely some preferences where environment variable injection
# doesn't really work for.
for var in "${!PLEX_PREFERENCE_@}"; do
value=${!var}
PreferenceValue=${value#*=}
PreferenceKey=${value%=*}
setPref $PreferenceKey $PreferenceValue
done
# touch /.firstRunComplete
# echo "Plex Media Server first run setup complete"
echo "Plex Media Server preferences update run complete"
\ No newline at end of file
#!/usr/bin/with-contenv bash
# This file contains part of the official PLEX 40-plex-first-run
# Here: https://github.com/plexinc/pms-docker/blob/master/root/etc/cont-init.d/40-plex-first-run
# It should live in /etc/cont-init.d/
# If we are debugging, enable trace
if [ "${DEBUG,,}" = "true" ]; then
set -x
fi
function setPref {
local key="$1"
local value="$2"
count="$(xmlstarlet sel -t -v "count(/Preferences/@${key})" "${prefFile}")"
count=$(($count + 0))
if [[ $count > 0 ]]; then
xmlstarlet ed --inplace --update "/Preferences/@${key}" -v "${value}" "${prefFile}"
else
xmlstarlet ed --inplace --insert "/Preferences" --type attr -n "${key}" -v "${value}" "${prefFile}"
fi
}
home="$(echo ~plex)"
pmsApplicationSupportDir="${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR:-${home}/Library/Application Support}"
prefFile="${pmsApplicationSupportDir}/Plex Media Server/Preferences.xml"
# If PKCSMANGLER__PFXINCONTAINERPATH is set, then assume we want to move the PFX Cert to that location
if [ ! -z "${PKCSMANGLER_PFXINCONTAINERPATH}" ]; then
# If it ends up a problem, we may need to set some kind of "don't replace existing PFX cert"
cp -f /shared/cert.pfx "${PKCSMANGLER_PFXINCONTAINERPATH}"
# If PKCSMANGLER__CUSTOMCERTDOMAIN is set, then assume we want to set the PLEX Preference customCertificatePath because we enabled setting PLEX Preferences
if [ ! -z "${PKCSMANGLER_CUSTOMCERTDOMAIN}" ]; then
setPref "customCertificatePath" "${PKCSMANGLER_PFXINCONTAINERPATH}"
fi
fi
# If PKCSMANGLER_PFXPASSWORD is set, then assume we want to set the PLEX Preference customCertificateKey
if [ ! -z "${PKCSMANGLER_PFXPASSWORD}" ]; then
setPref "customCertificateKey" "${PKCSMANGLER_PFXPASSWORD}"
fi
# If PKCSMANGLER__CUSTOMCERTDOMAIN is set, then assume we want to set the PLEX Preference customCertificateDomain
if [ ! -z "${PKCSMANGLER_CUSTOMCERTDOMAIN}" ]; then
PreferenceValue=${PKCSMANGLER_CUSTOMCERTDOMAIN#*=}
PreferenceKey=${PKCSMANGLER_CUSTOMCERTDOMAIN%=*}
setPref $PreferenceKey $PreferenceValue
fi
# touch /.firstRunComplete
# echo "Plex Media Server first run setup complete"
echo "PKCS Mangler run complete"
\ No newline at end of file
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}
{{- end }}
{{- else if contains "NodePort" .Values.serviceTCP.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "plex.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.serviceTCP.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "plex.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "plex.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.serviceTCP.port }}
{{- else if contains "ClusterIP" .Values.serviceTCP.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "plex.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80
{{- end }}
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "plex.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "plex.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "plex.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Common labels
*/}}
{{- define "plex.labels" -}}
helm.sh/chart: {{ include "plex.chart" . }}
{{ include "plex.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
{{/*
Selector labels
*/}}
{{- define "plex.selectorLabels" -}}
app.kubernetes.io/name: {{ include "plex.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
{{/*
Create the name of the service account to use
*/}}
{{- define "plex.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "plex.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
{{/*
abstract: |
Joins a list of values into a comma separated string
values: |
test:
- foo
- bar
usage: |
{{ include "joinListWithComma" .Values.test }}
return: |
foo,bar
*/}}
{{- define "joinListWithComma" -}}
{{- $local := dict "first" true -}}
{{- range $k, $v := . -}}{{- if not $local.first -}},{{- end -}}{{- $v -}}{{- $_ := set $local "first" false -}}{{- end -}}
{{- end -}}
\ No newline at end of file
{{- if .Values.plexPreferences.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.plexPreferences.configmap.name }}
labels:
{{- include "plex.labels" . | nindent 4 }}
{{- if .Values.plexPreferences.configmap.labels }}
{{ toYaml .Values.plexPreferences.configmap.labels | indent 4 }}
{{- end }}
{{- with .Values.plexPreferences.configmap.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
data:
# At some point figure out how to use a value/Variable here to be able to specify
# a different file or something.
{{ (tpl (.Files.Glob "configs/41-plex-preferences").AsConfig . ) | indent 2 }}
{{- end -}}
{{- if .Values.certificate.pkcsMangler.enabled }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.certificate.pkcsMangler.configmap.name }}
labels:
{{- include "plex.labels" . | nindent 4 }}
{{- if .Values.certificate.pkcsMangler.configmap.labels }}
{{ toYaml .Values.certificate.pkcsMangler.configmap.labels | indent 4 }}
{{- end }}
{{- with .Values.certificate.pkcsMangler.configmap.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
data:
# At some point figure out how to use a value/Variable here to be able to specify
# a different file or something.
{{ (tpl (.Files.Glob "configs/42-pkcs-mangler").AsConfig . ) | indent 2 }}
{{- end -}}
\ No newline at end of file
This diff is collapsed.
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "plex.fullname" . -}}
{{- $svcPort := .Values.serviceTCP.port -}}
{{- $ingressPath := .Values.ingress.path -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "plex.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ . | quote }}
http:
paths:
- path: {{ $ingressPath }}
backend:
serviceName: {{ $fullName }}-tcp
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- 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:
promtail.yaml: |
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: {{ .Values.logging.promtail.loki.url }}
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"
{{- end }}
{{- if .Values.certificate.pkcsMangler.enabled -}}
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.certificate.pkcsMangler.pfxPassword.secretName }}
labels:
{{- include "plex.labels" . | nindent 4 }}
{{- if .Values.certificate.pkcsMangler.pfxPassword.labels }}
{{ toYaml .Values.certificate.pkcsMangler.pfxPassword.labels | indent 4 }}
{{- end }}
{{- with .Values.certificate.pkcsMangler.pfxPassword.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
type: Opaque
stringData:
{{ .Values.certificate.pkcsMangler.pfxPassword.passwordKey }}: {{ .Values.certificate.pkcsMangler.pfxPassword.value }}
{{- end -}}
\ No newline at end of file
apiVersion: v1
kind: Service
metadata:
name: {{ include "plex.fullname" . }}-tcp
labels:
{{- include "plex.labels" . | nindent 4 }}
{{- if .Values.serviceTCP.labels }}
{{ toYaml .Values.serviceTCP.labels | indent 4 }}
{{- end }}
{{- with .Values.serviceTCP.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- if (or (eq .Values.serviceTCP.type "ClusterIP") (empty .Values.serviceTCP.type)) }}
type: ClusterIP
{{- if .Values.serviceTCP.clusterIP }}
clusterIP: {{ .Values.serviceTCP.clusterIP }}
{{end}}
{{- else if eq .Values.serviceTCP.type "LoadBalancer" }}
type: {{ .Values.serviceTCP.type }}
{{- if .Values.serviceTCP.loadBalancerIP }}
loadBalancerIP: {{ .Values.serviceTCP.loadBalancerIP }}
{{- end }}
{{- if .Values.serviceTCP.loadBalancerSourceRanges }}
loadBalancerSourceRanges:
{{ toYaml .Values.serviceTCP.loadBalancerSourceRanges | indent 4 }}
{{- end -}}
{{- else }}
type: {{ .Values.serviceTCP.type }}
{{- end }}
{{- if .Values.serviceTCP.externalIPs }}
externalIPs:
{{ toYaml .Values.serviceTCP.externalIPs | indent 4 }}
{{- end }}
{{- if .Values.serviceTCP.externalTrafficPolicy }}
externalTrafficPolicy: {{ .Values.serviceTCP.externalTrafficPolicy }}
{{- end }}
ports:
- name: pms
port: {{ .Values.serviceTCP.port }}
protocol: TCP
targetPort: pms
{{ if (and (eq .Values.serviceTCP.type "NodePort") (not (empty .Values.serviceTCP.nodePort))) }}
nodePort: {{.Values.serviceTCP.nodePort}}
{{ end }}
- name: http
port: 80
targetPort: pms
- name: https
port: 443
targetPort: pms
- name: plex-dlna
port: 1900
targetPort: plex-dlna
selector:
{{- include "plex.selectorLabels" . | nindent 4 }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "plex.fullname" . }}-udp
labels:
{{- include "plex.labels" . | nindent 4 }}
{{- if .Values.serviceUDP.labels }}
{{ toYaml .Values.serviceUDP.labels | indent 4 }}
{{- end }}
{{- with .Values.serviceUDP.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- if (or (eq .Values.serviceUDP.type "ClusterIP") (empty .Values.serviceUDP.type)) }}
type: ClusterIP
{{- if .Values.serviceUDP.clusterIP }}
clusterIP: {{ .Values.serviceUDP.clusterIP }}
{{end}}
{{- else if eq .Values.serviceUDP.type "LoadBalancer" }}
type: {{ .Values.serviceUDP.type }}
{{- if .Values.serviceUDP.loadBalancerIP }}
loadBalancerIP: {{ .Values.serviceUDP.loadBalancerIP }}
{{- end }}
{{- if .Values.serviceUDP.loadBalancerSourceRanges }}
loadBalancerSourceRanges:
{{ toYaml .Values.serviceUDP.loadBalancerSourceRanges | indent 4 }}
{{- end -}}
{{- else }}
type: {{ .Values.serviceUDP.type }}
{{- end }}
{{- if .Values.serviceUDP.externalIPs }}
externalIPs:
{{ toYaml .Values.serviceUDP.externalIPs | indent 4 }}
{{- end }}
{{- if .Values.serviceUDP.externalTrafficPolicy }}
externalTrafficPolicy: {{ .Values.serviceUDP.externalTrafficPolicy }}
{{- end }}
ports:
- name: plex-dlna-udp
port: 1900
protocol: UDP
targetPort: plex-dlna-udp
- name: plex-gdm1
port: 32410
protocol: UDP
targetPort: plex-gdm1
- name: plex-gdm2
port: 32412
protocol: UDP
targetPort: plex-gdm2
- name: plex-gdm3
port: 32413
protocol: UDP
targetPort: plex-gdm3
- name: plex-gdm4
port: 32414
protocol: UDP
targetPort: plex-gdm4
selector:
{{- include "plex.selectorLabels" . | nindent 4 }}
{{- if and (not .Values.persistence.transcode.claimName) .Values.persistence.transcode.enabled }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ template "plex.fullname" . }}-transcode
labels:
{{- include "plex.labels" . | nindent 4 }}
component: transcode
spec:
accessModes:
- {{ .Values.persistence.config.accessMode | quote }}
resources:
requests:
storage: {{ .Values.persistence.transcode.size | quote }}
{{- if .Values.persistence.transcode.storageClass }}
storageClassName: {{ .Values.persistence.transcode.storageClass | quote }}
{{- end }}
---
{{- end }}
{{- if not .Values.persistence.config.claimName }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ template "plex.fullname" . }}-config
labels:
{{- include "plex.labels" . | nindent 4 }}
component: config
spec:
accessModes:
- {{ .Values.persistence.config.accessMode | quote }}
resources:
requests:
storage: {{ .Values.persistence.config.size | quote }}
{{- if .Values.persistence.config.storageClass }}
storageClassName: {{ .Values.persistence.config.storageClass | quote }}
{{- end }}
---
{{- end }}
{{- if and (not .Values.persistence.data.claimName) .Values.persistence.data.enabled }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ template "plex.fullname" . }}-data
labels:
{{- include "plex.labels" . | nindent 4 }}
component: data
spec:
accessModes:
- {{ .Values.persistence.data.accessMode | quote }}
resources:
requests:
storage: {{ .Values.persistence.data.size | quote }}
{{- if .Values.persistence.data.storageClass }}
storageClassName: {{ .Values.persistence.data.storageClass | quote }}
{{- end }}
---
{{- end }}
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment