feat(bot): ✨ Migrate from Citus to PostgreSQL.
This commit is contained in:
@@ -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
|
If you see a ConfigMap and a Secret being created, that means you've successfully applied the
|
||||||
changes.
|
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
|
Now, you can initialize Redis. This step is pretty straightforward and you can forget about it
|
||||||
later.
|
later.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
kubectl apply -f k8s/redis.yml
|
kubectl apply -f k8s/redis.yml
|
||||||
```
|
kubectl apply -f k8s/psql.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();"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Setting Up Payphone
|
#### Setting Up Payphone
|
||||||
|
|||||||
@@ -1,49 +1,35 @@
|
|||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
name: citus-loadbalancer
|
name: postgresql
|
||||||
spec:
|
spec:
|
||||||
type: LoadBalancer
|
type: ClusterIP # Internal access only
|
||||||
selector:
|
selector:
|
||||||
app: citus
|
app: postgresql
|
||||||
ports:
|
ports:
|
||||||
- protocol: TCP
|
- protocol: TCP
|
||||||
port: 5432
|
port: 5432
|
||||||
targetPort: 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
|
apiVersion: apps/v1
|
||||||
kind: StatefulSet
|
kind: StatefulSet
|
||||||
metadata:
|
metadata:
|
||||||
name: citus
|
name: postgresql
|
||||||
spec:
|
spec:
|
||||||
serviceName: citus-headless
|
serviceName: postgresql
|
||||||
replicas: 3 # Set the desired number of replicas
|
replicas: 1 # Single-node PostgreSQL
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: citus
|
app: postgresql
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: citus
|
app: postgresql
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: citus
|
- name: postgres
|
||||||
image: citusdata/citus:latest
|
image: postgres:latest # Standard PostgreSQL image
|
||||||
env:
|
env:
|
||||||
- name: POSTGRES_DB
|
- name: POSTGRES_DB
|
||||||
value: "payphone"
|
value: "payphone"
|
||||||
@@ -54,15 +40,15 @@ spec:
|
|||||||
ports:
|
ports:
|
||||||
- containerPort: 5432
|
- containerPort: 5432
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: citus-storage
|
- name: postgres-storage
|
||||||
mountPath: /var/lib/postgresql/data
|
mountPath: /var/lib/postgresql/data
|
||||||
subPath: postgres
|
subPath: postgres
|
||||||
volumeClaimTemplates:
|
volumeClaimTemplates:
|
||||||
- metadata:
|
- metadata:
|
||||||
name: citus-storage
|
name: postgres-storage
|
||||||
spec:
|
spec:
|
||||||
accessModes: [ "ReadWriteOnce" ]
|
accessModes: [ "ReadWriteOnce" ]
|
||||||
storageClassName: "openebs-jiva-csi-default" # Update based on your storage class
|
storageClassName: openebs-hostpath # Your storage class
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
storage: 20Gi # Size for each pod's storage
|
storage: 20Gi # Adjust storage as needed
|
||||||
@@ -17,7 +17,7 @@ TORTOISE_ORM = {
|
|||||||
"default": {
|
"default": {
|
||||||
"engine": "tortoise.backends.asyncpg",
|
"engine": "tortoise.backends.asyncpg",
|
||||||
"credentials": {
|
"credentials": {
|
||||||
"host": "localhost" if IS_DEBUG else "citus-loadbalancer.default.svc.cluster.local",
|
"host": "localhost" if IS_DEBUG else "postgresql",
|
||||||
"port": "5432",
|
"port": "5432",
|
||||||
"user": "payphone",
|
"user": "payphone",
|
||||||
"password": "payphone",
|
"password": "payphone",
|
||||||
|
|||||||
Reference in New Issue
Block a user