From 68a8612dec294e3e45f16c59c14a8f82083e98e3 Mon Sep 17 00:00:00 2001 From: ruberoid Date: Thu, 4 Apr 2024 16:50:38 +0400 Subject: [PATCH] added deploy. --- _deploy/k8s/00_initial.sh | 9 ++ .../rabbit_full_cluster_default.yaml | 67 +++++++++++++ _deploy/k8s/_rabbit_bak/rabbitmq.yaml | 96 +++++++++++++++++++ _deploy/k8s/deployment.yaml | 33 ++++++- _deploy/k8s/rabbitmq.yaml | 5 + _deploy/k8s/sample.yaml | 45 +++++++++ _deploy/k8s/service.yaml | 15 +++ _deploy/rabbitmq/docker-compose.yml | 17 ++++ telegram-listener | 2 +- 9 files changed, 283 insertions(+), 6 deletions(-) create mode 100644 _deploy/k8s/_rabbit_bak/rabbit_full_cluster_default.yaml create mode 100644 _deploy/k8s/_rabbit_bak/rabbitmq.yaml create mode 100644 _deploy/k8s/rabbitmq.yaml create mode 100644 _deploy/k8s/sample.yaml create mode 100644 _deploy/k8s/service.yaml create mode 100644 _deploy/rabbitmq/docker-compose.yml diff --git a/_deploy/k8s/00_initial.sh b/_deploy/k8s/00_initial.sh index 9fcf52e..2d1983d 100755 --- a/_deploy/k8s/00_initial.sh +++ b/_deploy/k8s/00_initial.sh @@ -36,6 +36,15 @@ kubectl create secret docker-registry hubcred --docker-server=https://hub.musk.f # kubectl create secret generic protected-appsettings --from-file=.secrets/appsettings.protected.json --namespace=nocr # +# Initialize the rabitmq kubernetes cluster and deployment followed by: +# https://www.rabbitmq.com/kubernetes/operator/install-operator +# +# Then apply rabbitmq.yaml + + # Make the main deployment. + + + kubectl apply -f deployment.yaml diff --git a/_deploy/k8s/_rabbit_bak/rabbit_full_cluster_default.yaml b/_deploy/k8s/_rabbit_bak/rabbit_full_cluster_default.yaml new file mode 100644 index 0000000..58500ef --- /dev/null +++ b/_deploy/k8s/_rabbit_bak/rabbit_full_cluster_default.yaml @@ -0,0 +1,67 @@ +apiVersion: rabbitmq.com/v1beta1 +kind: RabbitmqCluster +metadata: + annotations: + kubectl.kubernetes.io/last-applied-configuration: | + {"apiVersion":"rabbitmq.com/v1beta1","kind":"RabbitmqCluster","metadata":{"annotations":{},"name":"rmqc","namespace":"nocr"}} + creationTimestamp: "2024-03-28T17:36:44Z" + finalizers: + - deletion.finalizers.rabbitmqclusters.rabbitmq.com + generation: 3 + name: rmqc + namespace: nocr + resourceVersion: "1932864" + uid: 435cb6a7-423e-4cac-8013-83aff7e165d9 +spec: + delayStartSeconds: 30 + image: rabbitmq:3.12.2-management + override: {} + persistence: + storage: 10Gi + rabbitmq: {} + replicas: 1 + resources: + limits: + cpu: "2" + memory: 2Gi + requests: + cpu: "1" + memory: 2Gi + secretBackend: + externalSecret: {} + service: + type: ClusterIP + terminationGracePeriodSeconds: 604800 + tls: {} +status: + binding: + name: rmqc-default-user + conditions: + - lastTransitionTime: "2024-03-28T17:37:28Z" + reason: AllPodsAreReady + status: "True" + type: AllReplicasReady + - lastTransitionTime: "2024-03-28T17:37:28Z" + reason: AtLeastOneEndpointAvailable + status: "True" + type: ClusterAvailable + - lastTransitionTime: "2024-03-28T17:36:44Z" + reason: NoWarnings + status: "True" + type: NoWarnings + - lastTransitionTime: "2024-03-28T17:37:28Z" + message: Finish reconciling + reason: Success + status: "True" + type: ReconcileSuccess + defaultUser: + secretReference: + keys: + password: password + username: username + name: rmqc-default-user + namespace: nocr + serviceReference: + name: rmqc + namespace: nocr + observedGeneration: 3 diff --git a/_deploy/k8s/_rabbit_bak/rabbitmq.yaml b/_deploy/k8s/_rabbit_bak/rabbitmq.yaml new file mode 100644 index 0000000..1817986 --- /dev/null +++ b/_deploy/k8s/_rabbit_bak/rabbitmq.yaml @@ -0,0 +1,96 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: rabbitmq +spec: + serviceName: rabbitmq + # Three nodes is the recommended minimum. Some features may require a majority of nodes + # to be available. + replicas: 3 + volumeClaimTemplates: [] + selector: + matchLabels: + app: rabbitmq + template: + spec: + # serviceAccountName: rabbitmq + terminationGracePeriodSeconds: 10 + nodeSelector: + # Use Linux nodes in a mixed OS kubernetes cluster. + # Learn more at https://kubernetes.io/docs/reference/kubernetes-api/labels-annotations-taints/#kubernetes-io-os + kubernetes.io/os: linux + containers: + - name: rabbitmq-k8s + image: rabbitmq:3.8 + volumeMounts: + - name: config-volume + mountPath: /etc/rabbitmq + # Learn more about what ports various protocols use + # at https://www.rabbitmq.com/networking.html#ports + ports: + - name: http + protocol: TCP + containerPort: 15672 + - name: amqp + protocol: TCP + containerPort: 5672 + livenessProbe: + exec: + # This is just an example. There is no "one true health check" but rather + # several rabbitmq-diagnostics commands that can be combined to form increasingly comprehensive + # and intrusive health checks. + # Learn more at https://www.rabbitmq.com/monitoring.html#health-checks. + # + # Stage 2 check: + command: ["rabbitmq-diagnostics", "status"] + initialDelaySeconds: 60 + # See https://www.rabbitmq.com/monitoring.html for monitoring frequency recommendations. + periodSeconds: 60 + timeoutSeconds: 15 + readinessProbe: + exec: + # This is just an example. There is no "one true health check" but rather + # several rabbitmq-diagnostics commands that can be combined to form increasingly comprehensive + # and intrusive health checks. + # Learn more at https://www.rabbitmq.com/monitoring.html#health-checks. + # + # Stage 1 check: + command: ["rabbitmq-diagnostics", "ping"] + initialDelaySeconds: 20 + periodSeconds: 60 + timeoutSeconds: 10 + imagePullPolicy: Always + env: + - name: MY_POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: MY_POD_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: RABBITMQ_USE_LONGNAME + value: "true" + # See a note on cluster_formation.k8s.address_type in the config file section + - name: K8S_SERVICE_NAME + value: rabbitmq + - name: RABBITMQ_NODENAME + value: rabbit@$(MY_POD_NAME).$(K8S_SERVICE_NAME).$(MY_POD_NAMESPACE).svc.cluster.local + - name: K8S_HOSTNAME_SUFFIX + value: .$(K8S_SERVICE_NAME).$(MY_POD_NAMESPACE).svc.cluster.local + - name: RABBITMQ_ERLANG_COOKIE + value: "mycookie" + - name: RABBITMQ_DEFAULT_USER + value: admin + - name: RABBITMQ_DEFAULT_PASS + value: admin + volumes: + - name: config-volume + configMap: + name: rabbitmq-config + items: + - key: rabbitmq.conf + path: rabbitmq.conf + - key: enabled_plugins + path: enabled_plugins diff --git a/_deploy/k8s/deployment.yaml b/_deploy/k8s/deployment.yaml index 5cc063d..d47060a 100644 --- a/_deploy/k8s/deployment.yaml +++ b/_deploy/k8s/deployment.yaml @@ -13,21 +13,44 @@ spec: labels: app: telegram-listener spec: + imagePullSecrets: + - name: hubcred containers: - name: telegram-listener image: hub.musk.fun/k8s/nocr/telegram_listener:latest - ports: - - containerPort: 80 env: - name: "ASPNETCORE_ENVIRONMENT" value: "k8s" + - name: "session_pathname" + value: "/app/.secrets/WTelegram.session" + - name: ASPNETCORE_rmqc_host + valueFrom: + secretKeyRef: + name: rmqc-default-user + key: host + - name: ASPNETCORE_rmqc_username + valueFrom: + secretKeyRef: + name: rmqc-default-user + key: username + - name: ASPNETCORE_rmqc_password + valueFrom: + secretKeyRef: + name: rmqc-default-user + key: password + - name: ASPNETCORE_rmqc_port + valueFrom: + secretKeyRef: + name: rmqc-default-user + key: port + - name: ASPNETCORE__RebusRabbitMqOptions__ConnectionString + value: "amqp://$(ASPNETCORE_rmqc_username):$(ASPNETCORE_rmqc_password)@$(ASPNETCORE_rmqc_host):$(ASPNETCORE_rmqc_port)/" volumeMounts: - name: secrets mountPath: /app/.secrets readOnly: true - imagePullSecrets: - - name: hubcred volumes: - name: secrets secret: - secretName: protected-appsettings + secretName: secretfiles + diff --git a/_deploy/k8s/rabbitmq.yaml b/_deploy/k8s/rabbitmq.yaml new file mode 100644 index 0000000..a7a4c7e --- /dev/null +++ b/_deploy/k8s/rabbitmq.yaml @@ -0,0 +1,5 @@ +apiVersion: rabbitmq.com/v1beta1 +kind: RabbitmqCluster +metadata: + name: rmqc + namespace: nocr diff --git a/_deploy/k8s/sample.yaml b/_deploy/k8s/sample.yaml new file mode 100644 index 0000000..50d3c99 --- /dev/null +++ b/_deploy/k8s/sample.yaml @@ -0,0 +1,45 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: example-nginx-deployment + namespace: nocr + labels: + app: nginx +spec: + replicas: 1 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 + env: + - name: ASPNETCORE_rmqc_host + valueFrom: + secretKeyRef: + name: rmqc-default-user + key: host + - name: ASPNETCORE_rmqc_username + valueFrom: + secretKeyRef: + name: rmqc-default-user + key: username + - name: ASPNETCORE_rmqc_password + valueFrom: + secretKeyRef: + name: rmqc-default-user + key: password + - name: ASPNETCORE_rmqc_port + valueFrom: + secretKeyRef: + name: rmqc-default-user + key: port + - name: ASPNETCORE__RebusRabbitMqOptions__ConnectionString + value: "amqp://$(ASPNETCORE_rmqc_username):$(ASPNETCORE_rmqc_password)@$(ASPNETCORE_rmqc_host):$(ASPNETCORE_rmqc_port)/" diff --git a/_deploy/k8s/service.yaml b/_deploy/k8s/service.yaml new file mode 100644 index 0000000..e04e464 --- /dev/null +++ b/_deploy/k8s/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: rabbitmq-np + namespace: nocr +spec: + type: NodePort + selector: + app: hello-world-server-0 + ports: + - name: hello-world-server-0 + protocol: TCP + port: 15672 + targetPort: 15672 + nodePort: 30001 diff --git a/_deploy/rabbitmq/docker-compose.yml b/_deploy/rabbitmq/docker-compose.yml new file mode 100644 index 0000000..8b1e3fd --- /dev/null +++ b/_deploy/rabbitmq/docker-compose.yml @@ -0,0 +1,17 @@ +version: "3" + +services: + nocr-rabbitmq: + image: rabbitmq:3-management-alpine + container_name: nocr-rabbitmq + ports: + - 5672:5672 + - 15672:15672 + environment: + RABBITMQ_DEFAULT_USER: admin + RABBITMQ_DEFAULT_PASS: admin + healthcheck: + test: rabbitmq-diagnostics -q ping + interval: 5s + timeout: 10s + retries: 3 diff --git a/telegram-listener b/telegram-listener index 53bda5b..d172a00 160000 --- a/telegram-listener +++ b/telegram-listener @@ -1 +1 @@ -Subproject commit 53bda5b83f8ae5c98ea83a6a6f25aa65aba024a2 +Subproject commit d172a00cb7d1655a3a2216504c4b482d84208377