[K8S] Upgrade of existing MD Core stack to a newer version by retaining existing shared database
Overview
This runbook documents the process used to upgrade the local MD Core deployment from 5.19.0 → 5.20.0 while keeping the existing PostgreSQL PVC (DB_MODE=4), database structure, and scan-processing history.
The same re-deployment flow can be used to also upgrade to a higher version of the MD Core application. The below article would implement the steps using a local cluster created by Minikube, that hosts 3 pods in total:
Item | Value |
|---|---|
Minikube profile |
|
Application namespace |
|
Helm release |
|
PostgreSQL deployment |
|
Existing PostgreSQL PVC |
|
Source database |
|
New database |
|
MD Core endpoints | http://192.168.59.107:8088/ |
Safety Rules
Rule | Note |
|---|---|
Do not delete active PVC | Do not delete the active PostgreSQL PVC before confirming which claim is mounted by |
Pin PVC when redeploying | Do not run a normal app redeploy without pinning the existing PVC. |
Avoid concurrent app pods | Do not run both MD Core application pods while doing a history migration. |
Pre-Checks
Confirm the current context and live resources:
Identify the active PostgreSQL PVC:
For the current deployment, the active claim is: postgres-core-20260722195541-60761
Back Up The Source Database
Step 1 - Acquire pod name:
Step 2 - Set backup path of choice:
Step 3 - Generate the backup:
Step 4 - Ensure information has been stored:
Stop MD Core During Migration
Scale the two application deployments down before running the database migration:
PostgreSQL must remain running !
Run The 5.20.0 History Migration Pod
Create a temporary migration pod using the 5.20.0 image. This pod reads from metadefender_core (source database) and creates the versioned target database metadefender_core_5_20_0.
This pod is a one-time migration runner and is sole purpose is to assist with the migration process - this pod should be removed before the real Helm deployment is started again.
Deploy the migration pod separately using the below example temporary .YAML file - by adjusting the image: opswat/metadefendercore-debian:5.20.0:
The control flow of the migration pod executes the following:
1 - Start a temporary pod based on the 5.20.0 image.
2 - Connect to the PG through the postgres-core:5432
3 - Authenticate using the mdcore-postgres-cred K8S secret
4 - Read the source database named metadefender_core
5 - Create the versioned target database, which becomes metadefender_core_5_20_0
6 - Copy/migrate config using the MDCORE_UPGRADE_FROM_DB_NAME, UPGRADE_DB and MIGRATE_HISTORY parameters and scan history into the new metadefender_core_5_20_0
For more information on the values.yaml:
metadefender-k8s/helm_charts/mdcore/values.yaml at main · OPSWAT/metadefender-k8s
Create the migration pod and apply the YAML:
md-core-520-prod-history-migration.yaml
Watch for migration success:
Expected success markers:
Verify History Was Preserved
Check the source and migrated database counts and confirm the migration of the scan-processing history:
Update Runtime Values
After migration, normal MD Core runtime should use the migrated database and should not keep upgrade mode enabled.
In mdcore-minikube-values.yaml:
The host-networked core components + init containers should also use the 5.20.0 image:
Render And Validate Helm
Render against the existing PostgreSQL PVC and dry-run to ensure configuration is accepted:
Then run the template against the Existing PostgreSQL PVC:
Dry-run the template and ensure the new variables are set in place:
Item | Expected |
|---|---|
image |
|
MDCORE_DB_NAME |
|
UPGRADE_DB |
|
MIGRATE_HISTORY |
|
claimName |
|
Finalize the the Helm Upgrade
Delete the temporary migration pod md-core-520-prod-history-migration before starting the real deployments!
Remove the temporary migration pod:
kubectl delete pod md-core-520-prod-history-migration -n md-core --ignore-not-found --wait=true
Upgrade the release while explicitly keeping the current PostgreSQL PVC:
Await the uptime on both Core deployments to confirm the success of the upgrade:
Confirm active PostgreSQL sessions are using the migrated database:
If everything has been set properly in place and there haven’t been no runtime error, the expected active database after upgrade should match: metadefender_core_5_20_0
Rollback Sequence
Data Divergence Warning: Any scan requests, audit records, or processing history generated while 5.20.0 was live exist solely in metadefender_core_5_20_0. Rolling back by pointing back to metadefender_core will not merge post-upgrade records back to the source database.
Because the original metadefender_core database remains intact, and assuming no pruning occurred in earlier Helm revisions, you can run a helm rollback. There are two options to revert the changes.
Keep the old source database metadefender_core until you are certain that the new 5.20.0 version is correct and properly deployed - only then it can be advisable to consider the option of removing any traces of the old one through a PG DROP statement and then removing obsolete not-bound PVCs.
Option 1: Change runtime values back to 5.20.0 -> 5.19.0 in the original configuration file
Configuration | Value / Details |
|---|---|
env |
|
core_components |
|
For a normal rollback sequence, MDCORE_DB_NAME is the important variable. MDCORE_UPGRADE_FROM_DB_NAME matters only during an upgrade; reverting it to metadefender_core_5_20_0 while rolling back can be misleading and dangerous if someone later sets UPGRADE_DB=true.
Since the original PVC would hold the information on both source and destination databases, you should keep it as it is - postgres-core-20260722195541-60761
Apply the re-adjustments through Helm:
Verify status:
Check if connections are on the original database:
The rollback version 5.19.0 should point back to metadefender_core, not metadefender_core_5_20_0.
Option 2: Use helm rollback if previous stable revision is present
Find the last good 5.19.0 revision, for example revision 24:
The helm rollback restores the old release values exactly - if that old revision already pointed to the 5.20.0 or to a different PVC, rollback would not return you to 5.19.0 safely, so kindly consider verifying that before running it.
Inspect what that revision would restore:
Confirm that the revision points to:
Rollback through Helm:
Verify pods and PG status:
References
Reference | Link |
|---|---|
OPSWAT MD Core Kubernetes upgrade documentation | https://www.opswat.com/docs/mdcore/container-deployment/upgrade-metadefender-core-version-on-k8s |
OPSWAT MD Core Docker image documentation | https://www.opswat.com/docs/mdcore/container-deployment/docker-image-published-on-opswat-docker-hub |
Support:
If further assistance is required, please log a support case or chat with our support engineer.