How to Develop an Application based on Microservices

This tutorial will show you how to deploy a microservices application using our Application Catalog and how to develop a single component of this application directly in Okteto Cloud without needing to understand the details of other components deployed by the application.

Prerequisites

Step 1: Deploy the Sample App

Okteto Cloud provides an Application Catalog to deploy Helm charts in one-click. For this guide, we will use the Movies App provided by the default Application Catalog, but you can also import your Helm charts into Okteto Cloud.

Log in to Okteto Cloud and click on the Deploy button on the top left. A dialog will open with the list of available applications you can deploy on your namespace. The list will look something like this:

Click on the Movies App to switch to the deployment configuration view of the application. There you give it a name, select a version, and customize the configuration values. Once you're ready, click on the Deploy button on the bottom of the dialog to launch your application:

The UI will reflect the state of your application in real-time. You can click on the downward-facing arrow to see the state of your application's individual components. The Movies App is a simple web app composed of: a React frontend , a Node.js api , and a mongodb database. Your application will be ready to go once it reaches the Running state.

Now click on the application's endpoint of the frontend component to access the Movies App. You should see something like this:

Cool no ๐Ÿ˜Ž? But ooh... seems like we have a bug in our application. The list of Movies and the list of Continue watching for Cindy are the same. Let us work on a fix now!

Step 2: Start your remote development environment

Execute the following commands in your local terminal to clone the Movies App:

$ git clone https://github.com/okteto/movies
$ cd movies

You now have a functioning git repository that contains the source code of the Movies App. Go to the source code of the api service and run the up command to create your remote development environment:

$ cd api
$ okteto up
โœ“ Development environment activated
โœ“ Files synchronized
Namespace: cindy
Name: api
Forward: 8080 -> 8080
9229 -> 9229
Welcome to your development environment. Happy coding!
okteto>

The okteto up command starts a remote development environment in Okteto Cloud, which means:

  • A file synchronization service is created to keep your changes up-to-date between your local filesystem and your development environment.
  • Container ports 8080 (the application) and 9229 (the debugger) are forwarded to localhost.
  • A remote shell is started in your remote development environment. Build, test and run your application as if you were in your local machine.

All of this (and more) can be customized via the okteto.yml manifest file, which lives side by side with the application source code. Use the.stignore file to avoid synchronizing build artifacts, git metadata or dependencies like node_modules.

Your remote development environment inherits all the Kubernetes configuration of the original api service. For example, api receives the database password via an environment variable, now available in the remote development environment. To check it out, execute the following command in the remote shell:

okteto> env | grep MONGODB_PASSWORD
MONGODB_PASSWORD[email protected]

Start the api service by executing the command below in the remote shell:

okteto> yarn start
yarn run v1.19.1
$ nodemon server.js
[nodemon] 1.19.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] starting `node server.js`
Server running on port 8080.

Step 3: Develop directly in Okteto Cloud

Open the server.js file in your favorite local IDE and modify the line 41 to query the watching collection instead of movies:

db.collection('watching').find().toArray( (err, results) =>{

Save your changes. Okteto will automatically synchronize your changes to your remote development environment. Take a look at the remote shell and notice how the changes are detected by nodemon and automatically hot reloaded.

[nodemon] restarting due to changes...
[nodemon] starting `node server.js`
Server running on port 8080.

Go back to the browser, and reload the Movies App. Your code fixes were instantly applied! No commit, build or push required ๐Ÿ˜Ž.

Next steps

Congratulations, you just developed your first Kubernetes application in Okteto Cloud ๐Ÿš€.

Okteto lets you develop your application while taking advantage of other services running in Kubernetes. This way you can:

  • Reduce local setup and eliminate integration issues by developing the same way your application runs in production
  • Test your application as fast as you type code, without typing either docker or kubectl in your inner loop cycle
  • No more CPU cycles wasted in your machine. Hardware and network just limited by the power of the cloud

Learn more about how to use our Application Catalog and how to add Your Own Application to Okteto Cloud.

Join the community on our channel in the Kubernetes Slack! If you don't have a Kubernetes slack account, you can sign up here.