Unable to start springboot app (not ready on kuberentes) after connection to redis instance in Kubernetes

9/6/2019

Spring boot app can not be started on kubernetes after connection to redis instance on the cloud.

set up the connection with redis is successful after that the pod is not started.

redis connection config file is:

@Configuration
public class RedisConfiguration {

    @Value("${spring.redis.host}")
    private String redisHostName;

    @Value("${spring.redis.port}")
    private int redisPort;

    @Value("${spring.redis.password}")
    private String redisServerPassword;

    @Bean
    LettuceConnectionFactory lettuceClientConfigurationConnectionFactory() {
        RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
        redisStandaloneConfiguration.setHostName(redisHostName);
        redisStandaloneConfiguration.setPort(redisPort);
        redisStandaloneConfiguration.setPassword(RedisPassword.of(redisServerPassword));
        redisStandaloneConfiguration.setDatabase(0);

        LettuceClientConfiguration.LettuceClientConfigurationBuilder lettuceClientConfiguration = LettuceClientConfiguration.builder();
        lettuceClientConfiguration.useSsl();
        return new LettuceConnectionFactory(redisStandaloneConfiguration, lettuceClientConfiguration.build());
    }

    @Bean
    public RedisTemplate<Object, Object> redisTemplate() {
        RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(lettuceClientConfigurationConnectionFactory());
        return redisTemplate;
    }

    @Bean
    public RedisCacheManager redisCacheManager(LettuceConnectionFactory lettuceClientConfigurationConnectionFactory) {
        RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
                .entryTtl(Duration.ofHours(1))
                .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(RedisSerializer.json()));
        redisCacheConfiguration.usePrefix();

        return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(lettuceClientConfigurationConnectionFactory)
                .cacheDefaults(redisCacheConfiguration).build();


    }
}

The redis message after running the pod is:

[logStarted] [] [] : Started ServiceApplication in 48.312 seconds (JVM running for 50.685) [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/]] [log] [] [] : Initializing Spring DispatcherServlet 'dispatcherServlet' [io.lettuce.core.EpollProvider] [] [] [] : Starting without optional epoll library [io.lettuce.core.KqueueProvider] [] [] [] : Starting without optional kqueue library

-- Yahya Benbelgacem
java
kubernetes
redis
spring-boot

0 Answers