├── .gitignore ├── terraform ├── README.md ├── .gitignore ├── sb2_kustomization_backup.yaml └── kube.tf ├── kubernetes-config ├── certs │ ├── namespace.yaml │ ├── kustomization.yaml │ └── certs.yaml ├── site │ ├── kustomization.yaml │ └── site.yaml ├── ingress │ ├── kustomization.yaml │ ├── nginx-ingress-values.yaml │ └── ingress.yaml ├── disk-cache │ ├── kustomization.yaml │ └── disk-cache.yaml ├── user-counter │ ├── kustomization.yaml │ └── user-counter.yaml ├── newleaf │ ├── kustomization.yaml │ ├── newleaf-config.yaml │ └── newleaf.yaml ├── pgbouncer │ ├── kustomization.yaml │ ├── pgbouncer-config.yaml │ ├── pgbouncer-repl.yaml │ └── pgbouncer-main.yaml ├── redis │ ├── kustomization.yaml │ ├── keydb-config.yaml │ ├── redis-config.yaml │ ├── redis-values.yaml │ ├── redis.yaml │ └── keydb.yaml ├── sample-pvc.yaml ├── sb-server │ ├── kustomization.yaml │ ├── rsync-config.yaml │ ├── error-server.yaml │ ├── db-dumper.yaml │ ├── sb-server-config.yaml │ ├── test-sb-server.yaml │ └── sb-server.yaml ├── kustomization.yaml ├── security-policy.yaml ├── sample-backup.yaml └── grafana │ └── helmfile.yaml ├── .gitmodules └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | env.sh 2 | -------------------------------------------------------------------------------- /terraform/README.md: -------------------------------------------------------------------------------- 1 | ```bash 2 | . ./env.sh 3 | terraform apply 4 | ``` 5 | -------------------------------------------------------------------------------- /kubernetes-config/certs/namespace.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: cert-manager -------------------------------------------------------------------------------- /kubernetes-config/site/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | 4 | resources: 5 | - site.yaml -------------------------------------------------------------------------------- /kubernetes-config/ingress/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | 4 | resources: 5 | - ingress.yaml -------------------------------------------------------------------------------- /kubernetes-config/disk-cache/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | 4 | resources: 5 | - disk-cache.yaml -------------------------------------------------------------------------------- /kubernetes-config/user-counter/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | 4 | resources: 5 | - user-counter.yaml -------------------------------------------------------------------------------- /kubernetes-config/newleaf/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | 4 | resources: 5 | - newleaf-config.yaml 6 | - newleaf.yaml -------------------------------------------------------------------------------- /kubernetes-config/certs/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | 4 | resources: 5 | - namespace.yaml 6 | - cert-manager.custom.yaml 7 | - certs.yaml -------------------------------------------------------------------------------- /terraform/.gitignore: -------------------------------------------------------------------------------- 1 | .terraform 2 | terraform.tfstate 3 | terraform.tfstate.backup 4 | .terraform.tfstate.lock.info 5 | .terraform.lock.hcl 6 | env.sh 7 | sb_kubeconfig.yaml 8 | sb2_kubeconfig.yaml -------------------------------------------------------------------------------- /kubernetes-config/pgbouncer/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | 4 | resources: 5 | - pgbouncer-config.yaml 6 | - pgbouncer-main.yaml 7 | - pgbouncer-repl.yaml -------------------------------------------------------------------------------- /kubernetes-config/redis/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | 4 | resources: 5 | - redis-config.yaml 6 | - redis.yaml 7 | - keydb-config.yaml 8 | - keydb.yaml -------------------------------------------------------------------------------- /kubernetes-config/sample-pvc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: PersistentVolumeClaim 3 | metadata: 4 | name: cluster3-repl1 5 | spec: 6 | accessModes: 7 | - ReadWriteOnce 8 | resources: 9 | requests: 10 | storage: 187Gi -------------------------------------------------------------------------------- /kubernetes-config/sb-server/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | 4 | resources: 5 | - db-dumper.yaml 6 | - rsync-config.yaml 7 | - sb-server-config.yaml 8 | - sb-server.yaml 9 | - error-server.yaml -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "secrets"] 2 | path = kubernetes-config/secrets 3 | url = https://github.com/ajayyy/kubernetes-secrets 4 | [submodule "terraform-hcloud-kube-hetzner"] 5 | path = terraform-hcloud-kube-hetzner 6 | url = https://github.com/ajayyy/terraform-hcloud-kube-hetzner -------------------------------------------------------------------------------- /kubernetes-config/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | 4 | resources: 5 | - secrets 6 | - certs 7 | - ingress 8 | - redis 9 | - newleaf 10 | - disk-cache 11 | - sb-server 12 | - site 13 | - user-counter 14 | - pgbouncer -------------------------------------------------------------------------------- /kubernetes-config/security-policy.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: policy/v1beta1 2 | kind: PodSecurityPolicy 3 | metadata: 4 | name: sysctl-policy 5 | spec: 6 | #todo: wrong since it needs to be enabled in the node first 7 | allowedUnsafeSysctls: 8 | - kernel.msgmax 9 | - net.core.somaxconn -------------------------------------------------------------------------------- /kubernetes-config/redis/keydb-config.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: keydb-config 5 | data: 6 | # latency-monitor-threshold 200 7 | keydb-config: | 8 | maxmemory-policy allkeys-lru 9 | maxmemory 4500mb 10 | 11 | appendonly no 12 | save "" 13 | 14 | server-threads 4 -------------------------------------------------------------------------------- /kubernetes-config/redis/redis-config.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: redis-config 5 | data: 6 | # io-threads 3 7 | # io-threads-do-reads yes 8 | # latency-monitor-threshold 200 9 | redis-config: | 10 | maxmemory-policy allkeys-lru 11 | maxmemory 4500mb 12 | 13 | appendonly no 14 | save "" -------------------------------------------------------------------------------- /kubernetes-config/newleaf/newleaf-config.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: newleaf-config 5 | data: 6 | newleaf-config: | 7 | # ============================== 8 | # You MUST set these settings. 9 | # ============================== 10 | 11 | # A URL that this site can be accessed on. Do not include a trailing slash. 12 | website_origin = "http://newleaf:3000" 13 | 14 | 15 | # ============================== 16 | # These settings are optional. 17 | # ============================== 18 | 19 | # The address of the interface to bind to. 20 | #bind_host = "0.0.0.0" 21 | 22 | # The port to bind to. 23 | #bind_port = 3000 -------------------------------------------------------------------------------- /kubernetes-config/pgbouncer/pgbouncer-config.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: pgbouncer-config 5 | data: 6 | PGBOUNCER_DATABASE: "*" 7 | PGBOUNCER_POOL_MODE: transaction 8 | # PGBOUNCER_QUERY_WAIT_TIMEOUT: 120 9 | PGBOUNCER_MAX_CLIENT_CONN: "50000" 10 | PGBOUNCER_DEFAULT_POOL_SIZE: "150" 11 | PGBOUNCER_SERVER_IDLE_TIMEOUT: "600" 12 | PGBOUNCER_AUTH_USER: postgres # See https://www.enterprisedb.com/postgres-tutorials/pgbouncer-authquery-and-authuser-pro-tips 13 | PGBOUNCER_AUTH_QUERY: SELECT usename, passwd FROM pg_shadow WHERE usename=$1 14 | PGBOUNCER_IGNORE_STARTUP_PARAMETERS: extra_float_digits statement_timeout 15 | # PGBOUNCER_IDLE_TRANSACTION_TIMEOUT: "480" -------------------------------------------------------------------------------- /kubernetes-config/redis/redis-values.yaml: -------------------------------------------------------------------------------- 1 | master: 2 | configuration: | 3 | maxmemory-policy allkeys-lru 4 | maxmemory 3500mb 5 | 6 | appendonly no 7 | save 60 100 8 | client-output-buffer-limit slave 80000000000 70000000000 60 9 | nodeSelector: 10 | ram: "8gb" 11 | resources: 12 | requests: 13 | memory: 7Gi 14 | persistence: 15 | size: 20Gi 16 | livenessProbe: 17 | failureThreshold: 24 18 | 19 | replica: 20 | replicaCount: 1 21 | configuration: | 22 | maxmemory-policy allkeys-lru 23 | maxmemory 3500mb 24 | 25 | appendonly no 26 | nodeSelector: 27 | ram: "8gb" 28 | resources: 29 | requests: 30 | memory: 7Gi 31 | persistence: 32 | size: 10Gi 33 | livenessProbe: 34 | enabled: false 35 | 36 | auth: 37 | enabled: false 38 | 39 | pdb: 40 | create: true 41 | minAvailable: 1 -------------------------------------------------------------------------------- /kubernetes-config/sb-server/rsync-config.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: rsync-config 5 | data: 6 | rsyncd-conf: | 7 | pid file = /var/run/rsyncd.pid 8 | lock file = /var/run/rsync.lock 9 | log file = /var/log/rsync.log 10 | # replace with user accessing the files 11 | 12 | [sponsorblock] 13 | use chroot = no 14 | max connections = 50 15 | # path to mirrored files 16 | path = /usr/src/app/database-export 17 | comment = sponsorblock-database 18 | read only = true 19 | refuse options = c delete zl 20 | # disallow checksumming and compression level to reduce CPU/IO load 21 | # disallow deleting files clientside 22 | 23 | [supersecretpriorityfolder] 24 | use chroot = no 25 | max connections = 10 26 | # path to mirrored files 27 | path = /usr/src/app/database-export 28 | comment = sponsorblock-database-priority 29 | read only = true 30 | refuse options = c delete zl 31 | # disallow checksumming and compression level to reduce CPU/IO load 32 | # disallow deleting files clientside -------------------------------------------------------------------------------- /kubernetes-config/sample-backup.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: pg.percona.com/v1 2 | kind: Pgtask 3 | metadata: 4 | labels: 5 | pg-cluster: cluster3 6 | pgouser: admin 7 | name: cluster3-backrest-full-backup9 8 | spec: 9 | name: cluster3-backrest-full-backup9 10 | parameters: 11 | backrest-command: backup 12 | # backup type can be: 13 | # Differential: Create a backup of everything since the last full backup was taken 14 | # --type=diff 15 | # Full: Back up the entire database 16 | # --type=full 17 | # Incremental: Back up everything since the last backup was taken, whether it was full, differential, or incremental 18 | # --type=incr 19 | # backup retention can be: 20 | # --repo1-retention-full=2 how many full backups to retain 21 | # --repo1-retention-diff=4 how many differential backups to retain 22 | # --repo1-retention-archive=6 how many sets of WAL archives to retain alongside 23 | # the full and differential backups that are retained 24 | backrest-opts: --type=full --repo1-retention-full=1 25 | backrest-s3-verify-tls: "false" 26 | # backrest-storage-type: "" 27 | job-name: cluster3-backrest-full-backup9 28 | pg-cluster: cluster3 29 | tasktype: backrest -------------------------------------------------------------------------------- /kubernetes-config/sb-server/error-server.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: error-server-deployment 5 | spec: 6 | replicas: 15 7 | selector: 8 | matchLabels: 9 | app: error-server 10 | template: 11 | metadata: 12 | labels: 13 | app: error-server 14 | name: error-server 15 | spec: 16 | containers: 17 | - image: ghcr.io/ajayyy/error-server:latest 18 | name: error-server 19 | ports: 20 | - containerPort: 80 21 | affinity: 22 | nodeAffinity: 23 | requiredDuringSchedulingIgnoredDuringExecution: 24 | nodeSelectorTerms: 25 | - matchExpressions: 26 | - key: ram 27 | operator: NotIn 28 | values: 29 | - 8gb 30 | - key: dbsize 31 | operator: NotIn 32 | values: 33 | - "true" 34 | - key: nginx 35 | operator: In 36 | values: 37 | - "true" 38 | - "extra-large" 39 | --- 40 | apiVersion: v1 41 | kind: Service 42 | metadata: 43 | name: error-service 44 | spec: 45 | ports: 46 | - port: 80 47 | protocol: TCP 48 | targetPort: 80 49 | selector: 50 | app: error-server -------------------------------------------------------------------------------- /terraform/sb2_kustomization_backup.yaml: -------------------------------------------------------------------------------- 1 | "apiVersion": "kustomize.config.k8s.io/v1beta1" 2 | "kind": "Kustomization" 3 | "patches": 4 | - "patch": | 5 | apiVersion: apps/v1 6 | kind: Deployment 7 | metadata: 8 | name: system-upgrade-controller 9 | namespace: system-upgrade 10 | spec: 11 | template: 12 | spec: 13 | containers: 14 | - name: system-upgrade-controller 15 | volumeMounts: 16 | - name: ca-certificates 17 | mountPath: /var/lib/ca-certificates 18 | volumes: 19 | - name: ca-certificates 20 | hostPath: 21 | path: /var/lib/ca-certificates 22 | type: Directory 23 | "target": 24 | "group": "apps" 25 | "kind": "Deployment" 26 | "name": "system-upgrade-controller" 27 | "namespace": "system-upgrade" 28 | "version": "v1" 29 | - "path": "kured.yaml" 30 | - "path": "ccm.yaml" 31 | "resources": 32 | - "https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/download/v1.20.0/ccm-networks.yaml" 33 | - "https://github.com/kubereboot/kured/releases/download/1.16.0/kured-1.16.0-dockerhub.yaml" 34 | - "https://raw.githubusercontent.com/rancher/system-upgrade-controller/master/manifests/system-upgrade-controller.yaml" 35 | - "hcloud-csi.yml" 36 | - "cert_manager.yaml" 37 | - "rancher.yaml" 38 | -------------------------------------------------------------------------------- /kubernetes-config/site/site.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: sb-site-deployment 5 | spec: 6 | replicas: 2 7 | selector: 8 | matchLabels: 9 | app: sb-site 10 | template: 11 | metadata: 12 | labels: 13 | app: sb-site 14 | name: sb-site 15 | spec: 16 | containers: 17 | - image: ghcr.io/ajayyy/sb-site:latest 18 | name: sb-site 19 | ports: 20 | - containerPort: 80 21 | resources: 22 | requests: 23 | memory: 20Mi 24 | limits: 25 | memory: 20Mi 26 | affinity: 27 | nodeAffinity: 28 | requiredDuringSchedulingIgnoredDuringExecution: 29 | nodeSelectorTerms: 30 | - matchExpressions: 31 | - key: ram 32 | operator: NotIn 33 | values: 34 | - 8gb 35 | - key: dbsize 36 | operator: NotIn 37 | values: 38 | - "true" 39 | - key: nginx 40 | operator: In 41 | values: 42 | - "true" 43 | - "extra-large" 44 | --- 45 | apiVersion: v1 46 | kind: Service 47 | metadata: 48 | name: sb-site-service 49 | spec: 50 | ports: 51 | - port: 80 52 | protocol: TCP 53 | targetPort: 80 54 | selector: 55 | app: sb-site -------------------------------------------------------------------------------- /kubernetes-config/disk-cache/disk-cache.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: disk-cache-deployment 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: disk-cache 10 | template: 11 | metadata: 12 | labels: 13 | app: disk-cache 14 | spec: 15 | containers: 16 | - image: ghcr.io/ajayyy/disk-cache:latest 17 | name: disk-cache 18 | ports: 19 | - containerPort: 8080 20 | resources: 21 | requests: 22 | memory: 300Mi 23 | limits: 24 | memory: 300Mi 25 | affinity: 26 | nodeAffinity: 27 | requiredDuringSchedulingIgnoredDuringExecution: 28 | nodeSelectorTerms: 29 | - matchExpressions: 30 | - key: ram 31 | operator: NotIn 32 | values: 33 | - 8gb 34 | - key: dbsize 35 | operator: NotIn 36 | values: 37 | - "true" 38 | - key: nginx 39 | operator: NotIn 40 | values: 41 | - "true" 42 | - "extra-large" 43 | - key: dump 44 | operator: NotIn 45 | values: 46 | - "true" 47 | --- 48 | apiVersion: v1 49 | kind: Service 50 | metadata: 51 | name: disk-cache-service 52 | spec: 53 | ports: 54 | - port: 8080 55 | protocol: TCP 56 | targetPort: 8080 57 | selector: 58 | app: disk-cache -------------------------------------------------------------------------------- /kubernetes-config/grafana/helmfile.yaml: -------------------------------------------------------------------------------- 1 | repositories: 2 | - name: prometheus-community 3 | url: https://prometheus-community.github.io/helm-charts 4 | 5 | helmDefaults: 6 | wait: true 7 | createNamespace: true 8 | cleanupOnFail: true 9 | 10 | releases: 11 | - name: prometheus-operator 12 | namespace: monitoring 13 | chart: prometheus-community/kube-prometheus-stack 14 | disableValidation: true 15 | values: 16 | - prometheus: 17 | prometheusSpec: 18 | storageSpec: 19 | volumeClaimTemplate: 20 | spec: 21 | accessModes: ["ReadWriteOnce"] 22 | resources: 23 | requests: 24 | storage: 50Gi 25 | set: 26 | - name: grafana.image.tag 27 | value: "11.2.1" 28 | - name: grafana.persistence.enabled 29 | value: true 30 | - name: grafana.persistence.size 31 | value: 10Gi 32 | - name: grafana.podDisruptionBudget.minAvailable 33 | value: 0 34 | - name: grafana.podDisruptionBudget.maxUnavailable 35 | value: 0 36 | - name: grafana.deploymentStrategy.type 37 | value: Recreate 38 | - name: prometheus.prometheusSpec.resources.requests.cpu 39 | value: 500m 40 | - name: prometheus.prometheusSpec.retention 41 | value: "90d" 42 | - name: prometheus.prometheusSpec.scrapeInterval 43 | value: "30s" 44 | - name: prometheus.prometheusSpec.evaluationInterval 45 | value: "30s" 46 | - name: prometheus.prometheusSpec.resources.requests.memory 47 | value: 3500Mi -------------------------------------------------------------------------------- /kubernetes-config/certs/certs.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: cert-manager.io/v1 3 | kind: ClusterIssuer 4 | metadata: 5 | name: zerossl 6 | spec: 7 | acme: 8 | server: https://acme.zerossl.com/v2/DV90 9 | externalAccountBinding: 10 | keyID: ms0O4sY0Vix0Qp9m5E_51A 11 | keySecretRef: 12 | name: zero-ssl-eabsecret 13 | key: secret 14 | privateKeySecretRef: 15 | name: zerossl-prod 16 | solvers: 17 | - http01: 18 | ingress: 19 | class: nginx 20 | --- 21 | apiVersion: cert-manager.io/v1 22 | kind: Certificate 23 | metadata: 24 | name: sponsor-cert 25 | spec: 26 | dnsNames: 27 | - sponsor.ajay.app 28 | - api.sponsor.ajay.app 29 | secretName: sponsor-cert 30 | issuerRef: 31 | name: zerossl 32 | kind: ClusterIssuer 33 | --- 34 | apiVersion: cert-manager.io/v1 35 | kind: Certificate 36 | metadata: 37 | name: test-cert 38 | spec: 39 | dnsNames: 40 | - k8s.sponsor.ajay.app 41 | secretName: test-cert 42 | issuerRef: 43 | name: zerossl 44 | kind: ClusterIssuer 45 | --- 46 | apiVersion: cert-manager.io/v1 47 | kind: Certificate 48 | metadata: 49 | name: graph-cert 50 | namespace: monitoring 51 | spec: 52 | dnsNames: 53 | - graph.sponsor.ajay.app 54 | secretName: graph-cert 55 | issuerRef: 56 | name: zerossl 57 | kind: ClusterIssuer 58 | # --- 59 | # apiVersion: cert-manager.io/v1 60 | # kind: Certificate 61 | # metadata: 62 | # name: longhorn-cert 63 | # namespace: longhorn-system 64 | # spec: 65 | # dnsNames: 66 | # - longhorn.sponsor.ajay.app 67 | # secretName: longhorn-cert 68 | # issuerRef: 69 | # name: zerossl 70 | # kind: ClusterIssuer -------------------------------------------------------------------------------- /kubernetes-config/pgbouncer/pgbouncer-repl.yaml: -------------------------------------------------------------------------------- 1 | # apiVersion: apps/v1 2 | # kind: Deployment 3 | # metadata: 4 | # name: pgbouncer-repl-deployment 5 | # spec: 6 | # replicas: 2 7 | # selector: 8 | # matchLabels: 9 | # type: repl 10 | # app: pgbouncer 11 | # template: 12 | # metadata: 13 | # labels: 14 | # type: repl 15 | # app: pgbouncer 16 | # spec: 17 | # containers: 18 | # - image: bitnami/pgbouncer 19 | # name: pgbouncer 20 | # ports: 21 | # - containerPort: 6432 22 | # envFrom: 23 | # - configMapRef: 24 | # name: pgbouncer-config 25 | # env: 26 | # - name: POSTGRESQL_HOST 27 | # value: cluster3-replica.default.svc 28 | # - name: POSTGRESQL_PASSWORD 29 | # valueFrom: { secretKeyRef: { name: cluster3-postgres-secret, key: password } } 30 | # topologySpreadConstraints: 31 | # - maxSkew: 1 32 | # topologyKey: topology.kubernetes.io/zone 33 | # whenUnsatisfiable: ScheduleAnyway 34 | # labelSelector: 35 | # matchLabels: 36 | # app: pgbouncer 37 | # affinity: 38 | # nodeAffinity: 39 | # requiredDuringSchedulingIgnoredDuringExecution: 40 | # nodeSelectorTerms: 41 | # - matchExpressions: 42 | # - key: dbsize 43 | # operator: In 44 | # values: 45 | # - "true" 46 | # --- 47 | # apiVersion: v1 48 | # kind: Service 49 | # metadata: 50 | # name: pgbouncer-repl-service 51 | # spec: 52 | # ports: 53 | # - port: 6432 54 | # protocol: TCP 55 | # targetPort: 6432 56 | # selector: 57 | # type: repl 58 | # app: pgbouncer -------------------------------------------------------------------------------- /kubernetes-config/user-counter/user-counter.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: usercount-deployment 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: user-counter 10 | template: 11 | metadata: 12 | labels: 13 | app: user-counter 14 | spec: 15 | containers: 16 | - image: ghcr.io/ajayyy/user-counter:latest 17 | name: usercount 18 | ports: 19 | - containerPort: 8080 20 | env: 21 | - name: PORT 22 | value: "8080" 23 | - name: DEFAULT_USER_COUNT 24 | value: "13033165" 25 | resources: 26 | requests: 27 | cpu: 700m 28 | memory: 1500Mi 29 | limits: 30 | memory: 1500Mi 31 | affinity: 32 | nodeAffinity: 33 | requiredDuringSchedulingIgnoredDuringExecution: 34 | nodeSelectorTerms: 35 | - matchExpressions: 36 | - key: ram 37 | operator: NotIn 38 | values: 39 | - 8gb 40 | - key: dbsize 41 | operator: NotIn 42 | values: 43 | - "true" 44 | - key: nginx 45 | operator: NotIn 46 | values: 47 | - "true" 48 | - "extra-large" 49 | - key: dump 50 | operator: NotIn 51 | values: 52 | - "true" 53 | securityContext: 54 | sysctls: 55 | - name: net.core.somaxconn 56 | value: "65535" 57 | --- 58 | apiVersion: v1 59 | kind: Service 60 | metadata: 61 | name: user-counter-service 62 | spec: 63 | ports: 64 | - port: 8080 65 | protocol: TCP 66 | targetPort: 8080 67 | selector: 68 | app: user-counter -------------------------------------------------------------------------------- /kubernetes-config/redis/redis.yaml: -------------------------------------------------------------------------------- 1 | # --- 2 | # apiVersion: v1 3 | # kind: PersistentVolumeClaim 4 | # metadata: 5 | # name: redis-pv-claim 6 | # spec: 7 | # accessModes: 8 | # - ReadWriteOnce 9 | # resources: 10 | # requests: 11 | # storage: 10Gi 12 | # --- 13 | # apiVersion: apps/v1 14 | # kind: Deployment 15 | # metadata: 16 | # name: redis-deployment 17 | # spec: 18 | # replicas: 1 19 | # selector: 20 | # matchLabels: 21 | # app: redis 22 | # template: 23 | # metadata: 24 | # labels: 25 | # app: redis 26 | # spec: 27 | # containers: 28 | # - image: redis:7.0 29 | # name: redis 30 | # # resources: 31 | # # requests: 32 | # # memory: 6Gi 33 | # ports: 34 | # - containerPort: 6379 35 | # volumeMounts: 36 | # # - mountPath: "/data" 37 | # # name: redis-data 38 | # - mountPath: "/usr/local/etc/redis" 39 | # name: config 40 | # args: 41 | # - "/usr/local/etc/redis/redis.conf" 42 | # volumes: 43 | # # - name: redis-data 44 | # # persistentVolumeClaim: 45 | # # claimName: redis-pv-claim # permission error when this is used 46 | # - name: config 47 | # configMap: 48 | # name: redis-config 49 | # items: 50 | # - key: redis-config 51 | # path: redis.conf 52 | # nodeSelector: 53 | # ram: "8gb" 54 | # sysctltest: "true" 55 | # securityContext: 56 | # sysctls: 57 | # - name: net.core.somaxconn 58 | # value: "65535" 59 | --- 60 | apiVersion: v1 61 | kind: Service 62 | metadata: 63 | name: redis-service 64 | spec: 65 | ports: 66 | - port: 6379 67 | protocol: TCP 68 | targetPort: 6379 69 | selector: 70 | app: redis -------------------------------------------------------------------------------- /kubernetes-config/redis/keydb.yaml: -------------------------------------------------------------------------------- 1 | # --- 2 | # apiVersion: v1 3 | # kind: PersistentVolumeClaim 4 | # metadata: 5 | # name: redis-pv-claim 6 | # spec: 7 | # accessModes: 8 | # - ReadWriteOnce 9 | # resources: 10 | # requests: 11 | # storage: 10Gi 12 | # --- 13 | # apiVersion: apps/v1 14 | # kind: Deployment 15 | # metadata: 16 | # name: keydb-deployment 17 | # spec: 18 | # replicas: 1 19 | # selector: 20 | # matchLabels: 21 | # app: keydb 22 | # template: 23 | # metadata: 24 | # labels: 25 | # app: keydb 26 | # spec: 27 | # containers: 28 | # - image: eqalpha/keydb:x86_64_v6.3.1 29 | # name: keydb 30 | # # resources: 31 | # # requests: 32 | # # memory: 6Gi 33 | # ports: 34 | # - containerPort: 6379 35 | # volumeMounts: 36 | # # - mountPath: "/data" 37 | # # name: redis-data 38 | # - mountPath: "/usr/local/etc/keydb" 39 | # name: config 40 | # args: 41 | # - "/usr/local/etc/keydb/keydb.conf" 42 | # volumes: 43 | # # - name: redis-data 44 | # # persistentVolumeClaim: 45 | # # claimName: redis-pv-claim # permission error when this is used 46 | # - name: config 47 | # configMap: 48 | # name: keydb-config 49 | # items: 50 | # - key: keydb-config 51 | # path: keydb.conf 52 | # nodeSelector: 53 | # ram: "8gb" 54 | # sysctltest: "true" 55 | # securityContext: 56 | # sysctls: 57 | # - name: net.core.somaxconn 58 | # value: "65535" 59 | # --- 60 | # apiVersion: v1 61 | # kind: Service 62 | # metadata: 63 | # name: keydb-service 64 | # spec: 65 | # ports: 66 | # - port: 6379 67 | # protocol: TCP 68 | # targetPort: 6379 69 | # selector: 70 | # app: keydb -------------------------------------------------------------------------------- /kubernetes-config/newleaf/newleaf.yaml: -------------------------------------------------------------------------------- 1 | # apiVersion: apps/v1 2 | # kind: Deployment 3 | # metadata: 4 | # name: newleaf-deployment 5 | # spec: 6 | # replicas: 1 7 | # selector: 8 | # matchLabels: 9 | # app: newleaf 10 | # template: 11 | # metadata: 12 | # labels: 13 | # app: newleaf 14 | # name: newleaf 15 | # spec: 16 | # containers: 17 | # - image: abeltramo/newleaf:latest 18 | # name: newleaf 19 | # resources: 20 | # requests: 21 | # # cpu: 700m 22 | # cpu: 1200m # take up two slots of sb-server 23 | # memory: 150Mi 24 | # limits: 25 | # memory: 150Mi 26 | # ports: 27 | # - containerPort: 3000 28 | # hostPort: 3000 # forces it to only run once per node 29 | # volumeMounts: 30 | # - mountPath: "/workdir/configuration.py" 31 | # subPath: "configuration.py" 32 | # name: config 33 | # volumes: 34 | # - name: config 35 | # configMap: 36 | # name: newleaf-config 37 | # items: 38 | # - key: newleaf-config 39 | # path: configuration.py 40 | # affinity: 41 | # nodeAffinity: 42 | # requiredDuringSchedulingIgnoredDuringExecution: 43 | # nodeSelectorTerms: 44 | # - matchExpressions: 45 | # - key: ram 46 | # operator: NotIn 47 | # values: 48 | # - 8gb 49 | # - key: dbsize 50 | # operator: NotIn 51 | # values: 52 | # - "true" 53 | # - key: nginx 54 | # operator: NotIn 55 | # values: 56 | # - "true" 57 | # - "extra-large" 58 | # --- 59 | # apiVersion: v1 60 | # kind: Service 61 | # metadata: 62 | # name: newleaf-service 63 | # spec: 64 | # ports: 65 | # - port: 3000 66 | # protocol: TCP 67 | # targetPort: 3000 68 | # selector: 69 | # app: newleaf -------------------------------------------------------------------------------- /kubernetes-config/pgbouncer/pgbouncer-main.yaml: -------------------------------------------------------------------------------- 1 | # apiVersion: apps/v1 2 | # kind: Deployment 3 | # metadata: 4 | # name: pgbouncer-main-deployment 5 | # spec: 6 | # replicas: 2 7 | # selector: 8 | # matchLabels: 9 | # type: main 10 | # app: pgbouncer 11 | # template: 12 | # metadata: 13 | # labels: 14 | # type: main 15 | # app: pgbouncer 16 | # spec: 17 | # containers: 18 | # - image: bitnami/pgbouncer 19 | # name: pgbouncer 20 | # ports: 21 | # - containerPort: 6432 22 | # hostPort: 9343 # forces it to only run once per node 23 | # resources: 24 | # requests: 25 | # cpu: 400m # todo: not applied 700m 26 | # envFrom: 27 | # - configMapRef: 28 | # name: pgbouncer-config 29 | # env: 30 | # - name: POSTGRESQL_HOST 31 | # value: 10.2.0.1 32 | # - name: POSTGRESQL_PORT 33 | # value: "5432" 34 | # - name: POSTGRES_USER 35 | # valueFrom: { secretKeyRef: { name: stackgres-secrets, key: username } } 36 | # - name: POSTGRESQL_PASSWORD 37 | # valueFrom: { secretKeyRef: { name: stackgres-secrets, key: password } } 38 | # affinity: 39 | # nodeAffinity: 40 | # requiredDuringSchedulingIgnoredDuringExecution: 41 | # nodeSelectorTerms: 42 | # - matchExpressions: 43 | # - key: ram 44 | # operator: NotIn 45 | # values: 46 | # - 8gb 47 | # - key: dbsize 48 | # operator: NotIn 49 | # values: 50 | # - "true" 51 | # - key: nginx 52 | # operator: In # Always in nginx now 53 | # values: 54 | # - "true" 55 | # - "extra-large" 56 | # --- 57 | # apiVersion: v1 58 | # kind: Service 59 | # metadata: 60 | # name: pgbouncer-main-service 61 | # spec: 62 | # ports: 63 | # - port: 6432 64 | # protocol: TCP 65 | # targetPort: 6432 66 | # selector: 67 | # type: main 68 | # app: pgbouncer -------------------------------------------------------------------------------- /kubernetes-config/sb-server/db-dumper.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: apps/v1 3 | kind: Deployment 4 | metadata: 5 | name: db-dumper-deployment 6 | spec: 7 | replicas: 1 8 | selector: 9 | matchLabels: 10 | app: db-dumper 11 | template: 12 | metadata: 13 | labels: 14 | app: db-dumper 15 | spec: 16 | containers: 17 | - image: ghcr.io/ajayyy/rsync-host@sha256:6662e19998a9eba64bc8db9cab5679ba46a04483bb3c8e3be3e1ef40d0c9f3ff 18 | name: db-dumper 19 | envFrom: 20 | - configMapRef: 21 | name: sb-server-config 22 | env: 23 | - name: postgres_user 24 | valueFrom: { secretKeyRef: { name: stackgres-secrets, key: username } } 25 | - name: postgres_password 26 | valueFrom: { secretKeyRef: { name: stackgres-secrets, key: password } } 27 | - name: postgresReadOnly_user 28 | valueFrom: { secretKeyRef: { name: stackgres-secrets, key: username } } 29 | - name: postgresReadOnly_password 30 | valueFrom: { secretKeyRef: { name: stackgres-secrets, key: password } } 31 | - name: dumpDatabase_enabled 32 | value: "true" 33 | - name: dumpDatabase_appExportPath 34 | value: "./database-export" 35 | ports: 36 | - containerPort: 8080 37 | name: web-server 38 | - containerPort: 873 39 | name: rsync-server 40 | volumeMounts: 41 | - mountPath: "/etc/rsyncd.conf" 42 | subPath: "rsyncd.conf" 43 | name: config 44 | resources: 45 | requests: 46 | cpu: 2400m 47 | memory: 2000Mi 48 | # limits: 49 | # memory: 700Mi 50 | volumes: 51 | - name: config 52 | configMap: 53 | name: rsync-config 54 | items: 55 | - key: rsyncd-conf 56 | path: rsyncd.conf 57 | affinity: 58 | nodeAffinity: 59 | requiredDuringSchedulingIgnoredDuringExecution: 60 | nodeSelectorTerms: 61 | - matchExpressions: 62 | - key: ram 63 | operator: NotIn 64 | values: 65 | - 8gb 66 | - key: dbsize 67 | operator: NotIn 68 | values: 69 | - "true" 70 | - key: nginx 71 | operator: NotIn 72 | values: 73 | - "true" 74 | - "extra-large" 75 | - key: dump 76 | operator: In 77 | values: 78 | - "true" 79 | --- 80 | apiVersion: v1 81 | kind: Service 82 | metadata: 83 | name: db-dumper-service 84 | spec: 85 | ports: 86 | - port: 8080 87 | protocol: TCP 88 | targetPort: 8080 89 | selector: 90 | app: db-dumper 91 | --- 92 | apiVersion: v1 93 | kind: Service 94 | metadata: 95 | name: rsync-service 96 | spec: 97 | type: NodePort 98 | ports: 99 | - port: 873 100 | protocol: TCP 101 | targetPort: 873 102 | nodePort: 31111 103 | selector: 104 | app: db-dumper 105 | --- 106 | apiVersion: policy/v1 107 | kind: PodDisruptionBudget 108 | metadata: 109 | name: db-dumper-pdb 110 | spec: 111 | minAvailable: 0 112 | selector: 113 | matchLabels: 114 | app: db-dumper -------------------------------------------------------------------------------- /kubernetes-config/sb-server/sb-server-config.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: sb-server-config 5 | data: 6 | postgres_enabled: "true" 7 | # postgres_max: "45" 8 | postgres_max: "60" 9 | # postgresPrivateMax: "3000" 10 | postgresPrivateMax: "60" 11 | postgres_maxTries: "2" 12 | # postgres_redisTimeoutThreshold: "1000" 13 | postgres_redisTimeoutThreshold: "0" 14 | postgresReadOnly_enabled: "false" 15 | postgresReadOnly_weight: "2" 16 | maxConnections: "2000" 17 | # Might need to raise or lower this when first starting 18 | maxResponseTime: "1000" 19 | maxResponseTimeWhileLoadingCache: "2000" 20 | etagExpiry: "15000" 21 | # postgresReadOnly_weight: "300" 22 | # postgresReadOnly_weight: "0" 23 | # postgresReadOnly_readTimeout: "200" 24 | postgresReadOnly_readTimeout: "5000" 25 | # postgresReadOnly_readTimeout: "200000" 26 | postgresReadOnly_max: "45" 27 | postgresReadOnly_maxTries: "2" 28 | postgresReadOnly_fallbackOnFail: "true" 29 | # postgresReadOnly_maxConcurrentRequests: "30" 30 | postgres_host: "10.1.0.2" 31 | # postgres_host: "pgbouncer-main-service" 32 | # postgres_host: "pgcat-service" 33 | # postgres_host: "5.161.49.113" 34 | # postgres_host: pgbouncer-main-service 35 | # postgres_host: gb 36 | postgres_port: "6432" 37 | # postgres_port: "5432" 38 | postgres_maxActiveRequests: "3000" 39 | postgresReadOnly_host: sb-db-replicas.second-db 40 | # postgresReadOnly_host: pgbouncer-repl-service 41 | # postgresReadOnly_host: cluster3-replica.default.svc 42 | # postgresReadOnly_port: "6432" 43 | postgresReadOnly_port: "5432" 44 | # postgresReadOnly_stopRetryThreshold: "800" 45 | redis_enabled: "true" 46 | redis_socket_host: "10.1.0.1" 47 | # redis_socket_host: "5.161.115.40" 48 | # redis_socket_host: keydb-service 49 | # redis_socket_host: redis-cluster-master 50 | # redis_socket_port: "6379" 51 | redis_socket_port: "32773" 52 | # redis_maxConnections: "3000" 53 | # redis_maxConnections: "5000" 54 | redis_maxConnections: "10000" 55 | redis_maxReadResponseTime: "500" 56 | #redis_clientCacheSize: "300000000" 57 | # redis_clientCacheSize: "200000000" # If resetting cache, lower to prevent crashes 58 | redis_clientCacheSize: "160000000" 59 | # redis_clientCacheSize: "80000000" 60 | redis_useCompression: "true" 61 | redis_dragonflyMode: "true" 62 | # useCacheForSegmentGroups: "true" 63 | # redis_maxConnections: "2000" 64 | # redis_maxWriteConnections: "2000" 65 | # redis_maxWriteConnections: "100" 66 | redis_maxWriteConnections: "300" 67 | # redis_disableHashCache: "true" 68 | redis_stopWritingAfterResponseTime: "300" 69 | # redis_stopWritingAfterResponseTime: "1000000" 70 | redis_commandsQueueMaxLength: "30000000000" 71 | # redis_maxConnections: "30000000" 72 | # redis_getTimeout: "1000" # Default 40\ 73 | redis_getTimeout: "20000" # Default 40\ 74 | redis_responseTimePause: "0" 75 | redisRateLimit: "false" 76 | redisRead_enabled: "false" 77 | redisRead_socket_host: "10.1.0.2" 78 | redisRead_socket_port: "32773" 79 | redisRead_weight: "1" 80 | mode: production 81 | # mode: development 82 | userCounterURL: "http://user-counter-service:8080" 83 | # userCounterURL: "" 84 | # userCounterRatio: "5" 85 | # userCounterRatio: "100" 86 | # newLeafURLs: "http://newleaf-service:3000" 87 | adminUserID: 7b89ea26f77bda8176e655eee86029f28c1e6514b6d6e3450bce362b5b126ca3 88 | diskCacheURL: "http://disk-cache-service:8080" 89 | rateLimit_vote_max: "1000000000" 90 | minReputationToSubmitFiller: "-0.01" 91 | minReputationToSubmitChapter: "0" 92 | dumpDatabase_minTimeBetweenMs: "3600000" 93 | deArrowPaywall: "true" 94 | 95 | youTubeKeys_visitorData: "Cgs0djZuYnNmTWZ3VSjUnOa1BjIKCgJDQRIEGgAgSw%3D%3D" 96 | youTubeKeys_poToken: "MnQXXRHA_gpGmhdlLii_DitbVfvEov8K4Lq-wqFpwabbOWncQhYVxLlo-RjK6hjZsfA1ApxRgZy5agCn8vfhJSuoZEO6c46O3ejSzEVyLEsErS3cjl-TvUB7-pvaqr20yc9i1NumfmamgM2S9Gv2gG7yb3yoZg==" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Create cluster 2 | 3 | ```bash 4 | cd terraform 5 | terraform apply 6 | ``` 7 | 8 | Destroy: 9 | 10 | ```bash 11 | cd terraform 12 | terraform destroy 13 | ``` 14 | 15 | 16 | ### Install nginx ingress 17 | 18 | ```bash 19 | helm upgrade --install ingress-nginx ingress-nginx \ 20 | --repo https://kubernetes.github.io/ingress-nginx \ 21 | --namespace ingress-nginx --create-namespace \ 22 | -f kubernetes-config/ingress/nginx-ingress-values.yaml 23 | ``` 24 | 25 | ### Install redis 26 | 27 | Docker compose file 28 | 29 | ```yaml 30 | version: '3.8' 31 | services: 32 | dragonfly: 33 | container_name: dragonfly 34 | image: 'docker.dragonflydb.io/dragonflydb/dragonfly' 35 | ulimits: 36 | memlock: -1 37 | #ports: 38 | # - "6379:6379" 39 | # For better performance, consider `host` mode instead `port` to avoid docker NAT. 40 | # `host` mode is NOT currently supported in Swarm Mode. 41 | # https://docs.docker.com/compose/compose-file/compose-file-v3/#network_mode 42 | network_mode: "host" 43 | entrypoint: dragonfly --cache_mode=true --port=32773 --snapshot_cron "* * * * *" 44 | restart: always 45 | volumes: 46 | - ./dragonflydata:/data 47 | ``` 48 | 49 | To setup replication, connect use: 50 | 51 | ```bash 52 | dragonfly --cache_mode=true --port=32773 --replicaof=10.2.0.2:32773 53 | ``` 54 | 55 | ### Setup postgres 56 | 57 | #### Ensure diff plugin is installed 58 | 59 | Needed for `helmfile` 60 | 61 | ```bash 62 | helm plugin install https://github.com/databus23/helm-diff 63 | ``` 64 | 65 | #### Install Grafana 66 | 67 | ```bash 68 | helmfile -f kubernetes-config/grafana/helmfile.yaml apply 69 | ``` 70 | 71 | #### Make sure secrets have been applied 72 | 73 | ```bash 74 | kubectl apply -f kubernetes-config/secrets 75 | ``` 76 | 77 | ### Then use kustomize 78 | 79 | Might have to run a second time to make sure cert works (will error if it fails) 80 | 81 | ```bash 82 | kubectl apply -k kubernetes-config 83 | ``` 84 | 85 | # Install other configs 86 | 87 | ```bash 88 | terraform apply -auto-approve 89 | 90 | kubectl apply -f kubernetes-config/secrets 91 | kubectl apply -f kubernetes-config/certs 92 | kubectl apply -f kubernetes-config/* 93 | ``` 94 | 95 | ## For setup from scratch 96 | 97 | ### Set default kustomize 98 | 99 | ```bash 100 | KUBECONFIG= 101 | ``` 102 | 103 | ### Prep Cert Manager 104 | 105 | Pre-setup (already done) 106 | ```bash 107 | cmctl x install --dry-run > cert-manager.custom.yaml 108 | ``` 109 | 110 | The cert manager yaml has already been created and is in kubernetes-config/certs 111 | 112 | # Other useful things 113 | 114 | ### Queries 115 | 116 | #### Get active queries 117 | 118 | ```sql 119 | SELECT pid, age(clock_timestamp(), query_start), usename, query 120 | FROM pg_stat_activity 121 | WHERE query != '' AND query NOT ILIKE '%pg_stat_activity%' AND state != 'idle' 122 | ORDER BY query_start asc; 123 | ``` 124 | 125 | #### Get blocked queries 126 | 127 | ```sql 128 | SELECT blocked_locks.pid AS blocked_pid, 129 | blocked_activity.usename AS blocked_user, 130 | blocking_locks.pid AS blocking_pid, 131 | blocking_activity.usename AS blocking_user, 132 | blocked_activity.query AS blocked_statement, 133 | blocking_activity.query AS current_statement_in_blocking_process 134 | FROM pg_catalog.pg_locks blocked_locks 135 | JOIN pg_catalog.pg_stat_activity blocked_activity ON blocked_activity.pid = blocked_locks.pid 136 | JOIN pg_catalog.pg_locks blocking_locks 137 | ON blocking_locks.locktype = blocked_locks.locktype 138 | AND blocking_locks.database IS NOT DISTINCT FROM blocked_locks.database 139 | AND blocking_locks.relation IS NOT DISTINCT FROM blocked_locks.relation 140 | AND blocking_locks.page IS NOT DISTINCT FROM blocked_locks.page 141 | AND blocking_locks.tuple IS NOT DISTINCT FROM blocked_locks.tuple 142 | AND blocking_locks.virtualxid IS NOT DISTINCT FROM blocked_locks.virtualxid 143 | AND blocking_locks.transactionid IS NOT DISTINCT FROM blocked_locks.transactionid 144 | AND blocking_locks.classid IS NOT DISTINCT FROM blocked_locks.classid 145 | AND blocking_locks.objid IS NOT DISTINCT FROM blocked_locks.objid 146 | AND blocking_locks.objsubid IS NOT DISTINCT FROM blocked_locks.objsubid 147 | AND blocking_locks.pid != blocked_locks.pid 148 | 149 | JOIN pg_catalog.pg_stat_activity blocking_activity ON blocking_activity.pid = blocking_locks.pid 150 | WHERE NOT blocked_locks.granted; 151 | ``` -------------------------------------------------------------------------------- /kubernetes-config/sb-server/test-sb-server.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: test-sb-server-deployment 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: test-sb-server 10 | template: 11 | metadata: 12 | labels: 13 | app: test-sb-server 14 | spec: 15 | containers: 16 | - image: ghcr.io/ajayyy/sb-server@sha256:c9c5bd230de8039d7f09b501ea3e600e711a590a1e39936fde09f765b7462a32 17 | name: sb-server 18 | # resources: 19 | # requests: 20 | # cpu: 1100m 21 | # memory: 1500Mi 22 | # limits: 23 | # memory: 1500Mi 24 | envFrom: 25 | - configMapRef: 26 | name: test-sb-server-config 27 | env: 28 | - name: postgres_user 29 | valueFrom: { secretKeyRef: { name: stackgres-secrets, key: username } } 30 | - name: postgres_password 31 | valueFrom: { secretKeyRef: { name: stackgres-secrets, key: password } } 32 | - name: postgresReadOnly_user 33 | valueFrom: { secretKeyRef: { name: stackgres-secrets, key: username } } 34 | - name: postgresReadOnly_password 35 | valueFrom: { secretKeyRef: { name: stackgres-secrets, key: password } } 36 | # - name: postgres_user 37 | # valueFrom: { secretKeyRef: { name: cluster3-postgres-secret, key: username } } 38 | # - name: postgres_password 39 | # valueFrom: { secretKeyRef: { name: cluster3-postgres-secret, key: password } } 40 | # - name: postgresReadOnly_user 41 | # valueFrom: { secretKeyRef: { name: cluster3-postgres-secret, key: username } } 42 | # - name: postgresReadOnly_password 43 | # valueFrom: { secretKeyRef: { name: cluster3-postgres-secret, key: password } } 44 | - name: globalSalt 45 | valueFrom: 46 | secretKeyRef: 47 | name: sb-server-secrets 48 | key: globalSalt 49 | optional: false 50 | - name: discordReportChannelWebhookURL 51 | valueFrom: 52 | secretKeyRef: 53 | name: sb-server-secrets 54 | key: discordReportChannelWebhookURL 55 | optional: false 56 | - name: discordFailedReportChannelWebhookURL 57 | valueFrom: 58 | secretKeyRef: 59 | name: sb-server-secrets 60 | key: discordFailedReportChannelWebhookURL 61 | optional: false 62 | - name: discordFirstTimeSubmissionsWebhookURL 63 | valueFrom: 64 | secretKeyRef: 65 | name: sb-server-secrets 66 | key: discordFirstTimeSubmissionsWebhookURL 67 | optional: false 68 | - name: patreon_clientId 69 | valueFrom: 70 | secretKeyRef: 71 | name: sb-server-secrets 72 | key: patreon_clientId 73 | optional: false 74 | - name: patreon_clientSecret 75 | valueFrom: 76 | secretKeyRef: 77 | name: sb-server-secrets 78 | key: patreon_clientSecret 79 | optional: false 80 | ports: 81 | - containerPort: 8080 82 | affinity: 83 | nodeAffinity: 84 | requiredDuringSchedulingIgnoredDuringExecution: 85 | nodeSelectorTerms: 86 | - matchExpressions: 87 | - key: ram 88 | operator: NotIn 89 | values: 90 | - 8gb 91 | - key: dbsize 92 | operator: NotIn 93 | values: 94 | - "true" 95 | - key: nginx 96 | operator: NotIn 97 | values: 98 | - "true" 99 | - "extra-large" 100 | --- 101 | apiVersion: v1 102 | kind: Service 103 | metadata: 104 | name: test-sb-server-service 105 | spec: 106 | ports: 107 | - port: 8080 108 | protocol: TCP 109 | targetPort: 8080 110 | selector: 111 | app: test-sb-server 112 | --- 113 | apiVersion: v1 114 | kind: ConfigMap 115 | metadata: 116 | name: test-sb-server-config 117 | data: 118 | postgres_enabled: "true" 119 | postgres_max: "45" 120 | postgres_maxTries: "2" 121 | postgresReadOnly_enabled: "true" 122 | postgresReadOnly_weight: "4" 123 | # postgresReadOnly_weight: "300" 124 | # postgresReadOnly_weight: "0" 125 | # postgresReadOnly_readTimeout: "200" 126 | postgresReadOnly_readTimeout: "2000" 127 | postgresReadOnly_max: "45" 128 | postgresReadOnly_maxTries: "2" 129 | postgresReadOnly_fallbackOnFail: "true" 130 | # postgresReadOnly_maxConcurrentRequests: "30" 131 | postgres_host: sb-db.second-db 132 | # postgres_host: cluster3.default.svc 133 | postgres_port: "5432" 134 | # postgresReadOnly_host: sb-db.main-db 135 | postgresReadOnly_host: sb-db.second-db 136 | # postgresReadOnly_host: cluster3-replica.default.svc 137 | postgresReadOnly_port: "5432" 138 | redis_enabled: "true" 139 | redis_socket_host: keydb-service 140 | # redis_socket_host: redis-cluster-master 141 | redis_socket_port: "6379" 142 | redis_getTimeout: "50000" # Default 40\ 143 | redisRead_enabled: "false" 144 | # redisRead_socket_host: redis-cluster-replicas 145 | redisRead_socket_port: "6379" 146 | mode: development 147 | # mode: development 148 | # userCounterURL: "http://user-counter-service:8080" 149 | newLeafURLs: "http://newleaf-service:3000" 150 | adminUserID: 7b89ea26f77bda8176e655eee86029f28c1e6514b6d6e3450bce362b5b126ca3 151 | diskCacheURL: "http://disk-cache-service:8080" 152 | rateLimit_vote_max: "1000000000" 153 | minReputationToSubmitFiller: "-0.01" 154 | dumpDatabase_minTimeBetweenMs: "3600000" -------------------------------------------------------------------------------- /kubernetes-config/ingress/nginx-ingress-values.yaml: -------------------------------------------------------------------------------- 1 | controller: 2 | 3 | allowSnippetAnnotations: true 4 | 5 | # Ensure this is up to date with IPs 6 | service: 7 | externalIPs: 8 | - 167.235.193.86 9 | - 49.13.125.48 10 | - 49.12.72.21 11 | - 128.140.123.101 12 | externalTrafficPolicy: Local 13 | # externalTrafficPolicy: Cluster 14 | # Maybe try setting this to cluster before doing an upgrade to not kill single nodes when daemonset restarts 15 | # They only restart when the image is updated though 16 | 17 | podLabels: 18 | app: nginx-service 19 | 20 | config: 21 | disable-access-log: true 22 | error-log-level: notice 23 | error-log-path: /dev/null 24 | access-log-path: /var/log/nginx/custom-access.log # /var/log/nginx/access.log is symlinked to stdout 25 | # "$http_referer" "$http_user_agent" 26 | #$remote_user 27 | log-format-upstream: '[$time_local] 28 | "$request" $status $body_bytes_sent 29 | "$gzip_ratio"' 30 | # 10080m = 1 week 31 | http-snippet: | 32 | proxy_cache_path /var/tmp/nginx-cache levels=1:2 keys_zone=static-cache:100m inactive=60m max_size=35g; 33 | proxy_cache_key "$scheme$request_method$host$request_uri"; 34 | 35 | limit_req_zone global zone=segmentLimit:20m rate=1500r/s; 36 | 37 | map $request_uri $segment_param { 38 | default $uri; 39 | "~\?.*videoID=([^&]+).*$" $1; 40 | } 41 | server-snippet: | 42 | error_page 502 503 /502.html; 43 | error_page 504 /504.html; 44 | error_page 429 /429.html; 45 | 46 | location = /502.html { 47 | ssi on; 48 | internal; 49 | return 200 'Bad Gateway: Could not connect to backend'; 50 | } 51 | 52 | location = /504.html { 53 | ssi on; 54 | internal; 55 | return 200 'Gateway Timeout: Could not connect to backend'; 56 | } 57 | 58 | location = /409.html { 59 | ssi on; 60 | internal; 61 | return 409 'Ratelimiting'; 62 | } 63 | location-snippet: | 64 | if ($request_method = 'OPTIONS') { 65 | add_header 'Access-Control-Allow-Origin' '*'; 66 | add_header 'Access-Control-Allow-Methods' 'GET, POST, DELETE'; 67 | add_header 'Access-Control-Allow-Headers' 'Content-Type'; 68 | # cache CORS for 24 hours 69 | add_header 'Access-Control-Max-Age' 86400; 70 | # return empty response for preflight 71 | add_header 'Content-Type' 'text/plain; charset=UTF-8'; 72 | add_header 'Content-Length' 0; 73 | # allow resource timing API 74 | add_header 'Timing-Allow-Origin' '*'; 75 | return 204; 76 | } 77 | max-worker-connections: 50000 78 | # max-worker-connections: 22000 79 | worker-processes: 16 80 | forwarded-for-header: "CF-Connecting-IP" 81 | # enable-real-ip: true 82 | proxy-real-ip-cidr: "173.245.48.0/20,103.21.244.0/22,103.22.200.0/22,103.31.4.0/22,141.101.64.0/18,108.162.192.0/18,190.93.240.0/20,188.114.96.0/20,197.234.240.0/22,198.41.128.0/17,162.158.0.0/15,104.16.0.0/13,104.24.0.0/14,172.64.0.0/13,1,73.245.48.0/20,103.21.244.0/22,103.22.200.0/22,103.31.4.0/22,141.101.64.0/18,108.162.192.0/18,190.93.240.0/20,188.114.96.0/20,197.234.240.0/22,198.41.128.0/17,162.158.0.0/15,104.16.0.0/13,104.24.0.0/14,172.64.0.0/13,131.0.72.0/22,131.0.72.0/22,2400:cb00::/32,2606:4700::/32,2803:f800::/32,2405:b500::/32,2405:8100::/32,2a06:98c0::/29,2c0f:f248::/32" 83 | # proxy-real-ip-cidr: "173.245.48.0/20,103.21.244.0/22,103.22.200.0/22,103.31.4.0/22,141.101.64.0/18,108.162.192.0/18,190.93.240.0/20,188.114.96.0/20,197.234.240.0/22,198.41.128.0/17,162.158.0.0/15,104.16.0.0/12,172.64.0.0/13,131.0.72.0/22,2400:cb00::/32,2606:4700::/32,2803:f800::/32,2405:b500::/32,2405:8100::/32,2a06:98c0::/29,2c0f:f248::/32" 84 | use-forwarded-headers: true 85 | limit-req-status-code: 429 86 | # upstream-keepalive-connections: 30000 87 | 88 | 89 | # required to have a replica on every node 90 | # that it might be scheduled on (label some nodes) 91 | # since otherwise packets might drop (local traffic policy) 92 | # use double to be safe 93 | # replicaCount: 12 94 | # replicaCount: 10 95 | 96 | kind: DaemonSet 97 | 98 | 99 | topologySpreadConstraints: 100 | - maxSkew: 1 101 | topologyKey: topology.kubernetes.io/zone 102 | whenUnsatisfiable: DoNotSchedule 103 | labelSelector: 104 | matchLabels: 105 | app: nginx-service 106 | 107 | # affinity: 108 | # podAntiAffinity: 109 | # requiredDuringSchedulingIgnoredDuringExecution: 110 | # - labelSelector: 111 | # matchExpressions: 112 | # - key: app 113 | # operator: In 114 | # values: 115 | # - nginx-service 116 | # topologyKey: kubernetes.io/hostname 117 | 118 | # nodeSelector: 119 | # nginx: "true" 120 | affinity: 121 | nodeAffinity: 122 | requiredDuringSchedulingIgnoredDuringExecution: 123 | nodeSelectorTerms: 124 | - matchExpressions: 125 | - key: nginx 126 | operator: In 127 | values: 128 | - "true" 129 | - "extra-large" 130 | 131 | resources: 132 | requests: 133 | cpu: 1.5 134 | 135 | sysctls: 136 | "net.ipv4.ip_local_port_range": "1024 60999" 137 | "net.core.somaxconn": "65535" 138 | 139 | terminationGracePeriodSeconds: 1 140 | 141 | livenessProbe: 142 | httpGet: 143 | # should match container.healthCheckPath 144 | path: "/healthz" 145 | port: 10254 146 | scheme: HTTP 147 | initialDelaySeconds: 10 148 | periodSeconds: 10 149 | timeoutSeconds: 4 150 | successThreshold: 1 151 | # Making it same as readiness to kill right away 152 | failureThreshold: 3 153 | readinessProbe: 154 | httpGet: 155 | # should match container.healthCheckPath 156 | path: "/healthz" 157 | port: 10254 158 | scheme: HTTP 159 | initialDelaySeconds: 10 160 | periodSeconds: 10 161 | timeoutSeconds: 4 162 | successThreshold: 1 163 | failureThreshold: 3 164 | 165 | # initContainers: 166 | # - command: 167 | # - sh 168 | # - -c 169 | # - sysctl -w net.core.somaxconn=65535; 170 | # securityContext: 171 | # privileged: true 172 | 173 | # forwarded-for-header: "CF-Connecting-IP" 174 | 175 | # Old option 176 | # hostNetwork: true -------------------------------------------------------------------------------- /kubernetes-config/sb-server/sb-server.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: sb-server-deployment 5 | spec: 6 | replicas: 100 #80 #60 #43 #50 #55 #77 #60 #54 #48 #42 #54 7 | selector: 8 | matchLabels: 9 | app: sb-server 10 | method: post 11 | template: 12 | metadata: 13 | labels: 14 | app: sb-server 15 | method: post 16 | spec: 17 | containers: 18 | - image: ghcr.io/ajayyy/sb-server@sha256:bcfa8c1186321a67d06a1244c172b739822523d475a217d9c643131850d16f3c 19 | name: sb-server 20 | resources: 21 | requests: 22 | # cpu: 1300m # Old limit to not make it overload memory 23 | cpu: 600m # 5 per node 24 | # cpu: 750m # 4 per node 25 | # cpu: 1000m # 3 per node 26 | memory: 750Mi 27 | limits: 28 | #memory: 750Mi # 750 29 | memory: 1300Mi 30 | envFrom: 31 | - configMapRef: 32 | name: sb-server-config 33 | env: 34 | - name: postgres_user 35 | valueFrom: { secretKeyRef: { name: stackgres-secrets, key: username } } 36 | - name: postgres_password 37 | valueFrom: { secretKeyRef: { name: stackgres-secrets, key: password } } 38 | - name: postgresReadOnly_user 39 | valueFrom: { secretKeyRef: { name: stackgres-secrets, key: username } } 40 | - name: postgresReadOnly_password 41 | valueFrom: { secretKeyRef: { name: stackgres-secrets, key: password } } 42 | # - name: postgres_user 43 | # valueFrom: { secretKeyRef: { name: cluster3-postgres-secret, key: username } } 44 | # - name: postgres_password 45 | # valueFrom: { secretKeyRef: { name: cluster3-postgres-secret, key: password } } 46 | # - name: postgresReadOnly_user 47 | # valueFrom: { secretKeyRef: { name: cluster3-postgres-secret, key: username } } 48 | # - name: postgresReadOnly_password 49 | # valueFrom: { secretKeyRef: { name: cluster3-postgres-secret, key: password } } 50 | - name: globalSalt 51 | valueFrom: 52 | secretKeyRef: 53 | name: sb-server-secrets 54 | key: globalSalt 55 | optional: false 56 | - name: discordReportChannelWebhookURL 57 | valueFrom: 58 | secretKeyRef: 59 | name: sb-server-secrets 60 | key: discordReportChannelWebhookURL 61 | optional: false 62 | - name: discordFailedReportChannelWebhookURL 63 | valueFrom: 64 | secretKeyRef: 65 | name: sb-server-secrets 66 | key: discordFailedReportChannelWebhookURL 67 | optional: false 68 | - name: discordFirstTimeSubmissionsWebhookURL 69 | valueFrom: 70 | secretKeyRef: 71 | name: sb-server-secrets 72 | key: discordFirstTimeSubmissionsWebhookURL 73 | optional: false 74 | - name: discordDeArrowLockedWebhookURL 75 | valueFrom: 76 | secretKeyRef: 77 | name: sb-server-secrets 78 | key: discordDeArrowLockedWebhookURL 79 | optional: false 80 | - name: discordDeArrowWarnedWebhookURL 81 | valueFrom: 82 | secretKeyRef: 83 | name: sb-server-secrets 84 | key: discordDeArrowWarnedWebhookURL 85 | optional: false 86 | - name: patreon_clientId 87 | valueFrom: 88 | secretKeyRef: 89 | name: sb-server-secrets 90 | key: patreon_clientId 91 | optional: false 92 | - name: patreon_clientSecret 93 | valueFrom: 94 | secretKeyRef: 95 | name: sb-server-secrets 96 | key: patreon_clientSecret 97 | optional: false 98 | - name: tokenSeed 99 | valueFrom: 100 | secretKeyRef: 101 | name: sb-server-secrets 102 | key: tokenSeed 103 | optional: false 104 | ports: 105 | - containerPort: 8080 106 | livenessProbe: 107 | httpGet: 108 | path: /api/status 109 | port: 8080 110 | initialDelaySeconds: 60 111 | periodSeconds: 1 112 | timeoutSeconds: 10 113 | failureThreshold: 6 114 | # readinessProbe: 115 | # httpGet: 116 | # path: /api/ready 117 | # port: 8080 118 | # initialDelaySeconds: 5 119 | # timeoutSeconds: 2 120 | # periodSeconds: 1 121 | affinity: 122 | nodeAffinity: 123 | requiredDuringSchedulingIgnoredDuringExecution: 124 | nodeSelectorTerms: 125 | - matchExpressions: 126 | - key: ram 127 | operator: NotIn 128 | values: 129 | - 8gb 130 | - key: dbsize 131 | operator: NotIn 132 | values: 133 | - "true" 134 | - key: nginx 135 | operator: NotIn 136 | values: 137 | - "true" 138 | - "extra-large" 139 | - key: dump 140 | operator: NotIn 141 | values: 142 | - "true" 143 | podAntiAffinity: 144 | requiredDuringSchedulingIgnoredDuringExecution: 145 | - labelSelector: 146 | matchExpressions: 147 | - key: app 148 | operator: In 149 | values: 150 | - db-dumper 151 | topologyKey: kubernetes.io/hostname 152 | # securityContext: 153 | # sysctls: 154 | # - name: net.core.somaxconn 155 | # value: "65535" 156 | --- 157 | apiVersion: v1 158 | kind: Service 159 | metadata: 160 | name: sb-server-service 161 | spec: 162 | ports: 163 | - port: 8080 164 | protocol: TCP 165 | targetPort: 8080 166 | selector: 167 | app: sb-server 168 | --- 169 | apiVersion: v1 170 | kind: Service 171 | metadata: 172 | name: sb-server-segments-service 173 | labels: 174 | app: sb-server 175 | spec: 176 | ports: 177 | - port: 8080 178 | protocol: TCP 179 | targetPort: 8080 180 | name: web 181 | selector: 182 | app: sb-server 183 | --- 184 | apiVersion: monitoring.coreos.com/v1 185 | kind: ServiceMonitor 186 | metadata: 187 | name: sb-server-servicemonitor 188 | labels: 189 | app: sb-server 190 | release: prometheus-operator 191 | spec: 192 | endpoints: 193 | - port: web 194 | interval: 1m 195 | selector: 196 | matchLabels: 197 | app: sb-server 198 | # --- 199 | # apiVersion: apps/v1 200 | # kind: Deployment 201 | # metadata: 202 | # name: sb-server-test-deployment 203 | # spec: 204 | # replicas: 1 #77 #60 #54 #48 #42 #54 205 | # selector: 206 | # matchLabels: 207 | # app: sb-server-test 208 | # method: post 209 | # template: 210 | # metadata: 211 | # labels: 212 | # app: sb-server-test 213 | # method: post 214 | # spec: 215 | # containers: 216 | # - image: ghcr.io/ajayyy/sb-server@sha256:7df3de00f91aece1e6199bdffff28b60ff2efc62c7810744feb26a1c20917f14 217 | # name: sb-server-test 218 | # command: ["/bin/sh"] 219 | # args: ["-c", "cd /usr/src/app; echo '{}' > config.json;node --inspect dist/src/index.js"] 220 | # resources: 221 | # requests: 222 | # # cpu: 1300m # Old limit to not make it overload memory 223 | # cpu: 600m 224 | # memory: 750Mi 225 | # limits: 226 | # #memory: 750Mi # 750 227 | # memory: 1100Mi 228 | # envFrom: 229 | # - configMapRef: 230 | # name: sb-server-config 231 | # env: 232 | # - name: postgres_user 233 | # valueFrom: { secretKeyRef: { name: stackgres-secrets, key: username } } 234 | # - name: postgres_password 235 | # valueFrom: { secretKeyRef: { name: stackgres-secrets, key: password } } 236 | # - name: postgresReadOnly_user 237 | # valueFrom: { secretKeyRef: { name: stackgres-secrets, key: username } } 238 | # - name: postgresReadOnly_password 239 | # valueFrom: { secretKeyRef: { name: stackgres-secrets, key: password } } 240 | # - name: redis_clientCacheSize 241 | # value: "0" 242 | # # - name: redis_disableHashCache 243 | # # value: "true" 244 | # # - name: redis_enabled 245 | # # value: "false" 246 | # # - name: postgres_port 247 | # # value: "5435" 248 | # # - name: postgres_user 249 | # # valueFrom: { secretKeyRef: { name: cluster3-postgres-secret, key: username } } 250 | # # - name: postgres_password 251 | # # valueFrom: { secretKeyRef: { name: cluster3-postgres-secret, key: password } } 252 | # # - name: postgresReadOnly_user 253 | # # valueFrom: { secretKeyRef: { name: cluster3-postgres-secret, key: username } } 254 | # # - name: postgresReadOnly_password 255 | # # valueFrom: { secretKeyRef: { name: cluster3-postgres-secret, key: password } } 256 | # - name: globalSalt 257 | # valueFrom: 258 | # secretKeyRef: 259 | # name: sb-server-secrets 260 | # key: globalSalt 261 | # optional: false 262 | # - name: discordReportChannelWebhookURL 263 | # valueFrom: 264 | # secretKeyRef: 265 | # name: sb-server-secrets 266 | # key: discordReportChannelWebhookURL 267 | # optional: false 268 | # - name: discordFailedReportChannelWebhookURL 269 | # valueFrom: 270 | # secretKeyRef: 271 | # name: sb-server-secrets 272 | # key: discordFailedReportChannelWebhookURL 273 | # optional: false 274 | # - name: discordFirstTimeSubmissionsWebhookURL 275 | # valueFrom: 276 | # secretKeyRef: 277 | # name: sb-server-secrets 278 | # key: discordFirstTimeSubmissionsWebhookURL 279 | # optional: false 280 | # - name: discordDeArrowLockedWebhookURL 281 | # valueFrom: 282 | # secretKeyRef: 283 | # name: sb-server-secrets 284 | # key: discordDeArrowLockedWebhookURL 285 | # optional: false 286 | # - name: patreon_clientId 287 | # valueFrom: 288 | # secretKeyRef: 289 | # name: sb-server-secrets 290 | # key: patreon_clientId 291 | # optional: false 292 | # - name: patreon_clientSecret 293 | # valueFrom: 294 | # secretKeyRef: 295 | # name: sb-server-secrets 296 | # key: patreon_clientSecret 297 | # optional: false 298 | # - name: tokenSeed 299 | # valueFrom: 300 | # secretKeyRef: 301 | # name: sb-server-secrets 302 | # key: tokenSeed 303 | # optional: false 304 | # ports: 305 | # - containerPort: 8080 306 | # # livenessProbe: 307 | # # httpGet: 308 | # # path: /api/status 309 | # # port: 8080 310 | # # initialDelaySeconds: 10 311 | # # periodSeconds: 1 312 | # # timeoutSeconds: 2 313 | # # failureThreshold: 1 314 | # # readinessProbe: 315 | # # httpGet: 316 | # # path: /api/status 317 | # # port: 8080 318 | # # initialDelaySeconds: 5 319 | # # periodSeconds: 1 320 | # affinity: 321 | # nodeAffinity: 322 | # requiredDuringSchedulingIgnoredDuringExecution: 323 | # nodeSelectorTerms: 324 | # - matchExpressions: 325 | # - key: ram 326 | # operator: NotIn 327 | # values: 328 | # - 8gb 329 | # - key: dbsize 330 | # operator: NotIn 331 | # values: 332 | # - "true" 333 | # - key: nginx 334 | # operator: NotIn 335 | # values: 336 | # - "true" 337 | # - "extra-large" 338 | # # securityContext: 339 | # # sysctls: 340 | # # - name: net.core.somaxconn 341 | # # value: "65535" 342 | # --- 343 | # apiVersion: v1 344 | # kind: Service 345 | # metadata: 346 | # name: sb-server-test-service 347 | # spec: 348 | # ports: 349 | # - port: 8080 350 | # protocol: TCP 351 | # targetPort: 8080 352 | # selector: 353 | # app: sb-server-test -------------------------------------------------------------------------------- /kubernetes-config/ingress/ingress.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1 2 | kind: Ingress 3 | metadata: 4 | name: sb-site-ingress 5 | # annotations: 6 | # regex makes it stop using other ingresses 7 | # nginx.ingress.kubernetes.io/use-regex: "true" 8 | spec: 9 | ingressClassName: nginx 10 | tls: 11 | - secretName: sponsor-cert 12 | rules: 13 | - host: api.sponsor.ajay.app 14 | http: &backend 15 | paths: 16 | - path: / 17 | pathType: Prefix 18 | backend: 19 | service: 20 | name: sb-site-service 21 | port: 22 | number: 80 23 | - path: /api 24 | pathType: Prefix 25 | backend: 26 | service: 27 | name: sb-server-service 28 | port: 29 | number: 8080 30 | # service: 31 | # name: sb-site-service 32 | # port: 33 | # number: 80 34 | - path: /database 35 | pathType: Prefix 36 | backend: &dbBackend 37 | service: 38 | name: db-dumper-service 39 | port: 40 | number: 8080 41 | - path: /database.json 42 | pathType: Prefix 43 | backend: *dbBackend 44 | - host: "sponsor.ajay.app" 45 | http: *backend 46 | --- 47 | apiVersion: networking.k8s.io/v1 48 | kind: Ingress 49 | metadata: 50 | name: sb-site-ingress-skip-segments 51 | annotations: 52 | nginx.ingress.kubernetes.io/upstream-hash-by: $segment_param 53 | nginx.ingress.kubernetes.io/proxy-buffering: "on" 54 | 55 | nginx.ingress.kubernetes.io/proxy-connect-timeout: "2" 56 | nginx.ingress.kubernetes.io/proxy-read-timeout: "8" 57 | 58 | nginx.ingress.kubernetes.io/default-backend: error-service 59 | nginx.ingress.kubernetes.io/custom-http-errors: "503,504" 60 | 61 | nginx.ingress.kubernetes.io/configuration-snippet: | 62 | internal; 63 | rewrite ^ $original_uri break; 64 | 65 | proxy_cache static-cache; 66 | # proxy_cache_valid 200 15m; 67 | # proxy_cache_valid 404 1s; 68 | # proxy_cache_valid 200 404 1m; 69 | # proxy_cache_valid 200 404 5m; 70 | proxy_cache_valid 200 404 1s; 71 | 72 | # When enabled, only one request at a time will be allowed to populate a new cache element identified 73 | proxy_cache_lock on; 74 | # proxy_cache_lock off; 75 | 76 | proxy_cache_revalidate on; 77 | 78 | # Will use cache instead 79 | proxy_next_upstream off; 80 | proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504; 81 | 82 | # proxy_connect_timeout 2s; 83 | # proxy_read_timeout 2s; 84 | 85 | add_header X-Cache-Status $upstream_cache_status always; 86 | # add_header X-Real-Cache-Status $upstream_cache_status; 87 | 88 | # limit_req zone=segmentLimit burst=1; 89 | nginx.ingress.kubernetes.io/server-snippet: | 90 | location /api/skipSegments { 91 | if ( $request_method = GET) { 92 | set $target_destination '/_read'; 93 | } 94 | if ( $request_method != GET) { 95 | set $target_destination '/_write'; 96 | } 97 | set $original_uri $uri; 98 | rewrite ^ $target_destination last; 99 | } 100 | spec: 101 | ingressClassName: nginx 102 | tls: 103 | - secretName: sponsor-cert 104 | rules: 105 | - host: api.sponsor.ajay.app 106 | http: &backend 107 | paths: 108 | - path: /_read 109 | pathType: Prefix 110 | backend: 111 | service: 112 | name: sb-server-segments-service 113 | port: 114 | number: 8080 115 | # service: 116 | # name: error-service 117 | # port: 118 | # number: 80 119 | - path: /_write 120 | pathType: Prefix 121 | backend: 122 | service: 123 | name: sb-server-segments-service 124 | port: 125 | number: 8080 126 | # service: 127 | # name: error-service 128 | # port: 129 | # number: 80 130 | - host: sponsor.ajay.app 131 | http: *backend 132 | --- 133 | apiVersion: networking.k8s.io/v1 134 | kind: Ingress 135 | metadata: 136 | name: sb-site-ingress-branding 137 | annotations: 138 | nginx.ingress.kubernetes.io/upstream-hash-by: $segment_param 139 | nginx.ingress.kubernetes.io/proxy-buffering: "on" 140 | 141 | nginx.ingress.kubernetes.io/proxy-connect-timeout: "2" 142 | nginx.ingress.kubernetes.io/proxy-read-timeout: "8" 143 | 144 | nginx.ingress.kubernetes.io/default-backend: error-service 145 | nginx.ingress.kubernetes.io/custom-http-errors: "503,504" 146 | 147 | nginx.ingress.kubernetes.io/configuration-snippet: | 148 | proxy_cache static-cache; 149 | # proxy_cache_valid 15m; 150 | # proxy_cache_valid 200 15m; 151 | # proxy_cache_valid 404 1m; 152 | # proxy_cache_valid 200 404 1m; 153 | # proxy_cache_valid 200 404 5m; 154 | proxy_cache_valid 200 404 1s; 155 | 156 | # When enabled, only one request at a time will be allowed to populate a new cache element identified 157 | proxy_cache_lock on; 158 | # proxy_cache_lock off; 159 | 160 | proxy_cache_revalidate on; 161 | 162 | # Will use cache instead 163 | proxy_next_upstream off; 164 | proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504; 165 | 166 | # proxy_connect_timeout 2s; 167 | # proxy_read_timeout 2s; 168 | 169 | add_header X-Cache-Status $upstream_cache_status always; 170 | 171 | # limit_req zone=segmentLimit burst=1000; 172 | spec: 173 | ingressClassName: nginx 174 | tls: 175 | - secretName: sponsor-cert 176 | rules: 177 | - host: api.sponsor.ajay.app 178 | http: &backend 179 | paths: 180 | - path: /api/branding 181 | pathType: Prefix 182 | backend: 183 | service: 184 | name: sb-server-segments-service 185 | port: 186 | number: 8080 187 | - host: sponsor.ajay.app 188 | http: *backend 189 | --- 190 | apiVersion: networking.k8s.io/v1 191 | kind: Ingress 192 | metadata: 193 | name: sb-site-ingress-video-labels 194 | annotations: 195 | nginx.ingress.kubernetes.io/upstream-hash-by: $segment_param 196 | nginx.ingress.kubernetes.io/proxy-buffering: "on" 197 | 198 | nginx.ingress.kubernetes.io/proxy-connect-timeout: "3s" 199 | 200 | nginx.ingress.kubernetes.io/configuration-snippet: | 201 | proxy_cache static-cache; 202 | proxy_cache_valid 5m; 203 | proxy_cache_lock on; 204 | proxy_cache_use_stale updating; 205 | add_header X-Cache-Status $upstream_cache_status; 206 | 207 | # limit_req zone=segmentLimit burst=1000; 208 | spec: 209 | ingressClassName: nginx 210 | tls: 211 | - secretName: sponsor-cert 212 | rules: 213 | - host: api.sponsor.ajay.app 214 | http: &backend 215 | paths: 216 | - path: /api/videoLabels 217 | pathType: Prefix 218 | backend: 219 | service: 220 | name: sb-server-segments-service 221 | port: 222 | number: 8080 223 | # service: 224 | # name: sb-site-service 225 | # port: 226 | # number: 80 227 | - host: sponsor.ajay.app 228 | http: *backend 229 | --- 230 | apiVersion: networking.k8s.io/v1 231 | kind: Ingress 232 | metadata: 233 | name: sb-site-ingress-cached 234 | annotations: 235 | nginx.ingress.kubernetes.io/proxy-buffering: "on" 236 | # nginx.ingress.kubernetes.io/service-upstream: "true" # for 503 handling? maybe not needed 237 | nginx.ingress.kubernetes.io/configuration-snippet: | 238 | proxy_cache static-cache; 239 | proxy_cache_valid 24h; 240 | proxy_cache_lock on; 241 | proxy_cache_use_stale updating; 242 | add_header X-Cache-Status $upstream_cache_status; 243 | spec: 244 | ingressClassName: nginx 245 | tls: 246 | - secretName: sponsor-cert 247 | rules: 248 | - host: api.sponsor.ajay.app 249 | http: &backend 250 | paths: 251 | - path: /api/brandingStats 252 | pathType: Prefix 253 | backend: &sb-server 254 | service: 255 | name: sb-server-service 256 | port: 257 | number: 8080 258 | - path: /api/getTopBrandingUsers 259 | pathType: Prefix 260 | backend: &sb-server 261 | service: 262 | name: sb-server-service 263 | port: 264 | number: 8080 265 | - path: /api/getTotalStats 266 | pathType: Prefix 267 | backend: &sb-server 268 | service: 269 | name: sb-server-service 270 | port: 271 | number: 8080 272 | # name: sb-site-service 273 | # port: 274 | # number: 80 275 | - path: /api/getTopUsers 276 | pathType: Prefix 277 | backend: 278 | service: 279 | # name: sb-server-service 280 | # port: 281 | # number: 8080 282 | name: sb-site-service 283 | port: 284 | number: 80 285 | - path: /api/getTopCategoryUsers 286 | pathType: Prefix 287 | backend: 288 | service: 289 | # name: sb-server-service 290 | # port: 291 | # number: 8080 292 | name: sb-site-service 293 | port: 294 | number: 80 295 | - host: "sponsor.ajay.app" 296 | http: *backend 297 | # --- 298 | # apiVersion: networking.k8s.io/v1 299 | # kind: Ingress 300 | # metadata: 301 | # name: test-sb-server-ingress 302 | # spec: 303 | # ingressClassName: nginx 304 | # tls: 305 | # - secretName: sponsor-test-cert 306 | # rules: 307 | # - host: api.sponsor.ajay.app 308 | # http: &backend 309 | # paths: 310 | # - path: / 311 | # pathType: Prefix 312 | # backend: 313 | # service: 314 | # name: sb-site-service 315 | # port: 316 | # number: 80 317 | # - path: /api 318 | # pathType: Prefix 319 | # backend: 320 | # service: 321 | # name: test-sb-server-service 322 | # port: 323 | # number: 8080 324 | # # service: 325 | # # name: sb-site-service 326 | # # port: 327 | # # number: 80 328 | --- 329 | apiVersion: networking.k8s.io/v1 330 | kind: Ingress 331 | metadata: 332 | name: graph-ingress 333 | namespace: monitoring 334 | spec: 335 | ingressClassName: nginx 336 | tls: 337 | - secretName: graph-cert 338 | rules: 339 | - host: graph.sponsor.ajay.app 340 | http: 341 | paths: 342 | - path: / 343 | pathType: Prefix 344 | backend: 345 | service: 346 | name: prometheus-operator-grafana 347 | port: 348 | number: 80 349 | # --- 350 | # apiVersion: networking.k8s.io/v1 351 | # kind: Ingress 352 | # metadata: 353 | # name: longhorn-ingress 354 | # namespace: longhorn-system 355 | # annotations: 356 | # nginx.ingress.kubernetes.io/auth-type: basic 357 | # nginx.ingress.kubernetes.io/auth-secret: management-auth 358 | # nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required' 359 | # spec: 360 | # ingressClassName: nginx 361 | # tls: 362 | # - secretName: longhorn-cert 363 | # rules: 364 | # - host: longhorn.sponsor.ajay.app 365 | # http: 366 | # paths: 367 | # - path: / 368 | # pathType: Prefix 369 | # backend: 370 | # service: 371 | # name: longhorn-frontend 372 | # port: 373 | # number: 80 374 | # --- 375 | # apiVersion: networking.k8s.io/v1 376 | # kind: Ingress 377 | # metadata: 378 | # name: sb-site-ingress-skip-segments-test 379 | # annotations: 380 | # # nginx.ingress.kubernetes.io/upstream-hash-by: $segment_param 381 | # nginx.ingress.kubernetes.io/proxy-buffering: "on" 382 | 383 | # nginx.ingress.kubernetes.io/proxy-connect-timeout: "2" 384 | # nginx.ingress.kubernetes.io/proxy-read-timeout: "2" 385 | 386 | # nginx.ingress.kubernetes.io/default-backend: error-service 387 | # nginx.ingress.kubernetes.io/custom-http-errors: "503,504" 388 | 389 | # nginx.ingress.kubernetes.io/configuration-snippet: | 390 | # proxy_cache static-cache; 391 | # # proxy_cache_valid 15m; 392 | # # proxy_cache_valid 200 15m; 393 | # # proxy_cache_valid 404 1m; 394 | # # proxy_cache_valid 200 404 1m; 395 | # # proxy_cache_valid 200 404 5m; 396 | # # proxy_cache_valid 200 404 1s; 397 | 398 | # # When enabled, only one request at a time will be allowed to populate a new cache element identified 399 | # proxy_cache_lock on; 400 | # # proxy_cache_lock off; 401 | 402 | # proxy_cache_revalidate on; 403 | 404 | # # Will use cache instead 405 | # proxy_next_upstream off; 406 | # proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504; 407 | 408 | # # proxy_connect_timeout 2s; 409 | # # proxy_read_timeout 2s; 410 | 411 | # add_header X-Cache-Status $upstream_cache_status always; 412 | 413 | # # limit_req zone=segmentLimit burst=1000; 414 | # # nginx.ingress.kubernetes.io/server-snippet: | 415 | # # location /notapi/test { 416 | # # if ( $request_method = GET) { 417 | # # set $target_destination '/_read_test'; 418 | # # } 419 | # # set $original_uri $uri; 420 | # # rewrite ^ $target_destination last; 421 | # # } 422 | # spec: 423 | # ingressClassName: nginx 424 | # tls: 425 | # - secretName: test-cert 426 | # rules: 427 | # - host: k8s.sponsor.ajay.app 428 | # http: &backend 429 | # paths: 430 | # - path: / 431 | # pathType: Prefix 432 | # backend: 433 | # service: 434 | # name: sb-server-test-service 435 | # port: 436 | # number: 8080 -------------------------------------------------------------------------------- /terraform/kube.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | # You have the choice of setting your Hetzner API token here or define the TF_VAR_hcloud_token env 3 | # within your shell, such as such: export TF_VAR_hcloud_token=xxxxxxxxxxx 4 | # If you choose to define it in the shell, this can be left as is. 5 | 6 | # Your Hetzner token can be found in your Project > Security > API Token (Read & Write is required). 7 | hcloud_token = "xxxxxxxxxxx" 8 | } 9 | 10 | module "kube-hetzner" { 11 | providers = { 12 | hcloud = hcloud 13 | } 14 | hcloud_token = var.hcloud_token != "" ? var.hcloud_token : local.hcloud_token 15 | 16 | # Then fill or edit the below values. Only the first values starting with a * are obligatory; the rest can remain with their default values, or you 17 | # could adapt them to your needs. 18 | 19 | # * For local dev, path to the git repo 20 | source = "../terraform-hcloud-kube-hetzner" 21 | # If you want to use the latest master branch 22 | # source = "github.com/kube-hetzner/terraform-hcloud-kube-hetzner" 23 | # For normal use, this is the path to the terraform registry 24 | # source = "kube-hetzner/kube-hetzner/hcloud" 25 | 26 | # You can optionally specify a version number 27 | # version = "1.2.0" 28 | 29 | # Note that some values, notably "location" and "public_key" have no effect after initializing the cluster. 30 | # This is to keep Terraform from re-provisioning all nodes at once, which would lose data. If you want to update 31 | # those, you should instead change the value here and manually re-provision each node. Grep for "lifecycle". 32 | 33 | # Customize the SSH port (by default 22) 34 | # ssh_port = 2222 35 | 36 | # * Your ssh public key 37 | ssh_public_key = file("/home/ajay/.ssh/certs/sponsorblock-k8s-2.pub") 38 | # * Your private key must be "ssh_private_key = null" when you want to use ssh-agent for a Yubikey-like device authentification or an SSH key-pair with a passphrase. 39 | # For more details on SSH see https://github.com/kube-hetzner/kube-hetzner/blob/master/docs/ssh.md 40 | ssh_private_key = file("/home/ajay/.ssh/certs/sponsorblock-k8s-2") 41 | # You can add additional SSH public Keys to grant other team members root access to your cluster nodes. 42 | # ssh_additional_public_keys = [] 43 | 44 | # You can also add additional SSH public Keys which are saved in the hetzner cloud by a label. 45 | # See https://docs.hetzner.cloud/#label-selector 46 | # ssh_hcloud_key_label = "role=admin" 47 | 48 | # If you want to use an ssh key that is already registered within hetzner cloud, you can pass its id. 49 | # If no id is passed, a new ssh key will be registered within hetzner cloud. 50 | # It is important that exactly this key is passed via `ssh_public_key` & `ssh_private_key` vars. 51 | # hcloud_ssh_key_id = "sb" 52 | 53 | # These can be customized, or left with the default values 54 | # * For Hetzner locations see https://docs.hetzner.com/general/others/data-centers-and-connection/ 55 | network_region = "eu-central" # change to `us-east` if location is ash 56 | 57 | # If you must change the network CIDR you can do so below, but it is highly advised against. 58 | # network_ipv4_cidr = "10.0.0.0/8" 59 | 60 | # If you must change the cluster CIDR you can do so below, but it is highly advised against. 61 | # Cluster CIDR must be a part of the network CIDR! 62 | # cluster_ipv4_cidr = "10.42.0.0/16" 63 | 64 | # For the control planes, at least three nodes are the minimum for HA. Otherwise, you need to turn off the automatic upgrades (see README). 65 | # **It must always be an ODD number, never even!** Search the internet for "splitbrain problem with etcd" or see https://rancher.com/docs/k3s/latest/en/installation/ha-embedded/ 66 | # For instance, one is ok (non-HA), two is not ok, and three is ok (becomes HA). It does not matter if they are in the same nodepool or not! So they can be in different locations and of various types. 67 | 68 | # Of course, you can choose any number of nodepools you want, with the location you want. The only constraint on the location is that you need to stay in the same network region, Europe, or the US. 69 | # For the server type, the minimum instance supported is cpx11 (just a few cents more than cx11); see https://www.hetzner.com/cloud. 70 | 71 | # IMPORTANT: Before you create your cluster, you can do anything you want with the nodepools, but you need at least one of each, control plane and agent. 72 | # Once the cluster is up and running, you can change nodepool count and even set it to 0 (in the case of the first control-plane nodepool, the minimum is 1). 73 | # You can also rename it (if the count is 0), but do not remove a nodepool from the list. 74 | 75 | # The only nodepools that are safe to remove from the list are at the end. That is due to how subnets and IPs get allocated (FILO). 76 | # You can, however, freely add other nodepools at the end of each list if you want. The maximum number of nodepools you can create combined for both lists is 255. 77 | # Also, before decreasing the count of any nodepools to 0, it's essential to drain and cordon the nodes in question. Otherwise, it will leave your cluster in a bad state. 78 | 79 | # Before initializing the cluster, you can change all parameters and add or remove any nodepools. You need at least one nodepool of each kind, control plane, and agent. 80 | # The nodepool names are entirely arbitrary, you can choose whatever you want, but no special characters or underscore, and they must be unique; only alphanumeric characters and dashes are allowed. 81 | 82 | # If you want to have a single node cluster, have one control plane nodepools with a count of 1, and one agent nodepool with a count of 0. 83 | 84 | # Please note that changing labels and taints after the first run will have no effect. If needed, you can do that through Kubernetes directly. 85 | 86 | # * Example below: 87 | 88 | control_plane_nodepools = [ 89 | { 90 | name = "control-plane-11-2", 91 | server_type = "cax11", 92 | location = "fsn1", 93 | labels = [], 94 | taints = [], 95 | count = 3 96 | } 97 | ] 98 | 99 | agent_nodepools = [ 100 | { 101 | name = "agent-21", 102 | server_type = "cax21", 103 | location = "fsn1", 104 | labels = [], 105 | taints = [], 106 | count = 19 #16 107 | }, 108 | { 109 | name = "agent-41-nginx", 110 | server_type = "cax41", 111 | location = "fsn1", 112 | labels = [ 113 | "nginx=extra-large" 114 | ], 115 | taints = [], 116 | count = 4 117 | }, 118 | { 119 | name = "agent-31-db-dumper", 120 | server_type = "cax31", 121 | location = "fsn1", 122 | labels = [ 123 | "dump=true" 124 | ], 125 | taints = [], 126 | count = 1 127 | } 128 | ] 129 | # Add custom control plane configuration options here. 130 | # E.g to enable monitoring for etcd, proxy etc: 131 | # control_planes_custom_config = { 132 | # etcd-expose-metrics = true, 133 | # kube-controller-manager-arg = "bind-address=0.0.0.0", 134 | # kube-proxy-arg ="metrics-bind-address=0.0.0.0", 135 | # kube-scheduler-arg = "bind-address=0.0.0.0", 136 | # } 137 | 138 | # You can enable encrypted wireguard for the CNI by setting this to "true". Default is "false". 139 | # FYI, Hetzner says "Traffic between cloud servers inside a Network is private and isolated, but not automatically encrypted." 140 | # Source: https://docs.hetzner.com/cloud/networks/faq/#is-traffic-inside-hetzner-cloud-networks-encrypted 141 | # It works with all CNIs that we support. 142 | # Just note, that if Cilium with cilium_values, the responsability of enabling of disabling Wireguard falls on you. 143 | # enable_wireguard = true 144 | 145 | # * LB location and type, the latter will depend on how much load you want it to handle, see https://www.hetzner.com/cloud/load-balancer 146 | load_balancer_type = "lb11" 147 | load_balancer_location = "fsn1" 148 | # Unused because disabled 149 | 150 | ### The following values are entirely optional (and can be removed from this if unused) 151 | 152 | # You can refine a base domain name to be use in this form of nodename.base_domain for setting the reserve dns inside Hetzner 153 | # base_domain = "mycluster.example.com" 154 | 155 | # Cluster Autoscaler 156 | # Providing at least one map for the array enables the cluster autoscaler feature, default is disabled 157 | # Please note that the autoscaler should not be used with initial_k3s_channel < "v1.25". So ideally lock it to "v1.25". 158 | # * Example below: 159 | # autoscaler_nodepools = [ 160 | # { 161 | # name = "autoscaled-small" 162 | # server_type = "cpx21" # must be same or better than the control_plane server type (regarding disk size)! 163 | # location = "fsn1" 164 | # min_nodes = 0 165 | # max_nodes = 5 166 | # } 167 | # ] 168 | 169 | # Enable etcd snapshot backups to S3 storage. 170 | # Just provide a map with the needed settings (according to your S3 storage provider) and backups to S3 will 171 | # be enabled (with the default settings for etcd snapshots). 172 | # Cloudflare's R2 offers 10GB, 10 million reads and 1 million writes per month for free. 173 | # For proper context, have a look at https://docs.k3s.io/backup-restore. 174 | # etcd_s3_backup = { 175 | # etcd-s3-endpoint = "xxxx.r2.cloudflarestorage.com" 176 | # etcd-s3-access-key = "" 177 | # etcd-s3-secret-key = "" 178 | # etcd-s3-bucket = "k3s-etcd-snapshots" 179 | # } 180 | 181 | # To use local storage on the nodes, you can enable Longhorn, default is "false". 182 | # See a full recap on how to configure agent nodepools for longhorn here https://github.com/kube-hetzner/terraform-hcloud-kube-hetzner/discussions/373#discussioncomment-3983159 183 | enable_longhorn = false 184 | 185 | # By default, longhorn is pulled from https://charts.longhorn.io. 186 | # If you need a version of longhorn which assures compatibility with rancher you can set this variable to https://charts.rancher.io. 187 | # longhorn_repository = "https://charts.rancher.io" 188 | 189 | # The namespace for longhorn deployment, default is "longhorn-system". 190 | # longhorn_namespace = "longhorn-system" 191 | 192 | # The file system type for Longhorn, if enabled (ext4 is the default, otherwise you can choose xfs). 193 | # longhorn_fstype = "xfs" 194 | 195 | # how many replica volumes should longhorn create (default is 3). 196 | # longhorn_replica_count = 1 197 | 198 | # When you enable Longhorn, you can go with the default settings and just modify the above two variables OR you can add a longhorn_values variable 199 | # with all needed helm values, see towards the end of the file in the advanced section. 200 | # If that file is present, the system will use it during the deploy, if not it will use the default values with the two variable above that can be customized. 201 | # After the cluster is deployed, you can always use HelmChartConfig definition to tweak the configuration. 202 | 203 | # Also, you can choose to use a Hetzner volume with Longhorn. By default, it will use the nodes own storage space, but if you add an attribute of 204 | # longhorn_volume_size (⚠️ not a variable, just a possible agent nodepool attribute) with a value between 10 and 10000 GB to your agent nodepool definition, it will create and use the volume in question. 205 | # See the agent nodepool section for an example of how to do that. 206 | 207 | # To disable Hetzner CSI storage, you can set the following to "true", default is "false". 208 | # disable_hetzner_csi = true 209 | 210 | # If you want to use a specific Hetzner CCM and CSI version, set them below; otherwise, leave them as-is for the latest versions. 211 | # hetzner_ccm_version = "" 212 | # hetzner_csi_version = "" 213 | 214 | # If you want to specify the Kured version, set it below - otherwise it'll use the latest version available. 215 | # kured_version = "" 216 | 217 | # If you want to enable the Nginx ingress controller (https://kubernetes.github.io/ingress-nginx/) instead of Traefik, you can set this to "nginx". Default is "traefik". 218 | # By the default we load optimal Traefik and Nginx ingress controller config for Hetzner, however you may need to tweak it to your needs, so to do, 219 | # we allow you to add a traefik_values and nginx_values, see towards the end of this file in the advanced section. 220 | # After the cluster is deployed, you can always use HelmChartConfig definition to tweak the configuration. 221 | # If you want to disable both controllers set this to "none" 222 | ingress_controller = "none" 223 | 224 | # You can change the number of replicas for selected ingress controller here. The default 0 means autoselecting based on number of agent nodes (1 node = 1 replica, 2 nodes = 2 replicas, 3+ nodes = 3 replicas) 225 | # ingress_replica_count = 1 226 | 227 | # Use the klipperLB (similar to metalLB), instead of the default Hetzner one, that has an advantage of dropping the cost of the setup. 228 | # Automatically "true" in the case of single node cluster (as it does not make sense to use the Hetzner LB in that situation). 229 | # It can work with any ingress controller that you choose to deploy. 230 | # Please note that because the klipperLB points to all nodes, we automatically allow scheduling on the control plane when it is active. 231 | # enable_klipper_metal_lb = "true" 232 | 233 | # If you want to configure additional arguments for traefik, enter them here as a list and in the form of traefik CLI arguments; see https://doc.traefik.io/traefik/reference/static-configuration/cli/ 234 | # They are the options that go into the additionalArguments section of the Traefik helm values file. 235 | # Example: traefik_additional_options = ["--log.level=DEBUG", "--tracing=true"] 236 | # traefik_additional_options = [] 237 | 238 | # By default traefik is configured to redirect http traffic to https, you can set this to "false" to disable the redirection. 239 | # traefik_redirect_to_https = false 240 | 241 | # If you want to disable the metric server set this to "false". Default is "true". 242 | # enable_metrics_server = false 243 | 244 | # If you want to allow non-control-plane workloads to run on the control-plane nodes, set this to "true". The default is "false". 245 | # True by default for single node clusters, and when enable_klipper_metal_lb is true. In those cases, the value below will be ignored. 246 | # allow_scheduling_on_control_plane = true 247 | 248 | # If you want to disable the automatic upgrade of k3s, you can set below to "false". 249 | # Ideally, keep it on, to always have the latest Kubernetes version, but lock the initial_k3s_channel to a kube major version, 250 | # of your choice, like v1.25 or v1.26. That way you get the best of both worlds without the breaking changes risk. 251 | # For production use, always use an HA setup with at least 3 control-plane nodes and 2 agents, and keep this on for maximum security. 252 | 253 | # The default is "true" (in HA setup i.e. at least 3 control plane nodes & 2 agents, just keep it enabled since it works flawlessly). 254 | # automatically_upgrade_k3s = false 255 | 256 | # The default is "true" (in HA setup it works wonderfully well, with automatic roll-back to the previous snapshot in case of an issue). 257 | # IMPORTANT! For non-HA clusters i.e. when the number of control-plane nodes is < 3, you have to turn it off. 258 | # automatically_upgrade_os = false 259 | 260 | # If you need more control over kured and the reboot behaviour, you can pass additional options to kured. 261 | # For example limiting reboots to certain timeframes. For all options see: https://kured.dev/docs/configuration/ 262 | # The default options are: `--reboot-command=/usr/bin/systemctl reboot --pre-reboot-node-labels=kured=rebooting --post-reboot-node-labels=kured=done --period=5m` 263 | # Defaults can be overridden by using the same key. 264 | # kured_options = { 265 | # "reboot-days": "su" 266 | # "start-time": "3am" 267 | # "end-time": "8am" 268 | # "time-zone": "Local" 269 | # } 270 | 271 | # Allows you to specify either stable, latest, testing or supported minor versions. 272 | # see https://rancher.com/docs/k3s/latest/en/upgrades/basic/ and https://update.k3s.io/v1-release/channels 273 | # ⚠️ If you are going to use Rancher addons for instance, it's always a good idea to fix the kube version to latest - 0.01, 274 | # at the time of writing the latest is v1.26, so setting the value below to "v1.25" will insure maximum compatibility with Rancher, Longhorn and so on! 275 | # The default is "v1.25". 276 | # initial_k3s_channel = "stable" 277 | 278 | # The cluster name, by default "k3s" 279 | cluster_name = "sb2" 280 | 281 | # Whether to use the cluster name in the node name, in the form of {cluster_name}-{nodepool_name}, the default is "true". 282 | # use_cluster_name_in_node_name = false 283 | 284 | # Extra k3s registries. This is useful if you have private registries and you want to pull images without additional secrets. 285 | # Or if you want to proxy registries for various reasons like rate-limiting. 286 | # It will create the registries.yaml file, more info here https://docs.k3s.io/installation/private-registry. 287 | # Note that you do not need to get this right from the first time, you can update it when you want during the life of your cluster. 288 | # The default is blank. 289 | /* k3s_registries = <<-EOT 290 | mirrors: 291 | hub.my_registry.com: 292 | endpoint: 293 | - "hub.my_registry.com" 294 | configs: 295 | hub.my_registry.com: 296 | auth: 297 | username: username 298 | password: password 299 | EOT */ 300 | 301 | # Additional environment variables for the host OS on which k3s runs. See for example https://docs.k3s.io/advanced#configuring-an-http-proxy . 302 | # additional_k3s_environment = { 303 | # "CONTAINERD_HTTP_PROXY" : "http://your.proxy:port", 304 | # "CONTAINERD_HTTPS_PROXY" : "http://your.proxy:port", 305 | # "NO_PROXY" : "127.0.0.0/8,10.0.0.0/8,", 306 | # } 307 | 308 | # Additional commands to execute on the host OS before the k3s install, for example fetching and installing certs. 309 | # preinstall_exec = [ 310 | # "curl https://somewhere.over.the.rainbow/ca.crt > /root/ca.crt", 311 | # "trust anchor --store /root/ca.crt", 312 | # ] 313 | 314 | # If you want to allow all outbound traffic you can set this to "false". Default is "true". 315 | # restrict_outbound_traffic = false 316 | 317 | # Adding extra firewall rules, like opening a port 318 | # More info on the format here https://registry.terraform.io/providers/hetznercloud/hcloud/latest/docs/resources/firewall 319 | # extra_firewall_rules = [ 320 | # { 321 | # description = "For Postgres" 322 | # direction = "in" 323 | # protocol = "tcp" 324 | # port = "5432" 325 | # source_ips = ["0.0.0.0/0", "::/0"] 326 | # destination_ips = [] # Won't be used for this rule 327 | # }, 328 | # { 329 | # description = "To Allow ArgoCD access to resources via SSH" 330 | # direction = "out" 331 | # protocol = "tcp" 332 | # port = "22" 333 | # source_ips = [] # Won't be used for this rule 334 | # destination_ips = ["0.0.0.0/0", "::/0"] 335 | # } 336 | # ] 337 | extra_firewall_rules = [ 338 | { 339 | description = "For web" 340 | direction = "in" 341 | protocol = "tcp" 342 | port = "80" 343 | source_ips = ["0.0.0.0/0", "::/0"] 344 | destination_ips = [] # Won't be used for this rule 345 | }, 346 | { 347 | description = "For web" 348 | direction = "in" 349 | protocol = "tcp" 350 | port = "443" 351 | source_ips = ["0.0.0.0/0", "::/0"] 352 | destination_ips = [] # Won't be used for this rule 353 | }, 354 | { 355 | description = "For rsync" 356 | direction = "in" 357 | protocol = "tcp" 358 | port = "31111" 359 | source_ips = ["0.0.0.0/0", "::/0"] 360 | destination_ips = [] # Won't be used for this rule 361 | }, 362 | { 363 | description = "For postgres outgoing" 364 | direction = "out" 365 | protocol = "tcp" 366 | port = "5432" 367 | source_ips = [] # Won't be used for this rule 368 | destination_ips = ["0.0.0.0/0", "::/0"] 369 | }, 370 | ] 371 | 372 | # If you want to configure a different CNI for k3s, use this flag 373 | # possible values: flannel (Default), calico, and cilium 374 | # As for Cilium, we allow infinite configurations via helm values, please check the CNI section of the readme over at https://github.com/kube-hetzner/terraform-hcloud-kube-hetzner/#cni. 375 | # Also, see the cilium_values at towards the end of this file, in the advanced section. 376 | # cni_plugin = "cilium" 377 | 378 | # You can choose the version of Calico that you want. By default, the latest is used. 379 | # More info on available versions can be found at https://github.com/projectcalico/calico/releases 380 | # Please note that if you are getting 403s from Github, it's also useful to set the version manually. However there is rarely a need for that! 381 | # calico_version = "v3.25.0" 382 | 383 | # If you want to disable the k3s default network policy controller, use this flag! 384 | # Both Calico and Ciliun cni_plugin values override this value to true automatically, the default is "false". 385 | # disable_network_policy = true 386 | 387 | # If you want to disable the automatic use of placement group "spread". See https://docs.hetzner.com/cloud/placement-groups/overview/ 388 | # That may be useful if you need to deploy more than 500 nodes! The default is "false". 389 | placement_group_disable = true 390 | 391 | # By default, we allow ICMP ping in to the nodes, to check for liveness for instance. If you do not want to allow that, you can. Just set this flag to true (false by default). 392 | # block_icmp_ping_in = true 393 | 394 | # You can enable cert-manager (installed by Helm behind the scenes) with the following flag, the default is "true". 395 | # enable_cert_manager = false 396 | 397 | # We download OpenSUSE MicroOS from a mirror. In case it somehow does not work for you (you get a 403), you can try other mirrors. 398 | # You can find a working mirror at https://download.opensuse.org/tumbleweed/appliances/openSUSE-MicroOS.x86_64-OpenStack-Cloud.qcow2.mirrorlist, 399 | # This is the official link which is the fastest but most of the time gives 403. 400 | # opensuse_microos_mirror_link = "https://download.opensuse.org/tumbleweed/appliances/openSUSE-MicroOS.x86_64-OpenStack-Cloud.qcow2" 401 | # This one is usually slow but never has any problems. 402 | # opensuse_microos_mirror_link = "https://ftp.gwdg.de/pub/opensuse/repositories/devel:/kubic:/images/openSUSE_Tumbleweed/openSUSE-MicroOS.x86_64-OpenStack-Cloud.qcow2" 403 | 404 | # IP Addresses to use for the DNS Servers, set to an empty list to use the ones provided by Hetzner, defaults to ["1.1.1.1", " 1.0.0.1", "8.8.8.8"]. 405 | # For rancher installs, best to leave it as default. 406 | # dns_servers = [] 407 | 408 | # When this is enabled, rather than the first node, all external traffic will be routed via a control-plane loadbalancer, allowing for high availability. 409 | # The default is false. 410 | use_control_plane_lb = false 411 | 412 | # Let's say you are not using the control plane LB solution above, and still want to have one hostname point to all your control-plane nodes. 413 | # You could create multiple A records of to let's say cp.cluster.my.org pointing to all of your control-plane nodes ips. 414 | # In which case, you need to define that hostname in the k3s TLS-SANs config to allow connection through it. It can be hostnames or IP addresses. 415 | # additional_tls_sans = ["cp.cluster.my.org"] 416 | 417 | # Oftentimes, you need to communicate to the cluster from inside the cluster itself, in which case it is important to set this value, as it will configure the hostname 418 | # at the load balancer level, and will save you from many slows downs when initiating communications from inside. Later on, you can point your DNS to the IP given 419 | # to the LB. And if you have other services pointing to it, you are also free to create CNAMES to point to it, or whatever you see fit. 420 | # If set, it will apply to either ingress controllers, Traefik or Ingress-Nginx. 421 | # lb_hostname = "" 422 | 423 | # You can enable Rancher (installed by Helm behind the scenes) with the following flag, the default is "false". 424 | # When Rancher is enabled, it automatically installs cert-manager too, and it uses rancher's own self-signed certificates. 425 | # See for options https://rancher.com/docs/rancher/v2.0-v2.4/en/installation/resources/advanced/helm2/helm-rancher/#choose-your-ssl-configuration 426 | # The easiest thing is to leave everything as is (using the default rancher self-signed certificate) and put Cloudflare in front of it. 427 | # As for the number of replicas, by default it is set to the numbe of control plane nodes. 428 | # You can customized all of the above by adding a rancher_values variable see at the end of this file in the advanced section. 429 | # After the cluster is deployed, you can always use HelmChartConfig definition to tweak the configuration. 430 | # IMPORTANT: Rancher's install is quite memory intensive, you will require at least 4GB if RAM, meaning cx21 server type (for your control plane). 431 | # ALSO, in order for Rancher to successfully deploy, you have to set the "rancher_hostname". 432 | enable_rancher = true 433 | 434 | # If using Rancher you can set the Rancher hostname, it must be unique hostname even if you do not use it. 435 | # If not pointing the DNS, you can just port-forward locally via kubectl to get access to the dashboard. 436 | # If you already set the lb_hostname above and are using a Hetzner LB, you do not need to set this one, as it will be used by default. 437 | # But if you set this one explicitly, it will have preference over the lb_hostname in rancher settings. 438 | rancher_hostname = "rancher.sponsor.ajay.app" 439 | 440 | # When Rancher is deployed, by default is uses the "latest" channel. But this can be customized. 441 | # The allowed values are "stable" or "latest". 442 | # rancher_install_channel = "stable" 443 | 444 | # Finally, you can specify a bootstrap-password for your rancher instance. Minimum 48 characters long! 445 | # If you leave empty, one will be generated for you. 446 | # (Can be used by another rancher2 provider to continue setup of rancher outside this module.) 447 | # rancher_bootstrap_password = "" 448 | 449 | # Separate from the above Rancher config (only use one or the other). You can import this cluster directly on an 450 | # an already active Rancher install. By clicking "import cluster" choosing "generic", giving it a name and pasting 451 | # the cluster registration url below. However, you can also ignore that and apply the url via kubectl as instructed 452 | # by Rancher in the wizard, and that would register your cluster too. 453 | # More information about the registration can be found here https://rancher.com/docs/rancher/v2.6/en/cluster-provisioning/registered-clusters/ 454 | # rancher_registration_manifest_url = "https://rancher.xyz.dev/v3/import/xxxxxxxxxxxxxxxxxxYYYYYYYYYYYYYYYYYYYzzzzzzzzzzzzzzzzzzzzz.yaml" 455 | 456 | # Extra values that will be passed to the `extra-manifests/kustomization.yaml.tpl` if its present. 457 | # extra_kustomize_parameters={} 458 | 459 | # It is best practice to turn this off, but for backwards compatibility it is set to "true" by default. 460 | # See https://github.com/kube-hetzner/terraform-hcloud-kube-hetzner/issues/349 461 | # When "false". The kubeconfig file can instead be created by executing: "terraform output --raw kubeconfig > cluster_kubeconfig.yaml" 462 | # Always be careful to not commit this file! 463 | # create_kubeconfig = false 464 | 465 | # Don't create the kustomize backup. This can be helpful for automation. 466 | # create_kustomization = false 467 | 468 | ### ADVANCED - Custom helm values for packages above (search _values if you want to located where those are mentioned upper in this file) 469 | # ⚠️ Inside the _values variable below are examples, up to you to find out the best helm values possible, we do not provide support for customized helm values. 470 | # Please understand that the indentation is very important, inside the EOTs, as those are proper yaml helm values. 471 | # We advise you to use the default values, and only change them if you know what you are doing! 472 | 473 | # Cilium, all Cilium helm values can be found at https://github.com/cilium/cilium/blob/master/install/kubernetes/cilium/values.yaml 474 | # The following is an example, please note that the current indentation inside the EOT is important. 475 | /* cilium_values = <