Migrating Docker Compose to Kubernetes.
About this task
To migrate docker compose to kubernetes complete the following steps:
Procedure
-
Export the existing Docker Compose MongoDB database.
-
Navigate to MongoDB database container shell.
docker exec -it <mongo_db_service> bash
-
Export all data from the MongoDB database.
-
Exit the MongoDB database container shell.
-
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.
-
Install MongoDB database in Kubernetes.
-
Install the MongoDB Helm chart with a root password of your choice.
helm install --set mongodbRootPassword=<root_password> --name velocity-mongo
stable/mongodb
-
Create a non-root MongoDB user.
-
Navigate to MongoDB database's Kubernetes pod.
kubectl exec -it --namespace default svc/accelerate-mongo-mongodb
/bin/bash
-
Open a MongoDB Shell session as the root user.
mongo admin -u root -p <root_password>
-
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"
}]})
-
Exit the MongoDB Shell.
-
Restore the Docker Compose database dump to the new MongoDB pod.
-
Use
kubectl get pods
to get all pods. Identify the MongoDB
pod.
-
Copy database dump folder from the Docker Compose installation location into the
MongoDB pod.
kubectl cp <dump_location> <full_pod_name>:/tmp/dump
-
Navigate to MongoDB pod shell.
kubectl exec -it --namespace default svc/accelerate-mongo-mongodb
/bin/bash
-
Change directory to dump directory.
-
List all MongoDB folder to verify the contents.
Note: Each folder is a database in MongoDB.
-
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.
-
Exit MongoDB pod shell.
exit
The new MongoDB server is ready for use. For Kubernetes installation directions,
see this page.
-
Configure SSL certificate.
-
Create a
accelerate-secret.yml file
with the following contents.
apiVersion: v1
data:
tls.crt: <base64_cert>
tls.key: <base64_key>
kind: Secret
metadata:
name: acceleratetls
namespace: default
type: Opaque
-
Encode the certificate and key files.
Save certificate and key files to the required folders.
-
Apply the
accelerate-secret.yml
file.
kubectl apply -f accelerate-secret.yml
-
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
-
Install
HCL™ Accelerate.
Before you begin, ensure settings.json
file is available in ~/.ucv
directory.
-
Run
the accelerate installer. All fields taken information from
settings.json
.
Select kubernetes
platform to generate Helm chart tgz
.
-
Use
Helm chart tgz
to install accelerate.
-
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>