I'm trying to deploy a redis pod to allow my staging app connecting to it (to avoid using Redis Managed Service in staging ENV).
I'm using Google Cloud Platform with GKE, so managed k8s cluster...
However, when I try to make a connection (from another redis pod only to test) I receive this message :
Could not connect to Redis at redis-cip.redis.svc.cluster.local:6379: Connection refused
The command that I use to make the test is this :
redis-cli -h redis-cip.redis.svc.cluster.local -p 6379
The URL is composed by :
Moreover,I use, as is already written in some question on StackOverflow, this redis configuration :
protected-mode no
maxmemory 32mb
maxmemory-policy allkeys-lru
In attached the full k8s mapping :
ConfigMap :
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-configmap
namespace: redis
data:
redis.conf: |
protected-mode no
maxmemory 32mb
maxmemory-policy allkeys-lru
Redis Deploy :
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
ClusterIP Service:
apiVersion: v1
kind: Service
metadata:
name: redis-cip
namespace: redis
labels:
app: redis
spec:
ports:
- port: 6379
targetPort: 6379
selector:
app: redis
type: ClusterIP
the connection gets refused because there are no pods with label app:redis
. add labels to your pod that are identical to service spec.selector
apiVersion: v1
kind: Pod
metadata:
name: redis
namespace: redis
labels:
app:redis
spec:
containers:
- name: redis
image: redis