<p>I'm working on the setup of a new Rails project, hosted with Google Kubernetes Engine. Everything was going fine until I switched my deployed server to production mode, with <code>RAILS_ENV=production</code>.</p>
<p>My Kubernetes pods don't reach the ready state anymore. The readiness probe is forbidden to hit the server apparently, since it return a 403 code.</p>
<p>When I run <code>kubectl describe pod &lt;name&gt;</code> on a stuck pod, I get this :</p>
<pre><code>Events:
  Type     Reason     Age                   From               Message
  ----     ------     ----                  ----               -------
  Normal   Scheduled  5m25s                 default-scheduler  Successfully assigned front to gke-interne-pool
  Normal   Pulling    5m24s                 kubelet            Pulling image &quot;registry/image:latest&quot;
  Normal   Pulled     5m24s                 kubelet            Successfully pulled image &quot;registry/image:latest&quot;
  Normal   Created    5m24s                 kubelet            Created container front
  Normal   Started    5m24s                 kubelet            Started container front
  Warning  Unhealthy  11s (x19 over 4m41s)  kubelet            Readiness probe failed: HTTP probe failed with statuscode: 403
</code></pre>
<p>The return of <code>kubectl logs &lt;name&gt;</code> for this pod shows indeed no request from the probe.</p>
<p>But when I launch a console with <code>kubectl exec -it deploy/front -- bash</code>, I can make a <code>curl -s http://localhost:3000</code>, which works perfectly, is displayed in the logs and returns 200.</p>
<p>My setup works in development mode but not in production, and so the Rails 6 app config is the main suspect. Something that I don't understand in the production mode of Rails 6 forbid my readiness probes to contact my pod.</p>
<p>Just in case, the readiness part of deployment.yaml :</p>
<pre><code>spec:
  containers:
    - name: front
      image: registry/image:latest
      ports:
      - containerPort: 3000
      readinessProbe:
        httpGet:
          path: &quot;/&quot;
          port: 3000
        initialDelaySeconds: 30
        periodSeconds: 15
</code></pre>

<p>Another potential cause of readiness 403 errors with Rails 6 is the allowed hosts list defined in config.</p>
<p>Typically, you'll have a line of code in <code>config/environments/production.rb</code> that looks something like:</p>
<pre class="lang-rb prettyprint-override"><code>config.hosts &lt;&lt; &quot;www.mydomain.com&quot;
</code></pre>
<p>This leads to the rejection of any requests that come from hosts other than &quot;www.mydomain.com&quot;. The readiness checks come from a private IP address within your cluster so they're going to be rejected given the above config.</p>
<p>One way to get around this is by adding an additional hosts entry that allows traffic from any private IP addresses:</p>
<pre class="lang-rb prettyprint-override"><code>config.hosts &lt;&lt; &quot;www.mydomain.com&quot;
config.hosts &lt;&lt; /\A10\.\d+\.\d+\.\d+\z/
</code></pre>
