Tutorial: deploy your application to a minikube cluster
Running Kubernetes locally is especially useful for prototyping, testing deployments, and learning Kubernetes workflows. Using the Docker and Kubernetes support available in RubyMine, 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:
Docker Desktop running
Enable required plugins
The functionality used in this tutorial relies on the following plugin:
The plugin is bundled and enabled in RubyMine by default. If the relevant feature is not available, make sure that you did not disable the plugin.
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.
Create a Rails application
To create a Rails application from scratch, do the following:
Run RubyMine and click New Project on the Welcome Screen.

In the New Project dialog, select Application in the Rails group Ruby on Rails in the Project Type group on the left pane.
Specify the following settings:

Name: specify a name for the project (rails-helloworld in our case).
Location: specify a path to the directory in which you want to create the project. By default, RubyMine creates a directory with the same name as the project.
Interpreter: select a Ruby interpreter that you want to use in your project.
Rails version: select a Rails version that you want to use in your project. If the Rails gem is not installed in the selected interpreter or the necessary Rails version is missing, click
in the field. Wait until RubyMine downloads all available Rails versions and select the necessary version from the dropdown. Click OK to continue.

If the selected version is not installed yet, RubyMine will install it upon project creation.
Extra options: provide additional Rails options for project creation in the Extra options field.
For example, you can specify arguments that you will normally use to append the
rails newcommand:--skip-teststo skip creation of test files,--skip-action-mailerto skip Action Mailer files,--skip-action-cableto skip Action Cable files, and so on.To get a full list of Rails options compatible with the Rails version in use, run the
rails new --helpcommand.
Click Create to close the New Project dialog.
RubyMine creates a new Rails application, installs the gem dependencies mentioned in Gemfile, and installs JavaScript dependencies mentioned in the project's package.json file. You can see this process in the Run tool window.

After installing all dependencies, you can see the project structure in the Project tool window (Alt+1) on the left. On the right, RubyMine automatically opens the main project files in the editor.

If you have Git installed in your operating system, generating a new Rails application also initializes a Git repository. You can learn how to work with Version control systems in RubyMine from the Version control section.
Now we have a functioning Rails application. To see it in action, you need to start a web server. Perform the following steps to do this:
Click the Run icon in the upper right corner.
RubyMine will show the process of preparing the application to run.

Open http://127.0.0.1:3000 in your browser to see the Rails default information page.

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.
Build the Docker image
Form the Project view, open Dockerfile in the editor.
Edit the file:
Change
ENV RAILS_ENV="production" \ BUNDLE_DEPLOYMENT="1" \ BUNDLE_PATH="/usr/local/bundle" \ BUNDLE_WITHOUT="development"to
ENV RAILS_ENV="development" \ BUNDLE_PATH="/usr/local/bundle"Change
EXPOSE 80 CMD ["./bin/thrust", "./bin/rails", "server"]to
EXPOSE 3000 CMD ["./bin/rails", "server", "-b", "0.0.0.0", "-p", "3000"]
In the gutter inside the Dockerfile, click
and select New Run Configuration.
In the Edit Run Configuration dialog, specify
rails-minikube-appin the Image tag field andrails-minikubein the Container name field. Then, click Run.
RubyMine creates a Dockerfile run configuration, which builds an image from the Dockerfile and then runs a container based on that image. To follow the whole process, open the Log tab in the Services tool window.
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 RubyMine.
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, providing a lightweight environment well suited for local development.
Add the minikube cluster to RubyMine
Open the Services tool window: go to or press Alt+8.
Select the Kubernetes node, click the Add Cluster button, and then select From Default Directory from the context menu.

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, RubyMine 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
Earlier in the tutorial, you already built the application image locally. However, the minikube cluster cannot automatically access images from your local Docker daemon. You need to load the image into minikube to make it available.
Load the Docker image into 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 load <image tag>where <image tag> is the value specified in the Run/Debug configuration as described above. In our example it should be:
minikube image load hello-world-docker-appValidate that the
rails-minikube-appimage is available in your cluster by running:minikube image ls | grep rails-minikube-appYou should see
docker.io/library/rails-minikube-app:latestin 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
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 as the manifest name, and press Enter.

If prompted, agree to add the file to Git.
Replace the content of the resulting file with the following code:
apiVersion: apps/v1 kind: Deployment metadata: name: rails-minikube labels: app: rails-minikube spec: replicas: 1 selector: matchLabels: app: rails-minikube template: metadata: name: rails-minikube labels: app: rails-minikube spec: containers: - name: rails-minikube image: rails-minikube-app imagePullPolicy: IfNotPresent ports: - containerPort: 3000 protocol: TCP restartPolicy: AlwaysOn 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 as the manifest name, and press Enter.
If prompted, agree to add the file to Git.
Replace the content of the resulting file with the following code:
apiVersion: v1 kind: Service metadata: name: rails-minikube spec: selector: app: rails-minikube ports: - protocol: TCP port: 3000 targetPort: 3000 type: NodePortOn 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 file in the editor.
Click the Forward Ports inlay hint next to the
- containerPort: 8080property.In the Forward Ports dialog, leave the default values and click Forward.
In the file, click the Open in Browser inlay hint.
You have learned how to deploy a Rails application to a local Kubernetes cluster using minikube and RubyMine. 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: