CategoriesDevOpsTips and Tricks

Kubernetes Cluster Setup with Kind-k8s Installer

By following this guide, you’ll be able to quickly and easily set up a Kubernetes cluster on your Windows PC with the following tech stack

  • WSL2 backend with Ubuntu
  • Docker Desktop
  • Kubectl – Windows

K8s Kind Installer

Kind is a simple, lightweight CNCF-certified Kubernetes installer CNCF K8s Installer

Compared to Minikube, Kind provides support for Hyperkit on Mac and Hyper-V on Windows hypervisors, including features such as Load balancer and Ingress support. Additionally, Kind supports multi-node clusters, including those with high availability (HA).

Quick prerequisites installation

#Kubectl Kind using powershell

curl.exe -Lo kind-windows-amd64.exe https://kind.sigs.k8s.io/dl/v0.22.0/kind-windows-amd64

Move-Item .\kind-windows-amd64.exe C:\Dev\env\kind\kind.exe

#Kubectl Install
curl.exe -LO "https://dl.k8s.io/release/v1.30.0/bin/windows/amd64/kubectl.exe

Create cluster

Creating a cluster with 1 control plane node and 3 workers

apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
name: ckad-cluster
nodes:
- role: control-plane
- role: worker
- role: worker
- role: worker

This will create all the necessary k8s control plane objects and worker nodes

Continue reading
CategoriesTesting

Spock Test Framework

Spock aims to be a more powerful alternative to the traditional JUnit stack, by leveraging Groovy features which seamlessly integrate with Java

Spock Features Highlights

  • Highly Expressive
  • Spock enforces a clear test structure
  • BDD style test can be expressive through the “given, when and then” blocks
  • Compatible with all major build tools and continuous integration providers
  • Inbuilt Mocking and Stubbing
  • Parameterized test and Data-driven test ( Data table-based and SQL table-based)

JUNIT -> SPOCK -> CUCUMBER

Spock lies between junit and cucumber

At a glance, the Spock framework is,

  • BDD style testing and specification framework
  • Which runs Junit under the hood
  • For Java and Groovy applications
  • Test case writing in Groovy
  • All three components combine with a single library
    • Unit testing
    • Mocking
    • BDD
Continue reading
CategoriesTestingTips and Tricks

Spring bean creation testing – Feature Toggling

Spring auto-configuration can be tricky when it comes to conditional based bean creation. The best way to ensure the proper application context is through meticulous testing.

Spring Boot 2.X provides some test helpers for easily configuring an ApplicationContext to simulate auto-configuration test scenarios.

Application Context Runner

Utility design to run an ApplicationContext and provide AssertJ style assertions. The test is best used as a field of a test class,

Let’s try this with a use case,

Feature Toggling

Let’s assume the application consists of multiple features and these features are toggled ( bean creation ) by environment configuration-based conditions,

Feature Definition

All the features of the application are defined as an enum and the enum contains a code and the application configuration itself. For simplicity let’s consider an app with 3 features.

public enum AppHubFeature {
LOGISTIC_UNIT_UPDATE("Logistic Unit Update", FeatureConfig.LOGISTIC_UNIT_UPDATE),
ORDER_STATUS_UPDATE("Order Status Update", FeatureConfig.ORDER_STATUS_UPDATE),
STOCK_ADJUSTMENT("Stock Adjustment", FeatureConfig.STOCK_ADJUSTMENT);
public static class FeatureConfig {
public static final String LOGISTIC_UNIT_UPDATE = "app-hub.feature.logistic-unit-update";
public static final String ORDER_STATUS_UPDATE = "app-hub.feature.order-line-status-update";
public static final String STOCK_ADJUSTMENT = "app-hub.feature.stock-adjustment";
}
public final String feature;
public final String config;
AppHubFeature(String feature, String config) {
this.feature = feature;
this.config = config;
}
public String config() {
return this.config;
}
public String feature() {
return this.feature;
}
}
Continue reading
CategoriesApplication DynamicsPerformance Engineering

Micrometer, Prometheus & Grafana

This is a monitoring infrastructure building task with some basic matrices. where the metrics are extracted, processed and visualized using the proposed setup to facilitate data-driven decision making.

Specifically, the following metrics were introduced,

  • Core JVM matrices like CPU, Memory, GC and threads…etc
  • Monitor any application method execution time

Application Dynamics

Any performance metrics analyzing platform based on following basic steps

  1. Performance Metric extraction
  2. Store Metrics ( Time-series database )
  3. Metrics stat-based visualization and alerting
Continue reading
CategoriesTips and Tricks

WSL2 as IntelliJ IDEA Run Target

Windows Subsystem for Linux (WSL) 2 provides a seamless Linux integration with many features. As developers, we can take full advantage of both OS at the same time.

WSL support on IntelliJ IDEA

For this example, I am using a Spring Boot project located in windows and run the project on a WSL2 Linux environment.

Continue reading
CategoriesTips and Tricks

Log4j2 custom layouts

Log4j22 provides multiple ways of creating a custom layout for many requirements. This article will explain simple ways to implement custom layouts using log4j2 plugins

In Log4j 2 a plugin is declared by adding a @Plugin annotation to the class declaration. During initialization, the Configuration will invoke the PluginManager to load the built-in Log4j plugins as well as any custom plugins.

Apache logging services

We can use both AbstractStringLayout or LogEventPatternConverter according to our requirements. Both options will provide a way to access log4j LogEvent that has all the relevant details about the log event to be customized.

Continue reading