Run and develop an application in Cloud Code for IntelliJ

Stay organized with collections Save and categorize content based on your preferences.

Now that you're all set up, you can either opt for a regular run of your application or start a development iteration cycle on your IDE to propagate any changes made to your source and dependencies to your live application. This page uses the Guestbook sample app to illustrate the running and developing on Kubernetes experience.

Choosing a run action

Before running

Before running your application, ensure you're set up to deploy your app to your preferred Kubernetes context. You can specify this in your configuration, on the Run tab and in the Deployment preferences section.

If you'd like to switch your current context, you can do so with the Kubernetes Explorer, accessible either from its sidebar panel on the right or using Tools > Cloud Code > Kubernetes > View Cluster Explorer.

To optimize your development loop by quickly picking up file changes of a certain type without having to perform an image rebuild, you can enable file syncing and hot reloading.

Continuous development on Kubernetes

The Develop on Kubernetes run target starts the development cycle on your Kubernetes cluster. After you start the development cycle, Cloud Code, using Skaffold, builds an image for the project, and then tags it, pushes it to the configured repository, and uses kubectl to deploy the project Kubernetes manifests.

  1. Click run action icon Develop on Kubernetes and then click Edit Configurations to open the Run/Debug Configurations dialog.
  2. Customize your deployment using the available configuration options.
  3. If you want Cloud Code to redeploy your application automatically after your changes are saved, under Watch mode - rebuild and redeploy, select On file save. New Kubernetes applications have On demand selected by default. For more information about watch modes, see Watch modes.
  4. If your application is configured to use Skaffold modules, you can select to only build or deploy specific modules.
  5. After you're satisfied with your configuration, click OK and then click run action icon Run.

Starting the Kubernetes cluster development cycle

Selecting Skaffold modules

This section outlines how to split your Skaffold project into modules so that you can develop and debug parts of your application independently.

To select Skaffold modules in IntelliJ, perform the following steps:

  1. Install the latest Insiders builds.
  2. Go to Run > Edit configurations and open the Build / Deploy tab.
  3. Select skaffold.yaml.
  4. Choose one of the following:
    • Build and deploy with all dependencies, or
    • Build and deploy with (if modules are available) and select any modules.
Build / Deploy tab showing the modules list.

Your selection persists for subsequent deployments. If you select a subset of modules, Cloud Code displays a warning about deploying a subset of modules and not the whole system.

Previewing your deployed app

  1. Click the Run button on your preferred run action. You can then view incoming application logs in the output window under the Logs tab.

    When the deployment starts, you'll see the list of forwarded ports for your deployed application.

  2. After the deployment is successful, you're notified that new service URLs are available. Click the Service URLs tab to view the URL(s), then click the URL link to open your browser with your running application.

    Viewing port-forwarded services in the Service URLs tab

    Alternatively, you can open the Event Log and then click the link to open your browser with your running application.

    The Deployed Resources pane shows what you deployed during the development session.

Viewing logs

In addition to seeing logs from running pods as a live stream in the terminal output as you're developing and running your application, you can view logs from a specific pod by navigating to the Kubernetes Explorer.

To view logs from a specific pod, follow these steps:

  1. Navigate to the Kubernetes Explorer. It can be accessed either from the side panel on the right or using Tools > Cloud Code > Kubernetes > View Cluster Explorer.

    Kubernetes Explorer panel open using the tab on the right side taskbar

  2. Select the pod you'd like to see logs from.

  3. Right-click the pod and then click Stream Logs. Alternatively, you can stream logs for individual containers running in pods.

    The Kubernetes Explorer Console displays the logs.

    Streaming logs from a pod using its right-click menu to output logs into the Kubernetes Explorer Console

Adding new features when developing on Kubernetes

If you started a development iteration cycle with Develop on Kubernetes and added more features to your project, you'll see how these changes get deployed to your Kubernetes cluster without stopping and removing the deployment, manually building and tagging the image, or updating the cluster.

If you're following along with the Guestbook app:

  1. Open the 'FrontendController.java' file from src/main/java/cloudcode/guestbook/frontend and add this new endpoint to the FrontendController class:

     @RequestMapping("/greeting")
     @ResponseBody
     public String greeting(@RequestParam(value="name", defaultValue="World") String name) {
        return String.format("Hello from Kubernetes with IntelliJ, %s!", name);
     }
     ```
    
  2. Add the necessary imports for the new annotations, RequestMapping and ResponseBody.

  3. Save the changes (Ctrl/Cmd+S) or build the project (use Build > Build Project menu).

    You can watch the progress and deployment logs in the console window. After the changes are propagated, confirm the updates by visiting the new endpoint URL: localhost:8080/greeting.

    Viewing the newly created endpoint in a browser

  4. To end the continuous development session, click the Stop button.

    The plugin deletes all Kubernetes resources used for the development session.

Storing secrets

If your code includes potentially sensitive data like API keys, passwords, and certificates, it is recommended you store them as secrets. With Cloud Code, you can securely store these secrets in Secret Manager and programmatically fetch them when you need them. For a detailed look at how you can create and manage secrets with Cloud Code, see the Secret Manager guide.

Viewing resource details

For keeping track of the status of your Kubernetes resources, you can use the Kubernetes Explorer, accessible from the side panel on the right. Alternatively, you can access the Kubernetes Explorer using Tools > Cloud Code > Kubernetes > View Cluster Explorer.

Kubernetes Explorer panel open using the tab on the right side taskbar

With the Kubernetes Explorer, you can access information about your clusters, nodes, workloads, and more, and set an active context, stream and view logs, and look up resource descriptions.

You can display the details of your deployed resources by right-clicking a resource label in the Kubernetes Explorer and then clicking Describe.

Describe option available when right-clicking an appropriate resource in the Kubernetes Explorer panel and choosing Describe

Configuration

When using the Develop on Kubernetes run configuration, you can customize your deployment by configuring available settings. Access the configuration options by selecting the run configuration from the dropdown and then selecting Edit Configurations.

Skaffold options

  • Skaffold configuration - selects a skaffold.yaml configuration file. Will be automatically detected if you have a skaffold.yaml in your project.
  • Deployment profile - selects a profile from the available options configured in your skaffold.yaml file.
  • Environment variables - allows you to configure additional environment variables to be passed to the Skaffold deployment process. Skaffold flags can also be configured as environment variables to be used in this field. Refer to the Skaffold CLI reference documentation for a comprehensive list of available Skaffold environment variables.
  • Verbosity - allows you to set your output verbosity level at trace, debug, info, warn, error, or fatal. The default verbosity level is warn.

Kubernetes options

  • Deployment Context - represents the Kubernetes context with which your application is deployed. The default behavior, if a deployment context is not specified, is deploying to your current system context if one exists.

    If you'd rather not deploy to the current context, under the Deployment section of Run/Debug settings, you can choose to:

    • Deploy locally to a minikube cluster - starts a Cloud Code-managed minikube cluster to run your app and stops the cluster after deployment stops. If a minikube cluster is already running, Cloud Code uses the existing minikube cluster for deployment.
    • Switch context and deploy to - changes the current context on your system to your specified context upon deployment.

      Selecting Kubernetes deployment context in a Cloud Code Kubernetes configuration

  • Delete deployments when finished - deletes Kubernetes deployments when the process is terminated. This is default behavior. Alternatively, you can toggle this setting to prevent deployments from being deleted

Container image storage options

Refer to the guide on storing your container image for details.

Build settings

Cloud Code supports Docker, Jib, and Buildpacks artifact types. Refer to the Configuring container image build preferences guide to learn about how to set your preferred builder and its relevant settings.

Getting support

To submit feedback or report an issue in your IntelliJ IDE, go to Tools > Cloud Code > Help / About > Submit feedback or report an issue to report an issue on GitHub, or ask a question on Stack Overflow.

You can also join the #cloud-code channel, which is part of the Google Cloud Slack community.