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
Log in to an OKD cluster:
$ odo login -u developer -p developer
Create a project:
$ odo project create myproject
Example output
✓ Project 'myproject' is ready for use
✓ 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:
$ 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:
Operators available in the cluster
NAME CRDs
etcdoperator.v0.9.4 EtcdCluster, EtcdBackup, EtcdRestore
mongodb-enterprise.v1.4.5 MongoDB, MongoDBUser, MongoDBOpsManager
etcdoperator.v0.9.4
is the Operator,EtcdCluster
,EtcdBackup
andEtcdRestore
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
.
Print the YAML of the service as a file on your local drive:
$ oc get csv/etcdoperator.v0.9.4 -o yaml
Verify that the values of the service are valid:
apiVersion: etcd.database.coreos.com/v1beta2
kind: EtcdCluster
metadata:
name: example
spec:
size: 3
version: 3.2.13
Start an
EtcdCluster
service from theetcdoperator.v0.9.4
Operator:$ odo service create etcdoperator.v0.9.4 EtcdCluster
Verify that a service has started:
$ 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.
To display the YAML of the service, run:
$ odo service create <operator-name> --dry-run
For example, to print YAML definition of
EtcdCluster
provided by theetcdoperator.v0.9.4
Operator, run:$ odo service create etcdoperator.v0.9.4 --dry-run
The YAML is saved as the
etcd.yaml
file.Modify the
etcd.yaml
file:apiVersion: etcd.database.coreos.com/v1beta2
kind: EtcdCluster
metadata:
name: my-etcd-cluster (1)
spec:
size: 1 (2)
version: 3.2.13
1 Change the name from example
tomy-etcd-cluster
2 Reduce the size from 3
to1
Start a service from the YAML file:
$ odo service create --from-file etcd.yaml
Verify that the
EtcdCluster
service has started with one pod instead of the pre-configured three pods:$ oc get pods | grep my-etcd-cluster