Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minimal dockerfile, k8s example #1188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docker/Dockerfile.minimal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:alpine
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets include this in the k8s folder with an explanation in the README, I'd like to keep maintain this dir as the place for GH image release


# Install required non-python dependencies.
# Just using the built-in ffmpeg for ease of creation.
RUN apk add --no-cache ffmpeg aria2

RUN --mount=type=cache,target=/root/.cache \
pip install ytdl-sub

VOLUME /config
VOLUME /media
# Default to a non-root user after build.
USER nobody
24 changes: 24 additions & 0 deletions kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Deploying with Kubernetes

## TL;DR

```console
$ git clone [email protected]:jmbannon/ytdl-sub.git
$ cd ytdl-sub/kubernetes
$ $EDITOR kustomization.yaml subs.yaml presets.yaml
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename these to subscriptions.yaml and config.yaml, to keep consistent with the documentation

$ kuzomise build . | kubectl apply -f -
```

## Configuration

Make sure you set the following to the right values for your kubernetes setup:
- `storageClassName` for each of the volumes in `./volumes.yaml`
- `namespace` in `kustomization.yaml`
- `images` overrides in `kustomization.yaml` if you don't want to use the minimal image
- `schedule` in `cronjob.yaml` if you want to run on a different schedule (defaults to
hourly.)

It should build a valid configuration without changing these kubernetes settings, but
it will probably not be what you're expecting.

See the normal documentation for configuring the `subs.yaml` and `presets.yaml` files.
Empty file added kubernetes/config.yaml
Empty file.
64 changes: 64 additions & 0 deletions kubernetes/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
apiVersion: batch/v1
kind: CronJob

metadata:
name: ytdl
spec:
schedule: '@hourly'
successfulJobsHistoryLimit: 3
concurrencyPolicy: Forbid
jobTemplate:
metadata:
labels:
app: ytdl
spec:
parallelism: 1
template:
metadata:
labels:
app: ytdl
spec:
containers:
- name: ytdl
image: kaictl/ytdl-sub:notlatest
command:
- ytdl-sub
- sub
volumeMounts:
# Where to download to
- mountPath: /media
name: media
# Storage for .ytdl-sub-working-directory.
- mountPath: /cache
name: cache
# Configuration and preset files location.
- mountPath: /config
name: config
# Run in the cache directory, just for ease of use.
workingDir: /cache/
# Run as non-root so we don't have security issues.
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
readOnlyRootFilesystem: false
runAsNonRoot: true
volumes:
- name: media
persistentVolumeClaim:
claimName: yt-media
- name: cache
persistentVolumeClaim:
claimName: yt-cache
- name: config
configMap:
name: ytdl
# More security settings. Runs as `nobody`.
securityContext:
fsGroup: 65534
fsGroupChangePolicy: OnRootMismatch
runAsGroup: 65534
runAsNonRoot: false
runAsUser: 65534
22 changes: 22 additions & 0 deletions kubernetes/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

# Set this to wherever you want your jobs to run. It should exist already.
namespace: ytdl-sub

images:
# Override this with your own image if you would like.
# This is a smaller image than the default that includes all the editor stuff.
- name: kaictl/ytdl-sub
newName: kaictl/ytdl-sub
Comment on lines +8 to +11
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be easier for others to point to the existing headless image in the configurations, and add in the docs on how to make it faster via custom image. Wdyt?

newTag: latest

resources:
- ./volumes.yaml
- ./cronjob.yaml

configMapGenerator:
- name: ytdl-config
files:
- ./config.yaml
- ./subscriptions.yaml
Empty file added kubernetes/subscriptions.yaml
Empty file.
38 changes: 38 additions & 0 deletions kubernetes/volumes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Final media storage.
# This should have enough space to store all the media you download. If you already have
# a media volume that you're serving stuff from (plex, etc.), then you can mount it
# here, or do the opposite and mount this volume to your running media server pods.
# It's recommended to use a separate volume from your other media downloads for safety.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: yt-media
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
# Set to the size of the storage volume you need
storage: 100Gi
# Will use the default storage class if not set, otherwise set to your desired
# storageclass name.
#storageClassName: my-video-storage-name
---

# For persistence of your cache, it is recommended to use a PVC for your /cache
# directory. Make sure the storage is fast enough, since it will be used as a cache for
# downloading a lot of small files, as well as temporary files while ytdl and ffmpeg do
# their work.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: yt-cache
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
# You probably don't need much storage, but that depends on the kinds of videos
# you download. I'd recommend at least 10Gi.
storage: 16Gi
#storageClassName: my-fast-storage-name