Upgrade/Deployment Strategy on K8S

For upgrading MetaDefender Core the container of the application contains the automation to upgrade the database schema and migrate the configuration data. There are 3 strategies that we would like to point out to use when upgrading it.

  1. Rolling Update ( Easy deployment where functionality test with new version is based on Kubernetes Probes )
  2. Blue-Green Deployment (2 or more activations licensed where is possible to test the new image before) - On RoadMap
  3. Blue-Green Deployment + Hot Backup ( When needed to go above the activations licensed ) - On RoadMap

As indicated in Deploying on K8S , the Kubernetes probes like Readiness and Liveness probes help the application to control the expected behavior, not to have a downtime, when doing an upgrade.

Rolling Update Strategy

When using the Rolling Update strategy provided by Kubernetes technology, these are the main points to consider

  • Traffic wont be sent to new pods until readiness probe is successful
  • Old version pods won’t be terminated until new version pods are ready to serve traffic
  • Rolling Update is the default strategy for deployment

How to upgrade using Rolling Update

Decide what data to migrate from version to version

When upgrading from one version to another, MetaDefender Core will create a new database migrating different data depending on what is indicated during the process. It can be migrated only configuration data or configuration data + processing history data.

  • Configuration data:

    • Workflow
    • Health check
    • User Management
  • Processing History Data

    • Scan results of previous scanned files

Pre-steps when migrating Processing History Data

Feature available starting from version 5.10.1

As the processing history data is the heaviest part of the data stored and is not always needed to be migrated, OPSWAT offers a way to only migrate the configuration data and save the time that it takes to migrate that sometimes can be high depending on the size of the processing history data.

There is a limitation when migrating the processing history, it is that is needed to stop the current pods running as we need to terminate all the connections to the database to migrate.

Following pre-steps are needed to follow when migrating the processing history

  • Must disable health check liveness probe in the helm chart before run with MIGRATE_HISTORY (Depending on the size of the database it can take a while to migrate all the data)
  • Check that there is enough space in the database server before starting the migration
  • Needed to stop MetaDefender Core pods

Configure Rolling Update Strategy

When using the Rolling Update strategy, there are two more options that let you fine-tune the update process:

  • maxSurge: The number of pods that can be created above the desired amount of pods during an update
  • maxUnavailable: The number of pods that can be unavailable during the update process

Both maxSurge and maxUnavailable can be specified as either an integer (e.g. 2) or a percentage (e.g. 50%), and they cannot both be zero.

To change this you need to edit the deployment strategy.

Bash
Copy

Variables to use during an upgrade

  1. MDCORE_UPGRADE _ FROM __DB NAME: old database name to migrate from (1st installation metadefender_core)
  2. UPGRADE_DB: To indicate if we want to enable the DB upgrade to the new version. It will create a new database with database name metadefender_core<new___version>
  3. MIGRATE_HISTORY: To migrate processing history. Follow Pre-steps

Step by step using kubectl

  • Set Up the environment variables for the pod to know what data will be needed to migrate
    • For MIGRATE_HISTORY please see pre-steps above and decide if it is really needed or not
Bash
Copy
  • Set new image version on the MetaDefender Core deployment
Bash
Copy

Step by step using helm

  • Set new image version in values.yaml helm file
    • For MIGRATE_HISTORY please see pre-steps above and decide if it is really needed or not
values.yaml
Copy
  • Run helm upgrade command with the environment variables desired if not indicated in values.yaml file when first deployment
Bash
Copy

Rollout Failed Update

Bash
Copy

How to upgrade with API Export/Import Configuration (Old-Fashioned way)

The steps needed to follow are:

1. Export the current configuration, like user management, worflows or settings configured. For it is needed to use the API endpoint Export Configuration (New version)

Bash
Copy

2. Adapt helm configuration to upgrade to the new image version

  • In case of controlling all the data from your values.yaml file, be sure that the maxUnavailable and maxSurge attributes of the deployment strategy is adapted to your deployment use case and the image version is changed to the new one
YAML
Copy
Bash
Copy
  • In case of controlling attributes from the helm install command, be sure that the maxUnavailable and maxSurge attributes of the deployment strategy is adapted to your deployment use case and the image version is changed to the new one
Bash
Copy

3. Import the configuration exported in the step 1 For it is needed to use the API endpoint Import Configuration (New version) . See how to use it in the example below.

Bash
Copy
Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard