Skip to content

Commit

Permalink
bumps reqs && reformat k8s files
Browse files Browse the repository at this point in the history
  • Loading branch information
bralbral committed Jun 20, 2024
1 parent 9049fae commit 087bce3
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 153 deletions.
12 changes: 10 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,21 @@ And use this image with [docker-compose.yml](./deploy/example.docker-compose.yml

> Stable release with `main` tag on [dockerhub](https://hub.docker.com/r/bral1488/telegram-youtube-notifier/tags)
Just copy [deployment.yml](deploy%2Fk8s%2Fexample.deployment.yml) and fill in sections in `ConfigMap`, `PersistentVolume` sections.
Manifests located in [k8s](deploy%2Fk8s) directory.

It consists of `Namespace`, `ConfigMap`, `PersistenVolume`, `PersistentVolumeClaim`, and `Deployment` files.

You need fill sections in [01_configmap.yaml](deploy%2Fk8s%2F01_configmap.yaml) and [02_persistent_volume.yaml](deploy%2Fk8s%2F02_persistent_volume.yaml) files.

> ⚠️ Deployment use `storageClassName: local-path`. A detailed description can be found [here](https://kubernetes.io/docs/concepts/storage/storage-classes/#local)
Apply deployment:

`kubectl apply -f deployment.yml`
`kubectl apply -f <directory with configs>`

Or you can do it step by step:

`kubectl apply -f <file from config dir>`

## Setup Cookies

Expand Down
5 changes: 5 additions & 0 deletions deploy/k8s/00_namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# create separate namespace
apiVersion: v1
kind: Namespace
metadata:
name: yt-notifier-namespace
51 changes: 51 additions & 0 deletions deploy/k8s/01_configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# create config map
# for config.yaml
# and cookies.txt (optional)
apiVersion: v1
kind: ConfigMap
metadata:
name: yt-notifier-config
namespace: yt-notifier-namespace
data:
config.yaml: |
bot:
token: XXXXXXXXXXXXXXXXXXXXX
chat_id: -100XXXXXXXXXXXXXXXXX
temp_chat_id: -100XXXXXXXXXXXX
report:
template: |
<h1>✅ СЕЙЧАС В ЭФИРЕ:</h1>
<br/>
<ol type='1'>
{% for channel in channels %}
<li>
<b><a href='{{channel.url}}'>{{channel.label}}</a></b> <br/>
{% if channel.concurrent_view_count is not none %}
<b>👀{{channel.concurrent_view_count}}</b>
{% endif %}
{% if channel.like_count is not none %}
<b>👍{{channel.like_count}}</b>
{% endif %}
{% if channel.duration is not none %}
<b>🕑{{channel.duration}}</b>
{% endif %}
</li>
<br/>
{% endfor %}
</ol>
<hr/>
<i>💬 Заходите в наш <a href='https://t.me/Discordovchat'>чат</a>.</i>
<br/>
<i>🤖 <a href='https://t.me/discordovo_feedback_bot'>Бот-предложка</a>, присылайте интересные ссылки на каналы/видео/картинки. </i>
empty: |
<b>🤷 Интересных стримов сейчас нет.</b>
<hr/>
<i>💬 Заходите в наш <a href='https://t.me/Discordovchat'>чат</a>.</i>
<br/>
<i>🤖 <a href='https://t.me/discordovo_feedback_bot'>Бот-предложка</a>, присылайте интересные ссылки на каналы/видео/картинки. </i>
start_scheduler: True
interval_s: 300
cookies.txt: |
# Netscape HTTP Cookie File
# This file is generated by yt-dlp. Do not edit.
24 changes: 24 additions & 0 deletions deploy/k8s/02_persistent_volume.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# create persistent volume for database
apiVersion: v1
kind: PersistentVolume
metadata:
name: yt-notifier-pv
namespace: yt-notifier-namespace
spec:
capacity:
storage: 128Mi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-path
local:
path: /path/to/database/on/host/machine
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- my-k8s-node # get value from kubectl get nodes
13 changes: 13 additions & 0 deletions deploy/k8s/03_persistent_volume_claim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# create volume claim for database
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: yt-notifier-pvc
namespace: yt-notifier-namespace
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 128Mi
storageClassName: local-path
53 changes: 53 additions & 0 deletions deploy/k8s/04_deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# create deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: yt-notifier
namespace: yt-notifier-namespace
spec:
replicas: 1
selector:
matchLabels:
app: yt-notifier
template:
metadata:
labels:
app: yt-notifier
spec:
containers:
- name: yt-notifier
image: bral1488/telegram-youtube-notifier:main
imagePullPolicy: Always
command: ["sh", "-c", "python -m src"]
volumeMounts:
- name: config-volume
mountPath: /app/config.yaml
subPath: config.yaml
readOnly: true
- name: config-volume
mountPath: /app/cookies.txt
subPath: cookies.txt
readOnly: true
- name: db-volume
mountPath: /db/youtube-notifier-bot.db
subPath: youtube-notifier-bot.db
resources:
limits:
memory: "256Mi"
cpu: "500m"
securityContext:
runAsUser: 0
env:
- name: SQLITE_DATABASE_FILE_PATH
value: "/db/youtube-notifier-bot.db"
volumes:
- name: config-volume
configMap:
name: yt-notifier-config
- name: db-volume
persistentVolumeClaim:
claimName: yt-notifier-pvc
tolerations:
- key: "node.kubernetes.io/disk-pressure"
operator: "Exists"
effect: "NoSchedule"
150 changes: 0 additions & 150 deletions deploy/k8s/example.deployment.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SQLITE_DATABASE_FILE_PATH: str = os.environ.get(
"SQLITE_DATABASE_FILE_PATH", os.path.join(ROOT_DIR, "youtube-notifier-bot.db")
)
VERSION: str = "2024-06-16.16"
VERSION: str = "2024-06-20.10"

__all__ = [
"CONFIG_FILE_PATH",
Expand Down

0 comments on commit 087bce3

Please sign in to comment.