Running a 4 node Kubernetes Cluster on Raspberry Pi

What I wanted to achieve: Using 4 of my Raspis for Kubernetes: Part 1 Learn how to deploy a Spring Boot application: Part 2 Expose this application to the internet: Part 3 Part 1: Setting up the cluster For my setup I use 1 Raspi 4 and 3 Raspi 3B. The Raspi 4 serves as master node, the others as client nodes. First I flashed HypriotOS on all 4 Raspis. Before commencing don’t forget to: ...

March 4, 2021 · 1 min · Jens

Testing Spring Boot Configuration Classes

The class to test @Configuration @ConfigurationProperties(prefix = "scheduler") @Data public class SchedulerConfig { private String rate; private final Activetime activetime = new Activetime(); @Data public static class Activetime { private int starts; private int ends; } } The unit test class SchedulerConfigTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner(); @EnableConfigurationProperties(SchedulerConfig.class) static class DummyConfigurationProps { } @Test void shouldConfigureScheduler() { this.contextRunner .withUserConfiguration(DummyConfigurationProps.class) .withPropertyValues("scheduler.rate=42","scheduler.activetime.starts=6","scheduler.activetime.ends=22") .run(context -> { SchedulerConfig schedulerConfig = context.getBean(SchedulerConfig.class); assertThat(schedulerConfig).isNotNull(); assertThat(schedulerConfig.getRate()).isEqualTo("42"); assertThat(schedulerConfig.getActivetime().getStarts()).isEqualTo(6); assertThat(schedulerConfig.getActivetime().getEnds()).isEqualTo(22); }); } }

March 4, 2021 · 1 min · Jens

Deploying Spring Boot Application To OpenShift With Maven

<!-- Retrofit pom with JKube-Plugin --> <build> ... <plugin> <groupId>org.eclipse.jkube</groupId> <artifactId>openshift-maven-plugin</artifactId> <version>${jkube.openshift.version}</version> </plugin> ... </build> # Login to OpenShift, this can be obtained in web console with 'Copy Login Command' $ oc login --token=41cxWS0NnARW2zxRCK5p2GQb31VNf7zEz-wuYMdhw1k --server=https://openshift.cluster.host:6443 # Build and deploy to OpenShift $ mvn oc:build oc:resource oc:apply # Watch the deployment $ oc get pods -w # Find out route $ oc get routes # Undeploy everything $ mvn oc:undeploy # As an alternative, remove everything related to this deployment $ oc delete all --selector app=myapplabel

August 18, 2020 · 1 min · Jens

Scheduled Kafka Consumer With Spring Boot

@Component @Slf4j public class ScheduledConsumer { private final BusinessService businessService; private final KafkaListenerEndpointRegistry registry; @Autowired public ScheduledConsumer(final BusinessService businessService, KafkaListenerEndpointRegistry registry) { this.businessService = businessService; this.registry = registry; } @Scheduled(cron = "${cron-expression.start}") public void resumeConsuming() { this.registry.getListenerContainers().forEach(MessageListenerContainer::resume); log.info("Resume consuming business objects..."); } @Scheduled(cron = "${cron-expression.stop}") public void pauseConsuming() { this.registry.getListenerContainers().forEach(MessageListenerContainer::pause); log.info("Pause consuming business objects..."); } @KafkaListener(id = "mycontainer", topics = "${topic}", autoStartup = "${consumer.autostart}") public void consume(final ConsumerRecord<String, BusinessObject> businessRecord, final Acknowledgment acknowledgment) { log.info("Processing business object..."); this.businessService.process(businessRecord.value()); acknowledgment.acknowledge(); } }

August 13, 2020 · 1 min · Jens