Developing with Kuby
Kuby used to ship with a default environment called "development" that was capable of running your application locally using the copy of Kubernetes that comes with Docker Desktop.
Unfortunately it proved to be too difficult to maintain, so support was removed in version 0.12.0.
Testing with Kind
While Kuby doesn't support developing your application inside Kubernetes, it does support deploying it to a local Kubernetes cluster for testing purposes using Kind.
Kind is a tool that can easily create ephemeral Kubernetes clusters on-the-fly. The kuby-kind gem features a Kuby provider that makes it a snap to deploy to a local cluster.
Configuring the Kind Provider
First, add the kuby-kind gem to your Gemfile and run
bundle install
.Create a development environment and configure Kind as the provider.
require 'kuby/kind'
Kuby.define('my-app') do
environment(:development) do
kubernetes do
provider :kind
end
end
endRun setup
bundle exec kuby -e development setup
Deploy
bundle exec kuby -e development deploy
Sharing Configuration Between Environments
To keep the code focused, the docker do ... end
section was omitted from the example above. Let's look at a more complete example.
We could duplicate configuration from the production environment, but it would be nice if we could share it instead. Configuration sharing can be done with Ruby lambas and instance_exec
. For example:
Kuby.define('my-app') do
shared = -> do
docker do
image_url 'registry.gitlab.com/username/repo'
credentials do
# ...
end
end
end
environment(:production) do
instance_exec(&shared)
kubernetes do
# production provider
provider :linode do
# ...
end
add_plugin :rails_app do
hostname 'myapp.com'
end
end
end
environment(:development) do
instance_exec(&shared)
kubernetes do
# development provider
provider :kind
add_plugin :rails_app do
# make the app available via localhost
hostname 'localhost'
tls_enabled false
end
end
end
end
All the Docker config is defined in one place and applied to each environment.
tip
Given the example code above, the Rails app should be available on localhost after being deployed to the local Kind cluster. If you'd rather use the production hostname instead (myapp.com in the example), you'll need to add an entry in your /etc/hosts file. It is also possible to use a tool like curl
by passing the Host
header, eg:
curl -H 'Host: myapp.com' http://localhost
TLS certificates are not supported by kuby-kind.