The goal for this assignment is to deploy an application locally (local computer is the host) using kubernetes.
The application has a database. The user will interact with the front-end in order to input or read data stored in the database.
The database is set up so that the front-end authenticate before accessing the back-end (wich is the database in this case).
We avoid using a cloud provider for the deployment for cost purposes.
This is not used in a production environment.
Note: Avoid pasting the $
sign; it is not part of the commands. The sign shows up when you use Linux.
- Create a cluster with a loadbalancer with port mapping โ8080:8081โ
k3d cluster create mycluster -p "8080:8081@loadbalancer"
You should see:
- port
8080
is for the access to the front-end. - port
8081
is for the access to the application - port
27017
is the port open in order to access the database
- Encode the username and password and put it in the secret.yaml file.
In the command line, type this:
$ echo -n mongo-root-username | base64
Output: bW9uZ28tcm9vdC11c2VybmFtZQ==
Then, do the same for the password:
$ echo -n mongo-root-password | base64
Output: bW9uZ28tcm9vdC1wYXNzd29yZA==
- Create the
yaml
files in your working directory.
- secret.yaml -> this file will authenticate the service for the database credentials.
- mongo-deploy.yaml -> this will create the deployment for mongoDB database.
- config_map.yaml
- mongo-express.yaml -> this is for the mongo-express deployment.
- Now, run these commands in the order they are given.
$ kubectl apply -f secret.yaml
$ kubectl apply -f mongo-deploy.yaml
$ kubectl apply -f config_map.yaml
$ kubectl apply -f mongo-express.yaml
- Verfy that the pods are running:
$ kubectl get pod
- Verify that the app is working by typing to the url:
localhost:8080
- This lab was from Kura Labs.
- https://zellwk.com/blog/crud-express-mongodb/