How to Develop and Debug Ruby Applications in Kubernetes

Image for post
Image for post

Kubernetes is an open-source project for automating deployment, scaling, and management of containers. It has rapidly become the standard to run production workloads and the community around it is just great!

But Kubernetes is not designed for developers. The typical development workflow looks like this: write code, build a Docker image, push it to the registry, redeploy, validate your changes and repeat. This flow is not only slow, but it also prevents us from benefiting from standard features of Ruby tools such as hot reloaders or debuggers.

Okteto was created to solve this problem. On this blog post, we will show you how Okteto improves the developer experience in Kubernetes for Ruby developers. You will be able to take full advantage of using an instant development environment, dependency caching, hot-reloading and even the Ruby debugger while developing your application directly in Kubernetes.

Step 1: Deploy the Ruby Sample App

For this post, we’ll be using a very simple Sinatra web app to show you how Okteto speeds up your development cycle. Execute the following commands to get a local version of the app.

The k8s.yml file contains the Kubernetes manifests to deploy the Ruby Sample App. Run the application by executing:

You can deploy to your own Kubernetes cluster or give Okteto Cloud a try. Okteto Cloud is a development platform for Kubernetes applications. Sign up today to get a free developer account with 4CPUs and 8GB of RAM.

deployment.apps “hello-world” created
service “hello-world” created

One command and a dev version of your application is ready to go 😎.

Step 2: Install the Okteto CLI

The Okteto CLI is an open-source project that lets you develop your applications directly in Kubernetes while taking advantage of your language’s toolkit. We will use it to speed up our development cycle instead of using the typical development workflow based on building docker images and redeploying containers.

Install the Okteto CLI by running the following command:



Step 3: Activate your development container in Kubernetes

With the Ruby Sample Application deployed, run the following command:

 ✓ Development container activated
✓ Files synchronized
Namespace: pchico83
Name: hello-world
Forward: 8080 -> 8080
1234 -> 1234
Welcome to your development container. Happy coding!

The okteto up command starts a development container, which means:

  • The Ruby Sample App container is updated with the docker image okteto/hello-world:ruby-dev. This image contains the required dev tools to build, test, debug and run the Ruby Sample App. Check the Dockerfile to see how it is generated.
  • A file synchronization service is created to keep your changes up-to-date between your local filesystem and your development container.
  • Container port 8080 (the application) and 1234 (the debugger) is forward to localhost.
  • A remote shell is started in your development container. Build, test and run your application as if you were in your local machine.

All of this (and more) can be customized via the okteto.yml manifest file:

You can also use the file .stignore to skip files from file synchronization. This is useful to avoid synchronizing vendor dependencies or git metadata.

Working in your development container is the same as working on your local machine. Start the application in hot-reload mode by running the following command:

[2020–03–20 09:23:04] INFO WEBrick 1.6.0
[2020–03–20 09:23:04] INFO ruby 2.7.0 (2019–12–25) [x86_64-linux]
== Sinatra (v2.0.8.1) has taken the stage on 8080 for development with backup from WEBrick
[2020–03–20 09:23:04] INFO WEBrick::HTTPServer#start: pid=66 port=8080

Okteto automatically forwards port 8080 from your local computer to the development container, making it accessible via localhost. Test your application by running the command below in a local shell:

Hello world!

Step 4: Develop directly in Kubernetes

Open the app.rb file in your favorite local IDE and modify the response message on line 7 to be Hello world from the cluster!. Save your changes.

Okteto will synchronize your changes to your development container in Kubernetes and Sinatra automatically detects them and reloads your application. Call your application from a local shell to validate the changes:

Hello world from the cluster!

Cool! Your code changes were instantly applied to Kubernetes. No commit, build or push required 😎!

Step 5: Debug directly in Kubernetes

Okteto enables you to debug your applications directly from your favorite IDE. Let’s take a look at how that works in VS Code, one of the most popular IDEs for Ruby development. If you haven’t done it yet, install the Ruby extension available from Visual Studio marketplace. This extension comes with debug definitions covering the default ruby-debug-ide client setup.

Now, cancel the execution of ruby app.rb from the development container shell by pressing ctrl + c. Rerun your application in debug mode:

Fast Debugger (ruby-debug-ide 0.7.0, debase, file filtering is supported) listens on

Open the Run view in VS Code and run the Connect to okteto debug configuration (or press the F5 shortcut):

Add a breakpoint on app.rb, line 8. Call your application by executing from your local shell:

The execution will halt at your breakpoint. You can then inspect the request, the available variables, etc…

Image for post
Image for post


Kubernetes has the potential to be a great development platform, providing replicable, resource-efficient and production-like development environments. We have shown you how to use Okteto to create a development workflow that also lets you take advantage of features like hot reloaders or debuggers while developing your application directly in Kubernetes.

Accelerate your development and start developing directly in Kubernetes today. Let us know what you think about it on Twitter, or in our #okteto channel in the Kubernetes community Slack.


Kubernetes for Developers

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store