> For the complete documentation index, see [llms.txt](https://audomsak.gitbook.io/developer-advocacy-2022/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://audomsak.gitbook.io/developer-advocacy-2022/application-deployment/microservices-deployment/hero-microservice.md).

# Hero Microservice

## Create a ConfigMap object to store application configurations

1. Click on ![add](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-2053c9da0b621063f466689f6d54afaaac341907%2Fadd-icon.png?alt=media) icon located at top right corner of web console.
2. Copy this YAML snippet to the editor and click **Create** button.

   *YAML snippet:*

   ```yaml
   apiVersion: v1
   kind: ConfigMap
   metadata:
     labels:
       app: rest-heroes
       application: heroes-service
       system: quarkus-super-heroes
     name: rest-heroes-config
   data:
     quarkus.hibernate-orm.database.generation: validate
     quarkus.hibernate-orm.sql-load-script: no-file
     quarkus.datasource.reactive.url: postgresql://heroes-db:5432/heroes_database
     quarkus.opentelemetry.tracer.exporter.otlp.endpoint: http://otel-collector:4317
     quarkus.http.access-log.enabled: "false"
     quarkus.http.access-log.pattern: >
       %h %l %u %t "%r" %s %b "User-Agent: %{i,User-Agent}" "x-request-id:
       %{i,x-request-id}" "x-b3-traceid: %{i,x-b3-traceid}"  " Referer:
       %{i,Referer}"
   ```

   ![Create a ConfigMap object](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-1427fad2d496f0d75e28f2b4ae6245335d69d2a3%2Fdeploy-1.png?alt=media)
3. A **rest-heroes-config** ConfigMap object should be created.

   ![Create a ConfigMap object](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-146056de829b4d8dc906a7d07e3e8edefff1bf4f%2Fdeploy-3.png?alt=media)

## Create a Secret object to store the secret configurations

1. Click on ![add](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-2053c9da0b621063f466689f6d54afaaac341907%2Fadd-icon.png?alt=media) icon located at top right corner of web console.
2. Copy this YAML snippet to the editor and click **Create** button.

   *YAML snippet:*

   ```yaml
   apiVersion: v1
   kind: Secret
   metadata:
     labels:
       app: rest-heroes
       application: heroes-service
       system: quarkus-super-heroes
     name: rest-heroes-config-creds
   data:
     quarkus.datasource.username: c3VwZXJtYW4=
     quarkus.datasource.password: c3VwZXJtYW4=
   type: Opaque
   ```

   ![Create a Secret object](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-e460130dfc19a18a64f82e495a21e0869c04bd90%2Fdeploy-4.png?alt=media)
3. A **rest-heroes-config-creds** Secret object should be created.

   ![Create a Secret object](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-b3d1130aaa8a2b492a8d6664b11c6a837cf19b11%2Fdeploy-5.png?alt=media)

## Deploy application with existing container image

1. Go to **Topology** menu, right click on view area then select **Add to Project -> Container Image** menu.

   ![Create a Secret object](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-cea61089c74872bb53c49491b248308fdab4c3ca%2Fdeploy-6.png?alt=media)
2. Enter following inputs:

   * **Image name from external registry:** `quay.io/asuksunt/rest-heroes:1.0`
   * **Runtime icon:** `quarkus`
   * **Application:** `heroes-service`
   * **Name:** `rest-heroes`

   ![Deploy application container](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-22bd1ccc46f35bd72f511488ba04eaae5163a835%2Fdeploy-7.png?alt=media)
3. Scroll down to the bottom of the page, select **8080** option for **Target port**, uncheck the **Create a route** checkbox, and then click **Health checks** link.

   ![Deploy application container](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-bc304d89b214151e034c5b021bf222d53884da03%2Fdeploy-8.png?alt=media)
4. Click **Add Readiness probe** link.

   ![Deploy application container](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-45f567a4cd7f59f237e13f5e510e3cc79f652e3a%2Fdeploy-9.png?alt=media)
5. Enter following inputs then click :heavy\_check\_mark: icon.

   * **Path:** `/q/health/ready`
   * **Port:** `8080`
   * **Period:** `30`
   * **Timeout:** `10`

   ![Deploy application container](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-acef269950e24d3fdd31a1740526460db46220df%2Fdeploy-10.png?alt=media)
6. Click **Add Liveness probe** link.

   ![Deploy application container](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-10419e878011a16f373476c491073a95535c1845%2Fdeploy-11.png?alt=media)
7. Enter following inputs then click :heavy\_check\_mark: icon.

   * **Path:** `/q/health/live`
   * **Port:** `8080`
   * **Period:** `30`
   * **Timeout:** `10`

   ![Deploy application container](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-4b5175757d72536746a4f6819e478069646a8240%2Fdeploy-12.png?alt=media)
8. Click **Deployment** link.

   ![Deploy application container](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-a3f806eff7ba323761c33584054b40b34e091dc0%2Fdeploy-13.png?alt=media)
9. Enter following environment variable. Then click **Resource limits** link.

   * **Name:** `KUBERNETES_NAMESPACE`
   * **Value:** `userX-super-heroes` where `X` is your user number.

   ![Deploy application container](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-c2c0015430905d65fc35f5e0b9495918870f6ed4%2Fdeploy-14.png?alt=media)
10. Enter following memory request and limit. Then click **Labels** link.

    * **Request:** `256`
    * **Limit:** `768`

    ![Deploy application container](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-3dbe51b80991123401484374b09acbfa09ae4718%2Fdeploy-15.png?alt=media)
11. Enter `system=quarkus-super-heroes` then click **Create** button.

    ![Deploy application container](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-efe2da7d01e9798a49238b9d8b67d8cf93255730%2Fdeploy-16.png?alt=media)

## Add application configurations in ConfigMap and Secret objects to application container

1. Click on **rest-heroes** entity in view area. A panel will show up, then click **rest-heroes** link.

   ![Deploy application container](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-5cca045de72f71981e8431031cd142a9371b91d1%2Fdeploy-17.png?alt=media)
2. Go to **Environment** tab to add environment variables to application container. Then click **Add all from ConfigMap or Secret** link.

   ![Deploy application container](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-03811ab1d53d805796ca09ed1d863cba81575401%2Fdeploy-18.png?alt=media)
3. Select **rest-heroes-config** ConfigMap and **rest-heroes-config-creds** Secret objects, then click **Save** button. And then go to **Topology** menu.

   ![Deploy application container](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-c8cecc6721b302bd5904d98edb3e822cbdc3e310%2Fdeploy-20.png?alt=media)
4. Hover mouse pointer over the **rest-heroes** entity, a bubble should show up and say *1 Running* which means there is 1 pod running.

   ![Deploy application container](https://1365375534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYKKHX3vDr97cJAqTjZDZ%2Fuploads%2Fgit-blob-a5cb88e4e5c7e023e7db6f15330010583fd1bf23%2Fdeploy-21.png?alt=media)

## What have you learnt?

1. How to create ConfigMap object with YAML to keep all application configurations.
2. How to create Secret object with YAML to keep all secret application configurations.
3. How to deploy application using existing container image with following additional configurations:
   * Application health checks e.g. liveness and readiness probes
   * Require and limit resource i.e. memory for application.
   * Environment variable for application container
   * User-defined label
4. Bind configurations from ConfigMap and Secret objects to application container via environment variables.
