# Kuby AnyCable

> A Kuby plugin designed for deploying AnyCable applications.

- URL: https://evilmartians.com/opensource/kuby-anycable
- GitHub: https://github.com/anycable/kuby-anycable
- Authors: Vladimir Dementyev

---

kuby-anycable is a Kuby plugin designed for deploying AnyCable applications and easily making the switch from Action Cable to AnyCable.

This plugin allows you to install all the required AnyCable components to a Kubernetes cluster.

## Usage

Here is the minimal configuration:

```ruby
# kuby.rb

require "kuby-anycable"

# ...

Kuby.define("my-app") do
  environment(:production) do
    #...

    kubernetes do
      add_plugin :rails_app do
        # ...
      end

      add_plugin :anycable_rpc
      add_plugin :anycable_go
    end
  end
end
```

What happens under the hood:

- RPC service definitions are created:
  - The current `rails_app` image is used for the container.
  - The `rails_app` Config Map is attached to the RPC container.
- AnyCable-Go service definitions are created:
  - The latest stable image is used for `anycable-go`.
  - Connected to the RPC service (using [DNS load balancing](https://docs.anycable.io/deployment/load_balancing?id=client-side-load-balancing) by default).
  - Redis URL is inferred from the RPC service `ANYCABLE_REDIS_URL` or `REDIS_URL`.
  - [Concurrency settings](https://docs.anycable.io/anycable-go/configuration?id=concurrency-settings) are adjusted according to the number of RPC servers and their concurrency settings.

Of course, you can customize the resources:

```ruby
add_plugin :anycable_rpc do
  replicas 2
  # Provide Redis URL explicitly.
  redis_url "redis://custom_url"
  # Override gRPC server port (but why?)
  port 50051
  # Expose additional port named 'metrics'
  # (e.g., if you use Prometheus exporter).
  # Disabled by default.
  metrics_port 3030
  # Shortcut for ENV['ANYCABLE_RPC_SERVER_ARGS__MAX_CONNECTION_AGE_MS']
  max_connection_age 300000
  # Shortcut for ENV['ANYCABLE_RPC_POOL_SIZE']
  rpc_pool_size 30
end

add_plugin :anycable_go do
  replicas 2
  # Provide Redis URL explicitly.
  redis_url "redis://custom_url"
  # Override web server port (but why?)
  port 8081
  # Metrics port (enabled by default and exposed as "metrics")
  metric_port 5001
  # Provide path to RPC server explicitly
  rpc_host "my-app-rpc:50051"
  # WebSocket endpoint path
  ws_path "/cable"
  # AnyCable-Go Dockerimage
  image "anycable/anycable-go:1.1"
  # Specify ENV['ANYCABLE_RPC_CONCURRENCY'] explicitly
  rpc_concurrency nil
  # Use a separate hostname for AnyCable-Go
  # (disabled by default)
  hostname nil
end
```
