Microservices with pebl — a complete and free cloud platform
Hatched by Kelvin
Jul 21, 2024
4 min read
5 views
Microservices with pebl — a complete and free cloud platform
Earn your web3 degree
Overview
In this guide, we will explore the capabilities of pebl, a complete and free cloud platform. Unlike traditional Infrastructure as Code approaches, pebl incorporates cloud capabilities directly into your application through language-specific SDKs. We will also delve into the concept of factorials and how they are calculated.
Getting Started with pebl
To begin, you need to sign up for a free account at pebl.io. Choose your desired identity provider and follow the steps. Don't forget to claim your free *.pebl.rocks subdomain, which we will use throughout the tutorial. Additionally, make sure you have Docker and the pebl CLI installed on your system. Instructions for installation can be found on the respective websites.
Creating a Simple Service with pebl
The core building block in pebl is a service, which is similar to a serverless application. Let's create a basic "Hello World" service using Python. Start by creating a project folder and a subfolder for the service. In the main.py file, define a Flask application with a root route that returns "hello, world!". Use the pebl.service() method to declare this Flask application as a service hosted at your *.pebl.rocks endpoint. With pebl, there's no need for separate configuration files or additional setup.
Running the Service Locally
Before deploying to the cloud runtime, it's important to test your code locally. Start a local pebl cluster with the pebl up command. Then navigate to the service folder and execute pebl run. This will build a Docker image and start a container with your service. Use the pebl info command to view the running cluster's details, including the port number. You can now send a request to your local server using curl.
Deploying to the Cloud Runtime
One of the key advantages of pebl is the ability to deploy the same application to different runtimes without modifications. To deploy your service to the cloud runtime, use the pebl deploy command. Ensure that you have authenticated with pebl auth before running the deploy command. Once the deployment is successful, you can send requests to your service using the *.pebl.rocks endpoint. Remember to use HTTPS, as pebl disallows non-TLS traffic.
Using Internal Services in pebl
In cloud workloads, it is common to break applications into smaller services. pebl supports this through internal services, which are only exposed to other workloads within the cluster. To demonstrate this, we will create an internal Go service that acts as a user service. Similar to the previous example, define a server object using the net/http package and pass it to the pebl.InternalService() method. Note that the endpoint can be any valid domain, such as .local or .internal.
Incorporating Redis into the Internal Service
pebl provides persistence through Redis, which can be easily incorporated into your application using the SDK. Update the Go service to include Redis functionality. Import the necessary packages, establish a connection to the Redis instance, and handle requests by retrieving user data from Redis. Deploy the updated Go service and test it locally. You can manage the data in the local Redis instance using the exposed port shown in the info pane.
Proxying Requests to Internal Services
To utilize the internal service, we will proxy a subset of requests from an external Python service to the internal Go service. Update the main.py file in the Python service to include a route for /user requests. Use the requests library to send these requests to the internal Go service at the specified endpoint. Update the Dockerfile to include the requests library. Run the Python service locally and test the /user endpoint to retrieve user data from the internal service.
Deploying the Services
Deploy the internal Go service first, followed by the Python service. pebl ensures zero downtime updates, meaning there won't be any dropped requests during the transition. Once the deployment is complete, you can send requests to the cloud runtime using the *.pebl.rocks endpoint. However, the Redis data will not be available unless you establish a tunnel to the cloud Redis instance using the pebl tunnel command. This allows you to manage the data in the cloud Redis instance using the redis-cli tool.
Factorials: Understanding the Concept
In mathematics, a factorial is denoted with an exclamation mark (!). It is the product of all positive integers up to and including a given number. For example, 5! is calculated as 5 * 4 * 3 * 2 * 1, resulting in 120. Factorials are commonly used in mathematical and statistical calculations.
Conclusion and Next Steps
In this guide, we have explored the capabilities of pebl, a powerful cloud platform that integrates cloud capabilities into your application. We have also gained an understanding of factorials and how they are calculated. To further explore pebl's offerings, refer to the SDK reference and follow the provided guides for common cloud tasks. Start earning your web3 degree by leveraging the features and benefits of pebl for your cloud-based applications.
Sources
Hatch New Ideas with Glasp AI 🐣
Glasp AI allows you to hatch new ideas based on your curated content. Let's curate and create with Glasp AI :)
Start Hatching 🐣