Migrating Docker Compose to Kubernetes#

Migrating Docker Compose to Kubernetes.

To migrate docker compose to kubernetes complete the following steps:

  1. Export the existing Docker Compose MongoDB database.

    1. Navigate to MongoDB database container shell.

      docker exec -it <mongo_db_service> bash

    2. Export all data from the MongoDB database.

      mongodump

    3. Exit the MongoDB database container shell.

      exit

    4. Copy the dump folder out of the MongoDB database container.

      docker cp <mongo_db_service>:/dump <DESTINATION>

      The MongoDB export is used in the final step.

  2. Install MongoDB database in Kubernetes.

    1. Install the MongoDB Helm chart with a root password of your choice.

      helm install --set mongodbRootPassword=<ROOT_PASSWORD> --name velocity-mongo stable/mongodb

  3. Create a non-root MongoDB user

    1. Navigate to MongoDB database's Kubernetes pod..

      kubectl exec -it --namespace default svc/accelerate-mongo-mongodb /bin/bash

    2. Open a MongoDB Shell session as the root user.

      mongo admin -u root -p <ROOT_PASSWORD>

    3. Create a non-root MongoDB user with the following roles and permissions.

      db.createUser ({ user: "<NEW_USERNAME>", pwd: "<NEW_PASSWORD>", roles: [{role: "readWriteAnyDatabase", db: "admin"}, {role: "dbAdminAnyDatabase", db: "admin"}, {role: "clusterAdmin", db: "admin" }]})

    4. Exit the MongoDB Shell.

      exit

  4. Restore the Docker Compose database dump to the new MongoDB pod.

    1. Use kubectl get pods to get all pods. Identify the MongoDB pod.

    2. Copy database dump folder from the Docker Compose installation location into the MongoDB pod.

      kubectl cp <DUMP_LOCATION> <FULL_POD_NAME>:/tmp/dump

    3. Navigate to MongoDB pod shell.

      kubectl exec -it --namespace default svc/accelerate-mongo-mongodb /bin/bash

    4. Change directory to dump directory.

      cd /tmp/dump

    5. List all MongoDB folder to verify the contents.

      ls

      Note: Each folder is a database in MongoDB.

    6. Restore all database except ADMIN

      mongorestore --uri="mongodb://<NEW_USERNAME>:<NEW_PASSWORD>@localhost:27017/?authSource=admin" <DB_NAME> -d <DB_NAME>

      Note: Delete the Docker Compose MongoDB export that was copied into the Kubermetes MongoDB pod at your earliest convenience.

    7. Exit MongoDB pod shell.

      exit

      The new MongoDB server is ready for use. For Kubernetes installation directions, see this page.

  5. Configure SSL certificate.

    1. Create a accelerate-secret.yml filewith the following contents.

      apiVersion: v1 data: tls.crt: <BASE64_CERT> tls.key: <BASE64_KEY> kind: Secret metadata: name: acceleratetls namespace: default type: Opaque

    2. Encode the certificate and key files.

      cat <FILE>.pem | base64

      Save certificate and key files to the required folders.

    3. Apply the accelerate-secret.yml file.

      kubectl apply -f accelerate-secret.yml

  6. Configure Kubernetes Ingress.

    Apply mandatory and cloud-generic Ingress-Nginx.yml files.

    kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.30.0/deploy/static/mandatory.yaml

    kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.30.0/deploy/static/provider/cloud-generic.yaml

  7. Install HCL Accelerate.

    Before you begin, ensure settings.json file is available in ~/.ucv directory.

    1. Run the accelerate installer. All fields taken information from settings.json.

      Select kubernetes platform to generate Helm chart tgz.

    2. Use Helm chart tgz to install accelerate.

    3. Install HCL Accelerate.

      helm install --set license=accept --set url.domain=<HOSTNAME> --set mongo.url=mongodb://<NEW_USERNAME>:<NEW_PASSWORD>@velocity-mongo-mongodb:27017/?authSource=admin --name accelerate <ACCELERATE_HELM_CHART>

Parent topic: Migrating