1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-06 06:46:26 +01:00
Files
openshift-docs/modules/managing-memcached-operator-using-olm.adoc

217 lines
6.4 KiB
Plaintext

// Module included in the following assemblies:
//
// * operators/operator_sdk/osdk-getting-started.adoc
[id="managing-memcached-operator-using-olm_{context}"]
= Managing a Go-based Operator using Operator Lifecycle Manager
The previous section has covered manually running an Operator. In the next
sections, we will explore using Operator Lifecycle Manager (OLM), which is what
enables a more robust deployment model for Operators being run in production
environments.
OLM helps you to install, update, and generally manage the lifecycle of all
of the Operators (and their associated services) on a Kubernetes cluster. It
runs as an Kubernetes extension and lets you use `oc` for all the lifecycle
management functions without any additional tools.
.Prerequisites
- OLM installed on a Kubernetes-based cluster (v1.8 or above to support the
`apps/v1beta2` API group), for example {product-title} {product-version}
Preview OLM enabled
- Memcached Operator built
.Procedure
. *Generate an Operator manifest.*
+
An Operator manifest describes how to display, create, and manage the
application, in this case Memcached, as a whole. It is defined by a
`ClusterServiceVersion` (CSV) object and is required for OLM to function.
+
From the `memcached-operator/` directory that was created when you built the
Memcached Operator, generate the CSV manifest:
+
[source,terminal]
----
$ operator-sdk generate csv --csv-version 0.0.1
----
+
[NOTE]
====
See
link:https://github.com/operator-framework/operator-lifecycle-manager/blob/master/doc/design/building-your-csv.md[Building a CSV for the Operator Framework]
for more information on manually defining a manifest file.
====
. *Create an OperatorGroup* that specifies the namespaces that the Operator will
target. Create the following OperatorGroup in the namespace where you will
create the CSV. In this example, the `default` namespace is used:
+
[source,yaml]
----
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: memcached-operator-group
namespace: default
spec:
targetNamespaces:
- default
----
. *Deploy the Operator.* Use the files that were generated into the `deploy/`
directory by the Operator SDK when you built the Memcached Operator.
.. Apply the Operator's CSV manifest to the specified namespace in the cluster:
+
[source,terminal]
----
$ oc apply -f deploy/olm-catalog/memcached-operator/0.0.1/memcached-operator.v0.0.1.clusterserviceversion.yaml
----
+
When you apply this manifest, the cluster does not immediately update because
it does not yet meet the requirements specified in the manifest.
.. Create the role, role binding, and service account to grant resource
permissions to the Operator, and the Custom Resource Definition (CRD) to create
the Memcached type that the Operator manages:
+
[source,terminal]
----
$ oc create -f deploy/crds/cache.example.com_memcacheds_crd.yaml
----
+
[source,terminal]
----
$ oc create -f deploy/service_account.yaml
----
+
[source,terminal]
----
$ oc create -f deploy/role.yaml
----
+
[source,terminal]
----
$ oc create -f deploy/role_binding.yaml
----
+
Because OLM creates Operators in a particular namespace when a manifest is
applied, administrators can leverage the native Kubernetes RBAC permission model
to restrict which users are allowed to install Operators.
. *Create an application instance.*
+
The Memcached Operator is now running in the `default` namespace. Users
interact with Operators via instances of `CustomResources`; in this case, the
resource has the kind `Memcached`. Native Kubernetes RBAC also applies to
`CustomResources`, providing administrators control over who can interact with
each Operator.
+
Creating instances of Memcached in this namespace will now trigger the Memcached
Operator to instantiate pods running the memcached server that are managed by
the Operator. The more `CustomResources` you create, the more unique instances
of Memcached are managed by the Memcached Operator running in this namespace.
+
[source,terminal]
----
$ cat <<EOF | oc apply -f -
apiVersion: "cache.example.com/v1alpha1"
kind: "Memcached"
metadata:
name: "memcached-for-wordpress"
spec:
size: 1
EOF
----
+
[source,terminal]
----
$ cat <<EOF | oc apply -f -
apiVersion: "cache.example.com/v1alpha1"
kind: "Memcached"
metadata:
name: "memcached-for-drupal"
spec:
size: 1
EOF
----
+
[source,terminal]
----
$ oc get Memcached
----
+
.Example output
[source,terminal]
----
NAME AGE
memcached-for-drupal 22s
memcached-for-wordpress 27s
----
+
[source,terminal]
----
$ oc get pods
----
+
.Example output
[source,terminal]
----
NAME READY STATUS RESTARTS AGE
memcached-app-operator-66b5777b79-pnsfj 1/1 Running 0 14m
memcached-for-drupal-5476487c46-qbd66 1/1 Running 0 3s
memcached-for-wordpress-65b75fd8c9-7b9x7 1/1 Running 0 8s
----
////
This procedure no longer works. The original CSV that was linked 404'd now, but
the newer one doesn't have a replaces field. Removing the step until a working
replacement is developed.
. *Update an application.*
+
Manually apply an update to the Operator by creating a new Operator manifest
with a `replaces` field that references the old Operator manifest. OLM
ensures that all resources being managed by the old Operator have their
ownership moved to the new Operator without fear of any programs stopping
execution. It is up to the Operators themselves to execute any data migrations
required to upgrade resources to run under a new version of the Operator.
+
The following commands demonstrate applying a new Operator manifest file using a
new version of the Operator and shows that the pods remain executing:
.. Download the manifest:
+
[source,terminal]
----
$ curl -Lo memcachedoperator.0.18.1.csv.yaml \
https://raw.githubusercontent.com/operator-framework/operator-sdk-samples/master/go/memcached-operator/deploy/olm-catalog/memcached-operator/manifests/memcached-operator.clusterserviceversion.yaml
----
.. Create the object:
+
[source,terminal]
----
$ oc apply -f memcachedoperator.0.18.1.csv.yaml
----
.. View the pods:
+
[source,terminal]
----
$ oc get pods
----
+
.Example output
[source,terminal]
----
NAME READY STATUS RESTARTS AGE
memcached-app-operator-66b5777b79-pnsfj 1/1 Running 0 3s
memcached-for-drupal-5476487c46-qbd66 1/1 Running 0 14m
memcached-for-wordpress-65b75fd8c9-7b9x7 1/1 Running 0 14m
----
////