This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.2.10. Creating instances of services managed by Operators
Creating instances of services managed by Operators in `odo` is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see https://access.redhat.com/support/offerings/techpreview/.
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.
2.10.1. 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. -
Enable experimental mode. To enable experimental mode in
odo
, run:odo preference set Experimental true
or use the environment variableodo config set --env ODO_EXPERIMENTAL=true
2.10.2. 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 OpenShift Container Platform cluster:
odo login -u developer -p developer
$ odo login -u developer -p developer
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a project:
odo project create myproject
$ odo project create myproject
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
✓ Project 'myproject' is ready for use ✓ New project created and now using project : myproject
✓ Project 'myproject' is ready for use ✓ New project created and now using project : myproject
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
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
$ odo catalog list services
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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
Operators available in the cluster NAME CRDs etcdoperator.v0.9.4 EtcdCluster, EtcdBackup, EtcdRestore mongodb-enterprise.v1.4.5 MongoDB, MongoDBUser, MongoDBOpsManager
Copy to Clipboard Copied! Toggle word wrap Toggle overflow etcdoperator.v0.9.4
is the Operator,EtcdCluster
,EtcdBackup
andEtcdRestore
are the CRDs provided by the Operator.
2.10.4. 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
$ oc get csv/etcdoperator.v0.9.4 -o yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the values of the service are valid:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start an
EtcdCluster
service from theetcdoperator.v0.9.4
Operator:odo service create etcdoperator.v0.9.4 EtcdCluster
$ odo service create etcdoperator.v0.9.4 EtcdCluster
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that a service has started:
oc get EtcdCluster
$ oc get EtcdCluster
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.10.5. 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
$ odo service create <operator-name> --dry-run
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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
$ odo service create etcdoperator.v0.9.4 --dry-run
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The YAML is saved as the
etcd.yaml
file.Modify the
etcd.yaml
file:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start a service from the YAML file:
odo service create --from-file etcd.yaml
$ odo service create --from-file etcd.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the
EtcdCluster
service has started with one pod instead of the pre-configured three pods:oc get pods | grep my-etcd-cluster
$ oc get pods | grep my-etcd-cluster
Copy to Clipboard Copied! Toggle word wrap Toggle overflow