Skip to main content
AI
  • Get started with AI

    • Red Hat AI

      Accelerate the development and deployment of enterprise AI solutions.

    • AI learning hub

      Explore learning materials and tools, organized by task.

    • AI interactive demos

      Click through scenarios with Red Hat AI, including training LLMs and more.

    • AI/ML learning paths

      Expand your Red Hat OpenShift AI knowledge using these learning resources.

    • AI quickstarts

      Focused AI use cases designed for fast deployment on Red Hat AI platforms.

    • No-cost AI training

      Foundational Red Hat AI training.

  • Featured resources

    • Red Hat OpenShift AI
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

Red Hat AI Factory with NVIDIA

Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.

Learn
  • Self-guided

    • Documentation

      Find answers, get step-by-step guidance, and learn how to use Red Hat products.

    • Learning paths

      Explore curated walkthroughs for common development tasks.

    • Guided learning

      Receive custom learning paths powered by our AI assistant.

    • See all learning
  • Hands-on

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

    • Interactive labs

      Learn by doing in these hands-on, browser-based experiences.

    • Interactive demos

      Click through product features in these guided tours.

  • Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics
  • Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
Build
  • Get started

    • Red Hat build of Podman Desktop

      A downloadable, local development hub to experiment with our products and builds.

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

  • Download products

    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products
  • Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset
  • References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
Community
  • Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions
  • Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github
  • Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

Join the Red Hat Developer program

Download Red Hat products and project builds, access support documentation, learning content, and more.

ConsoleDocsSupport Search
New For you

Recommended

We'll recommend resources you may like as you browse. Try these suggestions for now.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

Using Kubernetes ConfigMaps to define your Quarkus application's properties

January 23, 2020
Sebastien Blanc
Related topics:
DevOpsKubernetesQuarkus

    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 application.properties file, but the values match the ones for your local environment and won't work once deployed onto your cluster.

    So, 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:

    $ mvn io.quarkus:quarkus-maven-plugin:1.1.1.Final:create

    You can keep all of the default values while creating the new application. In this example, the application is named hello-app. Now, open the HelloResource.java file and refactor it to look like this:

    @Path("/hello")
    public class HelloResource {
     
     @ConfigProperty(name = "greeting.message")
     String message;
    
     @GET
     @Produces(MediaType.TEXT_PLAIN)
     public String hello() {
      return "hello " + message;
     }
    }
    

    In your application.properties file, now add greeting.message=localhost. The @ConfigProperty annotation is not in the scope of this article, but here we can see how easy it is to inject properties inside our code using this annotation.

    Now, let's start our application to see if it works as expected:

    $ mvn compile quarkus:dev

    Browse to http://localhost:8080/hello, which should output hello localhost. That's it for the Quarkus app. It's ready to go.

    Deploy the application to the Kubernetes cluster

    The idea here is to deploy this application to our Kubernetes cluster and replace the value of our greeting property with one that will work on the cluster. It is important to know here that all of the properties from application.properties are exposed, and thus can be overridden with environment variables. The convention is to convert the name of the property to uppercase and replace every dot (.) with an underscore (_). So, for instance, our greeting.message will become GREETING_MESSAGE.

    At this point, we are almost ready to deploy our app to Kubernetes, but we need to do three more things:

    1. Create a Docker image of your application and push it to a repository that your cluster can access.
    2. Define a ConfgMap resource.
    3. Generate the Kubernetes resources for our application.

    To create the Docker image, simply execute this command:

    $ 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 docker-hub or quay. If you are not able to push an image, you can use sebi2706/hello-app:latest.

    Next, create the file config-hello.yml:

    apiVersion: v1
    data:
        greeting: "Kubernetes"
    kind: ConfigMap
    metadata:
        name: hello-config
    

    Make sure that you are connected to a cluster and apply this file:

    $ kubectl apply -f config-hello.yml

    Quarkus comes with a useful extension, quarkus-kubernetes, that generates the Kubernetes resources for you. You can even tweak the generated resources by providing extra properties—for more details, check out this guide.

    After installing the extension, add these properties to our application.properties file so it generates extra configuration arguments for our containers specification:

    kubernetes.group=yourDockerUsername
    kubernetes.env-vars[0].name=GREETING_MESSAGE
    kubernetes.env-vars[0].value=greeting
    kubernetes.env-vars[0].configmap=hello-config

    Run mvn package and view the generated resources in target/kubernetes. The interesting part is in spec.containers.env:

    - 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:

    $ kubectl apply -f target/kubernetes/kubernetes.yml

    Expose your service:

    kubectl expose deployment hello --type=NodePort

    Then, browse to the public URL or do a curl. For instance, with Minikube:

    $ curl $(minikube service hello-app --url)/hello

    This command should output: hello Kubernetes.

    Conclusion

    Now you know how to use a ConfigMap in combination with environment variables and your Quarkus's application.properties. As we said in the introduction, this technique is particularly useful when defining a DB connection's URL (like QUARKUS_DATASOURCE_URL) or when using the quarkus-rest-client (ORG_SEBI_OTHERSERVICE_MP_REST_URL).

    Last updated: June 29, 2020

    Recent Posts

    • A day in the life of an NVIDIA H100 on Red Hat OpenShift 5

    • Migrate BuildConfigs to builds for Red Hat OpenShift with one plug-in install

    • Run Red Hat Enterprise Linux CoreOS on NVIDIA BlueField DPUs

    • Agent harness engineering: Separating model capabilities from enforcement

    • What's new for developers in Red Hat Enterprise Linux 10.3 and 9.9

    Red Hat Developers logo

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    Red Hat Developer

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility
    Ask AI