<p>I have a reccuring problem with container in different pods can't communicate with each other.
To make things simple, I created a cluster with only 2 containers in different pods:</p>
<ol>
<li>app that does only one thing: connecting to redis server.</li>
<li>redis-server container</li>
</ol>
<p>To make long story short: I'm keep getting  'connection refused' when trying to connect from the app to redis:</p>
<pre><code>$ kubectl logs app-deployment-86f848b46f-n7672

&gt; app@1.0.0 start
&gt; node ./app.js

LATEST
Error: connect ECONNREFUSED 10.104.95.63:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1133:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '10.104.95.63',
  port: 6379
}
</code></pre>
<p>the app identidfy the redis-service successfully but fails to connect</p>
<pre><code>$ kubectl get services
NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
app-service     ClusterIP   10.107.18.112   &lt;none&gt;        4000/TCP   2m42s
kubernetes      ClusterIP   10.96.0.1       &lt;none&gt;        443/TCP    29h
redis-service   ClusterIP   10.104.95.63    &lt;none&gt;        6379/TCP   29h
</code></pre>
<p>the app code:</p>
<pre><code>const redis = require(&quot;redis&quot;);
const bluebird = require(&quot;bluebird&quot;);
bluebird.promisifyAll(redis);
console.log('LATEST');
const host = process.env.HOST;
const port = process.env.PORT;
const client = redis.createClient({ host, port });

client.on(&quot;error&quot;, function (error) {
    console.error(error);
}); 
</code></pre>
<p>app's docker file:</p>
<pre><code>FROM node
WORKDIR &quot;/app&quot;
COPY ./package.json ./
RUN npm install
COPY . .
CMD [&quot;npm&quot;, &quot;start&quot;]
</code></pre>
<p>for the redis server I tried the default image of redis, and when it didn't work, I used a custome-made image without any bind to a specific ip and no protected-mode.</p>
<p>redis dockerfile:</p>
<pre><code>FROM redis:latest
COPY redis.conf /usr/local/etc/redis/redis.conf
CMD [ &quot;redis-server&quot;, &quot;/usr/local/etc/redis/redis.conf&quot; ]
</code></pre>
<p>Finally, I've created 2 deployments with respected ClusterIP services:</p>
<p>app deployment:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: app
  template:
    metadata:
      labels:
        component: app
    spec: 
      containers:
      - name: app
        image: user/redis-app:latest
        ports:
          - containerPort: 4000
        env:
          - name: HOST
            valueFrom:
              configMapKeyRef:
                name: app-env
                key: HOST
          - name: PORT
            valueFrom:
              configMapKeyRef:
                name: app-env
                key: PORT
</code></pre>
<p>app service:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: app-service
spec:
  type: ClusterIP
  selector:
    component: app
  ports:
    - port: 4000
      targetPort: 4000
</code></pre>
<p>env file:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: app-env
data:
   PORT: &quot;6379&quot;
   HOST: &quot;redis-service.default&quot;
</code></pre>
<p>redis deployment:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      db: redis
  template:
    metadata:
      labels:
        db: redis
    spec: 
      containers:
        - name: redis
          image: user/custome-redis:latest
          ports:
            - containerPort: 6379
</code></pre>
<p>redis service:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: redis-service
spec:
  type: ClusterIP
  selector:
    component: redis
  ports:
  - protocol: TCP
    port: 6379
    targetPort: 6379
</code></pre>
<p>Originally, I used Windows enviorment with WSL2 and Kubernetes running over docker with Docker Desktop installed. when it failed, I've provisioned a centos8 vm over virtualbox and installed kubernets with minikube - got the same results..</p>
<p>any ideas?....</p>

<p>Posting an answer out of comments since David Maze found the issue (added as a community wiki, feel free to edit)</p>
<p>It's very important to match labels between pods, deployments, services and other elements.</p>
<p>In the example above, there are different labels used for <code>redis</code> service:</p>
<p><code>component: redis</code> and <code>db: redis</code> which caused this issue.</p>
