<p>I'm trying to deploy a <strong>redis</strong> pod to allow my staging app connecting to it (to avoid using Redis Managed Service in staging ENV).</p>

<p>I'm using <strong>Google Cloud Platform</strong> with <strong>GKE</strong>, so managed k8s cluster...</p>

<p>However, when I try to make a connection (from another redis pod only to test) I receive this message :</p>

<pre><code>Could not connect to Redis at redis-cip.redis.svc.cluster.local:6379: Connection refused
</code></pre>

<p>The command that I use to make the test is this :</p>

<pre><code>redis-cli -h redis-cip.redis.svc.cluster.local -p 6379 
</code></pre>

<p>The URL is composed by :</p>

<ul>
<li>redis-cip: is the service ClusterIP that I use to allow connection to my redis POD</li>
<li>redis : is the namespace where is hosted redis POD</li>
</ul>

<p>Moreover,I use, as is already written in some question on StackOverflow, this redis configuration :</p>

<pre><code>protected-mode no
maxmemory 32mb
maxmemory-policy allkeys-lru
</code></pre>

<p>In attached the full k8s mapping :</p>

<p>ConfigMap :</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-configmap
  namespace: redis
data:
  redis.conf: |
    protected-mode no
    maxmemory 32mb
    maxmemory-policy allkeys-lru
</code></pre>

<p>Redis Deploy :</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: redis
  namespace: redis
spec:
  containers:
    - name: redis
      image: redis
      command:
        - redis-server
        - /usr/local/etc/redis/redis.conf
      env:
        - name: MASTER
          value: "true"
      ports:
        - containerPort: 6379
      volumeMounts:
        - mountPath: /redis-master-data
          name: data
        - mountPath: /usr/local/etc/redis/
          name: redis-configmap
      resources:
        requests:
          memory: {{ .Values.resources.requests.memory }}
          cpu: {{ .Values.resources.requests.cpu }}
        limits:
          memory: {{ .Values.resources.limits.memory }}
          cpu: {{ .Values.resources.limits.cpu }}
  volumes:
    - name: data
      emptyDir: {}
    - name: redis-configmap
      configMap:
        name: redis-configmap
</code></pre>

<p>ClusterIP Service:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: redis-cip
  namespace: redis
  labels:
    app: redis
spec:
  ports:
  - port: 6379
    targetPort: 6379
  selector:
    app: redis
  type: ClusterIP
</code></pre>

Alessandro Candon
<p>the connection gets refused because there are no pods with label <code>app:redis</code> .
add labels to your pod that are identical to service <code>spec.selector</code></p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: redis
  namespace: redis
  labels:
     app:redis
spec:
  containers:
    - name: redis
      image: redis
</code></pre>
