Okteto with Ruby
This guide takes the Ruby Sample App through the whole Okteto workflow, in an application environment in your Kubernetes cluster. The Ruby Sample App is a hello world Sinatra service. Its page shows a message, the Ruby version, and the pod that serves it.
The sample is small, but its configuration is optimized, so you can use it as a reference for your own Ruby application. Along the way, the guide points out what makes each step fast in a Ruby project: the cache mount that the build and the tests share, the ignore files that keep every upload small (.dockerignore, .oktetoignore, and .stignore), and sinatra/reloader and rdbg for hot reload and debugging from VS Code.
Prerequisites
- The Okteto CLI, installed and configured to access your Okteto instance. See the installation guide.
- To debug the application: VS Code with the VSCode rdbg Ruby Debugger extension.
Clone the Ruby Sample App and move into its folder. Every command in this guide runs from there:
git clone https://github.com/okteto/ruby-getting-started
cd ruby-getting-started
Build
The Ruby Sample App uses two container images. dev is the image you develop in: it has Ruby, the gems to run and test the application, and the tools to reload and debug it. hello-world is the production image: a slim Ruby image with nothing but the application and the gems it needs at run time. The build section of the okteto.yml file defines both:
build:
dev:
context: .
target: dev
hello-world:
context: .
target: prod
depends_on:
- dev
Both images come from the same Dockerfile. target picks the stage each image builds, and depends_on tells Okteto to build dev first, so hello-world finds its gems in the download cache that dev filled:
FROM ruby:4.0.10-trixie AS dev
# The cache mount keeps Bundler's download cache in the Okteto Build
# Service, which reuses it between builds. The tests of the Okteto
# Manifest use the same cache
RUN --mount=type=cache,target=/usr/local/bundle/cache \
gem install debug -v 1.11.1
ENV APP_ENV=development
WORKDIR /opt/app
COPY Gemfile Gemfile.lock ./
RUN --mount=type=cache,target=/usr/local/bundle/cache \
BUNDLE_FROZEN=true bundle install
COPY . .
FROM ruby:4.0.10-slim-trixie AS prod
ENV APP_ENV=production
WORKDIR /opt/app
COPY Gemfile Gemfile.lock ./
RUN --mount=type=cache,target=/usr/local/bundle/cache \
BUNDLE_FROZEN=true BUNDLE_WITHOUT=test bundle install
COPY . .
CMD ["ruby", "app.rb"]
The Dockerfile installs the debug gem, which provides rdbg for debugging, and the gems in Gemfile.lock before COPY . ., so a code change doesn't install them again. The gems include sinatra/reloader for hot reload. It only works in development mode, which the dev stage sets with APP_ENV=development. The prod stage sets APP_ENV=production and leaves out the test group's gems.
The three RUN instructions mount Bundler's download cache (/usr/local/bundle/cache) as a cache mount, which the Okteto Build Service keeps between builds. When a change to the Gemfile runs bundle install again, Bundler downloads only the gems that changed and takes the rest from the cache. The cache holds only the .gem files that Bundler downloads: the gems themselves are installed in the image, so the application has them at run time.
The build context makes the biggest difference, here and in any application. Every okteto build starts by uploading the Dockerfile's folder to the Okteto Build Service, and the .dockerignore file decides what goes in. The Ruby Sample App's .dockerignore excludes everything and then allows only what the build reads: the Gemfile, Gemfile.lock, the Ruby files, and the static folder with the page.
*
!Gemfile
!Gemfile.lock
!**/*.rb
!static
The upload stays small, and a change to any other file, such as the README or k8s.yml, doesn't rebuild the images.
Deploy
okteto deploy first builds the images that aren't built yet. Okteto pushes them to the Okteto Registry and stores their references in the OKTETO_BUILD_DEV_IMAGE and OKTETO_BUILD_HELLO_WORLD_IMAGE variables.
The Ruby Sample App deploys with a plain Kubernetes manifest. Its deploy section has a single command, which applies k8s.yml with kubectl:
deploy:
- envsubst < k8s.yml | kubectl apply -f -
In k8s.yml, the Deployment's image is the OKTETO_BUILD_HELLO_WORLD_IMAGE variable. envsubst replaces it with the image Okteto built, and then kubectl applies the file.
The deploy has its own ignore file. okteto deploy uploads your folder to the container that runs the command, and the .oktetoignore file decides what goes in. Its deploy section excludes everything except k8s.yml, the only file the command reads, so there's almost nothing to upload. Its destroy section does the same for okteto destroy:
[deploy]
*
!k8s.yml
[destroy]
*
!k8s.yml
To deploy the application, run okteto deploy:
okteto deploy
Okteto builds the two images, runs the deploy command, and prints the application's endpoint:
i Using cindy @ okteto.example.com as context
✓ Image 'registry.okteto.example.com/cindy/ruby-getting-started-dev:okteto' successfully pushed
✓ Image 'registry.okteto.example.com/cindy/ruby-getting-started-hello-world:okteto' successfully pushed
i Running stage 'envsubst < k8s.yml | kubectl apply -f -'
Executing command 'envsubst < k8s.yml | kubectl apply -f -'...
deployment.apps/hello-world created
service/hello-world created
Command 'envsubst < k8s.yml | kubectl apply -f -' successfully executed
i Endpoints available:
- https://hello-world-cindy.okteto.example.com
✓ Development environment 'ruby-getting-started' successfully deployed
Open the endpoint in your browser. The page shows the application's message, the Ruby version it runs on, and the pod that served the request:
Test
The Ruby Sample App has unit tests in test/app_test.rb, written with Minitest and Rack::Test. The test section of the Okteto Manifest defines a test, unit, that runs them:
test:
unit:
image: ${OKTETO_BUILD_DEV_IMAGE}
caches:
- /usr/local/bundle/cache
commands:
- bundle install
- bundle exec ruby test/app_test.rb
artifacts:
- coverage
The test runs with Remote Execution, in a container inside your cluster. The container starts from the development image, so it has the same Ruby version and gems as the Development Container. The first command checks those gems against Gemfile.lock, and the second one runs the tests. If any of the commands exits with a non-zero code, the test fails. When the test finishes, Okteto copies its artifacts, here the coverage folder with SimpleCov's report, to your machine.
The caches entry is the same folder that the Dockerfile mounts, and it's the same cache too: Okteto identifies a cache by its repository, context, and path, and the test and the build share all three. The development image already has the gems in Gemfile.lock, so bundle install has nothing to install. If a gem is missing, Bundler takes it from the cache when the build already downloaded it.
The tests have their own section in the .oktetoignore file, so okteto test uploads only what bundle install and the tests read:
[test]
*
!Gemfile
!Gemfile.lock
!**/*.rb
!static
Run the unit tests with okteto test:
okteto test
i Using cindy @ okteto.example.com as context
i Images were already built. To rebuild your images run 'okteto build'
i Executing test container 'unit'
i Running 'bundle install'
Bundle complete! 7 Gemfile dependencies, 17 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
✓ Command 'bundle install' successfully executed
i Running 'bundle exec ruby test/app_test.rb'
Run options: --seed 58510
# Running:
..
Finished in 0.006317s, 316.6065 runs/s, 949.8195 assertions/s.
2 runs, 6 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Unit Tests to coverage/index.html
Line coverage: 16 / 16 (100.00%)
✓ Command 'bundle exec ruby test/app_test.rb' successfully executed
✓ Test container 'unit' passed
The coverage report is now in the coverage folder, in the root folder of the Ruby Sample App on your machine. Open coverage/index.html in your browser to see which lines the tests run.
Running okteto deploy and okteto test after each change is usually fast enough, especially when a coding agent writes and tests the code on its own. With the Okteto skills, the agent runs this loop in its own Namespace and reports back the tests it ran, the application's endpoints, and a link to that Namespace.
Develop
A Development Container feels like developing on your machine: every change you save reloads the application, and you can attach a debugger. When you run okteto up, Okteto replaces the hello-world Deployment with the Development Container, keeps your local files synchronized with it, and runs the development image's hot reload and debugging tools in your cluster. This step is optional: coding agents work well with the okteto deploy and okteto test loop and don't need a Development Container.
While okteto up is running, a coding agent with the Okteto skills stops building, deploying, and testing, and only edits the code: File Sync copies each change to the Development Container, and hot reload applies it to the running application.
The dev Section
The dev section of the Okteto Manifest defines the Ruby Sample App's Development Container:
dev:
hello-world:
image: ${OKTETO_BUILD_DEV_IMAGE}
command: ruby app.rb
sync:
- .:/opt/app
persistentVolume:
enabled: false
forward:
- 1234:1234
The hello-world key is the name of the Deployment in k8s.yml that the Development Container replaces. This is what each field does:
image: the development image from thebuildsection.command: starts the application. The development image runs Sinatra in development mode, sosinatra/reloaderloadsapp.rbagain on the first request after the file changes.sync: synchronizes the Ruby Sample App's root folder with/opt/app, the development image's working directory.persistentVolume: disables the Development Container's persistent volume, so there's no volume to create and attach. Okteto synchronizes every file on eachokteto up, and the application starts right away, because the gems are part of the development image. The build's cache mount isn't, so abundle installin the Development Container downloads its gems again. For a larger project, keep the Development Container's gems in a persistent volume. Caches in Development Containers explains how.forward: forwards port1234, whererdbglistens, to your machine.
The third ignore file is .stignore, for File Sync. okteto up synchronizes your folder with the Development Container in both directions, and this file leaves out what shouldn't travel. That's the Git metadata, which is large and only matters on your machine, the Bundler settings and gems that each machine keeps in the project folder, and the coverage report that the tests generate inside the Development Container, which would otherwise come back to your machine:
.git
/.bundle
/vendor/bundle
/coverage
.vscode
.idea
.DS_Store
Hot Reload
Run okteto up to replace the hello-world Deployment with the Development Container:
okteto up
Okteto synchronizes your files and starts the application:
i Using cindy @ okteto.example.com as context
i 'ruby-getting-started' was already deployed. To redeploy run 'okteto deploy' or 'okteto up --deploy'
✓ Images successfully pulled
✓ Files synchronized
Context: okteto.example.com
Namespace: cindy
Name: hello-world
Forward: 1234 -> 1234
[2026-11-19 04:04:25] INFO WEBrick 1.9.2
[2026-11-19 04:04:25] INFO ruby 4.0.10 (2026-11-19) [x86_64-linux]
== Sinatra (v4.2.2) has taken the stage on 8080 for development with backup from WEBrick
[2026-11-19 04:04:25] INFO Rackup::Handler::WEBrick::Server#start: pid=83 port=8080
Now change the code. Open app.rb in your IDE, edit the message on line 7, and save the file:
set :message, 'Built, deployed, and tested on Okteto.'
Okteto synchronizes app.rb to the Development Container. sinatra/reloader notices the change on the next request and loads the file again, without restarting the server or printing anything.
A moment later, the page in your browser shows the new message. You don't even have to reload it, because the page asks the service for its info every second. Your change is running in your cluster, and you didn't build an image or redeploy the application.
When you're done, press Ctrl+C to stop Sinatra and exit okteto up.
Debugging with VS Code
To debug the application, start the Development Container with rdbg instead of ruby app.rb: rdbg runs the application with the debugger. Pass the command after --, and it replaces the command in the Okteto Manifest:
okteto up -- rdbg --open --nonstop --host 0.0.0.0 --port 1234 app.rb
--open --host 0.0.0.0 --port 1234 makes rdbg listen for a debugger on port 1234 of the Development Container, and --nonstop starts the application without waiting for the debugger to attach:
DEBUGGER: Debugger can attach via TCP/IP (0.0.0.0:1234)
[2026-11-19 04:06:26] INFO WEBrick 1.9.2
[2026-11-19 04:06:26] INFO ruby 4.0.10 (2026-11-19) [x86_64-linux]
== Sinatra (v4.2.2) has taken the stage on 8080 for development with backup from WEBrick
That's the port okteto up forwards to your machine, and the Ruby Sample App's .vscode/launch.json file tells VS Code to attach to it:
{
"version": "0.2.0",
"configurations": [
{
"name": "Connect to okteto",
"type": "rdbg",
"request": "attach",
"debugPort": "localhost:1234",
"localfsMap": "/opt/app:${workspaceFolder}"
}
]
}
localfsMap maps /opt/app, the path of the code in the Development Container, to the folder you open in VS Code. It's the same path as in the sync field of the Okteto Manifest. If you synchronize your code to another path, change /opt/app to match.
Open the Ruby Sample App in VS Code, go to the Run and Debug view, and run the Connect to okteto configuration. Now add a breakpoint on line 24 of app.rb, the first line of the /api/info route. The page in your browser asks the service for its info every second, so execution stops at the breakpoint right away, and you can inspect the request and the variables.
To end the debugging session, press Ctrl+C. It stops the application and rdbg, and exits okteto up. Then run okteto up again to go back to ruby app.rb.
Stopping the Development Container
When you finish developing, run okteto down. It stops the Development Container and brings back the hello-world Deployment with the production image:
okteto down
i Using cindy @ okteto.example.com as context
✓ Development container 'hello-world' deactivated
Destroy
To delete the application, run okteto destroy. It removes the Ruby Sample App's Deployment and Service from your Namespace:
okteto destroy
i Using cindy @ okteto.example.com as context
i Images were already built. To rebuild your images run 'okteto build'
✓ Development environment 'ruby-getting-started' successfully destroyed
FAQ
How do I set up my own repository the same way?
Use a coding agent with the Okteto skills. Ask it to set up your repository for Okteto: it discovers your services, writes the Okteto Manifest, and validates it with okteto build and okteto deploy.
How do I make builds, deploys, and okteto up faster?
Upload only the files that each command needs: the context upload is key to performance. Every okteto build, okteto deploy, okteto test, and okteto up uploads files from your machine, and three ignore files decide what gets uploaded: .dockerignore for the image builds, .oktetoignore for okteto deploy, okteto test, and okteto destroy, and .stignore for File Sync. A coding agent with the Okteto skills configures them for your application and measures how much faster your builds, deploys, and okteto up get. Optimize Your Application Environment covers these and other optimizations.
Do I need to deploy the whole application in every Namespace?
No. Okteto supports two models, and you choose one for your application:
- Full replica: every service of the application runs in your Namespace. In a monorepo, the
deploysection of the Okteto Manifest deploys every service, as in the quickstart, where one Helm chart deploys the three services of Kube Movies. In a multirepo, each repository has its own Okteto Manifest and lists the other repositories in itsdependenciessection, as in Deploy a Multi-Repo Application with Dependencies. Full replicas are simpler to configure and give you full isolation: nothing one environment does affects the others. Use them for an application with fewer than 20 services. - Overlay Namespace: your Namespace runs only the services you change, and Divert routes every other request to a Shared Namespace that runs the rest of the application. Overlay Namespaces are more cost-effective, faster to deploy, and more reliable, because each environment builds, deploys, and runs only the services it changes. Use them for an application with 20 services or more.
How do I create a Preview Environment of my application for every pull request?
Add a workflow to your CI pipeline that deploys the application in a Preview Environment when a pull request opens or changes, runs okteto test against it, and destroys it when the pull request closes. The workflow uses the Okteto Manifest, so okteto build, okteto deploy, and okteto test work the same way in your CI pipeline, for coding agents, and on developer machines. Follow the guide for GitHub Actions or for GitLab CI/CD.
How do I start each environment with realistic data?
Load the data with a script in your deploy commands, or copy the data of another application environment with a Volume Snapshot, which creates the volumes of your database from a snapshot of its volumes. Data from Volume Snapshots shows how.
How do I create resources outside Kubernetes, such as a cloud database?
Create them in the deploy and destroy commands with your infrastructure as code tool, so every environment gets its own resources. See the Create Cloud Infrastructure with Terraform tutorial, which creates an Amazon S3 bucket for each environment.
Can I access my application environment with kubectl?
Yes. Run okteto kubeconfig to add the credentials of your Okteto Namespaces to your kubeconfig file, and use kubectl as usual: kubectl get pods, kubectl logs, or kubectl describe. See Kubernetes Credentials for how Okteto generates those credentials.