diff --git a/.drone.yml b/.drone.yml index 16d1962..5725752 100644 --- a/.drone.yml +++ b/.drone.yml @@ -11,7 +11,7 @@ trigger: - main steps: - - name: step1 + - name: "Upload New Versions" image: alpine commands: - ./build-tools/upload-new-versions.sh @@ -20,6 +20,7 @@ steps: from_secret: gitea_password ARGO_TOKEN: from_secret: argo_token + # TODO - step to apply manifests image_pull_secrets: - dockerconfigjson diff --git a/application-manifests.yaml b/application-manifests.yaml index d6162b3..75cc87a 100644 --- a/application-manifests.yaml +++ b/application-manifests.yaml @@ -103,3 +103,32 @@ spec: prune: true syncOptions: - CreateNamespace=true +--- +# TODO - use Jsonnet or similar to automate building this from all the directories +# (and pull out the common config) +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: jellyfin + namespace: argo +spec: + project: default + + source: + repoURL: https://gitea.scubbo.org/scubbo/helm-charts.git + targetRevision: HEAD + path: charts/jellyfin + + helm: + valueFiles: + - values.yaml + + destination: + server: "https://kubernetes.default.svc" + namespace: jellyfin + + syncPolicy: + automated: + prune: true + syncOptions: + - CreateNamespace=true diff --git a/build-tools/upload-new-versions.sh b/build-tools/upload-new-versions.sh index 0abfcca..d64acdc 100755 --- a/build-tools/upload-new-versions.sh +++ b/build-tools/upload-new-versions.sh @@ -36,19 +36,3 @@ done find bundles -type f -exec curl -s --user "scubbo:$GITEA_PASSWORD" -X POST --upload-file '{}' https://gitea.scubbo.org/api/packages/scubbo/helm/api/charts \; rm -rf bundles; -# Call Argo UI to create/sync the Argo application. -# -# Prefer this over declarative GitOps - "upload a file like [here](https://argo-cd.readthedocs.io/en/stable/user-guide/helm/) -# stating which version should be used" - because that would require two changes for one version (one to declare and -# upload the new version, another to depend on it). Since we _own_ the chart definitions, there's no reason not to -# deploy the latest one immediately! -# -# An alternative approach (that would only have required a single update) would be for the Argo Application to track a -# Git Repo (at HEAD) rather than a Helm repo. In this case, merely pushing a new instance to HEAD would be sufficient to -# update the Argo App. However, I wanted to learn how to operate a Helm repo :) -for changed_chart in $changed_charts -do - app_name=$(basename $changed_chart) - # TODO - create app if it doesn't already exist - curl -s -X POST "argo-cd-argocd-server.argo.svc.cluster.local/api/v1/applications/$app_name/sync" -H "Authorization: Bearer ${ARGO_TOKEN}" -H "Content-Type: application/json" -done diff --git a/charts/jellyfin/Chart.yaml b/charts/jellyfin/Chart.yaml new file mode 100644 index 0000000..ef1b613 --- /dev/null +++ b/charts/jellyfin/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: jellyfin +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/charts/jellyfin/templates/NOTES.txt b/charts/jellyfin/templates/NOTES.txt new file mode 100644 index 0000000..31f6a91 --- /dev/null +++ b/charts/jellyfin/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "jellyfin.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.service.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 "jellyfin.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "jellyfin.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "jellyfin.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/jellyfin/templates/_helpers.tpl b/charts/jellyfin/templates/_helpers.tpl new file mode 100644 index 0000000..47b24d9 --- /dev/null +++ b/charts/jellyfin/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "jellyfin.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 "jellyfin.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 "jellyfin.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "jellyfin.labels" -}} +helm.sh/chart: {{ include "jellyfin.chart" . }} +{{ include "jellyfin.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "jellyfin.selectorLabels" -}} +app.kubernetes.io/name: {{ include "jellyfin.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "jellyfin.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "jellyfin.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/jellyfin/templates/deployment.yaml b/charts/jellyfin/templates/deployment.yaml new file mode 100644 index 0000000..01a22ea --- /dev/null +++ b/charts/jellyfin/templates/deployment.yaml @@ -0,0 +1,71 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "jellyfin.fullname" . }} + labels: + {{- include "jellyfin.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "jellyfin.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "jellyfin.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - mountPath: /media + name: jf-media + readOnly: True + - mountPath: /config + name: jf-config + - mountPath: /cache + name: jf-cache + tolerations: + - key: face + operator: Equal + value: bad + effect: NoSchedule + volumes: + - name: jf-media + persistentVolumeClaim: + claimName: jf-media-pvc + - name: jf-config + persistentVolumeClaim: + claimName: jf-config-pvc + - name: jf-cache + persistentVolumeClaim: + claimName: jf-cache-pvc + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/jellyfin/templates/ingress.yaml b/charts/jellyfin/templates/ingress.yaml new file mode 100644 index 0000000..d8de4a3 --- /dev/null +++ b/charts/jellyfin/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "jellyfin.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else 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 "jellyfin.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/jellyfin/templates/metrics/deployment.yaml b/charts/jellyfin/templates/metrics/deployment.yaml new file mode 100644 index 0000000..c968be0 --- /dev/null +++ b/charts/jellyfin/templates/metrics/deployment.yaml @@ -0,0 +1,28 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "jellyfin.fullname" . }}-metrics + labels: + app.kubernetes.io/name: jellyfin-metrics +spec: + selector: + matchLabels: + app.kubernetes.io/name: jellyfin-metrics + template: + metadata: + labels: + app.kubernetes.io/name: jellyfin-metrics + spec: + containers: + - name: jellyfin-metrics + image: "{{ .Values.metricsImage.repository }}:{{ .Values.metricsImage.tag | default .Chart.AppVersion }}" + imagePullPolicy: Always + env: + - name: API_URL + value: "{{ .Values.metrics.apiUrl }}" + - name: API_KEY + valueFrom: + secretKeyRef: + name: jellyfin-metrics-secret + key: api-key + diff --git a/charts/jellyfin/templates/metrics/service-monitor.yaml b/charts/jellyfin/templates/metrics/service-monitor.yaml new file mode 100644 index 0000000..ca3063f --- /dev/null +++ b/charts/jellyfin/templates/metrics/service-monitor.yaml @@ -0,0 +1,19 @@ +# Taken from https://cogarius.medium.com/3-3-complete-guide-to-ci-cd-pipelines-with-drone-io-on-kubernetes-drone-metrics-with-prometheus-c2668e42b03f +# Refer to https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#endpoint for explanation of fields +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + labels: + app: prometheus-operator + release: prometheus + name: jellyfin-count + namespace: prometheus +spec: + namespaceSelector: + matchNames: + - jellyfin + endpoints: + - port: metrics + selector: + matchLabels: + app.kubernetes.io/name: jellyfin-metrics diff --git a/charts/jellyfin/templates/metrics/service.yaml b/charts/jellyfin/templates/metrics/service.yaml new file mode 100644 index 0000000..9af8ef9 --- /dev/null +++ b/charts/jellyfin/templates/metrics/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "jellyfin.fullname" . }}-metrics + labels: + app.kubernetes.io/name: jellyfin-metrics +spec: + type: LoadBalancer + ports: + - port: 8555 + targetPort: 8555 + name: metrics + protocol: TCP + sessionAffinity: ClientIP + selector: + app.kubernetes.io/name: jellyfin-metrics \ No newline at end of file diff --git a/charts/jellyfin/templates/service.yaml b/charts/jellyfin/templates/service.yaml new file mode 100644 index 0000000..85f7667 --- /dev/null +++ b/charts/jellyfin/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "jellyfin.fullname" . }} + labels: + {{- include "jellyfin.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: 8096 + protocol: TCP + sessionAffinity: ClientIP + selector: + {{- include "jellyfin.selectorLabels" . | nindent 4 }} diff --git a/charts/jellyfin/templates/tests/test-connection.yaml b/charts/jellyfin/templates/tests/test-connection.yaml new file mode 100644 index 0000000..98fb0ee --- /dev/null +++ b/charts/jellyfin/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "jellyfin.fullname" . }}-test-connection" + labels: + {{- include "jellyfin.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "jellyfin.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/jellyfin/templates/volumes.yaml b/charts/jellyfin/templates/volumes.yaml new file mode 100644 index 0000000..42aacc0 --- /dev/null +++ b/charts/jellyfin/templates/volumes.yaml @@ -0,0 +1,71 @@ +{{- range .Values.volumes }} +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: jf-{{ .name }} +spec: + capacity: + storage: {{ .config.size | quote }} + accessModes: + - {{ .config.accessMode }} + nfs: + server: {{ .config.nfs.server }} + path: {{ .config.nfs.path }} + {{- if hasPrefix "ReadOnly" .config.accessMode }} + readOnly: true + {{- end}} + mountOptions: + - nfsvers=4.2 +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: jf-{{ .name }}-pvc +spec: + storageClassName: "" + volumeName: jf-{{ .name }} + accessModes: + - {{ .config.accessMode }} + volumeMode: Filesystem + resources: + requests: + storage: {{ .config.size | quote }} +{{- end}} +# --- +# # https://forum.jellyfin.org/t-could-not-apply-migration-migrateactivitylogdatabase +# apiVersion: v1 +# kind: PersistentVolume +# metadata: +# name: jf-config +# spec: +# capacity: +# storage: "100M" +# volumeMode: Filesystem +# accessModes: +# - ReadWriteMany +# storageClassName: local-storage +# local: +# path: /mnt/NEW_BERTHA/local-jellyfin-config +# nodeAffinity: +# required: +# nodeSelectorTerms: +# - matchExpressions: +# - key: kubernetes.io/hostname +# operator: In +# values: +# - rasnu2 +# --- +# apiVersion: v1 +# kind: PersistentVolumeClaim +# metadata: +# name: jf-config-pvc +# spec: +# storageClassName: "" +# volumeName: jf-config +# accessModes: +# - ReadWriteMany +# volumeMode: Filesystem +# resources: +# requests: +# storage: "100M" diff --git a/charts/jellyfin/values.yaml b/charts/jellyfin/values.yaml new file mode 100644 index 0000000..66e424a --- /dev/null +++ b/charts/jellyfin/values.yaml @@ -0,0 +1,120 @@ +# Default values for jellyfin. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: jellyfin/jellyfin + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "10.8.10" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: LoadBalancer + port: 8096 + +ingress: + enabled: true + className: "traefik" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: jellyfin.avril + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +# Custom values below here + +# This approach is still pretty lacking: +# - No type-checking +# - Assumes NFS +# - replication of nfsServer +# +# But hey, this is for my own use anyway. If people start referencing it, I can improve it! :P +volumes: + - name: cache + config: + size: 2G + accessMode: ReadWriteMany + nfs: + server: rassigma.avril + path: "/mnt/BERTHA/etc/jellyfin/cache" + - name: config + config: + size: 100M + accessMode: ReadWriteMany + nfs: + server: rassigma.avril + path: "/mnt/BERTHA/etc/jellyfin/config" + - name: media + config: + size: 3T + accessMode: ReadOnlyMany + nfs: + server: rasnu2.avril + path: "/mnt/NEW_BERTHA/ombi-data/media" + +metricsImage: + repository: gitea.scubbo.org/scubbo/jellyfin-library-count-prometheus-exporter + tag: latest + +metrics: + apiUrl: "http://jellyfin.avril"