earayu commited on
Commit
f4d58d7
·
1 Parent(s): e74af66

feat: add database helm

Browse files
deploy/kubeblocks-databases/Chart.yaml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ apiVersion: v2
2
+ name: kubeblocks-databases
3
+ description: A Helm chart to deploy PostgreSQL, Redis, Elasticsearch, and Qdrant clusters using KubeBlocks.
4
+ type: application
5
+ version: 0.1.0
6
+ appVersion: "1.0" # Or the version of KubeBlocks you are targeting
deploy/kubeblocks-databases/NOTES.txt ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This Helm chart has deployed KubeBlocks database clusters as configured in your values.yaml.
2
+
3
+ Enabled clusters:
4
+ {{- if .Values.postgresql.enabled }}
5
+ - PostgreSQL: {{ .Values.postgresql.name }} in namespace {{ .Values.global.namespace }}
6
+ {{- end }}
7
+ {{- if .Values.redis.enabled }}
8
+ - Redis: {{ .Values.redis.name }} in namespace {{ .Values.global.namespace }}
9
+ {{- end }}
10
+ {{- if .Values.elasticsearch.enabled }}
11
+ - Elasticsearch: {{ .Values.elasticsearch.name }} in namespace {{ .Values.global.namespace }}
12
+ {{- end }}
13
+ {{- if .Values.qdrant.enabled }}
14
+ - Qdrant: {{ .Values.qdrant.name }} in namespace {{ .Values.global.namespace }}
15
+ {{- end }}
16
+
17
+ You can check the status of your clusters using kubectl:
18
+ kubectl get clusters -n {{ .Values.global.namespace }}
19
+ kubectl get pods -n {{ .Values.global.namespace }}
20
+
21
+ For KubeBlocks specific commands, you might use the kbcli tool if installed.
deploy/kubeblocks-databases/README.md ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # KubeBlocks Databases Helm Chart
2
+
3
+ This Helm chart deploys and manages multiple database clusters (PostgreSQL, Redis, Elasticsearch, Qdrant) using [KubeBlocks](https://kubeblocks.io/).
4
+
5
+ ## Prerequisites
6
+
7
+ * Kubernetes cluster (version compatible with KubeBlocks)
8
+ * [Helm](https://helm.sh/docs/intro/install/) (version 3+) installed.
9
+ * [KubeBlocks](https://kubeblocks.io/docs/preview/user_docs/installation) installed in your Kubernetes cluster.
10
+ * `kubectl` configured to interact with your cluster.
11
+
12
+ ```bash
13
+ kubectl create namespace kb-system
14
+ kbcli kubeblocks install --version=1.0.0-beta.47 --namespace kb-system
15
+ ```
16
+
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ helm repo remove kubeblocks
22
+ helm repo add kubeblocks https://apecloud.github.io/helm-charts
23
+ helm repo update
24
+
25
+ helm upgrade --install kb-addon-elasticsearch kubeblocks/elasticsearch --namespace kb-system --version 1.0.0-alpha.0
26
+ helm upgrade --install kb-addon-qdrant kubeblocks/qdrant --namespace kb-system --version 1.0.0-alpha.0
27
+ helm upgrade --install kb-addon-postgresql kubeblocks/postgresql --namespace kb-system --version 1.0.0-alpha.0
28
+ helm upgrade --install kb-addon-redis kubeblocks/redis --namespace kb-system --version 1.0.0-alpha.0
29
+ ```
30
+
31
+ ```bash
32
+ kubectl create namespace demo
33
+ kubectl create secret generic postgresql-secret \
34
+ --namespace=demo \
35
+ --from-literal=username=postgres \
36
+ --from-literal=password=postgres
37
+ kubectl create secret generic redis-secret \
38
+ --namespace=demo \
39
+ --from-literal=username=default \
40
+ --from-literal=password=password
41
+ helm install kb-databases ./kubeblocks-databases -n demo --create-namespace \
42
+ --set redis.customSecretName=redis-secret,redis.customSecretNamespace=demo,postgresql.customSecretName=postgresql-secret,postgresql.customSecretNamespace=demo
43
+ ```
44
+
45
+ generate template:
46
+ ```bash
47
+ helm template kb-databases ./kubeblocks-databases -n demo --create-namespace \
48
+ --set redis.customSecretName=redis-secret,redis.customSecretNamespace=demo,postgresql.customSecretName=postgresql-secret,postgresql.customSecretNamespace=demo \
49
+ > rendered.yaml
50
+ ```
51
+
52
+ ## Verification
53
+
54
+ After installation, you can check the status of the deployed KubeBlocks clusters:
55
+
56
+ ```bash
57
+ kubectl get clusters -n demo
58
+ kubectl get pods -n demo
59
+ ```
60
+
61
+
62
+ You should see the `Cluster` resources for the enabled databases and their corresponding pods. The `NOTES.txt` output from Helm will also provide some of this information.
63
+
64
+ ```bash
65
+ kubectl get clusters -n demo
66
+ NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE
67
+ es-cluster Delete Running 121m
68
+ pg-cluster postgresql Delete Creating 121m
69
+ qdrant-cluster qdrant Delete Running 121m
70
+ redis-standalone redis Delete Running 121m
71
+
72
+ kubectl get pods -n demo
73
+ NAME READY STATUS RESTARTS AGE
74
+ es-cluster-mdit-0 3/3 Running 0 110m
75
+ pg-cluster-postgresql-0 5/5 Running 0 121m
76
+ qdrant-cluster-qdrant-0 2/2 Running 0 117m
77
+ redis-standalone-redis-0 3/3 Running 0 121m
78
+ ```
79
+
80
+ ## Connect
81
+
82
+ port-forward:
83
+ ```bash
84
+ echo "Starting Elasticsearch port-forward..."
85
+ kubectl port-forward -n demo service/es-cluster-mdit-http 9200:9200 &
86
+ ES_PID=$!
87
+ echo "Elasticsearch port-forward process ID: $ES_PID"
88
+ echo "Starting Qdrant port-forward..."
89
+ kubectl port-forward -n demo service/qdrant-cluster-qdrant-qdrant 6333:6333 &
90
+ QDRANT_PID=$!
91
+ echo "Qdrant port-forward process ID: $QDRANT_PID"
92
+ echo "Starting PostgreSQL port-forward..."
93
+ kubectl port-forward -n demo service/pg-cluster-postgresql-postgresql 5432:5432 &
94
+ PG_PID=$!
95
+ echo "PostgreSQL port-forward process ID: $PG_PID"
96
+ echo "Starting Redis port-forward..."
97
+ kubectl port-forward -n demo service/redis-standalone-redis-redis 6379:6379 &
98
+ REDIS_PID=$!
99
+ echo "Redis port-forward process ID: $REDIS_PID"
100
+ echo "All port-forwards have been started"
101
+ echo "Press Ctrl+C to stop all port-forwards"
102
+ # Capture Ctrl+C signal and clean up all processes
103
+ trap "kill $ES_PID $QDRANT_PID $PG_PID $REDIS_PID; echo 'All port-forwards stopped'; exit" INT
104
+ # Wait for any child process to finish
105
+ wait
106
+ ```
107
+
108
+ ## Uninstallation
109
+
110
+ To uninstall the deployed database clusters:
111
+
112
+ ```bash
113
+ helm uninstall kb-databases -n demo
114
+ ```
115
+ This will remove all Kubernetes resources associated with this Helm release, including the KubeBlocks `Cluster` objects. Depending on the `terminationPolicy` and KubeBlocks behavior, PVCs might also be deleted.
116
+
117
+
118
+ ## Configuration
119
+
120
+ The primary way to configure the deployments is through the `values.yaml` file.
121
+
122
+ ### Global Settings
123
+
124
+ These settings apply to all database clusters deployed by this chart:
125
+
126
+ ```yaml
127
+ global:
128
+ namespace: "demo"
129
+ terminationPolicy: "Delete" # Options: DoNotTerminate, Delete, WipeOut
130
+ ```
131
+
132
+ ### Per-Database Settings
133
+
134
+ Each database (PostgreSQL, Redis, Elasticsearch, Qdrant) has its own configuration block. Here's an example for PostgreSQL:
135
+
136
+ ```yaml
137
+ postgresql:
138
+ enabled: true # Set to true to deploy this database, false to skip
139
+ name: "pg-cluster" # Name of the KubeBlocks Cluster resource
140
+ serviceVersion: "14.7.2" # Database engine version
141
+ disableExporter: false # true to disable metrics exporter, false to enable
142
+ replicas: 2 # Number of replicas for the main component
143
+ resources: # CPU and Memory requests/limits
144
+ limits:
145
+ cpu: "0.5"
146
+ memory: "0.5Gi"
147
+ requests:
148
+ cpu: "0.5"
149
+ memory: "0.5Gi"
150
+ storage: "20Gi" # Storage size for the data volume (e.g., PVC)
151
+ ```
152
+
153
+ Refer to `values.yaml` for the full set of configurable options for each database.
154
+
155
+ **Key configurable parameters for each database:**
156
+
157
+ * `enabled`: (boolean) Deploy this database cluster.
158
+ * `name`: (string) Name for the KubeBlocks `Cluster` resource.
159
+ * `serviceVersion`: (string) Specific version of the database engine.
160
+ * `disableExporter`: (boolean) Enable/disable the metrics exporter. (Note: For Elasticsearch, this might be handled differently by its `componentDef`).
161
+ * `replicas`: (integer) Number of replicas for the primary database component.
162
+ * `resources`: (object) Standard Kubernetes resource requests and limits.
163
+ * `storage`: (string) Storage capacity for persistent volumes (e.g., "10Gi", "100Gi").
164
+ * `topology`: (string, for Redis) e.g., "standalone", "replication".
165
+ * `componentDef`: (string, for Elasticsearch) e.g., "elasticsearch-8".
deploy/kubeblocks-databases/templates/_helpers.tpl ADDED
File without changes
deploy/kubeblocks-databases/templates/elasticsearch-cluster.yaml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{- if .Values.elasticsearch.enabled }}
2
+ apiVersion: apps.kubeblocks.io/v1
3
+ kind: Cluster
4
+ metadata:
5
+ name: {{ .Values.elasticsearch.name }}
6
+ namespace: {{ .Values.global.namespace }}
7
+ spec:
8
+ terminationPolicy: {{ .Values.global.terminationPolicy }}
9
+ # Elasticsearch example provided doesn't specify clusterDef or topology at the spec level
10
+ # It's often defined by the componentDef within componentSpecs for KubeBlocks' ES
11
+ componentSpecs:
12
+ - name: mdit # Component name from your example, can be made configurable if needed
13
+ componentDef: {{ .Values.elasticsearch.componentDef }}
14
+ serviceVersion: "{{ .Values.elasticsearch.serviceVersion }}"
15
+ replicas: {{ .Values.elasticsearch.replicas }}
16
+ configs: # Hardcoding single-node config as per your example and simplicity request
17
+ - name: es-cm
18
+ variables:
19
+ mode: "single-node"
20
+ resources:
21
+ {{- toYaml .Values.elasticsearch.resources | nindent 8 }}
22
+ volumeClaimTemplates:
23
+ - name: data
24
+ spec:
25
+ storageClassName: ""
26
+ accessModes:
27
+ - ReadWriteOnce
28
+ resources:
29
+ requests:
30
+ storage: {{ .Values.elasticsearch.storage }}
31
+ {{- end }}
deploy/kubeblocks-databases/templates/mongodb-cluster.yaml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{- if .Values.mongodb.enabled }}
2
+ apiVersion: apps.kubeblocks.io/v1
3
+ kind: Cluster
4
+ metadata:
5
+ name: {{ .Values.mongodb.name }}
6
+ namespace: {{ .Values.global.namespace }}
7
+ spec:
8
+ terminationPolicy: {{ .Values.global.terminationPolicy }}
9
+ clusterDef: mongodb
10
+ topology: {{ .Values.mongodb.topology }}
11
+ componentSpecs:
12
+ - name: mongodb
13
+ serviceVersion: "{{ .Values.mongodb.serviceVersion }}"
14
+ disableExporter: {{ .Values.mongodb.disableExporter }}
15
+ replicas: {{ .Values.mongodb.replicas }}
16
+ resources:
17
+ {{- toYaml .Values.mongodb.resources | nindent 8 }}
18
+ volumeClaimTemplates:
19
+ - name: data
20
+ spec:
21
+ storageClassName: "{{ .Values.mongodb.storageClassName }}"
22
+ accessModes:
23
+ - ReadWriteOnce
24
+ resources:
25
+ requests:
26
+ storage: {{ .Values.mongodb.storage }}
27
+ {{- end }}
deploy/kubeblocks-databases/templates/postgresql-cluster.yaml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{- if .Values.postgresql.enabled }}
2
+ apiVersion: apps.kubeblocks.io/v1
3
+ kind: Cluster
4
+ metadata:
5
+ name: {{ .Values.postgresql.name }}
6
+ namespace: {{ .Values.global.namespace }}
7
+ spec:
8
+ terminationPolicy: {{ .Values.global.terminationPolicy }}
9
+ clusterDef: postgresql
10
+ topology: replication # As per your example
11
+ componentSpecs:
12
+ - name: postgresql # Default component name for PostgreSQL
13
+ serviceVersion: "{{ .Values.postgresql.serviceVersion }}"
14
+ disableExporter: {{ .Values.postgresql.disableExporter }}
15
+ labels:
16
+ # Specific label for Patroni scope
17
+ apps.kubeblocks.postgres.patroni/scope: {{ .Values.postgresql.name }}-postgresql
18
+ replicas: {{ .Values.postgresql.replicas }}
19
+ systemAccounts:
20
+ - name: postgres
21
+ secretRef:
22
+ name: {{ .Values.postgresql.customSecretName }}
23
+ namespace: {{ .Values.postgresql.customSecretNamespace }}
24
+ resources:
25
+ {{- toYaml .Values.postgresql.resources | nindent 8 }}
26
+ volumeClaimTemplates:
27
+ - name: data
28
+ spec:
29
+ storageClassName: "" # Or make this configurable if needed
30
+ accessModes:
31
+ - ReadWriteOnce
32
+ resources:
33
+ requests:
34
+ storage: {{ .Values.postgresql.storage }}
35
+ {{- end }}
deploy/kubeblocks-databases/templates/qdrant-cluster.yaml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{- if .Values.qdrant.enabled }}
2
+ apiVersion: apps.kubeblocks.io/v1
3
+ kind: Cluster
4
+ metadata:
5
+ name: {{ .Values.qdrant.name }}
6
+ namespace: {{ .Values.global.namespace }}
7
+ spec:
8
+ terminationPolicy: {{ .Values.global.terminationPolicy }}
9
+ clusterDef: qdrant
10
+ topology: cluster # As per your example
11
+ componentSpecs:
12
+ - name: qdrant # Default component name for Qdrant
13
+ serviceVersion: "{{ .Values.qdrant.serviceVersion }}"
14
+ disableExporter: {{ .Values.qdrant.disableExporter }}
15
+ replicas: {{ .Values.qdrant.replicas }}
16
+ resources:
17
+ {{- toYaml .Values.qdrant.resources | nindent 8 }}
18
+ volumeClaimTemplates:
19
+ - name: data
20
+ spec:
21
+ storageClassName: ""
22
+ accessModes:
23
+ - ReadWriteOnce
24
+ resources:
25
+ requests:
26
+ storage: {{ .Values.qdrant.storage }}
27
+ {{- end }}
deploy/kubeblocks-databases/templates/redis-cluster.yaml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{- if .Values.redis.enabled }}
2
+ apiVersion: apps.kubeblocks.io/v1
3
+ kind: Cluster
4
+ metadata:
5
+ name: {{ .Values.redis.name }}
6
+ namespace: {{ .Values.global.namespace }}
7
+ spec:
8
+ terminationPolicy: {{ .Values.global.terminationPolicy }}
9
+ clusterDef: redis
10
+ topology: {{ .Values.redis.topology }} # Use topology from values
11
+ componentSpecs:
12
+ - name: redis # Main Redis component
13
+ {{- if .Values.redis.serviceVersion }} # serviceVersion is optional for some clusterDefs
14
+ serviceVersion: "{{ .Values.redis.serviceVersion }}"
15
+ {{- end }}
16
+ {{- if (not ( eq .Values.redis.disableExporter nil )) }} # disableExporter is also optional
17
+ disableExporter: {{ .Values.redis.disableExporter }}
18
+ {{- end }}
19
+ replicas: {{ .Values.redis.replicas }}
20
+ systemAccounts:
21
+ - name: default
22
+ secretRef:
23
+ name: {{ .Values.redis.customSecretName }}
24
+ namespace: {{ .Values.redis.customSecretNamespace }}
25
+ resources:
26
+ {{- toYaml .Values.redis.resources | nindent 8 }}
27
+ volumeClaimTemplates:
28
+ - name: data
29
+ spec:
30
+ storageClassName: "" # Or make this configurable
31
+ accessModes:
32
+ - ReadWriteOnce
33
+ resources:
34
+ requests:
35
+ storage: {{ .Values.redis.storage }}
36
+ {{- end }}
deploy/kubeblocks-databases/values.yaml ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Global settings applicable to all database clusters
2
+ global:
3
+ namespace: "demo" # The namespace where all clusters will be deployed
4
+ terminationPolicy: "Delete" # Common termination policy
5
+
6
+ postgresql:
7
+ enabled: true
8
+ name: "pg-cluster" # Name for the PostgreSQL cluster
9
+ serviceVersion: "14.7.2"
10
+ disableExporter: false # Corresponds to Kubeblocks disableExporter
11
+ customSecretName:
12
+ customSecretNamespace:
13
+ replicas: 1
14
+ resources:
15
+ limits:
16
+ cpu: "1"
17
+ memory: "1Gi"
18
+ requests:
19
+ cpu: "1"
20
+ memory: "1Gi"
21
+ storage: "5Gi"
22
+
23
+ redis:
24
+ enabled: true
25
+ name: "redis-standalone" # Name for the Redis cluster
26
+ topology: "standalone" # Explicitly set topology
27
+ serviceVersion: "7.2.4" # Keep or update as needed
28
+ disableExporter: false # Keep or update as needed
29
+ customSecretName:
30
+ customSecretNamespace:
31
+ replicas: 1 # Standalone typically means 1 replica
32
+ resources:
33
+ limits:
34
+ cpu: "1"
35
+ memory: "1Gi"
36
+ requests:
37
+ cpu: "1"
38
+ memory: "1Gi"
39
+ storage: "5Gi"
40
+
41
+ elasticsearch:
42
+ enabled: true
43
+ name: "es-cluster" # Name for the Elasticsearch cluster
44
+ componentDef: "elasticsearch-8" # Example: "elasticsearch-8"
45
+ serviceVersion: "8.8.2"
46
+ replicas: 1 # For the 'mdit' component (or whatever the main ES component is named)
47
+ resources:
48
+ limits:
49
+ cpu: "1"
50
+ memory: "1Gi"
51
+ requests:
52
+ cpu: "1"
53
+ memory: "1Gi"
54
+ storage: "5Gi"
55
+
56
+ qdrant:
57
+ enabled: true
58
+ name: "qdrant-cluster" # Name for the Qdrant cluster
59
+ serviceVersion: "1.10.0"
60
+ disableExporter: false
61
+ replicas: 1
62
+ resources:
63
+ limits:
64
+ cpu: "1"
65
+ memory: "1Gi"
66
+ requests:
67
+ cpu: "1"
68
+ memory: "1Gi"
69
+ storage: "5Gi"
70
+
71
+ mongodb:
72
+ enabled: false
73
+ name: "mongo-cluster"
74
+ serviceVersion: "6.0.16"
75
+ topology: replicaset
76
+ disableExporter: false
77
+ replicas: 3
78
+ resources:
79
+ limits:
80
+ cpu: "0.5"
81
+ memory: "0.5Gi"
82
+ requests:
83
+ cpu: "0.5"
84
+ memory: "0.5Gi"
85
+ storageClassName: ""
86
+ storage: 20Gi