Skip to content

Plugin to support Kubernetes development in the IntelliJ family of IDEs - in development

License

Notifications You must be signed in to change notification settings

JetDC/google-container-tools-intellij

Repository files navigation

experimental Build Status Build Status Build Status

Google Container Tools for IntelliJ

This plugin adds support for Kubernetes development into the JetBrains family of IDEs, including IntelliJ (both Community and Ultimate editions), GoLand, PyCharm, WebStorm (and others).

Note: This plugin is still in development.

Table Of Contents

Features

  • One click deployment to Kubernetes clusters right from your IDE using Skaffold. Configure Skaffold to use your desired build and deployment strategies: works with kubectl, Helm, Google Cloud Build (for remote builds), Jib and Kanico.
  • Continuous development on Kubernetes. Watches the dependencies of your docker image or Jib Java project for changes, so that on any change, Skaffold builds and deploys your application to a Kubernetes cluster.
  • Automatic discovery and support for project with existing Skaffold configuration, in any language supported by your preferred JetBrains IDE.
  • Initial support for Skaffold configuration file editing and smart templates.

Prerequisites and required dependencies

This plugin uses familiar Kubernetes and container tools to bring you a rich Kubernetes experience in IntelliJ and other JetBrains IDEs. At the minimum, the following tools are expected to be installed and setup on your system and available in the system path:

  • kubectl for working with Kubernetes clusters and managing Kubernetes deployments.
  • Skaffold to support continuous development on a Kubernetes cluster, smart image building and tagging, and an array of supported deployment and build types.
  • Docker for building and pushing your container images. Note: Docker is optional if you are using Jib to build your container images.
  • Configured Kubernetes cluster. It could be a cluster for local development, such as Minikube or Docker Kubernetes cluster, or remote cluster, such as Google Kubernetes Engine cluster. We recommend Minikube cluster for local development.

Installing the plugin into your IDE

If you'd like to try out the plugin pre-release, you can build it from source and install it into your IDE:

  1. Clone this repository to your machine:
    git clone [email protected]:GoogleContainerTools/google-container-tools-intellij.git
  2. Build the plugin from the root of the repository:
    ./gradlew buildPlugin
  3. Find the .zip binary in the root of the repository under:
    build/distributions/google-container-tools-intellij.zip
  4. Install the plugin into your JetBrains IDE:
    1. Go to Preferences/Settings > Plugins
    2. Select the settings gear icon and then Install Plugin From Disk: manual-install
    3. Select the zip from step 3

Getting started

The plugin works in any of the JetBrains family of IDEs. The following shows an example using Kubernetes with Java and Spring Boot in IntelliJ IDEA (Community or Ultimate editions). Follow the installation steps above to install the plugin. Restart your IDE if prompted to activate the plugin.

Before we start, make sure all required dependencies are available on your machine.

Clone the repository to your local machine to get your copy of the repository:

git clone https://github.com/GoogleContainerTools/google-container-tools-intellij.git

Open the hello-spring-boot example from google-container-tools/examples directory with your IntelliJ IDE. You can either point to the directory or to the Maven build file (pom.xml). The project opens and loads:

opened Spring Boot hello world project

This project is a simple web application created with the popular Spring Boot framework. It uses the Jib Maven plugin to build a container image for the project, without needing to create a Dockerfile.

Once the project loads, the plugin will detect the Skaffold configuration and prompt to create the Kubernetes targets. The notification shows:

Kubernetes with Skaffold notification

Click Create run configurations for Kubernetes with Skaffold link to automatically create Kubernetes deployment and continuous development IDE run targets for the project:

Kubernetes with Skaffold pre-configured run targets

Now the new run targets can be used to build the project and deploy it to Kubernetes or develop on Kubernetes cluster continuously. With continuous development, the plugin uses Skaffold to watch the sources and dependencies of your project for changes, so that on any change, Skaffold builds and deploys your application to a Kubernetes cluster.

Specifying image repository

However, before we can deploy and develop, we need to make sure we have access to the image repository where the project image is about to be pushed. By default the project is configured to use Google Container Registry and a development project for the plugin which you probably don’t have access to. Once you have your repository set up (Google Container Registry, DockerHub, private repository, etc.), you can edit the run targets and specify it as a default image repository in run target settings:

specify your repository in run target settings

Note: this step is not required when you work with your own Kubernetes manifests and Skaffold configuration where you specify a repository and an image name that are accessible to you.

Continuous development on Kubernetes

Now you can set up a continuous development iteration cycle in your IDE. Click the run action for Develop on Kubernetes to start development cycle on your Kubernetes cluster:

run target click

The development cycle initiates and console window with the logs opens. The plugin uses Skaffold to build an image for the project, tag it, push it to the configured repository, and then uses kubectl to deploy the project Kubernetes manifests:

develop on Kubernetes console window

Once the build completes, the image is pushed and deployment starts, the console begins to stream logs from your Kubernetes deployment:

Spring Boot logs from Kubernetes deployment

As you can see, Spring Boot application initializes and launches built-in web server. Be default, Spring Boot web server uses port 8080 to serve the content. The plugin makes sure you don’t have to worry about accessing the deployment via remote addresses - all declared container ports are port-forwarded automatically!

automatic port-forwarding

Navigate your browser to localhost:8080 to access the Spring Boot application running on your Kubernetes cluster. Alternatively, use curl command to interact with the application:

browser showing root page of the application

$ curl localhost:8080
Hello, World of Kubernetes with IntelliJ!

You can check the details of the Kubernetes deployment and service using standard Kubernetes CLI commands (kubectl get deploy, etc.) or using Kubernetes dashboard for your Kubernetes cluster. The Kubernetes resources for the project are located in the k8s directory - there is one deployment and one service YAML file.

Adding new features

Now, let’s add more features to our Spring Boot project and see how they get deployed to your Kubernetes cluster without stopping and removing the deployment, manually building and tagging the image, or updating the cluster. Open HelloController.java file from src and add a new HTTP request mapping:

   @RequestMapping("/greeting")
    public String greeting(@RequestParam(value="name", defaultValue="World") String name) {
        return String.format("Hello from Kubernetes with IntelliJ, %s!", name);
    }

Save the changes (Ctrl-S) or build the project (use Build -> Build Project menu or the toolbar icon). The plugin picks up the changes, re-builds the project and image, and deploys the updated image to your Kubernetes cluster. You can watch the progress and deployment logs in the console window. Once the changes are propagated, we can confirm the updates by visiting the newly created endpoint:

browser showing new greeting page of the application

$ curl localhost:8080/greeting?name=User
Hello from Kubernetes with IntelliJ, User!

You can continue adding and testing new features and have them redeployed automatically to your Kubernetes cluster from your IDE on every change. Once you are finished, click stop to end the continuous development session. The plugin deletes all Kubernetes resources used for the development session.

Deployment to Kubernetes

You can use the other Kubernetes run target to build the image and deploy the project to your Kubernetes cluster once. Unlike continuous development, your project sources and dependencies are not watched, and the Skaffold process finishes once the image and deployment are complete.

deploy run target click

Setup existing Kubernetes projects with the plugin

(coming soon)

About

Plugin to support Kubernetes development in the IntelliJ family of IDEs - in development

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 96.6%
  • Shell 2.5%
  • Batchfile 0.9%