diff --git a/docs/src/main/asciidoc/deploying-to-kubernetes.adoc b/docs/src/main/asciidoc/deploying-to-kubernetes.adoc index bedfa35c269a5..b57e90a595ca3 100644 --- a/docs/src/main/asciidoc/deploying-to-kubernetes.adoc +++ b/docs/src/main/asciidoc/deploying-to-kubernetes.adoc @@ -1185,3 +1185,65 @@ The provided replicas <1>, labels <2> and environment variables <3> were retain If the resource name does not match the application name (or the overridden name) instead of reusing the resource a new one will be added. Same goes for the container. If the name of the container does not match the application name (or the overridden name), container specific configuration will be ignored. ==== + +== Service Binding + +Quarkus supports binding services to applications via the link:https://github.com/k8s-service-bindings/spec[Service Binding Specification for Kubernetes]. +Specifically Quarkus implements the link:https://github.com/k8s-service-bindings/spec#application-projection[Application Projection] part of the specification, thus allowing +applications running in appropriately configured Kubernetes clusters to consume services (such as a Database or a Broker) without the need for user configuration. + +Currently, the following Quarkus extensions support this feature: + +* quarkus-jdbc-mariadb +* quarkus-jdbc-mssql +* quarkus-jdbc-mysql +* quarkus-jdbc-postgresql + +This list of extensions will grow as more services with supported bindings become available on Kubernetes. + +To enable Service Binding support, in addition to one of the currently supported extensions, the `quarkus-kubernetes-service-binding` extension needs to be added to the application dependencies. + +=== Example using PostgreSQL + +If the Kubernetes cluster in which your Quarkus application runs supports provisioning a PostgreSQL database, one could use the following dependencies to take advantage of the Service Binding feature: + +[source,xml] +---- + + io.quarkus + quarkus-jdbc-postgresql + + + io.quarkus + quarkus-kubernetes-service-binding + + + + + io.quarkus + quarkus-hibernate-orm + +---- + +The configuration of the application could be as simple as: + +[source,properties] +---- +quarkus.hibernate-orm.database.generation=validate +---- + +You'll notice that all the configuration for the datasource is absent, as it will be auto-discovered by Quarkus when the application is deployed to Kubernetes. + +=== How does it work? + +When the application is deployed to an appropriately configured Kubernetes cluster, Kubernetes will create on the filesystem a set of files containing the runtime configuration (for example a file containing the URL of the database, another for the username). +Quarkus knows where in the file system to look for these files (as it consults the `SERVICE_BINDING_ROOT` environment variable which is set by Kubernetes) and if they exist, Quarkus knows how to map the values of these files to the appropriate extension configuration properties. + +An example of what the file system looks like can be seen link:https://github.com/quarkusio/quarkus/tree/e7efe6b3efba91b9c4ae26f9318f8397e23e7505/integration-tests/kubernetes-service-binding-jdbc/src/test/resources/k8s-sb[here]. +In that example, the `k8s-sb` directory is meant to be the root of all service bindings. Only one binding which exists in that case and it is named `fruit-db`. This binding has a `type` file indicating that it is a `postgresql` database +while the other files provide the necessary connection information. + +[TIP] +==== +For more details on how the discovery of the available properties works, please read the link:https://github.com/k8s-service-bindings/spec#application-projection[Application Projection] part of the Service Binding specification. +==== diff --git a/extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/KubernetesServiceBindingConfig.java b/extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/KubernetesServiceBindingConfig.java index a77e90540ebc7..a024098c77230 100644 --- a/extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/KubernetesServiceBindingConfig.java +++ b/extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/KubernetesServiceBindingConfig.java @@ -12,7 +12,7 @@ public class KubernetesServiceBindingConfig { /** * If enabled, Service Bindings will be looked in the file system */ - @ConfigItem + @ConfigItem(defaultValue = "true") public boolean enabled; /** diff --git a/integration-tests/kubernetes-service-binding-jdbc/pom.xml b/integration-tests/kubernetes-service-binding-jdbc/pom.xml index 164ead097e24e..67becae685e91 100644 --- a/integration-tests/kubernetes-service-binding-jdbc/pom.xml +++ b/integration-tests/kubernetes-service-binding-jdbc/pom.xml @@ -166,7 +166,6 @@ ${project.basedir}/src/test/resources/k8s-sb - true