mirror of
https://github.com/nofusscomputing/kubernetes.git
synced 2025-08-02 04:22:42 +00:00
feat(postgres): Add Component for HA multi-cluster replication
ref: #18
This commit is contained in:
86
manifests/postgres/components/ha/Cluster-main-02.yaml
Normal file
86
manifests/postgres/components/ha/Cluster-main-02.yaml
Normal file
@ -0,0 +1,86 @@
|
||||
---
|
||||
apiVersion: postgresql.cnpg.io/v1
|
||||
kind: Cluster
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/component: ha
|
||||
app.kubernetes.io/instance: production
|
||||
app.kubernetes.io/name: postgres
|
||||
app.kubernetes.io/part-of: production-ha
|
||||
name: main-02
|
||||
spec:
|
||||
affinity:
|
||||
additionalPodAntiAffinity:
|
||||
preferredDuringSchedulingIgnoredDuringExecution:
|
||||
- weight: 50
|
||||
podAffinityTerm:
|
||||
labelSelector:
|
||||
matchExpressions:
|
||||
- key: kubernetes.io/hostname
|
||||
operator: Exists
|
||||
topologyKey: kubernetes.io/hostname
|
||||
|
||||
enablePodAntiAffinity: true
|
||||
nodeAffinity:
|
||||
preferredDuringSchedulingIgnoredDuringExecution:
|
||||
- weight: 100
|
||||
preference:
|
||||
matchExpressions:
|
||||
- key: node-role.kubernetes.io/prime
|
||||
operator: Exists
|
||||
topologyKey: kubernetes.io/hostname
|
||||
|
||||
bootstrap:
|
||||
pg_basebackup:
|
||||
source: main-01
|
||||
|
||||
description: "Cluster PostgreSQL Instance"
|
||||
|
||||
enableSuperuserAccess: false
|
||||
|
||||
externalClusters: []
|
||||
|
||||
imageName: ghcr.io/cloudnative-pg/postgresql:-updated_by_patch-
|
||||
|
||||
inheritedMetadata:
|
||||
labels:
|
||||
app.kubernetes.io/component: ha
|
||||
app.kubernetes.io/instance: production
|
||||
app.kubernetes.io/name: postgres
|
||||
app.kubernetes.io/part-of: production-ha
|
||||
|
||||
instances: 3
|
||||
|
||||
monitoring: {}
|
||||
|
||||
nodeMaintenanceWindow:
|
||||
inProgress: false
|
||||
reusePVC: false
|
||||
|
||||
primaryUpdateStrategy: supervised
|
||||
|
||||
postgresql:
|
||||
parameters:
|
||||
max_parallel_workers: '34'
|
||||
max_replication_slots: '32'
|
||||
max_worker_processes: '34'
|
||||
|
||||
replica:
|
||||
primary: main-01
|
||||
source: main-01
|
||||
|
||||
resources:
|
||||
requests:
|
||||
cpu: "100m"
|
||||
memory: "100Mi"
|
||||
limits:
|
||||
cpu: "2"
|
||||
memory: "1Gi"
|
||||
|
||||
startDelay: 300
|
||||
|
||||
stopDelay: 300
|
||||
|
||||
storage:
|
||||
resizeInUseVolumes: false
|
||||
size: 10Gi
|
21
manifests/postgres/components/ha/Service-main-r.yaml
Normal file
21
manifests/postgres/components/ha/Service-main-r.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/component: ha
|
||||
app.kubernetes.io/instance: production
|
||||
app.kubernetes.io/name: postgres
|
||||
app.kubernetes.io/part-of: production-ha
|
||||
name: main-r
|
||||
spec:
|
||||
ports:
|
||||
- name: postgres
|
||||
port: 5432
|
||||
protocol: TCP
|
||||
targetPort: 5432
|
||||
selector:
|
||||
cnpg.io/cluster: -updated_by_replacement-
|
||||
cnpg.io/podRole: instance
|
||||
sessionAffinity: None
|
||||
type: ClusterIP
|
21
manifests/postgres/components/ha/Service-main-ro.yaml
Normal file
21
manifests/postgres/components/ha/Service-main-ro.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/component: ha
|
||||
app.kubernetes.io/instance: production
|
||||
app.kubernetes.io/name: postgres
|
||||
app.kubernetes.io/part-of: production-ha
|
||||
name: main-ro
|
||||
spec:
|
||||
ports:
|
||||
- name: postgres
|
||||
port: 5432
|
||||
protocol: TCP
|
||||
targetPort: 5432
|
||||
selector:
|
||||
cnpg.io/cluster: -updated_by_replacement-
|
||||
cnpg.io/instanceRole: replica
|
||||
sessionAffinity: None
|
||||
type: ClusterIP
|
21
manifests/postgres/components/ha/Service-main-rw.yaml
Normal file
21
manifests/postgres/components/ha/Service-main-rw.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/component: ha
|
||||
app.kubernetes.io/instance: production
|
||||
app.kubernetes.io/name: postgres
|
||||
app.kubernetes.io/part-of: production-ha
|
||||
name: main-rw
|
||||
spec:
|
||||
ports:
|
||||
- name: postgres
|
||||
port: 5432
|
||||
protocol: TCP
|
||||
targetPort: 5432
|
||||
selector:
|
||||
cnpg.io/cluster: -updated_by_replacement-
|
||||
cnpg.io/instanceRole: primary
|
||||
sessionAffinity: None
|
||||
type: ClusterIP
|
140
manifests/postgres/components/ha/kustomization.yaml
Normal file
140
manifests/postgres/components/ha/kustomization.yaml
Normal file
@ -0,0 +1,140 @@
|
||||
---
|
||||
|
||||
apiVersion: kustomize.config.k8s.io/v1alpha1
|
||||
kind: Component
|
||||
|
||||
|
||||
resources:
|
||||
# - ../../base
|
||||
- Cluster-main-02.yaml
|
||||
- Service-main-r.yaml
|
||||
- Service-main-ro.yaml
|
||||
- Service-main-rw.yaml
|
||||
|
||||
|
||||
patches:
|
||||
|
||||
# yamllint disable rule:indentation
|
||||
- patch: |-
|
||||
|
||||
- op: add
|
||||
path: /metadata/name
|
||||
value: main-01
|
||||
|
||||
- op: replace
|
||||
path: /spec/replica
|
||||
value:
|
||||
primary: main-01
|
||||
source: main-02
|
||||
|
||||
# yamllint enable rule:indentation
|
||||
target:
|
||||
group: postgresql.cnpg.io
|
||||
version: v1
|
||||
kind: Cluster
|
||||
name: main
|
||||
|
||||
# yamllint disable rule:indentation
|
||||
- patch: |-
|
||||
|
||||
- op: replace
|
||||
path: /spec/externalClusters
|
||||
value:
|
||||
|
||||
- name: main-01
|
||||
connectionParameters:
|
||||
host: main-01-rw.updated_by_replacement.svc
|
||||
user: streaming_replica
|
||||
dbname: postgres
|
||||
sslmode: verify-full
|
||||
sslKey:
|
||||
name: main-01-replication
|
||||
key: tls.key
|
||||
sslCert:
|
||||
name: main-01-replication
|
||||
key: tls.crt
|
||||
sslRootCert:
|
||||
name: main-01-ca
|
||||
key: ca.crt
|
||||
|
||||
- name: main-02
|
||||
connectionParameters:
|
||||
host: main-02-rw.updated_by_replacement.svc
|
||||
user: streaming_replica
|
||||
dbname: postgres
|
||||
sslmode: verify-full
|
||||
sslKey:
|
||||
name: main-02-replication
|
||||
key: tls.key
|
||||
sslCert:
|
||||
name: main-02-replication
|
||||
key: tls.crt
|
||||
sslRootCert:
|
||||
name: main-02-ca
|
||||
key: ca.crt
|
||||
|
||||
# yamllint enable rule:indentation
|
||||
target:
|
||||
group: postgresql.cnpg.io
|
||||
version: v1
|
||||
kind: Cluster
|
||||
|
||||
|
||||
|
||||
replacements:
|
||||
#
|
||||
# Add to Top-most Kustomization.yaml
|
||||
#
|
||||
# Updates extenal cluster DNS name octet that contains the namespace
|
||||
# - source:
|
||||
# kind: Cluster
|
||||
# name: main-01
|
||||
# fieldPath: metadata.namespace
|
||||
# targets:
|
||||
# - select:
|
||||
# kind: Cluster
|
||||
# fieldPaths:
|
||||
# - spec.externalClusters.[name=main-01].connectionParameters.host
|
||||
# - spec.externalClusters.[name=main-02].connectionParameters.host
|
||||
# options:
|
||||
# delimiter: "."
|
||||
# index: 1
|
||||
|
||||
|
||||
#
|
||||
# Add to Top-most Kustomization.yaml, if primary has be changed
|
||||
#
|
||||
# Updates each of the services to point the cluster that is denoted as primary
|
||||
# within cluster main-02
|
||||
- source:
|
||||
kind: Cluster
|
||||
name: main-02
|
||||
fieldPath: spec.replica.primary
|
||||
targets:
|
||||
- select:
|
||||
kind: Service
|
||||
name: main-r
|
||||
fieldPaths:
|
||||
- spec.selector.[cnpg.io/cluster]
|
||||
- select:
|
||||
kind: Service
|
||||
name: main-ro
|
||||
fieldPaths:
|
||||
- spec.selector.[cnpg.io/cluster]
|
||||
- select:
|
||||
kind: Service
|
||||
name: main-rw
|
||||
fieldPaths:
|
||||
- spec.selector.[cnpg.io/cluster]
|
||||
|
||||
# Dont change
|
||||
- source:
|
||||
kind: Cluster
|
||||
name: main-02
|
||||
fieldPath: metadata.labels.[app.kubernetes.io/part-of]
|
||||
targets:
|
||||
- select:
|
||||
kind: Cluster
|
||||
fieldPaths:
|
||||
- metadata.labels.[app.kubernetes.io/part-of]
|
||||
- spec.inheritedMetadata.labels.[app.kubernetes.io/part-of]
|
Reference in New Issue
Block a user