Repository navigation
Expand file tree
/
Copy pathREADME.md.gotmpl
More file actions
403 lines (302 loc) · 11.2 KB
/
Copy pathREADME.md.gotmpl
File metadata and controls
403 lines (302 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
MySQL Helm Chart
{{- $chartFile := .Files.Get "Chart.yaml" }}
{{- if $chartFile }}
{{- $chart := fromYaml $chartFile }}
  
[](https://artifacthub.io/packages/search?repo=comet-mysql-helm)
{{- end }}
{{ template "chart.description" . }}
## Features
- **Official MySQL Images**: Uses `docker.io/mysql:8.4.2`
- **Standalone Mode**: Simple single-instance deployment
- **Persistent Storage**: StatefulSet with PVC support (default 20Gi)
- **Configurable**: Customizable MySQL configuration
- **Secure**: Kubernetes secrets for passwords
- **Production Ready**: Resource limits, health checks, security contexts
- **Database Initialization**: Automated database and user creation (optional)
- **Automated Backups**: Scheduled backups to S3-compatible storage (optional)
- **Restore Operations**: One-time restore from S3-compatible storage (optional)
- **Global Labels**: Common labels support for all resources
## Prerequisites
- Kubernetes 1.19+
- Helm 3.0+
- PV provisioner support (if persistence is enabled)
## Installation
### Method 1: Helm Repository (Recommended)
Add the repository to your Helm configuration:
```bash
helm repo add mysql https://comet-ml.github.io/comet-mysql-helm/
helm repo update
```
Then install using the repository:
```bash
# Basic installation
helm install my-mysql mysql/mysql
# With custom values
helm install my-mysql mysql/mysql \
--set auth.rootPassword=mypassword \
--set auth.database=mydb \
--set primary.persistence.size=50Gi
# Using a values file
helm install my-mysql mysql/mysql -f my-values.yaml
```
### Method 2: Local Chart
Clone the repository and install directly:
```bash
git clone https://github.com/comet-ml/comet-mysql-helm.git
cd comet-mysql-helm
helm install my-mysql ./
```
## Using as a Dependency
To use this chart as a dependency in another Helm chart, add it to your `Chart.yaml`:
```yaml
dependencies:
- name: mysql
version: "{{- $cf := .Files.Get "Chart.yaml" }}{{- if $cf }}{{- $c := fromYaml $cf }}{{ $c.version }}{{- else }}0.1.7{{- end }}"
repository: "https://comet-ml.github.io/comet-mysql-helm/"
condition: mysql.enabled
```
Then run:
```bash
helm repo add mysql https://comet-ml.github.io/comet-mysql-helm/
helm dependency update
helm install my-app .
```
## Examples
See the `examples/` directory for complete example configurations:
- **Basic**: `simple-values.yaml`
- **Persistence**: `existing-pvc-values.yaml`
- **Configuration**: `extra-args-values.yaml` (command-line arguments)
- **Initialization**: `initdb-scripts-values.yaml` (SQL scripts), `init-job-mixed-values.yaml`, `init-job-secretref-values.yaml`
- **Availability**: `pdb-values.yaml` (Pod Disruption Budget)
- **Security**: `network-policy-values.yaml` (Network Policy), `tls-values.yaml` (TLS/SSL)
- **Backups**: `backup-aws-s3-values.yaml`, `backup-aws-iam-role-values.yaml`, `backup-minio-values.yaml`
- **Restore**: `restore-aws-s3-values.yaml`, `restore-aws-iam-role-values.yaml`, `restore-minio-values.yaml`
- **Complete Setup**: `complete-setup-values.yaml`
- **Labels**: `common-labels-values.yaml`
## Advanced Features
### Database Initialization
The chart supports two methods for database initialization:
#### Method 1: Init Scripts (initdbScripts)
SQL scripts that run automatically on first initialization (Bitnami-style):
```yaml
initdbScripts:
createdb.sql: |-
CREATE DATABASE IF NOT EXISTS myapp
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
CREATE USER IF NOT EXISTS 'myapp'@'%' IDENTIFIED BY 'myapp_password';
GRANT ALL ON `myapp`.* TO 'myapp'@'%';
FLUSH PRIVILEGES;
```
**Characteristics:**
- Runs automatically on first initialization only
- Scripts execute in alphabetical order
- Mounted to `/docker-entrypoint-initdb.d` (MySQL standard)
- Only runs when data directory is empty
#### Method 2: Init Job (Helm Hook)
Flexible init job that runs after MySQL is ready:
```yaml
initJob:
enabled: true
databases:
- name: myapp
username: myapp
password: myapp_password # or use passwordSecretRef
- name: production
username: produser
passwordSecretRef:
secretName: prod-db-secret
secretKey: password
```
**Characteristics:**
- Runs as Helm post-install/post-upgrade hook
- Supports both plain text passwords and secret references
- Runs every time (can be idempotent with IF NOT EXISTS)
- More flexible for dynamic configurations
**You can use both methods together** - initdbScripts run first, then initJob runs after.
```yaml
initJob:
enabled: true
databases:
- name: myapp
username: myapp
password: myapp_password # or use passwordSecretRef
- name: production
username: produser
passwordSecretRef:
secretName: prod-db-secret
secretKey: password
```
### MySQL Command-Line Arguments
You can pass additional command-line arguments to MySQL in two ways:
#### Method 1: Using `primary.extraFlags` (Appends to Configuration)
The `extraFlags` property automatically converts command-line flags to MySQL configuration format and **appends** them to the existing configuration (default or custom):
```yaml
primary:
extraFlags: "--max-connections=500 --max-allowed-packet=64M --log-bin-trust-function-creators=1 --thread-stack=256K"
```
**Benefits:**
- Flags are automatically converted to `my.cnf` format
- **Appends** to the default configuration (or your custom `primary.configuration`)
#### Method 2: Direct Configuration (Complete Override)
You can provide a complete MySQL configuration that **replaces** the default:
```yaml
primary:
configuration: |-
[mysqld]
authentication_policy='* ,,'
skip-name-resolve
port=3306
datadir=/var/lib/mysql
max-connections=500
max-allowed-packet=64M
log-bin-trust-function-creators=1
thread-stack=256K
```
**Use cases:**
- Complete control over the MySQL configuration
- When you need to override the entire default configuration
- Custom configurations that differ significantly from defaults
**Note:**
- `primary.extraFlags` **appends** flags to the existing configuration (default or custom)
- `primary.configuration` **completely replaces** the default configuration
- You can use both together: `primary.configuration` provides the base config, and `primary.extraFlags` adds additional flags on top
See `examples/extra-args-values.yaml` for a complete example.
### Automated Backups
Schedule regular backups to S3-compatible storage (AWS S3, MinIO, etc.):
```yaml
backup:
enabled: true
schedule: "0 2 * * *" # Daily at 2 AM
storage:
bucket: "my-backups"
region: "us-east-1"
prefix: "mysql-backups"
endpoint: "" # Empty for AWS S3, or "http://minio:9000" for MinIO
existingSecret: "aws-s3-credentials" # Optional - use IAM role if empty
retention: 7
databases: [] # Empty = all databases
```
### Restore from Backup
One-time restore operation:
```yaml
restore:
enabled: true
backupFile: "mysql_backup_20250130_020000.sql.gz"
storage:
bucket: "my-backups"
region: "us-east-1"
prefix: "mysql-backups"
existingSecret: "aws-s3-credentials"
```
### Pod Disruption Budget
Protect MySQL from voluntary disruptions (node drains, pod evictions):
```yaml
podDisruptionBudget:
enabled: true
minAvailable: 1 # Keep at least 1 pod available (for single replica)
# OR
# maxUnavailable: 0 # Prevent any disruption
```
### Network Policy
Restrict network traffic to/from MySQL pods:
```yaml
networkPolicy:
enabled: true
allowExternal: true # Allow all pods in namespace
# OR restrict to specific namespaces/pods:
# allowExternal: false
# allowedNamespaces:
# - matchLabels:
# name: production
# allowedPods:
# - matchLabels:
# app: myapp
```
## Connecting to MySQL
### From Within the Cluster
```bash
mysql -h <release-name>-mysql -u root -p
```
### Port Forward (for local development)
```bash
kubectl port-forward svc/<release-name>-mysql 3306:3306
mysql -h 127.0.0.1 -P 3306 -u root -p
```
## Upgrading
### From Helm Repository
```bash
helm repo update
helm upgrade my-mysql mysql/mysql -f values.yaml
```
### From Local Chart
```bash
helm upgrade my-mysql ./ -f values.yaml
```
## Migrate from Bitnami MySQL
When migrating from Bitnami MySQL chart to this custom MySQL chart:
1. **Set dataDir to Bitnami's path** in your values:
```yaml
primary:
dataDir: /bitnami/mysql/data
```
2. **Delete the MySQL StatefulSet before upgrading** (PVCs are preserved):
```bash
kubectl delete statefulset <release-name>-mysql --cascade=orphan
```
This allows Helm to recreate the StatefulSet with the new chart while reusing the existing PVC and data.
**Note**: The volume will be mounted at `/bitnami/mysql` (base folder), and MySQL will use `/bitnami/mysql/data` as its datadir, matching Bitnami's structure.
## Uninstalling
```bash
helm uninstall my-mysql
```
**Note**: This removes all Kubernetes components but **does not delete PVCs** by default. To delete PVCs:
```bash
kubectl delete pvc -l app.kubernetes.io/name=mysql
```
## Troubleshooting
### Check Pod Status
```bash
kubectl get pods -l app.kubernetes.io/name=mysql
kubectl describe pod <pod-name>
kubectl logs <pod-name>
```
### Check PVC
```bash
kubectl get pvc
kubectl describe pvc data-<release-name>-mysql-0
```
### Connect to MySQL Pod
```bash
kubectl exec -it <pod-name> -- /bin/bash
```
## Architecture
```
┌─────────────────────────────────────┐
│ Service (ClusterIP) │
│ <release-name>-mysql:3306 │
└─────────────────┬───────────────────┘
│
┌─────────────────▼───────────────────┐
│ StatefulSet (Primary) │
│ <release-name>-mysql-0 │
│ - MySQL 8.4.2 (Official Image) │
│ - Port 3306 │
│ - Health Checks │
│ - Resource Limits │
└─────────────────┬───────────────────┘
│
┌─────────────────▼───────────────────┐
│ PersistentVolumeClaim │
│ data-<release-name>-mysql-0 │
│ - /var/lib/mysql │
│ - Size: 20Gi (default) │
│ - Storage Class: configurable │
└─────────────────────────────────────┘
```
{{ template "chart.requirementsSection" . }}
{{ template "chart.valuesSection" . }}
## License
This chart is provided as-is.
{{ template "helm-docs.versionFooter" . }}