Deploy Database For Fight Microservice

Deploy MongoDB database with YAML file

Create a Secret object to store database configurations

  1. Click on add icon located at top right corner of web console.

    Create a Secret object
  2. Copy this YAML snippet to the editor and click Create button.

    YAML snippet:

    apiVersion: v1
    kind: Secret
    metadata:
      labels:
        app: fights-db
        application: fights-service
        system: quarkus-super-heroes
      name: fights-db-config
    data:
      MONGODB_DATABASE: ZmlnaHRz
      MONGODB_USERNAME: c3VwZXJmaWdodA==
      MONGODB_PASSWORD: c3VwZXJmaWdodA==
      MONGODB_ROOT_USER: c3VwZXI=
      MONGODB_ROOT_PASSWORD: c3VwZXI=
    type: Opaque
    Create a Secret object
  3. A fights-db-config Secret object should be created. You can view the secret values by click on Reveal values link.

    Create a Secret object

Deploy MongoDB database application container

  1. Click on add icon located at top right corner of web console.

  2. Copy this YAML snippet to the editor and click Create button. Please note that the fights-db-config Secret object gets bound to MongoDB container as environment variables.

    YAML snippet:

    Deploy MongoDB container
  3. A fights-db Deployment object should be created and there is 1 Pod running.

    Deploy MongoDB container

Craete a Service object for accessing MongoDB Pod

  1. Click on add icon located at top right corner of web console.

  2. Copy this YAML snippet to the editor and click Create button.

    YAML snippet:

    Create Service for MongoDB container
  3. A fights-db Service object should be created. Go to Pods tab you should be able to see the Service is pointing and will be forwarding traffic to the fights-db-xxxxxxx Pod which is the MongoDB pod.

    Service for MongoDB container
    Service is pointing to MongoDB container
  4. Go to Topology menu, you should see fights-db MongoDB entity.

    MongoDB entity

What have you learnt?

  1. How to create Kubernetes resources e.g. Secret, Deployment, and Service objects with YAML via OpenShift web console.

  2. How to view actual value stored in the Secret object.

  3. How to check which pod(s) the Service object is pointing and will be forwarding traffic to.

Last updated