Kubernetes
Kubernetes is a container orchestration engine for the deployment, scaling, and management of containerized applications. Install and enable the Kubernetes plugin for IntelliJ IDEA Ultimate to add the following features for managing your Kubernetes cluster:
Coding assistance for Kubernetes resource configuration files.
Coding assistance for Helm charts and templates.
Validation of custom resources with custom resource definition (CRD) specifications.
Coding assistance for Kustomize files: field and local file path completion, quick documentation, and navigation between Kustomize files and patches. The list of related Kustomize files appears in the editor at the top of the open Kustomize patch.
Interaction with the cluster from IntelliJ IDEA: use the Services tool window to see all resources of the Kubernetes cluster, jump to relevant resource definitions, view logs for containers running on pods, and much more.
The Kubernetes plugin supports Kubernetes versions 1.6 to 1.31 (you can select the applicable version).
note
The kubectl tool is required for communicating with a Kubernetes cluster. If you use Kubernetes features in IntelliJ IDEA (for example, add a cluster to the Services tool window) but kubectl is not installed on your computer, a notification will appear, providing you with the option to download and install the latest stable version of it.
The kubectl executable will be installed in
/usr (on macOS and Linux) or <home>\.jetbrains (on Windows)./local /bin
This functionality relies on the Kubernetes plugin, which is bundled and enabled in IntelliJ IDEA by default. If the relevant features are not available, make sure that you did not disable the plugin.
note
The Kubernetes plugin is not available in IntelliJ IDEA Community Edition.
Press CtrlAlt0S to open settings and then select Plugins.
Open the Installed tab, find the Kubernetes plugin, and select the checkbox next to the plugin name.
IntelliJ IDEA uses the default kubectl (and helm if you use it) executables as determined by the PATH
environment variable. If you install Kubernetes or Helm in custom directories, you can manually specify the path to them.
In the Settings dialog (CtrlAlt0S) , select Build, Execution, Deployment | Kubernetes.
In the Path to kubectl executable field, specify a path to the kubectl executable file.
In the Path to helm executable field, specify a path to the helm executable file.
Click Test to check the file location. If it's not found, you can either manually check the file location, or click Install, and IntelliJ IDEA will download and install missing software.
Information about clusters is stored in a kubeconfig file. IntelliJ IDEA detects the default kubeconfig file, which is usually $HOME/.kube/config
(this location can be changed by the KUBECONFIG
environment variable). If you want IntelliJ IDEA to get information about clusters from custom kubeconfig files and not just from the default one, you can specify them in the IDE settings. You can either apply it globally or use a different file for each project.
In the Settings dialog (CtrlAlt0S) , select Build, Execution, Deployment | Kubernetes.
Under Configuration, click and specify the path to a
kubeconfig
file.If you want to use the configuration file in all projects, select Global in the Scope column. To use it only in the current project, keep the Project scope.
When you add a file, IntelliJ IDEA validates its syntax and reports errors, if any.
tip
Besides kubeconfig files specified in the IDE settings, you can also add clusters from other custom kubeconfig files and from the clipboard.
IntelliJ IDEA provides completion for configuration key values, navigation to relevant selectors and definitions via gutter icons, specialized inspections that check for deprecated values and required keys, and other assistance features. These depend on the version of the API you are using. The Kubernetes plugin supports Kubernetes versions 1.6 to 1.31. By default, IntelliJ IDEA sets it to the latest version. However, if your resources use an earlier version, you can change it.
In the Settings dialog (CtrlAlt0S) , select Languages & Frameworks | Kubernetes.
Change the Kubernetes API version and Kustomize version options as necessary.
The Kubernetes plugin provides rich support for resource configuration files in YAML, and only basic support for the JSON format.
Feature | YAML | JSON |
---|---|---|
Supported | Supported | |
Supported | Supported | |
|
| |
Predefined templates for common resource kinds | No predefined live templates | |
Supported | Not supported | |
Supported | Not supported | |
Label definitions and selectors | Navigation using gutter icons, find usages, and renaming | Not supported |
Enhancements of the original Kubernetes model | Enums instead of plain strings where applicable | None |
IntelliJ IDEA recognizes Kubernetes resource configuration files using the following mandatory fields:
apiVersion
: identifies the versioned schema of the object representationkind
: identifies the resource type (for example,Service
,Pod
,Deployment
, and so on)
If both of the previous fields are present in a YAML or JSON file, IntelliJ IDEA will mark the file with the corresponding Kubernetes icon and enable all available features.
With IntelliJ IDEA, you can quickly create configuration files for some of the most popular resources in Kubernetes.
In the Project tool window Alt01, right-click a folder, select New or press AltInsert, and then select Kubernetes Resource.
In the Name field, type your resource name and select the file template from the list.
This will create a new file with its contents based on the selected file template.
Click to create the resource in a cluster. To change the target cluster, click .
Alternatively, in YAML files, you can use predefined live templates, for example:
kconfigmap
: Kubernetes ConfigMapkcronjob
: Kubernetes CronJobkdeployment
: Kubernetes Deploymentkingress
: Kubernetes Ingresskpod
: Kubernetes Podkresource
: Kubernetes Resource from Scratchkservice
: Kubernetes Service
tip
To view the list of all live templates for Kubernetes resources, edit them or create new ones, open the Settings dialog CtrlAlt0S, select Editor | Live Templates, and expand the Kubernetes group in the list.
IntelliJ IDEA validates your Kubernetes files against the Kubernetes API schema. This includes checking it for required keys or possible types of resource.
If your file contains apiVersion
and kind
, but it is not a Kubernetes file, you can disable such validation. You can suppress inspections and change their scope and severity in Settings | Editor | Inspections | Kubernetes. Or you can mark a file with a special directive to disable validation in it:
On top of a resource configuration file, add
# nonk8s
.Alternatively, if you already have a warning about an unknown resource, right-click it in the Problems tool window and select Show Quick-Fixes | Mark this file as non-Kubernetes.
Use the Services tool window to view your cluster, switch between namespaces, and modify the cluster resources.
To interact with Kubernetes clusters, add clusters in the Services tool window.
Open the Services tool window: select View | Tool Windows | Services or press Alt08.
Right-click a Kubernetes node in the Services tool window and select Add Clusters. Alternatively, click and select Kubernetes | Add Clusters.
Next, select the source for Kubernetes clusters to be added:
From Default Directory: get clusters from the default location (usually
$HOME/.kube/config
).From Custom kubeconfigs: select any kubeconfig file from your computer.
Paste kubeconfig Content: paste the kubeconfig content into the textarea that opens.
In the Add Clusters window that opens, select a cluster that you want to add and click Add Clusters.
Added Kubernetes clusters will be available in the Services tool window. You can open each of them in a separate tab by right-clicking a cluster and selecting Open in New Tab.
To monitor the cluster resources in real-time, you can connect to the cluster.
Connect to the cluster to interact with it in the IDE: follow logs, preview resources, view their configuration files, and get live updates when they are modified. Without connecting to the cluster, you can modify its resources in the editor.
Open the Services tool window: select View | Tool Windows | Services or press Alt08.
If you don't have clusters in the Services tool window, add a cluster.
Right-click a cluster and select Connect Cluster.
The kubeconfig file contains information about clusters, users, namespaces, and authentication.
Open the Services tool window: select View | Tool Windows | Services or press Alt08.
Select a cluster and click (Open kubeconfig File in Editor) on the toolbar. The action is also available when you right-click any Kubernetes object in the Services tool window.
This will open the kubeconfig file in a new tab of the editor. To change the default file opened by this action, you can specify a path to another file in Path to kubeconfig file.
When you change your kubeconfig file, the configuration is automatically reloaded. You can also reload it manually or disable automatic reload by right-clicking a cluster or any Kubernetes object and selecting More | Reload Configuration Automatically.
tip
By default, the maximum kubeconfig file size is limited to 10 MB. You can change this limit in Settings | Advanced Settings | Kubernetes | Maximum size of kubeconfig file to load in megabytes.
Kubernetes namespaces let you logically isolate resources within your cluster. With IntelliJ IDEA, you can quickly switch between namespaces.
Open the Services tool window: select View | Tool Windows | Services or press Alt08.
Right-click your cluster or any resource, select Namespaces (or click on the toolbar), and select the required namespace.
To view resources of all namespaces, select All Namespaces.
tip
If you want some of the namespaces to be displayed on top of the list, you can mark them as favorite by clicking .
note
If you don't have access to namespace resources due to the role-based access control, you can set up your custom namespace in Build, Execution, Deployment | Kubernetes | Namespaces. You can also quickly open this setting via the Customize Namespaces action, which is available if namespaces cannot be loaded from the cluster.
When you create a resource file locally, you can select the cluster to which to apply the resource by clicking . You can also choose it in advance, in IntelliJ IDEA settings.
In the Settings dialog (CtrlAlt0S) , select Languages & Frameworks | Kubernetes.
In the Cluster to use list, select a cluster to be used when applying local Kubernetes resources.
Open the Services tool window: select View | Tool Windows | Services or press Alt08.
Right-click a resource and select View YAML.
This will open the configuration file of the selected resource in a new tab of the editor. When you change a field, modified lines are highlighted in the gutter. You can click the highlighted area in the gutter to quickly preview or rollback changes.
Click to apply changes to the current cluster and namespace.
When you modify a resource configuration file, a toolbar appears at the top right. It lets you apply the changes, delete the resource, preview the diff, and roll back the changes.
note
Changing some of the Kubernetes object fields may result in creation of new objects. For example, if you change the resource name, applying this change will create a new resource. Or, if you change the namespace, applying this change will create a new resource in the specified namespace.
You can delete a resource in any of the following ways:
In the Services tool window, right-click a resource and select Delete (Current Cluster Not Configured).
In the Services tool window, select a resource and click (Delete Resource) on the toolbar.
If the resource YAML file is opened in the editor, hover over it and click . You can also click here to change the cluster where you want to delete the resource.
With port forwarding in Kubernetes, you can forward traffic from a local port on your computer to a port on a Kubernetes pod. IntelliJ IDEA lets you manage port forwarding: forward one or more local ports to remote ports, view the list of all forwarding sessions in your cluster, stop and restart forwarding sessions.
Open the Services tool window: select View | Tool Windows | Services or press Alt08.
Right-click a pod and select Forward Ports.
In the Forward Ports window that opens:
In the Addresses field, enter addresses to listen on.
In the Ports field, enter ports in the
<local port>:<remote port>
format, for example,8888:5000
to listen on local port 8888 and forward data to/from remote port 5000.
To view all active forwarding sessions, expand Network | Port Forwarding under your Kubernetes cluster.
To terminate a port forwarding session, right-click it and select Stop Port Forwarding or click on the toolbar. To restart a stopped forwarding session, right-click it and select Restart Port Forwarding or click on the toolbar.
With IntelliJ IDEA, you can quickly create Kubernetes Secrets.
Open the Services tool window: select View | Tool Windows | Services or press Alt08.
Select a cluster, expand Configuration, right-click Secrets, and select Create New Secret.
In the Create New Secret window that opens, specify the secret name, type, and namespace. To speed up secret creation, IntelliJ IDEA adds required data or annotation keys depending on the selected secret type.
In the Data and Annotations section, click Value and enter values for existing keys, or you can click and choose the way to provide values:
Add Manually to manually enter the value.
Use File Data to select a file (for example, an SSH key file or a Docker config.json) to use the file contents as the value.
You can view all your Secrets in the Services tool window, under Configuration. Once a Secret is created, you can start typing its name in secretName
fields of your Pod configuration. This will invoke completion for Secret names available in the cluster or in your project.
To keep IntelliJ IDEA synchronized with your clusters, use the following actions:
Reload Configuration to get the latest changes in your kubeconfig file.
Refresh Resources to get the latest changes in your Kubernetes resources. This is usually done automatically, provided you have the necessary permissions.
By default, the configuration is automatically reloaded when you change your kubeconfig file. You can still reload it manually.
Open the Services tool window: select View | Tool Windows | Services or press Alt08.
Right-click a cluster and select More | Reload Configuration.
If you want to disable automatic reload, clear the Reload Configuration Automatically option.
You can also check this setting in the IDE settings (CtrlAlt0S), in Build, Execution, Deployment | Kubernetes | Reload configuration automatically.
If you have connected to a cluster, any changes you make to its resources will be automatically reflected in the IDE. If your resources are not automatically updated (due to missing rights of your cluster role), there is a message about automatic refresh being forbidden in the Services tool window. In this case, you can refresh resources manually.
Open the Services tool window: select View | Tool Windows | Services or press Alt08.
Right-click a group of resources and select Refresh or click CtrlF5.
tip
Use the kubectl auth can-i command to check your access rights. For example, to check if you are allowed to manually get information about pods (required for the Refresh action), run:
kubectl auth can-i get pods
To check if you are allowed to get automatic updates on pods, run:
kubectl auth can-i watch pods
With IntelliJ IDEA, you can view cluster logs and logs from selected resources. You can filter them by date, source, and specific values in log messages.
Open the Services tool window: select View | Tool Windows | Services or press Alt08.
Select the log source in one of the following ways:
To view logs for all resources, select your Kubernetes cluster and click (Follow Log) on the toolbar of the Services tool window.
To view logs for a particular resource, select the resource and click (Follow Log) on the toolbar of the Services tool window. Alternatively, right-click a resource and select Follow Log.
If multiple containers exist in the pod, select the one you want to follow logs for from the displayed list of containers.
This will live tail logs of the selected resource with the --follow=true
flag and open them in a new editor tag.
Once you've opened logs, you can refine the log list using the following filters at the top of the editor:
(Open Pattern Matching): enter or select values or patterns that you want your log data to match. For example, if level information is present in your logs, you can select
warn
,error
, or other level values to show only logs corresponding to these levels.(Select Log Sources): select your cluster resources for which you want to show logs.
(Filter by Date and Time): select a time range for which you want to show logs.
(Select Log Fields): select whether you want to show log timestamps, source, and messages.
In the input field on top of the editor tab, enter values from log messages. Click to use regular expressions and to make the search case-sensitive.
To discard all the applied filters (except sources) and show all logs, click (Clear All Log Filters).
Open the Services tool window: select View | Tool Windows | Services or press Alt08.
Select a resource and, on the right side of the Services tool window, (Download Log) to save the log file.
You can configure log saving options in the IDE settings (CtrlAlt0S) under Build, Execution, Deployment | Kubernetes | Logs:
If you want to save logs in a location other than Scratches, specify a directory in Path to download logs to. Or select Ask where to save log before downloading to prompt you for the location every time you save logs.
If you want to include the log timestamp in the filename, select Append timestamp to log file name.
When the logs are open in the editor, you can use filters to refine them and then download the logs with the filters applied.
At the top of the editor, click .
This will download logs taking into account the applied filters.
Helm is a tool for managing Kubernetes applications. Helm charts are packages of pre-configured resource definitions that you run inside a Kubernetes cluster. A chart contains a description of the package Chart.yaml and one or more templates used to generate Kubernetes manifest files.
note
The Go Template plugin is required for Helm template syntax support.
note
If you use Helm features (for example, create a chart) but Helm is not installed on your computer, a notification will appear, providing you with the option to download and install the latest stable version of it. Helm will be installed in
/usr (on macOS and Linux) or <home>\.jetbrains (on Windows)./local /bin
Coding assistance for Helm charts and templates includes code completion, refactorings, inspections, quick-fixes, and quick documentation. Code completion includes values of dependencies from the specified repository (by default, from Helm Hub).
In Go template directives, IntelliJ IDEA provides completion for Helm built-in objects and for values passed from a values.yaml
file or from a custom values file. You can press Ctrl0B to navigate to a source of object values, for example, to a child chart value imported into a parent chart.
In template objects, you can use code folding: press CtrlNumPad + and CtrlNumPad - to toggle between values and directives. You can also hover over a value to expand and show the directive.
You can also use gutter icons to navigate between label definitions and label selectors, and between overridden and overriding values.
In the Project tool window, right-click a folder and select New | Helm Chart.
In the Create New Helm Chart window that opens, enter a name for the chart.
This runs the helm create command, which adds all the basic files required to get started:
.helmignore: Patterns to ignore when building packages
Chart.yaml: A basic chart description with metadata
values.yaml: Default values for chart templates
charts/: Directory for sub-charts
templates/: Directory for chart definitions
_helpers.tpl: Partials and functions for your templates
NOTES.txt: Information that is printed out after a chart is deployed
deployment.yaml: Example Kubernetes deployment definition
ingress.yaml: Example Kubernetes ingress definition
service.yaml: Example Kubernetes service definition
If a template file is opened in the editor, click on the right side of the editor.
Alternatively, right-click the template file in your project, point to Helm, and select Helm Template.
This runs the helm template command that renders a chart template. The rendered preview opens inside the diff viewer to compare it with the original template file.
Right-click the chart, point to Helm, and click Helm Dependency Update.
This runs the helm dependency update command.
In Helm 2, dependencies should be specified in the requirements.yaml file. This action also generates or updates requirements.lock.
In Helm 3, dependencies should be specified in the Chart.yaml file. If you specify the dependencies in the wrong file, IntelliJ IDEA provides an inspection with a quick-fix to move them.
There is also a gutter icon for updating dependencies in both the requirements.yaml and Chart.yaml files respectively.
Right-click the chart, point to Helm, and click Helm Lint.
This runs the helm lint command that executes a series of tests to discover possible problems without actually installing the chart.
If you extend the Kubernetes cluster with custom resources, IntelliJ IDEA can validate them with custom resource definition (CRD) specifications.
Press CtrlAlt0S to open settings and then select Languages & Frameworks | Kubernetes.
Click and either select a local CRD file or specify a URL. Then click OK.
Use and to rearrange the list of CRD files. This defines the priority for conflicting definitions: IntelliJ IDEA will use the lowest one if it is defined in more than one file.
By default, CRDs are applied to the current project only. Change the Scope: option to IDE
if you want a certain CRD to be available for any project that you open with this IDE instance.
note
When you apply changes, IntelliJ IDEA automatically downloads newly added CRDs from the specified URLs. It will download other modified CRDs only as the model reloads, which happens whenever you open the project or change other Kubernetes settings (for example, the order of CRDs), and it has been more than three hours since the last model reload. If it has been less than three hours since the last model reload, you can force a reload on the current model using the Reset Schema Cache button.
To load the CRD from the running Kubernetes cluster, enable Use API schema from the active cluster if available.
tip
By default, the maximum size of a CRD file is limited to 50 MB. You can change this limit in Settings | Advanced Settings | Kubernetes | Maximum size of CRD YAML file to load in megabytes.
You can view CRDs for the current cluster, including all their applied resources, under the Kubernetes node of the Services tool window.
The Kubernetes plugin supports CRD files of the following types:
The following example shows a simple CustomResourceDefinition specification for a custom resource stable.example.com/v1
of the kind CronTab
. Obligatory fields to identify the resource are metadata.name
, spec.group
, spec.versions
, and spec.names
.
note
Currently, not all fields from the OpenAPI schema can be used for validation (see
pattern
,minimum
, andmaximum
fields undervalidation.openAPIV3Schema
in the example). For more information, refer to CRD validation restrictions.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: crontabs.stable.example.com # Obligatory field to identify the resource
spec:
group: stable.example.com # Obligatory field to identify the resource
versions: # Obligatory field to identify the resource
- name: v1
served: true
storage: true
scope: Namespaced
names: # Obligatory field to identify the resource
plural: crontabs
singular: crontab
kind: CronTab
shortNames:
- ct
validation:
openAPIV3Schema: # Schema for validating custom objects
properties:
spec:
properties:
cronSpec:
type: string
pattern: '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$' # not supported for validation
replicas:
type: integer
minimum: 1 # not supported for validation
maximum: 10 # not supported for validation
The following example shows a simple OpenAPI v2.0 schema with a CRD specification for a custom resource sample/v1
of the kind Config
. The root definition of the custom resource must contain the x-kubernetes-group-version-kind
field with the specified group, version, and kind. In the example, the root.Definition
object uses a build
property to reference the some.Definition
object.
{
"swagger": "2.0",
"info": {
"title": "Sample Schema",
"version": "sample/v1"
},
"paths": {},
"definitions": {
"some.Definition": {
"description": "Example of a definition.",
"properties": {
"someProperty": {
"type": "string"
}
}
},
"root.Definition": {
"description": "This is the root definition for the resource",
"properties": {
"build": {
"$ref": "#/definitions/some.Definition"
}
},
"x-kubernetes-group-version-kind": [
{
"group": "sample",
"kind": "Config",
"version": "v1"
}
]
}
}
}
IntelliJ IDEA does not support the following OpenAPI v3 schema features:
multipleOf
maximum
exclusiveMaximum
minimum
exclusiveMinimum
maxLength
minLength
pattern
maxItems
minItems
uniqueItems
maxProperties
minProperties
allOf
oneOf
anyOf
not
format
default
nullable
readOnly
writeOnly
xml
externalDocs
example
deprecated
If you use the features described here frequently, the following tips may be helpful:
You can assign a keyboard shortcut for Kubernetes actions.
In the Settings dialog (CtrlAlt0S) , select Keymap.
Type
kubernetes
in the search field, then double-click an action to set a shortcut for it.
Alternatively, you can use the Find Action dialog CtrlShift0A, type the necessary action and, and press AltEnter.
For example, you can assign a shortcut to Interact with Cluster to quickly open the context menu while modifying a resource configuration file.
By default, IntelliJ IDEA uses code folding to render value references in Helm templates and definitions in Kubernetes configuration files as the actual values. You can click the value to expand it or press CtrlNumPad + and CtrlNumPad - to toggle folding. If you want to see the references and definitions expanded by default, do the following:
In the Settings dialog (CtrlAlt0S) , select Editor | General | Code Folding.
On the Code Folding page, clear the necessary checkboxes:
Kubernetes: value references in Helm templates
Kubernetes: EnvVar definitions in YAML files
Kubernetes: ExecAction definitions in YAML files
Thanks for your feedback!