![]() |
|
Using Kubernetes ConfigMaps to define your Quarkus application’s properties - Printable Version +- Sick Gaming (https://sickgaming.net) +-- Forum: Programming (https://sickgaming.net/forum-76.html) +--- Forum: Java & JVM Languages (https://sickgaming.net/forum-78.html) +--- Thread: Using Kubernetes ConfigMaps to define your Quarkus application’s properties (/thread-95593.html) |
Using Kubernetes ConfigMaps to define your Quarkus application’s properties - xSicKxBot - 06-09-2020 Using Kubernetes ConfigMaps to define your Quarkus application’s properties So, you wrote your Quarkus application, and now you want to deploy it to a Kubernetes cluster. Good news: Deploying a Quarkus application to a Kubernetes cluster is easy. Before you do this, though, you need to straighten out your application’s properties. After all, your app probably has to connect with a database, call other services, and so on. These settings are already defined in your Code: application.propertiesSo, how do you easily solve this problem? Let’s walk through an example. Create the example Quarkus application Instead of using a complex example, let’s take a simple use case that explains the concept well. Start by creating a new Quarkus app: Code: $ mvn io.quarkus:quarkus-maven-plugin:1.1.1.Final:createYou can keep all of the default values while creating the new application. In this example, the application is named Code: hello-appCode: HelloResource.javaCode: @Path("/hello") public class HelloResource { @ConfigProperty(name = "greeting.message") String message; @GET @Produces(MediaType.TEXT_PLAIN) public String hello() { return "hello " + message; } }In your Code: application.propertiesCode: greeting.message=localhostCode: @ConfigPropertyNow, let’s start our application to see if it works as expected: Code: $ mvn compile quarkus:devBrowse to Code: http://localhost:8080/helloCode: hello localhostDeploy the application to the Kubernetes cluster The idea here is to deploy this application to our Kubernetes cluster and replace the value of our Code: greetingCode: application.propertiesCode: .Code: _Code: greeting.messageCode: GREETING_MESSAGEAt this point, we are almost ready to deploy our app to Kubernetes, but we need to do three more things:
To create the Docker image, simply execute this command: Code: $ docker build -f src/main/docker/Dockerfile.jvm -t quarkus/hello-app .Be sure to set the right Docker username and to also push to an image registry, like Code: docker-hubCode: quayCode: sebi2706/hello-app:latestNext, create the file Code: config-hello.ymlCode: apiVersion: v1 data: greeting: "Kubernetes" kind: ConfigMap metadata: name: hello-configMake sure that you are connected to a cluster and apply this file: Code: $ kubectl apply -f config-hello.ymlQuarkus comes with a useful extension, Code: quarkus-kubernetesAfter installing the extension, add these properties to our Code: application.propertiesCode: kubernetes.group=yourDockerUsername kubernetes.env-vars[0].name=GREETING_MESSAGE kubernetes.env-vars[0].value=greeting kubernetes.env-vars[0].configmap=hello-configRun Code: mvn packageCode: target/kubernetesCode: spec.containers.envCode: - name: "GREETING_MESSAGE" valueFrom: configMapKeyRef: key: "greeting" name: "hello-config"Here, we see how to pass an environment variable to our container with a value coming from a ConfigMap. Now, simply apply the resources: Code: $ kubectl apply -f target/kubernetes/kubernetes.ymlExpose your service: Code: kubectl expose deployment hello --type=NodePortThen, browse to the public URL or do a curl. For instance, with Minikube: Code: $ curl $(minikube service hello-app --url)/helloThis command should output: Code: hello KubernetesConclusion Now you know how to use a ConfigMap in combination with environment variables and your Quarkus’s Code: application.propertiesCode: QUARKUS_DATASOURCE_URLCode: quarkus-rest-clientCode: ORG_SEBI_OTHERSERVICE_MP_REST_URLhttps://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fdevelopers.redhat.com%2Fblog%2F2020%2F01%2F23%2Fusing-kubernetes-configmaps-to-define-your-quarkus-applications-properties%2F&linkname=Using%20Kubernetes%20ConfigMaps%20to%20define%20your%20Quarkus%20application%E2%80%99s%20propertieshttps://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fdevelopers.redhat.com%2Fblog%2F2020%2F01%2F23%2Fusing-kubernetes-configmaps-to-define-your-quarkus-applications-properties%2F&linkname=Using%20Kubernetes%20ConfigMaps%20to%20define%20your%20Quarkus%20application%E2%80%99s%20propertieshttps://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fdevelopers.redhat.com%2Fblog%2F2020%2F01%2F23%2Fusing-kubernetes-configmaps-to-define-your-quarkus-applications-properties%2F&linkname=Using%20Kubernetes%20ConfigMaps%20to%20define%20your%20Quarkus%20application%E2%80%99s%20propertieshttps://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fdevelopers.redhat.com%2Fblog%2F2020%2F01%2F23%2Fusing-kubernetes-configmaps-to-define-your-quarkus-applications-properties%2F&linkname=Using%20Kubernetes%20ConfigMaps%20to%20define%20your%20Quarkus%20application%E2%80%99s%20propertieshttps://www.addtoany.com/add_to/print?linkurl=https%3A%2F%2Fdevelopers.redhat.com%2Fblog%2F2020%2F01%2F23%2Fusing-kubernetes-configmaps-to-define-your-quarkus-applications-properties%2F&linkname=Using%20Kubernetes%20ConfigMaps%20to%20define%20your%20Quarkus%20application%E2%80%99s%20propertieshttps://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fdevelopers.redhat.com%2Fblog%2F2020%2F01%2F23%2Fusing-kubernetes-configmaps-to-define-your-quarkus-applications-properties%2F&linkname=Using%20Kubernetes%20ConfigMaps%20to%20define%20your%20Quarkus%20application%E2%80%99s%20propertieshttps://www.addtoany.com/add_to/flipboard?linkurl=https%3A%2F%2Fdevelopers.redhat.com%2Fblog%2F2020%2F01%2F23%2Fusing-kubernetes-configmaps-to-define-your-quarkus-applications-properties%2F&linkname=Using%20Kubernetes%20ConfigMaps%20to%20define%20your%20Quarkus%20application%E2%80%99s%20properties The post Using Kubernetes ConfigMaps to define your Quarkus application’s properties appeared first on Red Hat Developer. |