From 3907be917d5a2b3492d2fdb5a112b0269694c575 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Sat, 8 Nov 2025 18:20:44 +0100 Subject: [PATCH] Replaced rabbitMQ with Kafka, fixed regcred --- deploy/k8s/api-cache.yml | 4 +- deploy/k8s/api-eventbus.yml | 101 +++++++++++++++++++++++------------- deploy/k8s/api-gateway.yml | 17 ++++-- deploy/k8s/api-logger.yml | 29 +++++++---- deploy/k8s/catalog-svc.yml | 19 ++++--- deploy/k8s/db-postgres.yml | 18 +++++-- deploy/k8s/identity-svc.yml | 15 +++--- deploy/k8s/secret.yml | 2 +- 8 files changed, 131 insertions(+), 74 deletions(-) diff --git a/deploy/k8s/api-cache.yml b/deploy/k8s/api-cache.yml index e0a34bd..e12a2ec 100644 --- a/deploy/k8s/api-cache.yml +++ b/deploy/k8s/api-cache.yml @@ -23,7 +23,7 @@ spec: resources: requests: storage: 5Gi - # storageClassName: api-cache-pv + storageClassName: api-cache-pv --- apiVersion: v1 kind: Service @@ -100,6 +100,8 @@ spec: - --redis.addr=redis://api-cache:6379 ports: - containerPort: 9121 + imagePullSecrets: + - name: regcred volumes: - name: api-cache-data persistentVolumeClaim: diff --git a/deploy/k8s/api-eventbus.yml b/deploy/k8s/api-eventbus.yml index 90c0d9c..ac4434e 100644 --- a/deploy/k8s/api-eventbus.yml +++ b/deploy/k8s/api-eventbus.yml @@ -1,4 +1,31 @@ apiVersion: v1 +kind: PersistentVolume +metadata: + name: api-eventbus-pv + namespace: egommerce +spec: + capacity: + storage: 10Gi + accessModes: + - ReadWriteOnce + storageClassName: api-eventbus-pv + hostPath: + path: "/home/keedosn/.egommerce/kafka" # Ensure this path exists on the node +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: api-eventbus-pvc + namespace: egommerce +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + storageClassName: api-eventbus-pv +--- +apiVersion: v1 kind: Service metadata: name: api-eventbus @@ -10,25 +37,22 @@ spec: selector: app: api-eventbus ports: - - name: api-eventbus + - name: api-eventbus-main protocol: TCP - port: 5672 + port: 9092 nodePort: 31200 - - name: api-eventbus-mngmnt + - name: api-eventbus-controller protocol: TCP - port: 15672 + port: 9093 nodePort: 31299 - # - name: api-eventbus-metrics - # protocol: TCP - # port: 15692 - # nodePort: 31201 --- apiVersion: apps/v1 -kind: Deployment +kind: StatefulSet metadata: name: api-eventbus namespace: egommerce spec: + serviceName: "api-eventbus" replicas: 1 selector: matchLabels: @@ -39,32 +63,35 @@ spec: app: api-eventbus spec: containers: - - name: api-eventbus - image: git.ego.freeddns.org/egommerce/api-eventbus:dev - imagePullPolicy: Always - command: [ - "rabbitmq-server" - ] - env: - - name: APP_NAME - value: api-eventbus - - name: RABBITMQ_ERLANG_COOKIE - value: rabbitmq - volumeMounts: - - name: eventbus-data - mountPath: /var/lib/rabbitmq - - name: eventbus-logs - mountPath: /var/log/rabbitmq - resources: - limits: - cpu: "1" - memory: 1G - ports: - - containerPort: 5672 - - containerPort: 15672 - - containerPort: 15692 + - name: api-eventbus + image: apache/kafka:latest + imagePullPolicy: Always # For future image + ports: + - containerPort: 9092 + name: eventbus + - containerPort: 9093 + name: eventbus-ctrl + volumeMounts: + - name: api-eventbus-storage + mountPath: /var/lib/kafka/data + env: + - name: KAFKA_PROCESS_ROLES + value: "broker,controller" + - name: KAFKA_CONTROLLER_LISTENER_NAMES + value: "CONTROLLER" + - name: KAFKA_LISTENERS + value: "PLAINTEXT://:9092,CONTROLLER://:9093" + - name: KAFKA_CONTROLLER_QUORUM_VOTERS + value: "1@localhost:9093" + - name: KAFKA_NODE_ID + value: "1" + - name: KAFKA_ADVERTISED_LISTENERS + value: "PLAINTEXT://localhost:9092" + - name: KAFKA_LOG_DIRS + value: "/var/lib/kafka/data" + imagePullSecrets: + - name: regcred volumes: - - name: eventbus-data - emptyDir: - - name: eventbus-logs - emptyDir: \ No newline at end of file + - name: api-eventbus-storage + persistentVolumeClaim: + claimName: api-eventbus-pvc \ No newline at end of file diff --git a/deploy/k8s/api-gateway.yml b/deploy/k8s/api-gateway.yml index 40683d2..7b98c4d 100644 --- a/deploy/k8s/api-gateway.yml +++ b/deploy/k8s/api-gateway.yml @@ -22,6 +22,7 @@ metadata: namespace: egommerce spec: controller: haproxy.org/ingress-controller/haproxy +# PROBABLY NOT NEEDED :D --- apiVersion: networking.k8s.io/v1 kind: Ingress @@ -34,6 +35,7 @@ metadata: haproxy.org/path-rewrite: | /api/identity/(.*) /\1 /api/catalog/(.*) /\1 + /api/basket/(.*) /\1 spec: ingressClassName: haproxy tls: @@ -58,6 +60,13 @@ spec: name: catalog-svc port: number: 443 + - path: /api/basket + pathType: Prefix + backend: + service: + name: basket-svc + port: + number: 443 --- apiVersion: apps/v1 kind: Deployment @@ -82,10 +91,10 @@ spec: resources: limits: cpu: 100m - memory: 512Mi + memory: 512M requests: cpu: 50m - memory: 256Mi + memory: 256M ports: - containerPort: 8443 args: @@ -119,4 +128,6 @@ spec: # runAsNonRoot: true # allowPrivilegeEscalation: false # seccompProfile: - # type: RuntimeDefault \ No newline at end of file + # type: RuntimeDefault + imagePullSecrets: + - name: regcred \ No newline at end of file diff --git a/deploy/k8s/api-logger.yml b/deploy/k8s/api-logger.yml index 81bb10d..5afa429 100644 --- a/deploy/k8s/api-logger.yml +++ b/deploy/k8s/api-logger.yml @@ -39,6 +39,8 @@ spec: - "-config.file=/etc/loki/loki.yaml" ports: - containerPort: 3100 + imagePullSecrets: + - name: regcred --- apiVersion: v1 kind: ServiceAccount @@ -98,10 +100,10 @@ spec: resources: limits: cpu: 100m - memory: 512Mi + memory: 512M requests: cpu: 50m - memory: 128Mi + memory: 256M livenessProbe: httpGet: path: /ready @@ -136,6 +138,8 @@ spec: capabilities: drop: - ALL + imagePullSecrets: + - name: regcred terminationGracePeriodSeconds: 60 volumes: - name: api-logger-promtail-run @@ -176,7 +180,7 @@ spec: resources: requests: storage: 5Gi - #storageClassName: api-logger-prometheus-pv + storageClassName: api-logger-prometheus-pv --- apiVersion: v1 kind: ServiceAccount @@ -271,11 +275,11 @@ spec: # port: prometheus-http resources: limits: - cpu: 150m - memory: 894Mi - requests: cpu: 100m - memory: 512Mi + memory: 512M + requests: + cpu: 50m + memory: 256M volumeMounts: # - name: config-volume # mountPath: /etc/prometheus @@ -293,6 +297,8 @@ spec: capabilities: drop: - ALL + imagePullSecrets: + - name: regcred volumes: - name: api-logger-prometheus-storage persistentVolumeClaim: @@ -340,7 +346,7 @@ spec: resources: requests: storage: 5Gi - #storageClassName: api-logger-grafana-pv + storageClassName: api-logger-grafana-pv --- apiVersion: apps/v1 kind: Deployment @@ -372,7 +378,6 @@ spec: initContainers: - name: curl image: curlimages/curl:latest - imagePullPolicy: IfNotPresent command: - /bin/sh args: @@ -403,10 +408,10 @@ spec: resources: limits: cpu: 100m - memory: 768Mi + memory: 512M requests: cpu: 50m - memory: 512Mi + memory: 256M volumeMounts: - name: api-logger-grafana-storage mountPath: /var/lib/grafana @@ -426,6 +431,8 @@ spec: capabilities: drop: - ALL + imagePullSecrets: + - name: regcred volumes: - name: api-logger-grafana-storage persistentVolumeClaim: diff --git a/deploy/k8s/catalog-svc.yml b/deploy/k8s/catalog-svc.yml index e8d73a5..0c2e7ed 100644 --- a/deploy/k8s/catalog-svc.yml +++ b/deploy/k8s/catalog-svc.yml @@ -5,7 +5,6 @@ metadata: namespace: egommerce annotations: haproxy.org/check: "true" - # haproxy.org/server-ca: "egommerce/ca-root" labels: app: catalog-svc spec: @@ -56,13 +55,11 @@ spec: - name: APP_NAME value: catalog-svc - name: APP_DOMAIN - value: catalog-svc.egommerce.local + value: catalog-svc.egommerce.io - name: APP_PATH_PREFIX value: /catalog - - name: API_EVENTBUS_URL - value: amqp://guest:guest@api-eventbus:5672 - - name: API_MONGODB_URL - value: mongodb://mongodb:12345678@mongo-db:27017 + - name: API_DATABASE_URL + value: postgres://egommerce:12345678@db-postgres:5432/egommerce?sslmode=disable readinessProbe: httpGet: scheme: HTTPS @@ -92,10 +89,10 @@ spec: resources: limits: cpu: 100m - memory: 512Mi + memory: 512M requests: cpu: 50m - memory: 256Mi + memory: 256M ports: - name: catalog-svc containerPort: 443 @@ -106,8 +103,8 @@ spec: # args: # - --web.listen-address=:9090 # - --web.telemetry-path=/metrics - - name: identity-scheduler # Scheduler Container - image: git.ego.freeddns.org/egommerce/identity-svc:dev + - name: catalog-scheduler # Scheduler Container + image: git.ego.freeddns.org/egommerce/catalog-svc:dev imagePullPolicy: Always command: [ "/usr/local/bin/scheduler" @@ -119,6 +116,8 @@ spec: requests: cpu: 50m memory: 256Mi + imagePullSecrets: + - name: regcred volumes: - name: catalog-cert hostPath: diff --git a/deploy/k8s/db-postgres.yml b/deploy/k8s/db-postgres.yml index ed7d89a..f80f5ab 100644 --- a/deploy/k8s/db-postgres.yml +++ b/deploy/k8s/db-postgres.yml @@ -23,7 +23,7 @@ spec: resources: requests: storage: 5Gi - #storageClassName: db-postgres-pv + storageClassName: db-postgres-pv --- apiVersion: v1 kind: Service @@ -86,7 +86,7 @@ spec: - name: APP_NAME value: db-postgres - name: APP_DOMAIN - value: db-postgres.egommerce.local + value: db-postgres.egommerce.io - name: POSTGRES_USER value: egommerce - name: POSTGRES_DB @@ -98,8 +98,11 @@ spec: value: /var/lib/postgresql/data resources: limits: - cpu: "1" + cpu: 100m memory: 512M + requests: + cpu: 50m + memory: 256M ports: - containerPort: 5432 volumeMounts: @@ -113,6 +116,15 @@ spec: env: - name: DATA_SOURCE_NAME value: "postgresql://postgres:12345678@db-postgres:5432/egommerce" #?sslmode=disable + resources: + limits: + cpu: 50m + memory: 256M + requests: + cpu: 25m + memory: 128M + imagePullSecrets: + - name: regcred volumes: - name: db-postgres-data persistentVolumeClaim: diff --git a/deploy/k8s/identity-svc.yml b/deploy/k8s/identity-svc.yml index 457a4d2..6a0abbb 100644 --- a/deploy/k8s/identity-svc.yml +++ b/deploy/k8s/identity-svc.yml @@ -5,7 +5,6 @@ metadata: namespace: egommerce annotations: haproxy.org/check: "true" - # haproxy.org/server-ca: "egommerce/ca-root" labels: app: identity-svc spec: @@ -56,13 +55,11 @@ spec: - name: APP_NAME value: identity-svc - name: APP_DOMAIN - value: identity-svc.egommerce.local + value: identity-svc.egommerce.io - name: APP_PATH_PREFIX value: /identity - - name: API_EVENTBUS_URL - value: amqp://guest:guest@api-eventbus:5672 - - name: API_MONGODB_URL - value: mongodb://mongodb:12345678@mongo-db:27017 + - name: API_DATABASE_URL + value: postgres://egommerce:12345678@db-postgres:5432/egommerce?sslmode=disable readinessProbe: httpGet: scheme: HTTPS @@ -92,10 +89,10 @@ spec: resources: limits: cpu: 100m - memory: 512Mi + memory: 512M requests: cpu: 50m - memory: 256Mi + memory: 256M ports: - name: identity-svc containerPort: 443 @@ -119,6 +116,8 @@ spec: requests: cpu: 50m memory: 256Mi + imagePullSecrets: + - name: regcred volumes: - name: identity-cert hostPath: diff --git a/deploy/k8s/secret.yml b/deploy/k8s/secret.yml index 7d787c1..d2098ac 100644 --- a/deploy/k8s/secret.yml +++ b/deploy/k8s/secret.yml @@ -4,5 +4,5 @@ metadata: name: regcred namespace: egommerce data: - .dockerconfigjson: ewoJImF1dGhzIjogewoJCSJnaXQuZWdvLmNsb3VkbnMuYmUiOiB7CgkJCSJhdXRoIjogImEyVmxaRzl6YmpwWGIyeHVaVFZQY0hKdlozSmhiVzkzWVc1cFpVQT0iCgkJfSwKCQkiaHR0cHM6Ly9pbmRleC5kb2NrZXIuaW8vdjEvIjogewoJCQkiYXV0aCI6ICJhMlZsWkc5emJqcGtiMk5yWlhKdmQyVTFiMkp5WVhwNSIKCQl9Cgl9Cn0= + .dockerconfigjson: ewogICAgICAgICJhdXRocyI6IHsKICAgICAgICAgICAgICAgICJnaXQuZWdvLmZyZWVkZG5zLm9yZyI6IHsKICAgICAgICAgICAgICAgICAgICAgICAgImF1dGgiOiAiYTJWbFpHOXpianBNYjJ0aGJHNWxOVTl3Y205bmNtRnRiM2RoYm1sbFFBPT0iCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgImh0dHBzOi8vaW5kZXguZG9ja2VyLmlvL3YxLyI6IHsKICAgICAgICAgICAgICAgICAgICAgICAgImF1dGgiOiAiYTJWbFpHOXpianBrYjJOclpYSnZkMlUxYjJKeVlYcDUiCiAgICAgICAgICAgICAgICB9CiAgICAgICAgfQp9 type: kubernetes.io/dockerconfigjson \ No newline at end of file