Populate the /ttconfig Directory

You can use different methods to ensure metadata files are placed in the /ttconfig directory of TimesTen containers. There is no requirement as to which method to use. Kubernetes provides such facilities as ConfigMaps, Secrets, and init containers for you to consider.

Using ConfigMaps and Secrets

You can use one or more ConfigMaps and one or more Secrets to incorporate metadata files into the TimesTen containers. This lets you specify different TimesTen metadata for different deployments. In addition, you can use Secrets for metadata that contains sensitive data, like passwords and certificates.

The use of a ConfigMap to populate the metadata into Pods is a standard Kubernetes technique. One benefit is that you can modify the ConfigMap after it is created, which results in the immediate update of the files that are in the Pod.

Note:

TimesTen may not immediately notice and act on the changed content of the files.

When you use ConfigMaps and Secrets to hold your metadata and then reference them in the TimesTenClassic object definition, the TimesTen Operator creates a Projected Volume called tt-config. This tt-config volume contains the contents of all the ConfigMaps and all the Secrets specified in the dbConfigMap and the dbSecret fields of your TimesTenClassic or your TimesTenScaleout object. This volume is mounted as /ttconfig in the TimesTen containers.

Note:

You can specify one or more ConfigMaps and/or Secrets in your TimesTenClassic or TimesTenScaleout object using the dbConfigMap and dbSecret datum. The result is that these ConfigMaps and/or Secrets are mounted read-only at /ttconfig. Since such a mount is read-only, you cannot write into it from an init container. Alternatively, you can use an emptydir volume and use an init container to write files into it. However, you cannot combine ConfigMaps and Secrets with an init container. For information about using an init container, see Using an init container.

To use ConfigMaps and Secrets, follow this process:

  • Decide what facilities will contain what metadata files. For example, you can use one ConfigMap for all the metadata files. Or, for example, you can use one ConfigMap for the db.ini metadata file and one Secret for the adminUser and the schema.sql metadata files. There is no specific requirement.

  • Create the directory (or directories) that will contain the metadata files.

  • Use the kubectl create command to create the ConfigMap and the Secrets in the Kubernetes cluster.

  • Include the ConfigMaps and Secrets in your TimesTenClassic or your TimesTenScaleout object definition.

The following examples illustrate how to use ConfigMaps and Secrets for a TimesTenClassic or a TimesTenScaleout object.

Example Using One ConfigMap

This example uses one ConfigMap (called sample) for the db.ini, the adminUser, and the schema.sql metadata files.

You can use this ConfigMap for a TimesTenClassic or a TimesTenScaleout object.

  1. On your development host, from the directory of your choice, create an empty subdirectory for the metadata files. This example creates the cm_sample subdirectory. (The cm_sample directory is used in the remainder of this example to denote this directory.)
    mkdir -p cm_sample
  2. Change to the ConfigMap directory.
    cd cm_sample
  3. Create the db.ini file. In this db.ini file, define the PermSize and DatabaseCharacterSet connection attributes.
    vi db.ini
    
    PermSize=200
    DatabaseCharacterSet=AL32UTF8
    ConnectionCharacterSet=AL32UTF8
  4. Create the adminUser file. In this adminUser file, create the sampleuser user with the samplepw password.
    vi adminUser
    
    sampleuser/samplepw
  5. Create the schema.sql file. In this schema.sql file, define the s sequence and the emp table for the sampleuser user. The Operator automatically initializes your database with these object definitions.
    vi schema.sql
    
    create sequence sampleuser.s;
    create table sampleuser.emp (
      id number not null primary key,
      name char(32)
    );
  6. Create the ConfigMap. The files in the cm_sample directory are included in the ConfigMap. These files are later available in the TimesTen containers.

    In this example:

    • The name of the ConfigMap is sample. Replace sample with a name of your choosing.

    • This example uses cm_sample as the directory where the files that will be copied into the ConfigMap reside. If you use a different directory, replace cm_sample with the name of your directory.

    kubectl create configmap sample --from-file=cm_sample
    The output is the following:
    configmap/sample created
  7. Verify the contents of the ConfigMap.
    kubectl describe configmap sample
    The output is the following:
    Name:         sample
    Namespace:    mynamespace
    Labels:       <none>
    Annotations:  <none>
     
    Data
    ====
    adminUser:
    ----
    sampleuser/samplepw
     
    db.ini:
    ----
    PermSize=200
    DatabaseCharacterSet=AL32UTF8
    ConnectionCharacterSet=AL32UTF8
     
    schema.sql:
    ----
    create sequence sampleuser.s;
    create table sampleuser.emp (
      id number not null primary key,
      name char(32)
    );
    
    Events:  <none>
  8. Include the ConfigMap in the object definition. In the dbConfigMap field, specify the name of the your ConfigMap (sample, in this example).

    Note this example uses a storageSize of 250Gi (suitable for a production environment). For demonstration purposes, a storageSize of 50Gi is adequate.

    This is an example of using the ConfigMap for a TimesTenClassic object.

    apiVersion: timesten.oracle.com/v1
    kind: TimesTenClassic
    metadata:
      name: sample
    spec:
      ttspec:
        storageClassName: oci-bv
        storageSize: 250Gi
        image: container-registry.oracle.com/timesten/timesten:22.1.1.19.0
        imagePullSecret: sekret
        dbConfigMap:
        - sample
    
    This is an example of using the ConfigMap for a TimesTenScaleout object.
    apiVersion: timesten.oracle.com/v1
    kind: TimesTenScaleout
    metadata:
      name: sample
    spec:
      ttspec:
        storageClassName: oci-bv
        storageSize: 250Gi
        image: container-registry.oracle.com/timesten/timesten:22.1.1.19.0
        imagePullSecret: sekret
        k: 2
        nReplicaSets: 3
        nZookeeper: 3
        dbConfigMap:
        - sample

    The sample ConfigMap holds the metadata files. The tt-config volume contains the contents of the sample ConfigMap.

Example Using One ConfigMap and One Secret

This example uses one ConfigMap (called myconfig) for the db.ini metadata file and one Secret (called mysecret) for the adminUser and the schema.sql metadata files.

You can use this ConfigMap and Secret for a TimesTenClassic or a TimesTenScaleout object.

  1. On your development host, from the directory of your choice:
    • Create one empty subdirectory for the ConfigMap. This example creates the cm_myconfig subdirectory. (The cm_myconfig directory is used in the remainder of this example to denote this directory.) This directory will contain the db.ini metadata file.

    • Create a second empty subdirectory for the Secret. This example creates the secret_mysecret subdirectory. (The secret_mysecret directory is used in the remainder of this example to denote this directory.) This directory will contain the adminUser and the schema.sql metadata files.

    mkdir -p cm_myconfig
    mkdir -p secret_mysecret
  2. Change to the ConfigMap directory.
    cd cm_myconfig
  3. Create the db.ini file in this ConfigMap directory (cm_myconf, in this example). In this db.ini file, define the PermSize and DatabaseCharacterSet connection attributes.
    vi db.ini
    
    PermSize=200
    DatabaseCharacterSet=AL32UTF8
    ConnectionCharacterSet=AL32UTF8
  4. Change to the Secret directory.
    cd secret_mysecret
  5. Create the adminUser file in this Secret directory (secret_mysecret in this example). In this adminUser file, create the sampleuser user with the samplepw password.
    vi adminUser
    
    sampleuser/samplepw
  6. Create the schema.sql file in this Secret directory (secret_mysecret in this example). In this schema.sql file, define the s sequence and the emp table for the sampleuser user. The Operator automatically initializes your database with these object definitions.
    vi schema.sql
    
    create sequence sampleuser.s;
    create table sampleuser.emp (
      id number not null primary key,
      name char(32)
    );
  7. Create the ConfigMap. The files in the cm_myconfig directory are included in the ConfigMap and, later, will be available in the TimesTen containers.

    In this example:

    • The name of the ConfigMap is myconfig. Replace myconfig with a name of your choosing.

    • This example uses cm_myconfig as the directory where the files that will be copied into the ConfigMap reside. If you use a different directory, replace cm_myconfig with the name of your directory.

    Create the ConfigMap.

    kubectl create configmap myconfig --from-file=cm_myconfig
    The output is the following:
    configmap/myconfig created
  8. Verify the contents of the ConfigMap.
    kubectl describe configmap myconf
    
    The output is the following:
    Name:         myconfig
    Namespace:    mynamespace
    Labels:       <none>
    Annotations:  <none>
     
    Data
    ====
    db.ini:
    ----
    PermSize=200
    DatabaseCharacterSet=AL32UTF8
    ConnectionCharacterSet=AL32UTF8
     
    Events:  <none>
  9. Create the Secret. The files in the secret_mysecret directory are included in the Secret and, later, will be available in the TimesTen containers.

    In this example:

    • The name of the Secret is mysecret. Replace mysecret with a name of your choosing.

    • This example uses secret_mysecret as the directory where the files that will be copied into the Secret reside. If you use a different directory, replace secret_mysecret with the name of your directory.

    kubectl create secret generic mysecret --from-file=secret_mysecret
    The output is the following:
    secret/mysecret created
  10. Verify the Secret. Note the contents of the adminUser and the schema.sql files are not displayed.
    kubectl describe secret mysecret
    The output is the following:
    
    Name:         mysecret
    Namespace:    mynamespace
    Labels:       <none>
    Annotations:  <none>
     
    Type:  Opaque
     
    Data
    ====
    adminUser:   12 bytes
    schema.sql:  98 bytes
  11. Include the ConfigMap and the Secret in the object definition.
    • In the dbConfigMap field, specify the name of the your ConfigMap.

    • In the dbSecret field, specify the name of the your Secret.

    This is an example of using the ConfigMap and the Secret for a TimesTenClassic object.

    apiVersion: timesten.oracle.com/v1
    kind: TimesTenClassic
    metadata:
      name: sample
    spec:
      ttspec:
        storageClassName: oci-bv
        storageSize: 250Gi
        image: container-registry.oracle.com/timesten/timesten:22.1.1.19.0
        imagePullSecret: sekret
        dbConfigMap:
        - myconfig
        dbSecret:
        - mysecret
    This is an example of using the ConfigMap and the Secret for a TimesTenScaleout object.
    apiVersion: timesten.oracle.com/v1
    kind: TimesTenScaleout
    metadata:
      name: sample
    spec:
      ttspec:
        storageClassName: oci-bv
        storageSize: 250Gi
        image: container-registry.oracle.com/timesten/timesten:22.1.1.19.0
        imagePullSecret: sekret
        k: 2
        nReplicaSets: 3
        nZookeeper: 3
        dbConfigMap:
        - myconfig
        dbSecret:
        - mysecret

    The myconfig ConfigMap and the mysecret Secret holds the metadata files. The tt-config volume contains the contents of the myconfig ConfigMap and the mysecret Secret.

Example Using One ConfigMap for a TimesTenScaleout Object

This example shows you how to create a metadata file for a direct connectable and a metadata file for a client/server connectable. It then shows you how to include these connectables in a ConfigMap for a TimesTenScaleout object. The ConfigMap also includes the db.ini, adminUser, and schema.sql metadata files.

  1. On your development host, from the directory of your choice, create an empty subdirectory for the metadata files. This example creates the cm_samplescaleout subdirectory. (The cm_samplescaleout directory is used in the remainder of this example to denote this directory.)
    mkdir -p cm_samplescaleout
  2. Change to the ConfigMap directory.
    cd cm_samplescaleout
  3. Create the direct connectable.
    vi samplescaleout.connect
    
    ConnectionCharacterSet=AL32UTF8
  4. Create the client/server connectable.
    vi samplecsscaleout.csconnect
    
    ConnectionCharacterSet=AL32UTF8
    TTC_Timeout=30
  5. Create the db.ini file. In this db.ini file, define the PermSize and DatabaseCharacterSet connection attributes.
    vi db.ini
    
    PermSize=200
    DatabaseCharacterSet=AL32UTF8
  6. Create the adminUser file. In this adminUser file, create the sampleuser user with the samplepw password.
    vi adminUser
    
    sampleuser/samplepw
  7. Create the schema.sql file. In this schema.sql file, define the s sequence and the emp table for the sampleuser user. The Operator automatically initializes your database with these object definitions.
    vi schema.sql
    
    create sequence sampleuser.s;
    create table sampleuser.emp (
      id number not null primary key,
      name char(32)
    );
  8. Create the ConfigMap. The files in the cm_samplescaleout directory are included in the ConfigMap. These files are later available in the TimesTen containers.

    In this example:

    • The name of the ConfigMap is samplescaleout. Replace samplescaleout with a name of your choosing.

    • This example uses cm_samplescaleout as the directory where the files that will be copied into the ConfigMap reside. If you use a different directory, replace cm_samplescaleout with the name of your directory.

    kubectl create configmap samplescaleout --from-file=cm_samplescaleout
    The output is the following:
    configmap/samplescaleout created
  9. Verify the contents of the ConfigMap.
    kubectl describe configmap samplescaleout
    The output is the following:
    Name:         samplescaleout
    Namespace:    mynamespace
    Labels:       <none>
    Annotations:  <none>
     
    Data
    ====
    adminUser:
    ----
    sampleuser/samplepw
     
    db.ini:
    ----
    PermSize=200
    DatabaseCharacterSet=AL32UTF8
    
    sampleconnectable.connect:
    ----
    ConnectionCharacterSet=AL32UTF8
    
    samplecsconnectable.csconnect:
    ----
    ConnectionCharacterSet=AL32UTF8
    TTC_Timeout=30
     
    schema.sql:
    ----
    create sequence sampleuser.s;
    create table sampleuser.emp (
      id number not null primary key,
      name char(32)
    );
    
    Events:  <none>
  10. Include the ConfigMap in the object definition.

    Note this example uses a storageSize of 250Gi (suitable for a production environment). For demonstration purposes, a storageSize of 50Gi is adequate.

    apiVersion: timesten.oracle.com/v1
    kind: TimesTenScaleout
    metadata:
      name: samplescaleout
    spec:
      ttspec:
        storageClassName: oci-bv
        storageSize: 250Gi
        image: container-registry.oracle.com/timesten/timesten:22.1.1.19.0
        imagePullSecret: sekret
        k: 2
        nReplicaSets: 3
        nZookeeper: 3
        dbConfigMap:
        - samplescaleout

Using an init container

You can use an init container to place your metadata files into the /ttconfig directory of the TimesTen containers. An init container lets you to create your own scripts to populate the /ttconfig directory. You can use an init container for TimesTenClassic and for TimesTenScaleout objects. For more information about init containers, see:

https://kubernetes.io/docs/concepts/workloads/pods/init-containers

Note:

You can specify one or more ConfigMaps and/or Secrets in your TimesTenClassic or TimesTenScaleout object using the dbConfigMap and dbSecret datum. The result is that these ConfigMaps and/or Secrets are mounted read-only at /ttconfig. Since such a mount is read-only, you cannot write into it from an init container. Alternatively, you can use an emptydir volume and use an init container to write files into it. However, you cannot combine ConfigMaps and Secrets with an init container. For information about using ConfigMaps and Secrets, see Using ConfigMaps and Secrets.

Here is an example that illustrates how to use an init container for a TimesTenClassic object. The template element is required. This element is applied to Pods that contain the TimesTen Classic instances. The example shows you where to specify the script that populates the /ttconfig directory. It also uses the tt-config volume name in the volumes field of the TimesTenClassic object. If you specify a volume with the tt-config name, it is automatically mounted at /ttconfig in your TimesTen containers.

apiVersion: timesten.oracle.com/v1
kind: TimesTenClassic
metadata:
  name: init1
spec:
  ttspec:
    storageClassName: oci-bv
    storageSize: 250Gi
    image: container-registry.oracle.com/timesten/timesten:22.1.1.19.0
    imagePullSecret: sekret
  template:
    spec:
      imagePullSecrets: 
      - name: sekret
      initContainers:
      - name: initclassic
        image: container-registry.oracle.com/timesten/timesten:22.1.1.19.0
        command:
        - sh
        - "-c"
        - |
          /bin/bash <<'EOF'
          Your script to populate /ttconfig goes here
          EOF
        volumeMounts:
        - name: tt-config
          mountPath: /ttconfig
      volumes:
      - name: tt-config
        emptyDir: {}

When using an init container for a TimesTenScaleout object, the metadata files must be placed in both the dataTemplate and the mgmtTemplate elements.