Rails - ActionCable: "action_cable.url" for Kubernetes/Minikube Rails - ActionCable: "action_cable.url" for Kubernetes/Minikube kubernetes kubernetes

Rails - ActionCable: "action_cable.url" for Kubernetes/Minikube


I have an answer: in a Minikube cluster, don't put anything and disable forgery protection, Rails will default the correct value. When Nginx is front of a Rails pod and a standalone ActionCable/websocket pod (the Rails image is launched with bundle exec puma -p 28080 cable/config.ru), if I name "cable-svc" the service that exposes the ActionCable container, and "rails-svc" the one for the Rails container, you need to:

  • in K8, don't set the config for CABLE_URI
  • in the Rails backend, you don't have the URL (unknown 127.0.0.1:some_port), do:
# config.action_cable.url <-- comment thisconfig.action_cable.disable_request_forgery_protection=true
  • in the Nginx config, add a specific location for the "/cable" path:
upstream rails {  server rails-svc:3000;}server {  [...root, location @rails {...}]  location /cable {    proxy_http_version 1.1;    proxy_set_header Upgrade $http_upgrade;    proxy_set_header Connection "Upgrade";    proxy_pass "http://cable-svc:28080";  }}

Check the logs, no more WebSockets in Rails, and Cable responds.