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
ocCLI 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
odoCLI. -
Enable experimental mode. To enable experimental mode in
odo, run:odo preference set Experimental trueor 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 developerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a project:
odo project create myproject
$ odo project create myprojectCopy 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 : myprojectCopy 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 servicesCopy 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, MongoDBOpsManagerCopy to Clipboard Copied! Toggle word wrap Toggle overflow etcdoperator.v0.9.4is the Operator,EtcdCluster,EtcdBackupandEtcdRestoreare 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 yamlCopy 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
EtcdClusterservice from theetcdoperator.v0.9.4Operator:odo service create etcdoperator.v0.9.4 EtcdCluster
$ odo service create etcdoperator.v0.9.4 EtcdClusterCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that a service has started:
oc get EtcdCluster
$ oc get EtcdClusterCopy 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-runCopy to Clipboard Copied! Toggle word wrap Toggle overflow For example, to print YAML definition of
EtcdClusterprovided by theetcdoperator.v0.9.4Operator, run:odo service create etcdoperator.v0.9.4 --dry-run
$ odo service create etcdoperator.v0.9.4 --dry-runCopy to Clipboard Copied! Toggle word wrap Toggle overflow The YAML is saved as the
etcd.yamlfile.Modify the
etcd.yamlfile: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.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the
EtcdClusterservice 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-clusterCopy to Clipboard Copied! Toggle word wrap Toggle overflow