Add a database as a dependency
The Movies app requires an instance of MongoDB to be running in your Development Environment.
You could deploy MongoDB as part of your deploy
section in the okteto.yaml
file, but in this case, you are going to use the repo https://github.com/okteto/mongodb as a dependency.
This repo is already pre-configured with a Docker Compose file to deploy MongoDB in Okteto.
To instruct Okteto to deploy this repository in your Development Environment, add the following section to your okteto.yaml
file:
dependencies:
mongodb:
repository: https://github.com/okteto/mongodb
wait: true
The wait
flag instructs Okteto to wait until MongoDB is ready before running the deploy commands.
Deploy the Movies app to apply the changes:
okteto deploy
i Using cindy @ okteto.example.com as context
i Deploying dependency 'mongodb'
...
✓ Repository 'mongodb' successfully deployed
i Running 'Helm Install'
Release "movies" does not exist. Installing it now.
NAME: movies
LAST DEPLOYED: Fri Jan 19 23:54:00 2024
NAMESPACE: cindy
STATUS: deployed
REVISION: 2
TEST SUITE: None
NOTES:
Success! Your application will be available shortly.
i Endpoints available:
- https://movies-cindy.okteto.example.com
- https://movies-cindy.okteto.example.com/api
✓ Development environment 'movies' successfully deployed
You can see that MongoDB is now running from the Okteto UI:
Using variables to set runtime configurations
But it looks like the api Deployment is still unable to connect to MongoDB...
Note that the file chart/values.yaml
has a password hardcoded.
This won't probably be compliant with your security practices and is for example only.
Also, the default MongoDB password is password
instead of change-me!
. Luckily, you can pass runtime configuration to your Development Environment using Okteto Variables.
For example, you can define a local environment variable to configure the MongoDB password:
export MONGODB_PASSWORD=password
Or even better, create an Okteto Admin Variable to make this variable available across all your Development Environments in Okteto.
Once you have done this, update your okteto.yaml
file to configure the MongoDB password using this environment variable.
You should also enable the seed
job to load the MongoDB instance with initial data:
deploy:
- name: Helm Install
command: |
helm upgrade --install movies chart \
--set mongodb.password=${MONGODB_PASSWORD} \
--set seed.enabled=true
Running seed data scripts can be slow with real world databases. For those scenarios, you can use our Volume Snapshots feature to clone this data from an existing database in seconds 🚀
Deploy the Movies app to apply the changes:
okteto deploy
i Using cindy @ okteto.example.com as context
i Running 'Helm Install'
Release "movies" does not exist. Installing it now.
NAME: movies
LAST DEPLOYED: Fri Jan 19 23:54:00 2024
NAMESPACE: cindy
STATUS: deployed
REVISION: 2
TEST SUITE: None
NOTES:
Success! Your application will be available shortly.
i Endpoints available:
- https://movies-cindy.okteto.example.com
- https://movies-cindy.okteto.example.com/api
✓ Development environment 'movies' successfully deployed
Finally, you can access the endpoint of the Movies app to see something like this:
Next Steps
The Movies app is using pre-built images to deploy your Development Environment...
This is not ideal since you won't be able to deploy your local changes, let's build the images of the Movies app in next step of this guide 😎