I have a k8s cluster with a redis service and a java service, both in the same namespace. The redis pod gets created, I can port forward it and connect using redis-cli, also tried creating a pod with a busybox image just to try pring and telnet redis 6379, both works. However, using my java service to connect does not work. Any ideas on why that could be happening? Maybe its some redis configuration.
I get this error
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
using on the service:
public void test() {
final JedisPoolConfig poolConfig = buildPoolConfig();
JedisPool jedisPool = new JedisPool("redis", 6379);
try(Jedis jedis = jedisPool.getResource()) {
jedis.set( "somekey", "somevalue" );
}
}
And here is my redis service yaml file
apiVersion: v1
kind: ConfigMap
metadata:
name: redis
data:
redis-config: |
maxmemory 2mb
maxmemory-policy allkeys-lru
---
apiVersion: v1
kind: Service
metadata:
name: redis
spec:
ports:
- port: 6379
targetPort: 6379
selector:
app: redis
clusterIP: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
spec:
selector:
matchLabels:
app: redis
strategy:
type: Recreate
template:
metadata:
labels:
app: redis
spec:
containers:
- image: redis:6.2.6
name: redis
command:
- redis-server
- "/redis-master/redis.conf"
env:
- name: MASTER
value: "true"
ports:
- containerPort: 6379
resources:
limits:
memory: 300Mi
cpu: 800m
volumeMounts:
- mountPath: /redis-master-data
name: data
- mountPath: /redis-master
name: config
volumes:
- name: data
emptyDir: {}
- name: config
configMap:
name: redis
items:
- key: redis-config
path: redis.conf