---
title: Deploying an application via operator
exercise: 5
date: '2023-12-06'
tags: ['openshift','containers','kubernetes','operator-framework']
draft: false
authors: ['default']
summary: "Exploring alternative deployment approaches."
---

Another alternative approach for deploying and managing the lifecycle of more complex applications is via the [Operator Framework](https://operatorframework.io).

The goal of an **Operator** is to put operational knowledge into software. Previously this knowledge only resided in the minds of administrators, various combinations of shell scripts or automation software like Ansible. It was outside of your Kubernetes cluster and hard to integrate. **Operators** change that.

**Operators** are the missing piece of the puzzle in Kubernetes to implement and automate common Day-1 (installation, configuration, etc.) and Day-2 (re-configuration, update, backup, failover, restore, etc.) activities in a piece of software running inside your Kubernetes cluster, by integrating natively with Kubernetes concepts and APIs. 

With Operators you can stop treating an application as a collection␃of primitives like **Pods**, **Deployments**, **Services** or **ConfigMaps**, but instead as a singular, simplified custom object that only exposes the specific configuration values that make sense for the specific application.




## 5.1 - Deploying an operator

Deploying an application via an **Operator** is generally a two step process. The first step is to deploy the **Operator** itself.

Once the **Operator** is installed we can deploy the application.

For this exercise we will install the **Operator** for the [Grafana](https://grafana.com) observability platform.

Let's start in the **Topology** view of the **Developer** perspective.

Copy the following YAML snippet to your clipboard:

```yaml
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: grafana-operator
  namespace: userX
spec:
  channel: v5
  installPlanApproval: Automatic
  name: grafana-operator
  source: community-operators
  sourceNamespace: openshift-marketplace
```

Click the **+** button in the top right corner menu bar of the OpenShift web console. This is a fast way to quickly import snippets of YAML for testing or exploration purposes.

Paste the above snippet of YAML into the editor and replace the instance of `userX` with your assigned user.

Click **Create**. In a minute or so you should see the Grafana operator installed and running in your project.

<Zoom>
|![operator-deployment](/ocp-app-delivery-workshop/static/images/operator-deployment.gif) | 
|:-------------------------------------------------------------------:|
| *Deploying grafana operator via static yaml*                        |
</Zoom>


## 5.2 - Deploying an operator driven application

With our Grafana operator now running it will be listening for the creation of a `grafana` custom resource. When one is detected the operator will deploy the Grafana application according to the specifcation we supplied.

Let's switch over to the **Administrator** perspective for this next task to deploy our Grafana instance.

Under the **Operators** category in the left hand menu click on **Installed Operators**.

In the **Installed Operators** list you should see a **Grafana Operator** entry, click into that.

On the **Operator details** screen you will see a list of "Provided APIs". These are custom resource types that we can now deploy with the help of the operator.

Click on **Create instance** under the provided API titled `Grafana`.

On the next **Create Grafana** screen click on **YAML View** radio button and enter the following, replacing the two instances of `userX` with your assigned user then click **Create**.

```yaml
apiVersion: grafana.integreatly.org/v1beta1
kind: Grafana
metadata:
  labels:
    dashboards: grafana
    folders: grafana
  name: grafana
  namespace: userX
spec:
  config:
    auth:
      disable_login_form: 'false'
    log:
      mode: console
    security:
      admin_password: example
      admin_user: example
  route:
    spec:
      tls:
        termination: edge
      host: grafana-userX.apps.cluster-dsmsm.dynamic.opentlc.com
```

<Zoom>
|![grafana-deployment](/ocp-app-delivery-workshop/static/images/grafana-deployment.gif) | 
|:-------------------------------------------------------------------:|
| *Deploying grafana application via the grafana operator*            |
</Zoom>


## 5.3 Logging into the application

While we are in the **Administrator** perspective of the web console let's take a look at a couple of sections to confirm our newly deployed Grafana application is running as expected.

For our first step click on the **Workloads** category on the left hand side menu and then click **Pods**.

We should see that a `grafana-deployment-<id>` pod with a **Status** of `Running`.

<Zoom>
|![grafana-pod](/ocp-app-delivery-workshop/static/images/grafana-pod.png) | 
|:-------------------------------------------------------------------:|
| *Confirming the grafana pod is running*                             |
</Zoom>


Now that we know the Grafana application **Pod** is running let's open the application and confirm we can log in.

Click the **Networking** category on the left hand side menu and then click **Routes**.

Click the **Route** named `grafana-route` and open the url on the right hand side under the **Location** header.

Once the new tab opens we should be able to login to Grafana using the credentials we supplied in the previous step in the YAML configuration.

<Zoom>
|![grafana-route](/ocp-app-delivery-workshop/static/images/grafana-route.gif) | 
|:-------------------------------------------------------------------:|
| *Confirming the grafana route is working*                           |
</Zoom>


## 5.4 - Bonus objective: Grafana dashboards

If you have time, take a while to learn about the https://grafana.com/grafana/dashboards and how Grafana can be used to visualise just about anything.


Well done, you've finished exercise 5! 🎉 
