Subscribing to an Operator
Begin my creating a new namespace called myproject
. Set kubectl to consider it your default namespace, so that you don't have to specify it with every command.
kubectl create namespace myproject
kubectl config set-context --current --namespace=myproject
Next, create an OperatorGroup to ensure Operators installed to this namespace will be capable of watching for Custom Resources within the myproject
namespace.
cat > mariadb-operatorgroup.yaml <<EOF
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: mariadb-operatorgroup
namespace: myproject
spec:
targetNamespaces:
- myproject
EOF
Create the OperatorGroup:
oc create -f mariadb-operatorgroup.yaml
Verify the OperatorGroup has been successfully created:
oc get operatorgroup mariadb-operatorgroup
Create a Subscription manifest for the MariaDB Operator. Ensure the installPlanApproval
is set to Manual
. This allows you to review the InstallPlan before choosing to install the Operator:
cat > mariadb-subscription.yaml <<EOF
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: mariadb-operator-app
namespace: myproject
spec:
channel: alpha
installPlanApproval: Manual
name: mariadb-operator-app
source: operatorhubio-catalog
sourceNamespace: olm
EOF
Create the Subscription:
kubectl create -f mariadb-subscription.yaml
And verify the Subscription was created:
kubectl get subscription
Creating the subscription triggers OLM to generate an InstallPlan:
kubectl get installplan
Fetch the InstallPlan and observe the Kubernetes objects that will be created once it is approved:
MARIADB_INSTALLPLAN=`kubectl get installplan -o jsonpath={$.items[0].metadata.name}`
kubectl get installplan $MARIADB_INSTALLPLAN -o yaml
Install the Operator by approving the InstallPlan. You can kubectl edit installplan $MARIADB_INSTALLPLAN
, change the value of Approved
to true
, then save the file to apply the change. OR, run the following command to set Approved=true
in one shot:
kubectl patch installplan $MARIADB_INSTALLPLAN --type='json' -p '[{"op": "replace", "path": "/spec/approved", "value":true}]'
Once the InstallPlan is approved, you will see the newly provisioned ClusterServiceVersion, ClusterResourceDefinition, Role and RoleBindings, Service Accounts, and MariaDB Operator Deployment.
kubectl get clusterserviceversion
kubectl get crd | grep mariadb
kubectl get serviceaccounts | grep mariadb
kubectl get roles | grep mariadb
kubectl get rolebindings | grep mariadb
kubectl get deployments
When the MariaDB Operator is running, you can observe its logs:
MARIADB_OPERATOR=`kubectl get pods -o jsonpath={$.items[0].metadata.name}`
kubectl logs $MARIADB_OPERATOR
The MariaDB Operator is now installed and running, watching for the creation of a MariaDB Custom Resource (CR) in the `myproject` namespace.