Tutorial: Deploy your application to a minikube cluster
In this tutorial, you will learn how to start a local Kubernetes cluster with minikube directly from IntelliJ IDEA and deploy a sample application to it. As part of this process, you will build the application, create a Docker image, and deploy it to minikube.
Running Kubernetes locally is especially useful for prototyping, testing deployments, and learning Kubernetes workflows. Using the Docker and Kubernetes support available in IntelliJ IDEA, you will be able to start the cluster, deploy resources, and inspect your application without leaving the IDE.
Before you start
Before you start, make sure that you have the following installed and configured:
Enable required plugins
The functionality used in this tutorial relies on the following plugins:
The plugins are bundled and enabled in IntelliJ IDEA by default. If the relevant features are not available, make sure that you did not disable any of the plugins.
Press Ctrl+Alt+S to open settings and then select .
Open the Installed tab, find the required plugins, and select the checkboxes next to the plugin names to enable them.
Clone the sample project
To get started, clone the Spring PetClinic application from GitHub or open this project in IntelliJ IDEA if you already have it on your machine.
The source code of the application is hosted on GitHub at https://github.com/spring-projects/spring-petclinic.
In the main menu, go to .
Specify the URL of the repository and click Clone.
In the Open or Import Project dialog, select Gradle project to use Gradle as the main build system for the project.
If necessary, agree to open the cloned project in a new window.
Build the application
Before deploying the application to Kubernetes, you need to build it and package into a container image. In this tutorial, you will use a Gradle task to compile the application source code, run tests, and produce an executable JAR file. This JAR file will later be used when creating a Docker image.
Open the Gradle tool window.
Expand the project node (spring-petclinic), then the Tasks node, and double-click the build task to run it.

Wait for IntelliJ IDEA to finish the task. As a result, the IDE creates the build directory with artifacts in the project root.

Containerize the application
In this step, you will package the built application into a Docker image. Kubernetes will run this image later as a container in a pod.
Create a Dockerfile
In the Project tool window Alt+1, right-click the project root, point to New, and click File.
In the New File dialog, type Dockerfile and press Enter.
Paste the following code to the new Dockerfile:
FROM eclipse-temurin:17-jre WORKDIR /app COPY build/libs/*.jar app.jar EXPOSE 8080 ENTRYPOINT ["java", "-jar", "app.jar"]
The created Dockerfile contains instructions for building a Docker image based on the eclipse-temurin:17-jre image, which provides a lightweight Java 17 runtime environment.
When you build the image, Docker copies the executable JAR file produced by the Gradle build from the build/libs directory of the project into the /app directory inside the container.
When you start a container from the image, Docker runs the java -jar app.jar command, which starts the Spring Petclinic application.
Build and run the image
In the gutter inside the Dockerfile, click
and select Run on 'Docker'.

IntelliJ IDEA creates a Dockerfile run configuration, which builds an image from the Dockerfile and then runs a container based on that image.
Connect to minikube
Now that you have a Docker image with your application, you need to start a local Kubernetes cluster to deploy it to. We will use minikube to run a local, single-node Kubernetes cluster directly from IntelliJ IDEA.
Start minikube with the Docker driver
Open the Terminal tool window: go to or press Alt+F12.
Run the following command to start a local Kubernetes cluster and instruct minikube to use Docker as the virtualization driver:
minikube start --driver=dockerVerify that your cluster is up and running by using the command:
minikube status
Using the Docker driver runs the minikube cluster inside Docker containers, which is lightweight and well suited for local development.
Add the minikube cluster to IntelliJ IDEA
Open the Services tool window: go to or press Alt+8.
Right-click the Kubernetes node and select .
In the Add Clusters dialog, select minikube and click Add Clusters.
The added cluster will become available in the Services tool window.
In the Services tool window, right-click the minikube cluster and select Connect Cluster.

At this point, IntelliJ IDEA is connected to the running minikube cluster and can display its Kubernetes resources. You can explore namespaces, nodes, and other cluster objects directly from the Services tool window.
Deploy the application
Although you already ran the application container locally to verify that it works, Kubernetes starts its own containers from the image. The image needs to be available to the minikube cluster before you can deploy the application.
Build the Docker image in minikube
Open the Terminal tool window: go to or press Alt+F12.
Run the following command to build the container image in minikube:
minikube image build -t petclinic:local .Validate that the
petclinic:localimage is available in your cluster by running:minikube image ls | grep petclinicYou should see
docker.io/library/petclinic:localin the output.
Now that the image is available in minikube, the next step is to describe how Kubernetes will run it. Let us create two Kubernetes manifests: Deployment, which helps you run your container in a pod, and Service, which exposes your app so that you can access it from your machine.
Create a Deployment manifest
In the Project tool window (Alt+1) , right-click the project name and select .
In the New Kubernetes Resource dialog, select the Deployment file type, specify
petclinic-deploymentas the manifest name, and press Enter.
Replace the content of the resulting petclinic-deployment.yaml file with the following code:
apiVersion: apps/v1 kind: Deployment metadata: name: petclinic spec: replicas: 1 selector: matchLabels: app: petclinic template: metadata: labels: app: petclinic spec: containers: - name: petclinic image: petclinic:local imagePullPolicy: IfNotPresent ports: - containerPort: 8080On the floating toolbar, select the current cluster and namespace, then click
Apply to deliver the changes to the local cluster.

Create a Service manifest
In the Project tool window (Alt+1) , right-click the project name and select .
In the New Kubernetes Resource dialog, select the Service file type, specify
petclinic-serviceas the manifest name, and press Enter.Replace the content of the resulting petclinic-service.yaml file with the following code:
apiVersion: v1 kind: Service metadata: name: petclinic spec: type: NodePort selector: app: petclinic ports: - port: 8080 targetPort: 8080On the floating toolbar, select the current cluster and namespace, then click
Apply to deliver the changes to the local cluster.
Access the application
Open the Terminal tool window: go to or press Alt+F12.
Run the following command to start the application:
minikube service petclinic
You have learned how to deploy a Spring application to a local Kubernetes cluster using minikube and IntelliJ IDEA. This approach enables quick local testing and experimentation with Kubernetes without requiring a remote cluster.
Next steps
Learn how to work with Kubernetes from these topics: