title: Java : Connecting to Redis cluster running in minikube
body: <p>I have a Redis cluster with 3 master and 3 slaves running in minikube.</p>
  
  <pre><code>PS D:\redis\main\kubernetes-redis-cluster&gt; kubectl exec -ti redis-1-2723908297-prjq5 -- /bin/bash
  root@redis-1:/data# redis-cli -p 7000 -c
  127.0.0.1:7000&gt; cluster info
  cluster_state:ok
  cluster_slots_assigned:16384
  cluster_slots_ok:16384
  cluster_slots_pfail:0
  cluster_slots_fail:0
  cluster_known_nodes:6
  cluster_size:3
  cluster_current_epoch:6
  cluster_my_epoch:2
  cluster_stats_messages_ping_sent:9131
  cluster_stats_messages_pong_sent:9204
  cluster_stats_messages_meet_sent:3
  cluster_stats_messages_sent:18338
  cluster_stats_messages_ping_received:9202
  cluster_stats_messages_pong_received:9134
  cluster_stats_messages_meet_received:2
  cluster_stats_messages_received:18338
  
  
  
  127.0.0.1:7000&gt; cluster nodes
  de9a4780d93cb7eab8b77abdaaa96a081adcace3 172.17.0.7:7000@17000 slave ee4deab0525d054202e612b317924156ff587021 0 15099603
  02577 4 connected
  b3a3c05225e0a7fe8ae683dd4316e724e7a7daa6 172.17.0.5:7000@17000 myself,master - 0 1509960301000 2 connected 5461-10922
  8bebd48850ec77db322ac51501d59314582865a3 172.17.0.6:7000@17000 master - 0 1509960302000 3 connected 10923-16383
  ee4deab0525d054202e612b317924156ff587021 172.17.0.4:7000@17000 master - 0 1509960303479 1 connected 0-5460
  28a1c75e9976bc375a13e55160f2aae48defb242 172.17.0.8:7000@17000 slave b3a3c05225e0a7fe8ae683dd4316e724e7a7daa6 0 15099603
  02477 5 connected
  32e9de12324b8571a6256285682fa066d79161ab 172.17.0.9:7000@17000 slave 8bebd48850ec77db322ac51501d59314582865a3 0 15099603
  02000 6 connected
  127.0.0.1:7000&gt;
  </code></pre>
  
  <p>I am able to set/fetch key/values via redis-cli without any issue.
  Now I am trying to connect to redis cluster from a simple java program running from eclipse.</p>
  
  <p>I understand that I need to forward the port. I executed below command.</p>
  
  <pre><code>kubectl port-forward redis-0-334270214-fd4k0 7000:7000
  </code></pre>
  
  <p>Now when I execute below program.</p>
  
  <pre><code>public class Main {
      public static void main(String[] args) {
      GenericObjectPoolConfig config = new GenericObjectPoolConfig();
      config.setMaxTotal(500);
      config.setMaxIdle(500);
      config.setMaxWaitMillis(60000);
      config.setTestOnBorrow(true);
      config.setMaxWaitMillis(20000);
  
      Set&lt;HostAndPort&gt; jedisClusterNode = new HashSet&lt;HostAndPort&gt;();
      jedisClusterNode.add(new HostAndPort("192.168.99.100", 31695));
  
      JedisCluster jc = new JedisCluster(jedisClusterNode, config);
  
      jc.set("prime", "1 is primeee");
      String keyVal = jc.get("prime");
      System.out.println(keyVal);
      }
  }
  </code></pre>
  
  <p>Then I get below exception.</p>
  
  <pre><code>Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
      at redis.clients.util.Pool.getResource(Pool.java:53)
      at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
      at redis.clients.jedis.JedisSlotBasedConnectionHandler.getConnectionFromSlot(JedisSlotBasedConnectionHandler.java:66)
      at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:116)
      at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
      at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
      at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
      at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
      at redis.clients.jedis.JedisClusterCommand.run(JedisClusterCommand.java:31)
      at redis.clients.jedis.JedisCluster.set(JedisCluster.java:103)
      at com.redis.main.Main.main(Main.java:25)
  Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out
      at redis.clients.jedis.Connection.connect(Connection.java:207)
      at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
      at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
      at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
      at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:819)
      at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:429)
      at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:360)
      at redis.clients.util.Pool.getResource(Pool.java:49)
      ... 10 more
  Caused by: java.net.SocketTimeoutException: connect timed out
      at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.SocksSocketImpl.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at redis.clients.jedis.Connection.connect(Connection.java:184)
      ... 17 more
  </code></pre>
  
  <p>Redis services are created and running as well..</p>
  
  <pre><code>PS C:\Users\rootmn&gt; kubectl get services
  NAME         CLUSTER-IP   EXTERNAL-IP   PORT(S)                          AGE
  kubernetes   10.0.0.1     &lt;none&gt;        443/TCP                          11h
  redis-0      10.0.0.105   &lt;pending&gt;     7000:31695/TCP,17000:31596/TCP   10h
  redis-1      10.0.0.7     &lt;pending&gt;     7000:30759/TCP,17000:30646/TCP   10h
  redis-2      10.0.0.167   &lt;pending&gt;     7000:32591/TCP,17000:30253/TCP   10h
  redis-3      10.0.0.206   &lt;pending&gt;     7000:31644/TCP,17000:31798/TCP   10h
  redis-4      10.0.0.244   &lt;pending&gt;     7000:30186/TCP,17000:32701/TCP   10h
  redis-5      10.0.0.35    &lt;pending&gt;     7000:30628/TCP,17000:32396/TCP   10h
  </code></pre>
  
  <p>Telnet to redis ip port works fine.
  Am I doing something wrong here. What would cause this issue ?</p>