<p>While deploying to kubernetes , redis connection is not able to establish connection because of jedis connection refused error.</p>

<pre><code>"message": "Cannot get Jedis connection; nested exception is 
redis.clients.jedis.exceptions.JedisConnectionException: 
java.net.ConnectException: Connection refused (Connection refused)",
</code></pre>

<p>Deployment yaml file:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: redis-master
spec:
  selector:
    matchLabels:
      app: redis
  replicas: 1
  template:
    metadata:
      labels:
        app: redis
    spec:
      containers:
      - name: redis-master
        image: gcr.io/google_containers/redis:e2e

        ports:
        - containerPort: 6379

        volumeMounts:
        - name: redis-storage
          mountPath: /data/redis

      volumes:
      - name: redis-storage
---
apiVersion: v1
kind: Service
metadata:
  name: redis-master
  labels:
    app: redis
spec:
  ports:
    - port: 6379
  selector:
    app: redis
</code></pre>

<p>---Sample Jedis code used in project:</p>

<pre><code>JedisConnectionFactory jedisConnectionFactoryUpdated() {

        RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
        redisStandaloneConfiguration.setHostName("redis-master");
        redisStandaloneConfiguration.setPort(6379);

        JedisClientConfigurationBuilder jedisClientConfiguration = JedisClientConfiguration.builder();
        jedisClientConfiguration.connectTimeout(Duration.ofSeconds(60));// 60s connection timeout

        JedisConnectionFactory jedisConFactory = new JedisConnectionFactory(redisStandaloneConfiguration,
                jedisClientConfiguration.build());

        return jedisConFactory;
    }
</code></pre>

<p>Does anybody overcome this issue? TIA.</p>

<p>You need to first update your service to reflect: </p>

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

<p>Once you have done so you can check whether or not your redis service is up and responding by using nmap. Here is an example using my nmap image:</p>

<pre><code>kubectl run --image=appsoa/docker-alpine-nmap --rm -i -t nm -- -Pn 6379 redis-master
</code></pre>

<p>Also, make sure that both redis &amp; your spring boot app are deployed to the same namespace. If not, you need to explicity define your hostname using . (i.e.: "redis-master.mynamespace").</p>
