Deploy di un Cluster PostgreSQL HA su Aruba Managed Kubernetes

A dedicated cloud solution for Italy’s largest weather portal

The company

3BMeteo has been in the professional meteorology business for 15 years. 3BMeteo services are designed to meet the demands of its high-tech clientele. The team is made up of professional meteorologists and developers working 7 days a week to develop new updates for apps and services, as well as modelers responsible for optimizing forecasting systems and creating new physical and mathematical scenarios.

One of the company's main priorities is its relationship with the public, thanks to a dedicated media department working day in, day out, with Italy's main radio stations, television channels and newspapers. The control room team provides professional advice for different industrial sectors, and currently represents Italy's largest operating hub.

The benefits

The solution involved a series of improvements, starting with increased resilience implicit in an active/active infrastructure, like the one implemented. The service uptime is guaranteed by state-of-the-art technology used in the Data Centers and SLAs guaranteeing continuity of service when faced with any kind of adverse event.

Alongside the Dedicated Cloud solution, a total application refactory specifically for 3BMeteo was also provided, with a view to making the most of the distributed infrastructure, active on several nodes at the same time, thereby offering maximum computing power as well as the aforementioned fault tolerance.

Thanks to the type of Dedicated Cloud used, the old (monolithic) application architecture actually became a more agile, efficient microservice architecture, facilitating:

  • faster development of all internal and external services;
  • the migration of key parts of these services, such as Load Balancing, Authentication (Zero Trust) and Application Logic in Edge, which are now essential as they offer greater flexibility, scalability and security to a system and a growing business like 3BMeteo.


Another important element is the considerable attention paid to green issues: first of all, the proximity of 3BMeteo's headquarters to the Aruba Global Cloud Data Center, one of the three sites housing 3Bmeteo infrastructure, has allowed a more efficient and successful direct relationship, making the two organizations a marriage made in heaven.

Using a provider that uses renewable energy to offer its services also offers huge benefits: Aruba is GO certified – meaning that it uses energy from renewable sources, as well as being able to produce more energy thanks to its hydroelectric plant and photovoltaic systems within the technological campus.


curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

  • Interfaccia per la gestione di PostgreSQL. Di seguito il comando per installare psql:

sudo apt update
sudo apt install curl ca-certificates -y
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /usr/share/keyrings/postgresql-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/postgresql-keyring.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt update
sudo apt install postgresql-client -y

Passaggi per il Deploy

Configurazione del cluster Aruba Managed Kubernetes

  1. Accedi al portale Aruba Cloud e apri il tuo ambiente Kubernetes.
  2. Verifica le risorse assegnate: il tuo cluster dovrebbe avere nodi sufficienti per supportare l'alta disponibilità. È consigliabile avere almeno 2 nodi.

Installazione dell'Operator di PostgreSQL

1. Aggiungi il repository Helm per il postgres-operator.


helm repo add postgres-operator-charts https://opensource.zalando.com/postgres-operator/charts/postgres-operator


kubectl create namespace my-namespace

2. Installa l'operator usando Helm nel namespace. In questo esempio è stato usato il nome per l'operator "postgres-operator" e per namespace "my-namespace", se non viene inserito il namespace sarà utilizzato quello di default.


helm install postgres-operator postgres-operator-charts/postgres-operator --namespace my-namespace

3. Verifica che l'operator sia attivo.


kubectl get pod -l app.kubernetes.io/name=postgres-operator -n my-namespace

Se il pod dell'operatore è in esecuzione puoi proseguire creando la risorsa custom postgresql (CRD).

Deploy del Cluster PostgreSQL

1. Clona e accedi al repository dell'operatore.


git clone https://github.com/zalando/postgres-operator.git


cd postgres-operator

2. In questo caso andiamo ad utilizzare un semplice manifest "minimal-postgres-manifest.yaml" per la creazione dell'istanza PostgreSQL in HA. Puoi modificare il file manifest per adattarlo al tuo ambiente.


nano ./manifests/minimal-postgres-manifest.yaml

Di seguito un esempio di file.


apiVersion: "acid.zalan.do/v1"
kind: postgresql
metadata:
name: acid-minimal-cluster
spec:
teamId: "acid"
volume:
size: 5Gi
numberOfInstances: 2
users:
zalando: # database owner
- superuser
- createdb
app_user: [] # role for application "app"
databases:
app: zalando \ # dbname: owner
preparedDatabases:
bar: {}
postgresql:
version: "17"

Nel file vengono indicati i parametri essenziali:

- nome dell'istanza;
- dimensione del volume persistente, in questo caso 5Gi, che verranno creati dinamicamente (su Aruba Cloud il volume si identifica come Block Storage);
- numero di istanze da deployare, in questo caso 2;
- utenti e database.
Prosegui con il deploy nel namespace "my-namespace".

3. Crea il cluster PostgreSQL


kubectl apply -f manifests/minimal-postgres-manifest.yaml -n

Dopo che il manifesto del cluster è stato inviato, l'operatore creerà risorse di servizio ed endpoint, oltre a uno StatefulSet che avvierà i 2 nuovi pod specificati nel manifesto.
 

Nel frattempo puoi controllare dalla Cloud Management Platform la creazione dei volumi come indicato nel manifesto.

I pod del database possono essere identificati dal suffisso del loro numero, a partire da -0.

Per quanto riguarda i servizi e gli endpoint, ce ne sarà uno per il pod master e un altro per tutte le repliche (suffisso -repl).

Controlla che tutti i componenti siano in esecuzione.

Usa la Label application=spilo per filtrare ed elencare l'etichetta spilo-role per vedere chi è attualmente il master.


kubectl get pods -l application=spilo -L spilo-role -n postgres --namespace my-namespace

Connettersi al database

Configura un port-forward su un pod del database per connetterti direttamente dal tuo host, utilizza il pod con il ruolo di master ed eseguiamo il seguente comando.


kubectl port-forward acid-minimal-cluster-0 6432:5432 -n default --namespace my-namespace

Lascia l'attività in background e apri un'altra CLI sul server, recupera la password che viene memorizzata nel secret di Kubernetes durante la creazione del cluster, che in questo caso si chiama acid-minimal-cluster.


export PGPASSWORD=$(kubectl get secret --namespace my-namespace postgres.acid-minimal-cluster.credentials.postgresql.acid.zalan.do -o 'jsonpath={.data.password}' | base64 -d)

Poiché le connessioni non crittografate vengono rifiutate di default, imposta la modalità SSL su require.


export PGSSLMODE=require

Connetti al database usando un client di postgres, ad esempio il client psql che hai preinstallato e aggiornato.


psql -U postgres -h localhost -p 6432

Collega il database "app" definito nella CRD dell'operator.


\c app

Crea una semplice tabella.


create table aruba_table(a varchar(50), b integer);

Inserisci una riga con dati.


insert into aruba_table values('Tutorial demo', '1');

Visualizza i dati appena inseriti.


select * from aruba_table;

Adesso visualizza le tabelle presenti nel database app.


** "\d"{}

Di seguito il comando per uscire dall'ambiente database.


\q

Testare l'alta affidabilità del Cluster

Elimina il pod nel cluster Kubernetes che ha il ruolo di master e verifica la procedura di failover.


kubectl delete pod acid-minimal-cluster-0 -n my-namespace

Dopo l'eliminazione verifica che il ruolo del master sia stato assegnato al pod acid-minimal-cluster-1, e che il pod acid-minimal-cluster-0 sia stato ricreato con ruolo di replica.


kubectl get pods -l application=spilo -L spilo-role -n postgres --namespace my-namespace

Vai sulla shell lasciata in background e riconnettiti sul master, che in questo caso è -1.


kubectl port-forward acid-minimal-cluster-1 6432:5432 -n default --namespace my-namespace

Connettiti al database usando il client psql preinstallato e aggiornato.


psql -U postgres -h localhost -p 6432

Collega il database "app" definito nella CRD dell'operator.


\c app

Visualizza i dati rimasti dopo la cancellazione del pod.


select * from aruba_table;

Il tuo cluster PostgreSQL HA su Aruba Managed Kubernetes è pronto all'uso.

Puoi ora procedere con il monitoraggio e la gestione operativa del tuo cluster e prepararti a scalare a seconda delle esigenze delle tue applicazioni.

Considera di esplorare ulteriormente Aruba Cloud Management Platform per automatizzare e ottimizzare ancora di più i tuoi processi IT.

Cancellazione ambiente

Di seguito la sequenza per cancellare tutto l'ambiente creato durante il tutorial.


helm uninstall postgres-operator -n my-namespace
kubectl delete all --all -n my-namespace
kubectl delete namespace my-namespace
helm repo remove postgres-operator-charts
rm -rf postgres-operator

 

Get started with Aruba Cloud

Looking for a custom solution?

Have a chat with our solution architects.

Get in touch