<p>I have a pod with a database running. My goal is to initialize the db with k8s Job using Helm Hooks.<br />
I have managed to set up the Job with the schema script.</p>
<p>Unfortunately I have some issues with connecting from <code>command</code> of Job to the existing Pod.</p>
<p>Here's my error:</p>
<pre><code>Connection error: ('Unable to connect to any servers', {'127.0.0.1': error(111, &quot;Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused&quot;)}]
</code></pre>
<p>On the Pod I have Cassandra container running, on my Job I'm using the following command:</p>
<pre><code>command: [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;cqlsh -f /path/to/schema.cql&quot;]
</code></pre>
<p>Do I have to define somehow the way to connect to the Pod? I have a Service with Cassandra running as well.</p>

Forin
<p>Helm hook creates a new pod as part of the hook.You can not use <code>127.0.0.1</code> or <code>localhost</code> to connect to a pod from another pod because they are in different network namespace. You should use the <code>&lt;PODIP&gt;:9042</code> or if the pod is exposed by a service then use the service name i.e <code>&lt;service-name&gt;.&lt;namespace-name&gt;.svc.cluster.local:9042</code></p>
<p>Alternative to helm hook you can use an <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">initcontainer</a> wherein you can use <code>127.0.0.1</code> or <code>localhost</code>.</p>
