From 07aee2537ac516deb756c735eb4517059f44ebc1 Mon Sep 17 00:00:00 2001 From: Spencer Koch Date: Mon, 11 Dec 2023 14:26:54 -0600 Subject: [PATCH] feat: migrate plex to k8s --- .../apps/kube-system/csi-driver-nfs/ks.yaml | 2 +- kubernetes/apps/media/kustomization.yaml | 9 ++ kubernetes/apps/media/namespace.yaml | 7 + .../apps/media/plex/app/helmrelease.yaml | 126 ++++++++++++++++++ .../apps/media/plex/app/kustomization.yaml | 7 + kubernetes/apps/media/plex/app/pvc.yaml | 11 ++ kubernetes/apps/media/plex/ks.yaml | 21 +++ .../external-services/kustomization.yaml | 1 - .../external-services/plex-docker.yaml | 38 ------ 9 files changed, 182 insertions(+), 40 deletions(-) create mode 100644 kubernetes/apps/media/kustomization.yaml create mode 100644 kubernetes/apps/media/namespace.yaml create mode 100644 kubernetes/apps/media/plex/app/helmrelease.yaml create mode 100644 kubernetes/apps/media/plex/app/kustomization.yaml create mode 100644 kubernetes/apps/media/plex/app/pvc.yaml create mode 100644 kubernetes/apps/media/plex/ks.yaml delete mode 100644 kubernetes/apps/networking/external-services/plex-docker.yaml diff --git a/kubernetes/apps/kube-system/csi-driver-nfs/ks.yaml b/kubernetes/apps/kube-system/csi-driver-nfs/ks.yaml index eabc1b54..bfda8bad 100644 --- a/kubernetes/apps/kube-system/csi-driver-nfs/ks.yaml +++ b/kubernetes/apps/kube-system/csi-driver-nfs/ks.yaml @@ -3,7 +3,7 @@ apiVersion: kustomize.toolkit.fluxcd.io/v1 kind: Kustomization metadata: - name: cluster-apps-csi-driver-nfs + name: csi-driver-nfs namespace: flux-system labels: substitution.flux.home.arpa/disabled: "true" diff --git a/kubernetes/apps/media/kustomization.yaml b/kubernetes/apps/media/kustomization.yaml new file mode 100644 index 00000000..0105a0ca --- /dev/null +++ b/kubernetes/apps/media/kustomization.yaml @@ -0,0 +1,9 @@ +--- +# yaml-language-server: $schema=https://json.schemastore.org/kustomization +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + # Pre Flux-Kustomizations + - ./namespace.yaml + # Flux-Kustomizations + - ./plex/ks.yaml diff --git a/kubernetes/apps/media/namespace.yaml b/kubernetes/apps/media/namespace.yaml new file mode 100644 index 00000000..e4b066b2 --- /dev/null +++ b/kubernetes/apps/media/namespace.yaml @@ -0,0 +1,7 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: media + labels: + kustomize.toolkit.fluxcd.io/prune: disabled diff --git a/kubernetes/apps/media/plex/app/helmrelease.yaml b/kubernetes/apps/media/plex/app/helmrelease.yaml new file mode 100644 index 00000000..df44e7ac --- /dev/null +++ b/kubernetes/apps/media/plex/app/helmrelease.yaml @@ -0,0 +1,126 @@ +--- +# yaml-language-server: $schema=https://kubernetes-schemas.devbu.io/helm.toolkit.fluxcd.io/helmrelease_v2beta1.json +apiVersion: helm.toolkit.fluxcd.io/v2beta1 +kind: HelmRelease +metadata: + name: plex +spec: + interval: 30m + chart: + spec: + chart: app-template + version: 2.4.0 + sourceRef: + kind: HelmRepository + name: bjw-s + namespace: flux-system + maxHistory: 2 + install: + remediation: + retries: 3 + upgrade: + cleanupOnFail: true + remediation: + retries: 3 + uninstall: + keepHistory: false + dependsOn: + # - name: intel-device-plugin-gpu + # namespace: kube-system + - name: csi-driver-nfs + namespace: kube-system + values: + controllers: + main: + annotations: + reloader.stakater.com/auto: "true" + containers: + main: + image: + repository: ghcr.io/onedr0p/plex + tag: 1.32.8.7639-fb6452ebf@sha256:637fe10cef736f249d96cb004c12f81646c81ca17ddce22374ea8782aa6646c2 + env: + TZ: UTC + probes: + liveness: &probes + enabled: true + custom: true + spec: + httpGet: + path: /identity + port: 32400 + initialDelaySeconds: 0 + periodSeconds: 10 + timeoutSeconds: 1 + failureThreshold: 3 + readiness: *probes + startup: + enabled: false + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: { drop: ["ALL"] } + resources: + requests: + # gpu.intel.com/i915: 1 + cpu: 200m + memory: 2Gi + limits: + # gpu.intel.com/i915: 1 + memory: 6Gi + pod: + # affinity: + # podAntiAffinity: + # requiredDuringSchedulingIgnoredDuringExecution: + # - labelSelector: + # matchExpressions: + # - key: app.kubernetes.io/name + # operator: In + # values: ["frigate"] + # topologyKey: kubernetes.io/hostname + # nodeSelector: + # intel.feature.node.kubernetes.io/gpu: "true" + securityContext: + runAsUser: 1001 + runAsGroup: 1001 + runAsNonRoot: true + fsGroup: 1001 + fsGroupChangePolicy: OnRootMismatch + # supplementalGroups: [44, 105, 10000] + service: + main: + ports: + http: + port: 32400 + ingress: + main: + enabled: true + className: external + annotations: + external-dns.alpha.kubernetes.io/target: external.${SECRET_DOMAIN} + nginx.ingress.kubernetes.io/backend-protocol: "HTTP" + hosts: + - host: &host "{{ .Release.Name }}.${SECRET_DOMAIN}" + paths: + - path: / + service: + name: main + port: http + tls: + - hosts: + - *host + persistence: + config: + enabled: true + existingClaim: plex-config + tmp: + type: emptyDir + transcode: + type: emptyDir + media: + type: nfs + server: 192.168.5.10 + path: /storage/plex-data/Media + globalMounts: + - path: /media + readOnly: true diff --git a/kubernetes/apps/media/plex/app/kustomization.yaml b/kubernetes/apps/media/plex/app/kustomization.yaml new file mode 100644 index 00000000..bc58b31b --- /dev/null +++ b/kubernetes/apps/media/plex/app/kustomization.yaml @@ -0,0 +1,7 @@ +--- +# yaml-language-server: $schema=https://json.schemastore.org/kustomization +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ./helmrelease.yaml + - ./pvc.yaml diff --git a/kubernetes/apps/media/plex/app/pvc.yaml b/kubernetes/apps/media/plex/app/pvc.yaml new file mode 100644 index 00000000..beb93c90 --- /dev/null +++ b/kubernetes/apps/media/plex/app/pvc.yaml @@ -0,0 +1,11 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: plex-config +spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 100Gi + storageClassName: nfs-slow diff --git a/kubernetes/apps/media/plex/ks.yaml b/kubernetes/apps/media/plex/ks.yaml new file mode 100644 index 00000000..32975db7 --- /dev/null +++ b/kubernetes/apps/media/plex/ks.yaml @@ -0,0 +1,21 @@ +--- +# yaml-language-server: $schema=https://kubernetes-schemas.devbu.io/kustomize.toolkit.fluxcd.io/kustomization_v1.json +apiVersion: kustomize.toolkit.fluxcd.io/v1 +kind: Kustomization +metadata: + name: &app plex + namespace: flux-system +spec: + targetNamespace: media + commonMetadata: + labels: + app.kubernetes.io/name: *app + path: ./kubernetes/apps/media/plex/app + prune: true + sourceRef: + kind: GitRepository + name: home-kubernetes + wait: false + interval: 30m + retryInterval: 1m + timeout: 5m diff --git a/kubernetes/apps/networking/external-services/kustomization.yaml b/kubernetes/apps/networking/external-services/kustomization.yaml index a2a011e2..af47f507 100644 --- a/kubernetes/apps/networking/external-services/kustomization.yaml +++ b/kubernetes/apps/networking/external-services/kustomization.yaml @@ -4,7 +4,6 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization namespace: networking resources: - - ./plex-docker.yaml - ./proxmox.yaml - ./pihole.yaml - ./unifi.yaml diff --git a/kubernetes/apps/networking/external-services/plex-docker.yaml b/kubernetes/apps/networking/external-services/plex-docker.yaml deleted file mode 100644 index 08a75970..00000000 --- a/kubernetes/apps/networking/external-services/plex-docker.yaml +++ /dev/null @@ -1,38 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - name: plex-docker - namespace: networking -spec: - type: ExternalName - ports: - - name: https - port: 32400 - targetPort: 32400 - externalName: 192.168.5.10 ---- -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: plex-docker - namespace: networking - annotations: - external-dns.alpha.kubernetes.io/target: external.${SECRET_DOMAIN} - nginx.ingress.kubernetes.io/backend-protocol: "HTTPS" -spec: - ingressClassName: external - tls: - - hosts: - - plex.${SECRET_DOMAIN} - rules: - - host: plex.${SECRET_DOMAIN} - http: - paths: - - path: / - pathType: Prefix - backend: - service: - name: plex-docker - port: - number: 32400