feat(bot): ✨ Migrate from Citus to PostgreSQL.

This commit is contained in:
Nyeki.py
2024-11-01 14:37:30 -03:00
parent f9da23fc1a
commit 00ad045a35
3 changed files with 17 additions and 64 deletions
+2 -35
View File
@@ -167,47 +167,14 @@ kubectl apply -f k8s/secrets.yml
If you see a ConfigMap and a Secret being created, that means you've successfully applied the
changes.
#### Setting Up Redis
#### Setting Up Redis and PostgreSQL
Now, you can initialize Redis. This step is pretty straightforward and you can forget about it
later.
```sh
kubectl apply -f k8s/redis.yml
```
#### Setting Up Citus Database
This step requires some updates in the `k8s/citus.yml` file. Open the file and make sure that the
default amount of replicas fits your needs. At least one is needed.
```sh
kubectl apply -f k8s/citus.yml
```
Once all the nodes are up and running, you have to connect them. The node `citus-0` is always used
as the coordinator node. Run the following command to set the coordinator host:
```sh
kubectl exec citus-0 -- psql -U payphone payphone -c "SELECT citus_set_coordinator_host('citus-0.citus-headless.default.svc.cluster.local', 5432);"
```
Once that command was run, you need to add the rest of the nodes to the cluster. To do that, run
the following command replacing `<node-index>` with the index of the node you're adding, once per
node.
```sh
kubectl exec citus-0 -- psql -U payphone payphone -c "SELECT * from citus_add_node('citus-<node-index>.citus-headless.default.svc.cluster.local', 5432);"
```
For example, if you had 3 replicas in total, you'd run the command 2 times, once for node 1 and
once for node 2 (node 0 is the coordinator, so you don't have to add it).
As an optional step, you can check that the nodes were successfully connected running the following
command, which will show all the nodes connected:
```sh
kubectl exec citus-0 -- psql -U payphone payphone -c "SELECT * FROM citus_get_active_worker_nodes();"
kubectl apply -f k8s/psql.yml
```
#### Setting Up Payphone
+14 -28
View File
@@ -1,49 +1,35 @@
apiVersion: v1
kind: Service
metadata:
name: citus-loadbalancer
name: postgresql
spec:
type: LoadBalancer
type: ClusterIP # Internal access only
selector:
app: citus
app: postgresql
ports:
- protocol: TCP
port: 5432
targetPort: 5432
---
apiVersion: v1
kind: Service
metadata:
name: citus-headless
spec:
selector:
app: citus
ports:
- protocol: TCP
port: 5432
targetPort: 5432
clusterIP: None # Headless service for direct pod access
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: citus
name: postgresql
spec:
serviceName: citus-headless
replicas: 3 # Set the desired number of replicas
serviceName: postgresql
replicas: 1 # Single-node PostgreSQL
selector:
matchLabels:
app: citus
app: postgresql
template:
metadata:
labels:
app: citus
app: postgresql
spec:
containers:
- name: citus
image: citusdata/citus:latest
- name: postgres
image: postgres:latest # Standard PostgreSQL image
env:
- name: POSTGRES_DB
value: "payphone"
@@ -54,15 +40,15 @@ spec:
ports:
- containerPort: 5432
volumeMounts:
- name: citus-storage
- name: postgres-storage
mountPath: /var/lib/postgresql/data
subPath: postgres
volumeClaimTemplates:
- metadata:
name: citus-storage
name: postgres-storage
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "openebs-jiva-csi-default" # Update based on your storage class
storageClassName: openebs-hostpath # Your storage class
resources:
requests:
storage: 20Gi # Size for each pod's storage
storage: 20Gi # Adjust storage as needed
+1 -1
View File
@@ -17,7 +17,7 @@ TORTOISE_ORM = {
"default": {
"engine": "tortoise.backends.asyncpg",
"credentials": {
"host": "localhost" if IS_DEBUG else "citus-loadbalancer.default.svc.cluster.local",
"host": "localhost" if IS_DEBUG else "postgresql",
"port": "5432",
"user": "payphone",
"password": "payphone",