From 90c114c647f5e75952be6839f44728775a391d24 Mon Sep 17 00:00:00 2001 From: Shakar Bakr <5h4k4r.b4kr@gmail.com> Date: Mon, 27 Oct 2025 13:22:19 +0300 Subject: [PATCH] Add example ConfigMap and Secret for MSSQL backup configuration - Introduced `k8s-mssql-configmap-example.yaml` and `k8s-mssql-secret-example.yaml` to provide templates for non-sensitive and sensitive configurations, respectively. - Updated `README.md` and `k8s-statefulset-test.yaml` to reference the new example files. - Created `k8s-statefulset-with-sidecar.yaml` for deploying MSSQL with a backup sidecar, enhancing the backup functionality. Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com> --- README.md | 2 +- tests/README.md | 7 ++++++- .../k8s-mssql-configmap-example.yaml | 6 +++--- .../k8s-mssql-secret-example.yaml | 10 +++++----- tests/k8s-statefulset-test.yaml | 10 +++++----- .../k8s-statefulset-with-sidecar.yaml | 10 +++++----- tests/test-mssql-k8s.sh | 2 +- 7 files changed, 26 insertions(+), 21 deletions(-) rename k8s-mssql-configmap-example.yaml => tests/k8s-mssql-configmap-example.yaml (94%) rename k8s-mssql-secret-example.yaml => tests/k8s-mssql-secret-example.yaml (86%) rename k8s-statefulset-with-sidecar.yaml => tests/k8s-statefulset-with-sidecar.yaml (90%) diff --git a/README.md b/README.md index 0dc7013..f9975ba 100644 --- a/README.md +++ b/README.md @@ -232,7 +232,7 @@ For MSSQL StatefulSets with `ReadWriteOnce` volumes, use the **sidecar pattern** **Example: StatefulSet with Backup Sidecar** -See [`k8s-statefulset-with-sidecar.yaml`](./k8s-statefulset-with-sidecar.yaml) for a complete example. +See [`tests/k8s-statefulset-with-sidecar.yaml`](./tests/k8s-statefulset-with-sidecar.yaml) for a complete example. ```yaml apiVersion: apps/v1 diff --git a/tests/README.md b/tests/README.md index 2c1cd75..8fc75b8 100644 --- a/tests/README.md +++ b/tests/README.md @@ -11,7 +11,12 @@ This directory contains automated test scripts for validating the backup and res - **`test-mssql-k8s.sh`**: Tests MSSQL StatefulSet with backup sidecar (requires existing S3/MinIO) - **`test-mssql-k8s-with-minio.sh`**: Complete automated test that deploys MinIO alongside MSSQL - **`setup-minio-k8s.sh`**: Helper script to deploy MinIO in Kubernetes -- **`k8s-statefulset-test.yaml`**: Test StatefulSet configuration used by the test scripts + +### Kubernetes Configuration Examples +- **`k8s-statefulset-with-sidecar.yaml`**: Production-ready MSSQL StatefulSet with backup sidecar +- **`k8s-statefulset-test.yaml`**: Test StatefulSet configuration used by automated test scripts +- **`k8s-mssql-configmap-example.yaml`**: Example ConfigMap for non-sensitive configuration +- **`k8s-mssql-secret-example.yaml`**: Example Secret for sensitive credentials ## Usage diff --git a/k8s-mssql-configmap-example.yaml b/tests/k8s-mssql-configmap-example.yaml similarity index 94% rename from k8s-mssql-configmap-example.yaml rename to tests/k8s-mssql-configmap-example.yaml index e9ff7e4..dffe144 100644 --- a/k8s-mssql-configmap-example.yaml +++ b/tests/k8s-mssql-configmap-example.yaml @@ -3,9 +3,9 @@ # # Usage: # 1. Copy this file and update with your actual values -# 2. Apply: kubectl apply -f k8s-mssql-configmap.yaml -# 3. Create secret: kubectl apply -f k8s-mssql-secret.yaml -# 4. Deploy: kubectl apply -f k8s-statefulset-with-sidecar.yaml +# 2. Apply: kubectl apply -f tests/k8s-mssql-configmap.yaml +# 3. Create secret: kubectl apply -f tests/k8s-mssql-secret.yaml +# 4. Deploy: kubectl apply -f tests/k8s-statefulset-with-sidecar.yaml apiVersion: v1 kind: ConfigMap diff --git a/k8s-mssql-secret-example.yaml b/tests/k8s-mssql-secret-example.yaml similarity index 86% rename from k8s-mssql-secret-example.yaml rename to tests/k8s-mssql-secret-example.yaml index d408ea6..c4ef53d 100644 --- a/k8s-mssql-secret-example.yaml +++ b/tests/k8s-mssql-secret-example.yaml @@ -1,12 +1,12 @@ # Example mssql-general Secret # This secret contains ONLY sensitive credentials (passwords, keys) -# Non-sensitive configuration is in the ConfigMap (k8s-mssql-configmap-example.yaml) +# Non-sensitive configuration is in the ConfigMap (tests/k8s-mssql-configmap-example.yaml) # # Usage: # 1. Copy this file and update with your actual values -# 2. Apply ConfigMap: kubectl apply -f k8s-mssql-configmap.yaml -# 3. Apply Secret: kubectl apply -f k8s-mssql-secret.yaml -# 4. Deploy: kubectl apply -f k8s-statefulset-with-sidecar.yaml +# 2. Apply ConfigMap: kubectl apply -f tests/k8s-mssql-configmap.yaml +# 3. Apply Secret: kubectl apply -f tests/k8s-mssql-secret.yaml +# 4. Deploy: kubectl apply -f tests/k8s-statefulset-with-sidecar.yaml apiVersion: v1 kind: Secret @@ -53,7 +53,7 @@ stringData: # - AWS Secrets Manager, Azure Key Vault, or HashiCorp Vault # # 3. Non-sensitive configuration (bucket, endpoints, schedule): -# These are now in the ConfigMap (k8s-mssql-configmap-example.yaml) +# These are now in the ConfigMap (tests/k8s-mssql-configmap-example.yaml) # This keeps secrets clean and allows easier configuration changes # # 4. Alternative: Create secret from command line: diff --git a/tests/k8s-statefulset-test.yaml b/tests/k8s-statefulset-test.yaml index 806bff1..28df03a 100644 --- a/tests/k8s-statefulset-test.yaml +++ b/tests/k8s-statefulset-test.yaml @@ -5,9 +5,9 @@ # MSSQL's native backup files. # # Prerequisites: -# 1. Create the ConfigMap: kubectl apply -f k8s-mssql-configmap-example.yaml -# 2. Create the Secret: kubectl apply -f k8s-mssql-secret-example.yaml -# 3. Apply this StatefulSet: kubectl apply -f k8s-statefulset-with-sidecar.yaml +# 1. Create the ConfigMap: kubectl apply -f tests/k8s-mssql-configmap-example.yaml +# 2. Create the Secret: kubectl apply -f tests/k8s-mssql-secret-example.yaml +# 3. Apply this StatefulSet: kubectl apply -f tests/k8s-statefulset-test.yaml # # The backup container will automatically run backups according to the SCHEDULE. # @@ -117,14 +117,14 @@ spec: # # This StatefulSet uses a ConfigMap for non-sensitive config and a Secret for credentials: # -# ConfigMap (mssql-config) - See k8s-mssql-configmap-example.yaml +# ConfigMap (mssql-config) - See tests/k8s-mssql-configmap-example.yaml # - DATABASE_SERVER, DATABASE_HOST, DATABASE_NAME, DATABASE_PORT # - MSSQL_DATA_DIR, MSSQL_EXTRA_OPTS # - SCHEDULE, BACKUP_KEEP_DAYS # - S3_BUCKET, S3_PREFIX, S3_REGION, S3_ENDPOINT, S3_S3V4 # Note: DATABASE_HOST is overridden to "localhost" in the StatefulSet for sidecar pattern # -# Secret (mssql-general) - See k8s-mssql-secret-example.yaml +# Secret (mssql-general) - See tests/k8s-mssql-secret-example.yaml # - MSSQL_SA_PASSWORD # - DATABASE_USER, DATABASE_PASSWORD # - S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY diff --git a/k8s-statefulset-with-sidecar.yaml b/tests/k8s-statefulset-with-sidecar.yaml similarity index 90% rename from k8s-statefulset-with-sidecar.yaml rename to tests/k8s-statefulset-with-sidecar.yaml index a95dd6c..b3475b3 100644 --- a/k8s-statefulset-with-sidecar.yaml +++ b/tests/k8s-statefulset-with-sidecar.yaml @@ -5,9 +5,9 @@ # MSSQL's native backup files. # # Prerequisites: -# 1. Create the ConfigMap: kubectl apply -f k8s-mssql-configmap-example.yaml -# 2. Create the Secret: kubectl apply -f k8s-mssql-secret-example.yaml -# 3. Apply this StatefulSet: kubectl apply -f k8s-statefulset-with-sidecar.yaml +# 1. Create the ConfigMap: kubectl apply -f tests/k8s-mssql-configmap-example.yaml +# 2. Create the Secret: kubectl apply -f tests/k8s-mssql-secret-example.yaml +# 3. Apply this StatefulSet: kubectl apply -f tests/k8s-statefulset-with-sidecar.yaml # # The backup container will automatically run backups according to the SCHEDULE. # @@ -116,14 +116,14 @@ spec: # # This StatefulSet uses a ConfigMap for non-sensitive config and a Secret for credentials: # -# ConfigMap (mssql-config) - See k8s-mssql-configmap-example.yaml +# ConfigMap (mssql-config) - See tests/k8s-mssql-configmap-example.yaml # - DATABASE_SERVER, DATABASE_HOST, DATABASE_NAME, DATABASE_PORT # - MSSQL_DATA_DIR, MSSQL_EXTRA_OPTS # - SCHEDULE, BACKUP_KEEP_DAYS # - S3_BUCKET, S3_PREFIX, S3_REGION, S3_ENDPOINT, S3_S3V4 # Note: DATABASE_HOST is overridden to "localhost" in the StatefulSet for sidecar pattern # -# Secret (mssql-general) - See k8s-mssql-secret-example.yaml +# Secret (mssql-general) - See tests/k8s-mssql-secret-example.yaml # - MSSQL_SA_PASSWORD # - DATABASE_USER, DATABASE_PASSWORD # - S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY diff --git a/tests/test-mssql-k8s.sh b/tests/test-mssql-k8s.sh index cca1678..50dd48f 100755 --- a/tests/test-mssql-k8s.sh +++ b/tests/test-mssql-k8s.sh @@ -19,7 +19,7 @@ DATABASE_NAME="TestDB" MSSQL_DATA_DIR="${MSSQL_DATA_DIR:-/var/opt/mssql/data}" S3_BUCKET="${S3_BUCKET:-test-backups}" S3_ENDPOINT="${S3_ENDPOINT:-}" # Set this if using MinIO or other S3-compatible storage -STATEFULSET_FILE="${STATEFULSET_FILE:-$(dirname "$0")/../k8s-statefulset-with-sidecar.yaml}" +STATEFULSET_FILE="${STATEFULSET_FILE:-$(dirname "$0")/k8s-statefulset-with-sidecar.yaml}" # Cleanup function cleanup() {