Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial: How to Create a Development Environment with Realistic Data in Okteto #959

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copy link

netlify bot commented Dec 20, 2024

Deploy Preview for okteto-docs failed.

Name Link
🔨 Latest commit afe1dc4
🔍 Latest deploy log https://app.netlify.com/sites/okteto-docs/deploys/67b8c0ebc9d5750008ab3b86

Copy link
Member

@rberrelleza rberrelleza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! My main suggestion is to use okteto deploy instead of kubectl commands to deploy the environment. okteto/fastapi-snapshot-app#2 has those changes, I just tested it and it works

Using Okteto Volume Snapshots, you can quickly create development environments that include production or staging data—without manually copying databases or waiting for CI/CD pipelines.

:::tip
Volume Snapshots are also useful for loading test data when running tests in Okteto Test. If your tests require a database with preloaded data, you can configure your test environment to restore from a snapshot instead of initializing an empty database. This ensures consistency across test runs and reduces setup time.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should do a benchmark at some point but I wouldn't be surprise is there's a 5-10X difference

Suggested change
Volume Snapshots are also useful for loading test data when running tests in Okteto Test. If your tests require a database with preloaded data, you can configure your test environment to restore from a snapshot instead of initializing an empty database. This ensures consistency across test runs and reduces setup time.
Volume Snapshots are also useful for loading test data when running tests in Okteto Test. If your tests require a database with preloaded data, you can configure your test environment to restore from a snapshot instead of initializing an empty database. This ensures consistency across test runs and significantly reduces setup time.

Comment on lines +42 to +45
```console
okteto kubeconfig
kubectl apply -f manifests/
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```console
okteto kubeconfig
kubectl apply -f manifests/
```
```console
okteto deploy


Expected output:
```console
deployment.apps/fastapi-snapshot-demo created
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we put the okteto output? (I can send a PR to the sample to use okteto.yaml and deploy)

Suggested change
deployment.apps/fastapi-snapshot-demo created
i Using clone-wars @ demo.okteto.dev as context
i Running stage 'kubectl apply -f manifests'
Executing command 'kubectl apply -f manifests'...
deployment.apps/fastapi-snapshot-demo unchanged
service/fastapi-snapshot-demo unchanged
persistentvolumeclaim/data unchanged
service/mongodb unchanged
statefulset.apps/mongodb unchanged
Command 'kubectl apply -f manifests' successfully executed
i Endpoints available:
- https://fastapi-snapshot-demo-cindy.example.okteto.com
✓ Development environment 'fastapi-snapshot-app' successfully deployed

"ingredients": ["Flour", "Milk", "Sugar", "Vegetable Oil"]
}'
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: how about a first step to put the endpoint on an env var, and then we use that for all the curls?


A Volume Snapshot will capture the database state at this moment.

Create a new manifest file `snapshot.yml` in the `manifests` folder and add the following to it:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is currently available at the root of the repo, its the vol.yaml file (I think). should we remove it? (or maybe we keep a separate branch with all the completed manifests?

spec:
volumeSnapshotClassName: okteto-snapshot-class
source:
persistentVolumeClaimName: data-mongodb-0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

today, the sample creates a PVC called data. do you want me to update it so it's called data-mongodb-0 instead?

Comment on lines +24 to +26
- A **Kubernetes cluster with Okteto** installed
- Familiarity with **Kubernetes manifests**
- [kubectl](https://kubernetes.io/docs/tasks/tools/) installed on your machine
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also need to create the volumesnapshotclass that we use (https://kubernetes.io/docs/concepts/storage/volume-snapshot-classes/). I believe we have docs for this, I don't think we create one by default when you install Okteto (which maybe we should?)

### 1. Create a New Namespace for Development

```console
okteto namespace create data-clone-$YOUR_OKTETO_USERNAME
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we are no longer multitenant, the suffix is not needed by default. maybe we don't include it to keep it simpler?

cp manifests/{k8s.yml,mongo.yml} data-clone-manifest
```

Update `mongo.yml` to reference the snapshot:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the mongo.yml on the repo is diferent, it declares the volumeclaim first and then it uses it on the stateful set. do you want to change the sample to this model?


```console
mkdir data-clone-manifest
cp manifests/{k8s.yml,mongo.yml} data-clone-manifest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we include the manifests already on a separate folder ? or do you think there's value on the user manually modifying it as a learning experience?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants