initial commit

This commit is contained in:
allard
2025-11-23 18:58:51 +01:00
commit 376a944abc
1553 changed files with 314731 additions and 0 deletions

19
odroid/cnpg/README.md Executable file
View File

@@ -0,0 +1,19 @@
#Installatie:
============
kubectl apply --server-side -f \
https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/release-1.26/releases/cnpg-1.26.0.yaml
#Cluster aanmaken:
----------------
kubectl apply -f postgres15.yaml
#Monitoring
-----------
kubectl create ns monitoring
helm upgrade --install \
-f https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/main/docs/src/samples/monitoring/kube-stack-config.yaml \
prometheus-community \
prometheus-community/kube-prometheus-stack -n monitoring
kubectl apply -n monitoring -f \
https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/main/docs/src/samples/monitoring/prometheusrule.yaml

View File

@@ -0,0 +1,11 @@
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: odroid-cnpg
title: Cnpg (odroid)
spec:
type: service
lifecycle: production
owner: platform-team
partOf:
- ../catalog-info.yaml

16082
odroid/cnpg/cnpg-1.23.2.yaml Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,6 @@
microk8s kubectl delete secret minio-creds -n postgres
microk8s kubectl create secret generic minio-creds \
--from-literal=MINIO_ACCESS_KEY=Gudh6fKAlGv5PFWxLrCS \
--from-literal=MINIO_SECRET_KEY=L2CxDKJAvXS2h0KyWWX3fu9twiVIzR1tZpoEYINl \
--from-literal=REGION=us-east \
-n postgres

View File

@@ -0,0 +1,7 @@
apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
name: pg-backup-example
spec:
cluster:
name: pg-backup

View File

@@ -0,0 +1,47 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: post-init-sql-configmap
data:
configmap.sql: |
create table configmaps (i integer);
insert into configmaps (select generate_series(1,10000));
---
apiVersion: v1
kind: Secret
metadata:
name: post-init-sql-secret
stringData:
secret.sql: |
create table secrets (i integer);
insert into secrets (select generate_series(1,10000));
---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example-initdb
spec:
instances: 3
bootstrap:
initdb:
database: appdb
owner: appuser
postInitSQL:
- create table numbers (i integer)
- insert into numbers (select generate_series(1,10000))
postInitTemplateSQL:
- create extension intarray
postInitApplicationSQL:
- create table application_numbers (i integer)
- insert into application_numbers (select generate_series(1,10000))
postInitApplicationSQLRefs:
configMapRefs:
- name: post-init-sql-configmap
key: configmap.sql
secretRefs:
- name: post-init-sql-secret
key: secret.sql
storage:
size: 1Gi

View File

@@ -0,0 +1,25 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: postgresql-pvc-template
spec:
instances: 3
# Example of rolling update strategy:
# - unsupervised: automated update of the primary once all
# replicas have been upgraded (default)
# - supervised: requires manual supervision to perform
# the switchover of the primary
primaryUpdateStrategy: unsupervised
# Persistent storage configuration
storage:
size: 1Gi
pvcTemplate:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: standard
volumeMode: Filesystem

View File

@@ -0,0 +1,32 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: pg-backup
spec:
instances: 3
# Example of rolling update strategy:
# - unsupervised: automated update of the primary once all
# replicas have been upgraded (default)
# - supervised: requires manual supervision to perform
# the switchover of the primary
primaryUpdateStrategy: unsupervised
# Persistent storage configuration
storage:
storageClass: standard
size: 1Gi
# Backup properties
backup:
barmanObjectStore:
destinationPath: s3://BUCKET_NAME/path/to/folder
s3Credentials:
accessKeyId:
name: aws-creds
key: ACCESS_KEY_ID
secretAccessKey:
name: aws-creds
key: ACCESS_SECRET_KEY
wal:
compression: gzip

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,21 @@
apiVersion: v1
kind: Service
metadata:
name: grafana-lb
namespace: monitoring
spec:
externalTrafficPolicy: Cluster
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ports:
- nodePort: 30093
port: 3000
protocol: TCP
targetPort: 3000
selector:
app.kubernetes.io/instance: prometheus-community
app.kubernetes.io/name: grafana
type: LoadBalancer
status:
loadBalancer:

View File

@@ -0,0 +1,8 @@
apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
name: postgres13-backup
namespace: postgres
spec:
cluster:
name: postgres13

View File

@@ -0,0 +1,50 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: postgres13
namespace: postgres
spec:
imageName: ghcr.io/cloudnative-pg/postgresql:13.14-3
instances: 3
superuserSecret:
name: superuser-secret
bootstrap:
initdb:
postInitSQL:
- CREATE USER admin WITH PASSWORD 'Postgres01@'
- ALTER USER admin WITH SUPERUSER
- CREATE USER harbor WITH PASSWORD 'harbor'
- CREATE DATABASE harbor OWNER harbor
storage:
size: 5Gi
monitoring:
enablePodMonitor: true
backup:
barmanObjectStore:
destinationPath: 's3://backups/'
endpointURL: 'http://minio.postgres:9000'
s3Credentials:
accessKeyId:
name: minio-creds
key: MINIO_ACCESS_KEY
secretAccessKey:
name: minio-creds
key: MINIO_SECRET_KEY
retentionPolicy: "1d"
---
apiVersion: v1
kind: Service
metadata:
name: postgres13-lb
namespace: postgres
spec:
selector:
cnpg.io/cluster: postgres13
role: primary
ports:
- port: 5432
targetPort: 5432
type: LoadBalancer

View File

@@ -0,0 +1,46 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: postgres13-1
namespace: postgres
spec:
instances: 3
imageName: ghcr.io/cloudnative-pg/postgresql:13.14-3
superuserSecret:
name: superuser-secret
storage:
size: 5Gi
storageClass: nfs-client
monitoring:
enablePodMonitor: true
backup:
barmanObjectStore:
destinationPath: 's3://backups/'
endpointURL: 'http://minio.postgres:9000'
s3Credentials:
accessKeyId:
name: minio-creds
key: MINIO_ACCESS_KEY
secretAccessKey:
name: minio-creds
key: MINIO_SECRET_KEY
retentionPolicy: "1d"
bootstrap:
recovery:
source: postgres13
externalClusters:
- name: postgres13
barmanObjectStore:
destinationPath: 's3://backups/'
endpointURL: 'http://minio.postgres:9000'
s3Credentials:
accessKeyId:
name: minio-creds
key: MINIO_ACCESS_KEY
secretAccessKey:
name: minio-creds
key: MINIO_SECRET_KEY

View File

@@ -0,0 +1,46 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: postgres13
namespace: postgres
spec:
instances: 3
imageName: ghcr.io/cloudnative-pg/postgresql:13.14-3
superuserSecret:
name: superuser-secret
storage:
size: 5Gi
storageClass: nfs-client
monitoring:
enablePodMonitor: true
backup:
barmanObjectStore:
destinationPath: 's3://backups/'
endpointURL: 'http://minio.postgres:9000'
s3Credentials:
accessKeyId:
name: minio-creds
key: MINIO_ACCESS_KEY
secretAccessKey:
name: minio-creds
key: MINIO_SECRET_KEY
retentionPolicy: "1d"
bootstrap:
recovery:
source: postgres13-1
externalClusters:
- name: postgres13-1
barmanObjectStore:
destinationPath: 's3://backups/'
endpointURL: 'http://minio.postgres:9000'
s3Credentials:
accessKeyId:
name: minio-creds
key: MINIO_ACCESS_KEY
secretAccessKey:
name: minio-creds
key: MINIO_SECRET_KEY

View File

@@ -0,0 +1,9 @@
apiVersion: postgresql.cnpg.io/v1
kind: ScheduledBackup
metadata:
name: postgres13-backup
spec:
schedule: "0 0 14 * * *"
backupOwnerReference: self
cluster:
name: postgres13

View File

@@ -0,0 +1,8 @@
apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
name: postgres14-backup
namespace: postgres
spec:
cluster:
name: postgres14

View File

@@ -0,0 +1,50 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: postgres14
namespace: postgres
spec:
imageName: ghcr.io/cloudnative-pg/postgresql:14.11-3
instances: 3
superuserSecret:
name: superuser-secret
bootstrap:
initdb:
postInitSQL:
- CREATE USER admin WITH PASSWORD 'Postgres01@'
- ALTER USER admin WITH SUPERUSER
- CREATE USER harbor WITH PASSWORD 'harbor'
- CREATE DATABASE harbor OWNER harbor
storage:
size: 5Gi
monitoring:
enablePodMonitor: true
backup:
barmanObjectStore:
destinationPath: 's3://backups/'
endpointURL: 'http://minio.postgres:9000'
s3Credentials:
accessKeyId:
name: minio-creds
key: MINIO_ACCESS_KEY
secretAccessKey:
name: minio-creds
key: MINIO_SECRET_KEY
retentionPolicy: "1d"
---
apiVersion: v1
kind: Service
metadata:
name: postgres14-lb
namespace: postgres
spec:
selector:
cnpg.io/cluster: postgres14
role: primary
ports:
- port: 5432
targetPort: 5432
type: LoadBalancer

9
odroid/cnpg/script.sh Executable file
View File

@@ -0,0 +1,9 @@
CLUSTER_NAME=postgres13
NAMESPACE=postgres
PRIMARY=$(kubectl get cluster -n "$NAMESPACE" "$CLUSTER_NAME" -o jsonpath='{.status.currentPrimary}')
for pvc in $(kubectl get pvc -n "$NAMESPACE" -l"cnpg.io/cluster=$CLUSTER_NAME" -o name); do
ROLE=$([ "$pvc" = "persistentvolumeclaim/$PRIMARY" ] && echo primary || echo replica)
kubectl label -n "$NAMESPACE" "$pvc" --overwrite "cnpg.io/instanceRole=$ROLE" "role=$ROLE"
done
kubectl delete pod -n "$NAMESPACE" -l "cnpg.io/cluster=$CLUSTER_NAME"

View File

@@ -0,0 +1,8 @@
apiVersion: v1
data:
username: cG9zdGdyZXMK
password: UG9zdGdyZXMwMUA=
kind: Secret
metadata:
name: superuser-secret
type: kubernetes.io/basic-auth

2
odroid/cnpg/tenant.txt Normal file
View File

@@ -0,0 +1,2 @@
LyxDkhkSaQvoLUfb
ew3h3CEilTbGu6rpGG918zl0LdnVP32s