Microservice applications are popular, and for good reason. They offer flexibility over monolithic applications, and superior scalability when containerized and deployed to Kubernetes. To be functional, a microservice application must run all its services.
Issues arise when you want to build your application as a whole for your CI/CD pipeline and still be able to develop a subset of microservices. This is where Skaffold modules help.
Skaffold modules give microservice developers the ability to build and deploy parts of their applications separately. This results in an efficient development flow that enables:
Iterating on and debugging a subset of microservices
Cross-boundary microservice debugging
Reduced build time and faster iterations when using remote dependencies and prebuilt artifacts
Skaffold is a command line tool that facilitates continuous development for Cloud Native applications. Skaffold handles the workflow for building, pushing, and deploying your application, and provides building blocks for creating CI/CD pipelines.
To support iterative microservice development for Skaffold users using IDEs, module support was recently added to Cloud Code. Cloud Code is Google Cloud’s IDE plugin for IntelliJ and Visual Studio Code. With Cloud Code, we’re bringing Skaffold to where you’re at; developing locally in your favorite IDE.
This post walks through how to develop and debug a sample microservice application with Skaffold modules from your IDE. We’ll also take a look at how to add Skaffold modules support to your own application.
Develop and debug microservices separately
Let’s see Skaffold modules in action with the IntelliJ version of Cloud Code. We’ll try Skaffold modules with Cloud Code’s Guestbook sample. The Guestbook sample is a simple microservice application that’s available in Node.js, Java, Python, and Go.
If you’re a Visual Studio Code user, install Cloud Code and check out our documentation for creating a sample Kubernetes app and configuring modules.
Before you begin
1. Install the Cloud Code plugin for JetBrains IDEs.
2. Create a new Cloud Code project by opening IntelliJ and navigating to File > New > Project… > Cloud Code: Kubernetes > Java: Guestbook.
Run the application
The Java Guestbook sample has a frontend and backend microservice. As you would expect, the frontend microservice provides the UI, while the backend stores and serves records from a database. For more details about the guestbook sample application, open the sample’s README.md file.
First, edit the “Develop on Kubernetes” configuration. Under the Run tab, either select an existing Kubernetes cluster or “Deploy locally to a minikube cluster” to spin up a minikube cluster for free.
Now let’s deploy the full Guestbook application by running the “Develop on Kubernetes” configuration.
Cloud Code now builds the Guestbook sample application, packages it into containers, and deploys to the current Kubernetes cluster configured on your machine. The Run tool window looks similar to the following once the application is deployed. Clicking each step narrows the scope of the displayed logs, allowing you to focus on a specific container.
Open the Service URLs tab to access the port-forwarded application endpoints locally. You can test that the application is working by clicking the java-guestbook-frontend URL.
Once you’ve confirmed the application works, click the stop button. Cloud Code stops the application and cleans up the deployment in your cluster.
Run a single microservice
You’ve probably noticed that it takes a while to deploy this entire application. Now imagine having to deploy a much larger application with over a dozen microservices when you only want to develop one! This is where Cloud Code and Skaffold modules come into play.
Let’s edit the “Develop on Kubernetes” run configuration and select the Build/Deploy tab:
Here you can see all the microservices of the application. For a microservice to appear in this list, it needs to be defined as a Skaffold module in your skaffold.yaml file. skaffold.yaml provides specifications for an application’s workflow. This sample has already done that.
Let’s build and deploy the “frontend” microservice.
Click OK and run “Develop on Kubernetes” again. This time Cloud Code only builds and deploys the frontend microservice.
Without the backend microservice, the frontend is just a UI view with no data. Deploying just the frontend allows testing that the frontend fails gracefully when the backend is unavailable.
More than likely your microservice development and debugging happens in a shared development cluster, where a backend team deploys their microservice that’s available for your frontend to interact with. This way, the backend and the frontend teams can develop a larger application independently while using the power of Cloud Code IDEs.
With Skaffold modules, backend and frontend code can live in either the same or separate repositories. Microservices can then be built together with a root skaffold.yaml file when all modules are selected. Each team can then work on their part by developing their module. See our documentation for more info on common Skaffold module use cases.
The larger your application and the more independent microservices it has, the more productive this workflow becomes.
Debug a microservice
Debugging your microservices is almost the same process as running them in your remote Kubernetes cluster. Run the “Develop on Kubernetes” configuration in debug mode.
Cloud Code ensures the container and application inside it run in debug mode and connects them to the IDE.
Now set breakpoints as if you are running locally and step through your application running in your remote cluster! You can find more details about debugging here.
Configure Skaffold modules for your application
The Guestbook sample shows one way to use Skaffold modules with a very simple microservice application. If you’re working on a small microservice application, reference the Guestbook sample’s root skaffold.yaml. It provides a great starting point on how to structure your Skaffold configuration file.
This root configuration lists all the microservices of the application. Each microservice has its own Skaffold configuration that defines how to build and deploy it to Kubernetes. This sample has two Skaffold configurations for the frontend and backend.
You could provide alternative root configurations, such as a local development root that configures the backend with a local MySQL or PostgreSQL instance, or that activates specific Skaffold profiles.
To see Skaffold modules implemented in a larger example, see the Bank of Anthos application. It has 5+ larger microservices configured as Skaffold modules and is fully supported by Cloud Code IDEs. This is a great example of a large application that can be developed with Cloud Code and deployed with Cloud Deploy using the same Skaffold configuration.
Check out the Skaffold documentation to learn more about configuring Skaffold modules.
Next steps
We encourage you to try configuring your microservice project with Skaffold modules to experience the power and productivity of Skaffold and Cloud Code.
If you need help, join our GCP Community Slack Channel, #cloud-code, to connect with the community and ask questions.
To learn more about how Skaffold and Cloud Code work together, see Kubernetes development, simplified—Skaffold is now GA.
Cloud BlogRead More