.
Nexus Repository Manager can be deployed in kubernetes platform, with embedded orient or h2 database, using Sonatype helm charts.
Note: We strongly recommend against running Nexus Repository 3 with embedded database within container orchestration environments such as Kubernetes. Doing so can lead to severe data corruption.
This article explains migrating Nexus pro instances to external DB
Prerequisites
- Kubernetes 1.19+
- kubectl CLI with admin access
- Nexus Pro instance, with embedded DB.
- External Postgresql DB for nexus instance
- Adequate free space on persistent volume (minimum of Double the existing DB size or 10GB)
- Familiarize high level steps from migration document
Identifying Nexus Deployment
Collect below details from existing nexus deployment
- Namespace in which nexus is deployed (This example uses nx3)
- Deployment name
$ kubectl get deploy -n nx3
NAME READY UP-TO-DATE AVAILABLE AGE
nex3-nexus-repository-manager 1/1 1 1 41m
sri-postgres 1/1 1 1 99d - Note down the Nexus image version and arguments used for the deployment
spec:
containers:
- env:
- name: INSTALL4J_ADD_VM_PARAMS
value: |-
-Xms2703M -Xmx2703M
-XX:+UnlockExperimentalVMOptions
-XX:+UseCGroupMemoryLimitForHeap
-Djava.util.prefs.userRoot=/nexus-data/javaprefs
-Dnexus.licenseFile=/etc/nexus-license/license.lic
- name: NEXUS_SECURITY_RANDOMPASSWORD
value: "true"
image: sonatype/nexus3:3.42.0
imagePullPolicy: IfNotPresent
Preparing for migration
- Schedule adequate downtime for migration
- Perform a full backup using normal backup procedures
- Shut down Nexus Repository gracefully
$ kubectl -n nx3 scale --replicas=0 deploy/nex3-nexus-repository-manager
deployment.apps/nex3-nexus-repository-manager scaled
$ kubectl get deploy -n nx3
NAME READY UP-TO-DATE AVAILABLE AGE
nex3-nexus-repository-manager 0/0 0 0 79m
sri-postgres 1/1 1 1 99d - Create a patch file as below, replacing with local DB values and patch the deployment to stop nexus from starting
$ cat patch-file.yaml
spec:
template:
spec:
containers:
- name: nexus-repository-manager
command: ["/bin/bash"]
args: ["-c", "while true; do echo ; sleep 100;done"]
env:
- name: INSTALL4J_ADD_VM_PARAMS
value: "-Xms2703M -Xmx2703M -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Djava.util.prefs.userRoot=/nexus-data/javaprefs -Dnexus.licenseFile=/etc/nexus-license/license.lic -Dnexus.datastore.enabled=true -Dnexus.datastore.nexus.jdbcUrl=jdbc:postgresql://sri-postgres-svc:5432/nexusdb -Dnexus.datastore.nexus.username=nexus -Dnexus.datastore.nexus.password=nexus123"
livenessProbe:
failureThreshold: 600
readinessProbe:
failureThreshold: 600$ kubectl -n nx3 patch deployment nex3-nexus-repository-manager --patch-file patch-file.yaml
deployment.apps/nex3-nexus-repository-manager patched -
Alternately you edit the deployment directly as below (replacing with local values)
$ kubectl -n nx3 edit deployment nex3-nexus-repository-manager
deployment.apps/nex3-nexus-repository-manager edited
Also increase the failureThreshold of readiness probe and liveness probe, to avoid pod restarts during migration.readinessProbe:
failureThreshold: 600
livenessProbe:
failureThreshold: 600 - Start the Deployment and login to nexus instance
$ kubectl -n nx3 scale --replicas=1 deploy/nex3-nexus-repository-manager
deployment.apps/nex3-nexus-repository-manager scaled
$ kubectl get pods -n nx3
NAME READY STATUS RESTARTS AGE
nex3-nexus-repository-manager-7c6f767dd5-sldq2 0/1 Running 0 43s
sri-postgres-5ff49c75f4-f85dc 1/1 Running 27 (21h ago) 99d
$ kubectl -n nx3 exec -it nex3-nexus-repository-manager-7c6f767dd5-sldq2 -- /bin/bash
bash-4.4$ - Change to persistent volume and download the latest DB migrator
bash-4.4$ cd /nexus-data
bash-4.4$ pwd
/nexus-data
bash-4.4$ curl -s -L -O https://download.sonatype.com/nexus/nxrm3-migrator/nexus-db-migrator-3.42.0-02.jar
bash-4.4$ ls -l nexus-db-migrator-3.42.0-02.jar
-rw-r--r-- 1 nexus nexus 45324415 Nov 8 04:16 nexus-db-migrator-3.42.0-02.jar
Executing the migration
1. Start the migrator from nexus-data/db directory, replacing with local DB values
bash-4.4$ cd /nexus-data/db
bash-4.4$ java -Xmx4G -Xms4G -XX:MaxDirectMemorySize=4014M -jar ../nexus-db-migrator-3.42.0-02.jar --migration_type=postgres --db_url="jdbc:postgresql://sri-postgres-svc:5432/nexusdb?user=nexus&password=nexus123"
04:44:41 [main] WARN c.s.n.d.migrator.MigratorApplication - Please ensure any Nexus Repository instance has been gracefully shut down before proceeding.
04:44:41 [main] INFO c.s.n.d.migrator.MigratorApplication - Do you want to continue [y/n]?
y
04:44:42 [main] INFO c.s.n.d.migrator.MigratorApplication - --content_migration parameter is absent. Setting it to true.
04:44:42 [main] INFO c.s.n.d.migrator.MigratorApplication - Force parameter wasn't found. Setting it to false by default.
04:44:42 [main] INFO c.s.n.d.migrator.MigratorApplication - ------------------------------------------------------------
04:44:42 [main] INFO c.s.n.d.migrator.MigratorApplication - Java version: Red Hat, Inc. 1.8.0_345
04:44:42 [main] INFO c.s.n.d.migrator.MigratorApplication - JVM arguments: -Xmx4G -Xms4G -XX:MaxDirectMemorySize=4014M
04:44:42 [main] INFO c.s.n.d.migrator.MigratorApplication - Migrator arguments: --migration_type=postgres --db_url=jdbc:postgresql://sri-postgres-svc:5432/nexusdb?user=nexus&password=**** --content_migration=true --force=false
04:44:42 [main] INFO c.s.n.d.migrator.MigratorApplication - ------------------------------------------------------------
04:44:43 [main] INFO c.s.n.d.migrator.MigratorApplication - Starting MigratorApplication v3.42.0-02 using Java 1.8.0_345 on nex3-nexus-repository-manager-5bd8797685-rvtv5 with PID 37 (/nexus-data/nexus-db-migrator-3.42.0-02.jar started by nexus in /nexus-data/db)
04:44:43 [main] INFO c.s.n.d.migrator.MigratorApplication - No active profile set, falling back to 1 default profile: "default"
04:44:44 [main] INFO o.s.b.c.r.s.JobRepositoryFactoryBean - No database type set, using meta data indicating: POSTGRES
04:44:44 [main] INFO c.s.n.d.migrator.MigratorApplication - Started MigratorApplication in 1.668 seconds (JVM running for 3.576)
04:44:44 [main] INFO o.s.b.a.b.JobLauncherApplicationRunner - Running default command line with: [--migration_type=postgres, --db_url=jdbc:postgresql://sri-postgres-svc:5432/nexusdb?user=nexus&password=nexus123, --content_migration=true, --force=false]
04:44:44 [main] INFO c.s.n.d.m.validator.PathValidator - Validating Orient directory: /nexus-data/db
04:44:44 [main] INFO c.s.n.d.m.validator.PathValidator - Validating Orient directory: /nexus-data/db
04:44:44 [main] INFO c.s.n.d.m.l.ProvidingJobInfoListener - Migration job started at Tue Nov 08 04:44:44 GMT 2022
04:44:44 [main] INFO o.s.batch.core.job.SimpleStepHandler - Executing step: [startHealthCheckDeciderStep]
04:44:44 [main] INFO o.s.batch.core.step.AbstractStep - Step: [startHealthCheckDeciderStep] executed in 24ms
04:44:44 [main] INFO o.s.batch.core.job.SimpleStepHandler - Executing step: [exportFilesStep]
04:44:44 [main] INFO c.s.n.d.m.export.JsonFilesExporter - Export may take several minutes depending on the amount of data
04:44:45 [main] INFO c.s.n.d.m.export.JsonFilesExporter - Exported config JSON file path /tmp/export_json-8995273030735844695/config
04:44:45 [main] INFO c.s.n.d.m.export.JsonFilesExporter - Exported security JSON file path /tmp/export_json-8995273030735844695/security
04:44:46 [main] INFO c.s.n.d.m.export.JsonFilesExporter - Exported component JSON file path /tmp/export_json-8995273030735844695/component
04:44:46 [main] INFO o.s.batch.core.step.AbstractStep - Step: [exportFilesStep] executed in 1s637ms
04:44:46 [main] INFO o.s.batch.core.job.SimpleStepHandler - Executing step: [readFileStep]
04:44:46 [main] INFO c.s.n.db.migrator.reader.FileReader - Current migration type is postgres.
04:44:46 [main] INFO c.s.n.db.migrator.reader.FileReader - Total number of config and security records to be processed = 36
04:44:46 [main] INFO o.s.batch.core.step.AbstractStep - Step: [readFileStep] executed in 98ms
04:44:46 [main] INFO o.s.batch.core.job.SimpleStepHandler - Executing step: [initDatabaseStep]
04:44:47 [main] INFO o.s.batch.core.step.AbstractStep - Step: [initDatabaseStep] executed in 498ms
04:44:47 [main] INFO o.s.batch.core.job.SimpleStepHandler - Executing step: [processConfigStep]
04:44:47 [main] INFO c.s.n.d.m.p.QuartzJobDetailProcessor - Filtered QuartzJobDetail record Cleanup service
04:44:47 [main] INFO c.s.n.d.m.p.QuartzJobDetailProcessor - Filtered QuartzJobDetail record Storage facet cleanup
04:44:47 [main] INFO c.s.n.d.m.p.QuartzTriggerProcessor - Filtered QuartzTrigger record Cleanup service
04:44:47 [main] INFO c.s.n.d.m.p.QuartzTriggerProcessor - Filtered QuartzTrigger record Storage facet cleanup
04:44:47 [main] INFO o.s.batch.core.step.AbstractStep - Step: [processConfigStep] executed in 100ms
04:44:47 [main] INFO o.s.batch.core.job.SimpleStepHandler - Executing step: [processComponentStep]
04:44:47 [main] INFO o.s.batch.core.step.AbstractStep - Step: [processComponentStep] executed in 116ms
04:44:47 [main] INFO o.s.batch.core.job.SimpleStepHandler - Executing step: [createRebuildRepositoryTasksStep]
04:44:47 [main] INFO o.s.batch.core.step.AbstractStep - Step: [createRebuildRepositoryTasksStep] executed in 11ms
04:44:47 [main] INFO o.s.batch.core.job.SimpleStepHandler - Executing step: [finalDatabaseStep]
04:44:47 [main] INFO o.s.batch.core.step.AbstractStep - Step: [finalDatabaseStep] executed in 26ms
04:44:47 [main] INFO c.s.n.d.m.l.ProvidingJobInfoListener - Migration job finished at Tue Nov 08 04:44:47 GMT 2022
04:44:47 [main] INFO c.s.n.d.m.l.ProvidingJobInfoListener - Migration job took 2 seconds to execute
04:44:47 [main] INFO c.s.n.d.m.l.ProvidingJobInfoListener - 78 records were processed
04:44:47 [main] INFO c.s.n.d.m.l.ProvidingJobInfoListener - 4 records were filtered
04:44:47 [main] INFO c.s.n.d.m.l.ProvidingJobInfoListener - 0 records were skipped
04:44:47 [main] INFO c.s.n.d.m.l.ProvidingJobInfoListener - 74 records were migrated
04:44:47 [main] INFO c.s.n.d.m.l.ProvidingJobInfoListener - Created 'Rebuild repository browse' and 'Rebuild repository search' tasks. They will automatically one-time run after starting your Nexus Repository instance.
04:44:47 [main] INFO c.s.n.d.m.l.ProvidingJobInfoListener - Migrated only early access formats: [APT, COCOAPODS, CONAN, CONDA, DOCKER, GITLFS, GO, HELM, MAVEN2, NPM, NUGET, P2, PYPI, R, RAW, RUBYGEMS, YUM]
04:44:47 [main] INFO c.s.n.d.m.l.ProvidingJobInfoListener - Cleaning orient temporary files...
04:44:47 [main] INFO c.s.n.d.m.l.ProvidingJobInfoListener - Cleaning finished
Starting with external DB
Now that data is migrated to external database, stop the deployment and remove the command and args from the nexus deployment.
-
Stop Deployment
$ kubectl -n nx3 scale --replicas=0 deploy/nex3-nexus-repository-manager
deployment.apps/nex3-nexus-repository-manager scaled
-
Create a deployment patch file as below and execute kubectl patch with it to remove command and args
$ cat patch-remove.yaml
- op: remove
path: "/spec/template/spec/containers/0/command"
- op: remove
path: "/spec/template/spec/containers/0/args"
$ kubectl patch deploy nex3-nexus-repository-manager -n nx3 --patch-file patch-remove.yaml --type=json
deployment.apps/nex3-nexus-repository-manager patched - Start Nexus Deployment
$ kubectl -n nx3 scale --replicas=1 deploy/nex3-nexus-repository-manager
3. Login to Nexus UI and confirm External DB is used
deployment.apps/nex3-nexus-repository-manager scaled
$ kubectl get pods -n nx3
NAME READY STATUS RESTARTS AGE
nex3-nexus-repository-manager-7fffb698d8-kgj7q 0/1 Running 1 (18s ago) 40s
sri-postgres-5ff49c75f4-f85dc 1/1 Running 27 (22h ago) 99d