Testing Application code local while using k8s for for the deployment of app Testing Application code local while using k8s for for the deployment of app kubernetes kubernetes

Testing Application code local while using k8s for for the deployment of app


Did you consider using spring boot profiles for this purpose? We are using it effectively for long across our teams. For this purpose, you'll have to extract the service(s) host as separate properties in application.yml (or application.properties) and use this host in rest of the properties as a variable. Following snippet explains this

application.yml----------------serviceA:  host: service-A-Name  api-one-endpoint: http://${serviceA.host}/api/v1/one  api-two-endpoint: http://${serviceA.host}/api/v1/two  api-three-endpoint: http://${serviceA.host}/api/v1/three  api-four-endpoint: http://${serviceA.host}/api/v1/four

In production (any hosted/managed environment for that matter), you provide appropriate value for spring property serviceA.host. In your use case, you'll be using this value AS-IS and provide k8s service name binding instead.

For local dev environment, you only need to override single property. For simple use case (say you need to override only single property), you can pass it as an agrument to your spring boot launcher (e.g. "--serviceA.host=localhost"). If you have many services (you likely do) even then you'll need to override well known few host name properties only. Using a dedicated dev profiles is much better in this case. Following example illustrate same scenario

application-dev.yml-------------------serviceA:  host: mylocalhost:9090

Then you use this profile in your eclipse/intellij launcher configuraiton for execution or debugging purpose by adding "--spring.profiles.active=dev" as and additional argument and spring boot will use updated host from dev profile. In fact combining these two approaches gives you even more flexibility for advance cases. If you agree on a common port convention across team then you can even check-in application-dev.yml for usage by everyone pretty much as-is.

spring boot profiles is much more powerful feature, I'll strongly recommend to go through it's documentation and few tutorial (like this one) to understand it fully and exploit it effectively for use cases like this one.