Developing Edge Services
In this tutorial we get to experience how a frontend developer could use Codezero when developing an Edge Service. In the Sample Project, the Frontend Service is an Edge Service that makes calls to the Core and Socket services.
Traditionally the frontend developer would need to run all (or many) of an application's microservices locally just to work on the single Frontend Service. In this tutorial we will run only the Frontend Service and teleport the other services in the cluster to your local machine.
In this tutorial, you will learn:
- How to develop an Edge Service locally while it accesses Services in Cluster
- How to configure a service based on local and in-cluster environments
It is assumed you have the standard prerequisites:
- A Kubernetes cluster
- The Codezero CLI installed
- The sample project cloned locally
The tutorial assumes you are at the root of the Sample Project repo, and have completed the Sample Project tutorial.
Run the Edge Service Locally
Let start by running the Frontend service locally:
You should be able to access the local Frontend service at
http://localhost:3030, however you should see that the Socket and Core sections show errors. This is because the Frontend is not able to access the upstream services.
This is where you would use Codezero's Teleport. First, we need the local frontend service to know that we wish to use the teleported configuration. We tell the Frontend service to use Teleport by adding
teleport=1 as a URL parameter:
This will tell the Frontend service to reference the following upstream services:
...instead of trying to access those services locally:
Start the Codezero Daemon
Assuming you have already installed the CLI, run:
To verify that the daemon is running:
czctl session list
You should see a message that you have no running sessions. Reminder that you can run
czctl help if you ever get stuck.
Teleport into the Cluster
You can now teleport into the sample-project namespace using the following command:
czctl teleport namespace sample-project
You should now see the failed connections on the webpage start to work because the in-cluster services can now be accessed by your local Frontend.
You will see an error under File, but don't worry about that as we will fix it in a future tutorial.
Launch your favorite IDE and open the folder
packages/frontend. You can make changes to the frontend code here and see that you are able to test against the in-cluster
After making changes, stop and start the frontend service, and perform a hard refresh in your browser to ensure your changes take effect.
When you are done, you can close the Teleport session using:
czctl session close