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 change 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 your application, ensure you're set up to deploy your app to your preferred Kubernetes context. This can be specified in your Run on Kubernetes configuration, under 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.
Run on Kubernetes
For a regular run of your application, you can use the Kubernetes run target,
Run on Kubernetes , to build the image and deploy the project to your
Kubernetes cluster. Your project sources and dependencies are not watched, and
the Skaffold process finishes once the image and deployment are complete.
For more information on customizing your deployment, refer to available configuration options.
Continuous development on Kubernetes
Click the run action for Develop on Kubernetes
to start the development cycle on your Kubernetes cluster. Once the development
cycle initiates, 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.
For more information on customizing your deployment, refer to available configuration options.
Previewing your deployed app
Once you click the Run button on your preferred run action, you can view incoming application logs in the output window.
After the deployment starts, you'll see the list of forwarded ports for your deployed application.
Once the deployment is successful, you'll be prompted with a notification stating that your service is now accessible via local URLs. Click 'View' to open the Event Log.
In the Event log, find the port where your application is being served. Click on the link to open your browser with your running application.
View your newly deployed application!
Viewing logs
While you can see a live stream of the logs from running pods within the terminal output as you are developing and running your application, you can also view logs from a specific pod by navigating to the Kubernetes Explorer.
To view logs from a specific pod, follow these steps:
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.
Select the pod you'd like to see logs from.
Right click the pod and select Stream Logs. Alternatively, you can stream logs for individual containers running in pods.
This will output logs to 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:
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); } ```
Add in the necessary imports for the new annotations,
RequestMapping
andResponseBody
.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. Once the changes are propagated, confirm the updates by visiting the new endpoint URL:
localhost:8080/greeting
.Once you're finished, click the Stop button to end the continuous development session. This action causes the plugin to delete 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, refer to 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, it can be accessed using Tools > Cloud Code > Kubernetes > View Cluster Explorer.
With the Kubernetes Explorer, you can access information about your clusters, nodes, workloads, and more, as well as set an active context, stream and view logs, and look up resource descriptions.
You can conveniently run a kubectl describe
on your deployed resources to display
its details by right-clicking its label within the Kubernetes explorer and choosing Describe.
Configuration
When using the Run on Kubernetes and Develop on Kubernetes Run Configurations, you can customize your deployment by configuring available settings. Access the configuration options by selecting the Run Configuration from the dropdown and 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
, orfatal
. The default verbosity level iswarn
.
- Kubernetes options
- Deployment Context - represents the Kubernetes context with which your application will be deployed.
The default behavior is deploying to your current system context.
Alternatively, you can choose to deploy to a fixed context by selecting Switch context and deploy to (under the Deployment section of Run/Debug settings). This option will change the current context on your system to your specified context upon deployment.
- 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
- Deployment Context - represents the Kubernetes context with which your application will be deployed.
The default behavior is deploying to your current system context.
Alternatively, you can choose to deploy to a fixed context by selecting Switch context and deploy to (under the Deployment section of Run/Debug settings). This option will change the current context on your system to your specified context upon deployment.
- 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.