feat(database): add cnpg for database management

This commit is contained in:
Vegard Hagen
2024-08-25 23:58:06 +02:00
parent cb1c2cdebb
commit d3338da90a
16 changed files with 138 additions and 2 deletions

View File

@@ -0,0 +1,37 @@
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: database
namespace: argocd
labels:
dev.stonegarden: database
spec:
generators:
- git:
repoURL: https://github.com/vehagn/homelab
revision: HEAD
directories:
- path: k8s/infra/database/*
template:
metadata:
name: '{{ path.basename }}'
labels:
dev.stonegarden: controllers
spec:
project: database
source:
plugin:
name: kustomize-build-with-helm
repoURL: https://github.com/vehagn/homelab
targetRevision: HEAD
path: '{{ path }}'
destination:
name: in-cluster
namespace: argocd
syncPolicy:
automated:
selfHeal: true
prune: true
syncOptions:
- ApplyOutOfSyncOnly=true
- ServerSideApply=true

View File

@@ -0,0 +1,15 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: cnpg-system
resources:
- ns.yaml
helmCharts:
- name: cloudnative-pg
repo: https://cloudnative-pg.github.io/charts
releaseName: cnpg
namespace: cnpg-system
includeCRDs: true
version: 0.22.0
valuesFile: values.yaml

View File

@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: cnpg-system

View File

View File

@@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
commonLabels:
dev.stonegarden: auth
app.kubernetes.io/managed-by: argocd
resources:
- ns.yaml
- project.yaml
- application-set.yaml

View File

@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: cnpg-database

View File

@@ -0,0 +1,10 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example
namespace: cnpg-database
spec:
instances: 3
storage:
storageClass: proxmox-csi
size: 4G

View File

@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: cnpg-database
resources:
- cnpg-cluster.yaml

View File

@@ -0,0 +1,17 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: single-example
namespace: cnpg-database
spec:
instances: 1
affinity:
nodeSelector:
topology.kubernetes.io/zone: euclid
storage:
size: 4G
pvcTemplate:
storageClassName: proxmox-csi
volumeName: pv-single-database
accessModes:
- ReadWriteOnce

View File

@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: cnpg-database
resources:
- cnpg-single.yaml

View File

@@ -0,0 +1,18 @@
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: database
namespace: argocd
spec:
sourceRepos:
- 'https://github.com/vehagn/homelab'
destinations:
- namespace: 'argocd'
server: '*'
- namespace: 'cnpg-database'
server: '*'
- namespace: 'cnpg-system'
server: '*'
clusterResourceWhitelist:
- group: '*'
kind: '*'

View File

@@ -32,3 +32,6 @@ spec:
automated:
selfHeal: true
prune: true
syncOptions:
- ApplyOutOfSyncOnly=true
- ServerSideApply=true

View File

@@ -26,4 +26,4 @@ spec:
prune: true
syncOptions:
- ApplyOutOfSyncOnly=true
- ServerSideApply=true
- ServerSideApply=true

View File

@@ -29,6 +29,7 @@ tofu state rm "module.volumes.module.proxmox-volume[\"pv-qbittorrent-config\"].r
tofu state rm 'module.volumes.module.proxmox-volume["pv-keycloak"].restapi_object.proxmox-volume'
tofu state rm 'module.volumes.module.proxmox-volume["pv-netbird-management"].restapi_object.proxmox-volume'
tofu state rm 'module.volumes.module.proxmox-volume["pv-netbird-signal"].restapi_object.proxmox-volume'
tofu state rm 'module.volumes.module.proxmox-volume["pv-database"].restapi_object.proxmox-volume'
```
## import proxmox volume
@@ -46,6 +47,7 @@ tofu import 'module.volumes.module.proxmox-volume["pv-radarr-config"].restapi_ob
tofu import 'module.volumes.module.proxmox-volume["pv-remark42"].restapi_object.proxmox-volume' /api2/json/nodes/euclid/storage/local-zfs/content/local-zfs:vm-9999-pv-remark42
tofu import 'module.volumes.module.proxmox-volume["pv-sonarr-config"].restapi_object.proxmox-volume' /api2/json/nodes/cantor/storage/local-zfs/content/local-zfs:vm-9999-pv-sonarr-config
tofu import 'module.volumes.module.proxmox-volume["pv-torrent-config"].restapi_object.proxmox-volume' /api2/json/nodes/euclid/storage/local-zfs/content/local-zfs:vm-9999-pv-torrent-config
tofu import 'module.volumes.module.proxmox-volume["pv-database"].restapi_object.proxmox-volume' /api2/json/nodes/euclid/storage/local-zfs/content/local-zfs:vm-9999-pv-database
```
## import persistent volume

View File

@@ -17,7 +17,7 @@ resource "restapi_object" "proxmox-volume" {
})
lifecycle {
prevent_destroy = true
prevent_destroy = false
}
}

View File

@@ -152,5 +152,9 @@ module "volumes" {
node = "abel"
size = "10G"
}
pv-single-database = {
node = "euclid"
size = "4G"
}
}
}