<p>I have a deployment with a php image that connects with a redis deployment in the 6379 port.</p>

<p>The problem is that the php application connects in the host 127.0.0.1 of its own pod, but the redis is in another pod (and have its own ClusterIP service). </p>

<p>I can't change the app code, so I want to redirect the 6379 port of php pod for the same port on the redis port.</p>

<p>How I can do this?</p>

mayconfsbrito
<p>kubernetes uses <a href="http://www.dest-unreach.org/socat/" rel="nofollow noreferrer"><code>socat</code></a> for doing port-forwarding from <code>kubectl</code>, so if they trust it that much, it seems reasonable you could trust it, too.</p>

<p>Place it in a 2nd container that runs alongside your php container, run <code>socat</code> in forwarding mode, and hope for the best:</p>

<pre><code>containers:
- name: my-php
  # etc
- name: redis-hack
  image: my-socat-container-image-or-whatever
  command:
  - socat
  - TCP4-LISTEN:6379,fork
  - TCP4:$(REDIS_SERVICE_HOST):$(REDIS_SERVICE_PORT)
  # assuming, of course, your Redis ClusterIP service is named `redis`; adjust accordingly
</code></pre>

<p>Since all Pods share the same network namespace, the second container will listen on "127.0.0.1" also</p>

<p>Having said all of that, as commentary on your situation, it is a <strong>terrible</strong> situation to introduce this amount of hackery to work around a very, very simple problem of just not having the app hard-code "127.0.0.1" as the redis connection host</p>
