From 087bce324cf0d9d07e13af34db2dd31da6c4b04a Mon Sep 17 00:00:00 2001 From: bral bral Date: Thu, 20 Jun 2024 10:25:23 +0300 Subject: [PATCH] bumps reqs && reformat k8s files --- README.MD | 12 +- deploy/k8s/00_namespace.yaml | 5 + deploy/k8s/01_configmap.yaml | 51 +++++++ deploy/k8s/02_persistent_volume.yaml | 24 ++++ deploy/k8s/03_persistent_volume_claim.yaml | 13 ++ deploy/k8s/04_deployment.yaml | 53 ++++++++ deploy/k8s/example.deployment.yml | 150 --------------------- src/constants.py | 2 +- 8 files changed, 157 insertions(+), 153 deletions(-) create mode 100644 deploy/k8s/00_namespace.yaml create mode 100644 deploy/k8s/01_configmap.yaml create mode 100644 deploy/k8s/02_persistent_volume.yaml create mode 100644 deploy/k8s/03_persistent_volume_claim.yaml create mode 100644 deploy/k8s/04_deployment.yaml delete mode 100644 deploy/k8s/example.deployment.yml diff --git a/README.MD b/README.MD index 3197cb4..44e3181 100644 --- a/README.MD +++ b/README.MD @@ -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 ` + +Or you can do it step by step: + +`kubectl apply -f ` ## Setup Cookies diff --git a/deploy/k8s/00_namespace.yaml b/deploy/k8s/00_namespace.yaml new file mode 100644 index 0000000..188afe9 --- /dev/null +++ b/deploy/k8s/00_namespace.yaml @@ -0,0 +1,5 @@ +# create separate namespace +apiVersion: v1 +kind: Namespace +metadata: + name: yt-notifier-namespace \ No newline at end of file diff --git a/deploy/k8s/01_configmap.yaml b/deploy/k8s/01_configmap.yaml new file mode 100644 index 0000000..ed105cf --- /dev/null +++ b/deploy/k8s/01_configmap.yaml @@ -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: | +

✅ СЕЙЧАС В ЭФИРЕ:

+
+
    + {% for channel in channels %} +
  1. + {{channel.label}}
    + {% if channel.concurrent_view_count is not none %} + 👀{{channel.concurrent_view_count}} + {% endif %} + {% if channel.like_count is not none %} + 👍{{channel.like_count}} + {% endif %} + {% if channel.duration is not none %} + 🕑{{channel.duration}} + {% endif %} +
  2. +
    + {% endfor %} +
+
+ 💬 Заходите в наш чат. +
+ 🤖 Бот-предложка, присылайте интересные ссылки на каналы/видео/картинки. + empty: | + 🤷 Интересных стримов сейчас нет. +
+ 💬 Заходите в наш чат. +
+ 🤖 Бот-предложка, присылайте интересные ссылки на каналы/видео/картинки. + + start_scheduler: True + interval_s: 300 + cookies.txt: | + # Netscape HTTP Cookie File + # This file is generated by yt-dlp. Do not edit. \ No newline at end of file diff --git a/deploy/k8s/02_persistent_volume.yaml b/deploy/k8s/02_persistent_volume.yaml new file mode 100644 index 0000000..aa0d261 --- /dev/null +++ b/deploy/k8s/02_persistent_volume.yaml @@ -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 \ No newline at end of file diff --git a/deploy/k8s/03_persistent_volume_claim.yaml b/deploy/k8s/03_persistent_volume_claim.yaml new file mode 100644 index 0000000..eb319f8 --- /dev/null +++ b/deploy/k8s/03_persistent_volume_claim.yaml @@ -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 \ No newline at end of file diff --git a/deploy/k8s/04_deployment.yaml b/deploy/k8s/04_deployment.yaml new file mode 100644 index 0000000..096a86c --- /dev/null +++ b/deploy/k8s/04_deployment.yaml @@ -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" diff --git a/deploy/k8s/example.deployment.yml b/deploy/k8s/example.deployment.yml deleted file mode 100644 index d2e33ce..0000000 --- a/deploy/k8s/example.deployment.yml +++ /dev/null @@ -1,150 +0,0 @@ -# create separate namespace -apiVersion: v1 -kind: Namespace -metadata: - name: yt-notifier-namespace ---- -# 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: | -

✅ СЕЙЧАС В ЭФИРЕ:

-
-
    - {% for channel in channels %} -
  1. - {{channel.label}}
    - {% if channel.concurrent_view_count is not none %} - 👀{{channel.concurrent_view_count}} - {% endif %} - {% if channel.like_count is not none %} - 👍{{channel.like_count}} - {% endif %} - {% if channel.duration is not none %} - 🕑{{channel.duration}} - {% endif %} -
  2. -
    - {% endfor %} -
-
- 💬 Заходите в наш чат. -
- 🤖 Бот-предложка, присылайте интересные ссылки на каналы/видео/картинки. - empty: | - 🤷 Интересных стримов сейчас нет. -
- 💬 Заходите в наш чат. -
- 🤖 Бот-предложка, присылайте интересные ссылки на каналы/видео/картинки. - - start_scheduler: True - interval_s: 300 - cookies.txt: | - # Netscape HTTP Cookie File - # This file is generated by yt-dlp. Do not edit. ---- -# 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 ---- -# 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 ---- -# 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" diff --git a/src/constants.py b/src/constants.py index 1fc1505..17fb319 100755 --- a/src/constants.py +++ b/src/constants.py @@ -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",