Creating instances of services managed by Operators

Operators are a method of packaging, deploying, and managing Kubernetes services. With odo, you can create instances of services from the custom resource definitions (CRDs) provided by the Operators. You can then use these instances in your projects and link them to your components.

To create services from an Operator, you must ensure that the Operator has valid values defined in its metadata to start the requested service. odo uses the metadata.annotations.alm-examples YAML file of an Operator to start the service. If this YAML has placeholder values or sample values, a service cannot start. You can modify the YAML file and start the service with the modified values. To learn how to modify YAML files and start services from it, see Creating services from YAML files.

Prerequisites

  • Install the oc CLI and log into the cluster.

    • Note that the configuration of the cluster determines the services available to you. To access the Operator services, a cluster administrator must install the respective Operator on the cluster first. To learn more, see Adding Operators to the cluster.
  • Install the odo CLI.

Creating a project

Create a project to keep your source code, tests, and libraries organized in a separate single unit.

Procedure

  1. Log in to an OKD cluster:

    1. $ odo login -u developer -p developer
  2. Create a project:

    1. $ odo project create myproject

    Example output

    1. Project 'myproject' is ready for use
    2. New project created and now using project : myproject

Listing available services from the Operators installed on the cluster

With odo, you can display the list of the Operators installed on your cluster, and the services they provide.

  • To list the Operators installed in current project, run:

    1. $ odo catalog list services

    The command lists Operators and the CRDs. The output of the command shows the Operators installed on your cluster. For example:

    1. Operators available in the cluster
    2. NAME CRDs
    3. etcdoperator.v0.9.4 EtcdCluster, EtcdBackup, EtcdRestore
    4. mongodb-enterprise.v1.4.5 MongoDB, MongoDBUser, MongoDBOpsManager

    etcdoperator.v0.9.4 is the Operator, EtcdCluster, EtcdBackup and EtcdRestore are the CRDs provided by the Operator.

Creating a service from an Operator

If an Operator has valid values defined in its metadata to start the requested service, you can use the service with odo service create.

  1. Print the YAML of the service as a file on your local drive:

    1. $ oc get csv/etcdoperator.v0.9.4 -o yaml
  2. Verify that the values of the service are valid:

    1. apiVersion: etcd.database.coreos.com/v1beta2
    2. kind: EtcdCluster
    3. metadata:
    4. name: example
    5. spec:
    6. size: 3
    7. version: 3.2.13
  3. Start an EtcdCluster service from the etcdoperator.v0.9.4 Operator:

    1. $ odo service create etcdoperator.v0.9.4 EtcdCluster
  4. Verify that a service has started:

    1. $ oc get EtcdCluster

Creating services from YAML files

If the YAML definition of the service or custom resource (CR) has invalid or placeholder data, you can use the --dry-run flag to get the YAML definition, specify the correct values, and start the service using the corrected YAML definition. Printing and modifying the YAML used to start a service odo provides the feature to print the YAML definition of the service or CR provided by the Operator before starting a service.

  1. To display the YAML of the service, run:

    1. $ odo service create <operator-name> --dry-run

    For example, to print YAML definition of EtcdCluster provided by the etcdoperator.v0.9.4 Operator, run:

    1. $ odo service create etcdoperator.v0.9.4 --dry-run

    The YAML is saved as the etcd.yaml file.

  2. Modify the etcd.yaml file:

    1. apiVersion: etcd.database.coreos.com/v1beta2
    2. kind: EtcdCluster
    3. metadata:
    4. name: my-etcd-cluster (1)
    5. spec:
    6. size: 1 (2)
    7. version: 3.2.13
    1Change the name from example to my-etcd-cluster
    2Reduce the size from 3 to 1
  3. Start a service from the YAML file:

    1. $ odo service create --from-file etcd.yaml
  4. Verify that the EtcdCluster service has started with one pod instead of the pre-configured three pods:

    1. $ oc get pods | grep my-etcd-cluster