Published on
Exercise 5

Deploying an application via operator

Authors
  • Name
    Twitter

Another alternative approach for deploying and managing the lifecycle of more complex applications is via the Operator Framework.

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 observability platform.

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

Copy the following YAML snippet to your clipboard:

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.

|operator-deployment | |:-------------------------------------------------------------------:| | Deploying grafana operator via static yaml |

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.

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-xxz98.xxz98.sandbox619.opentlc.com

|grafana-deployment | |:-------------------------------------------------------------------:| | Deploying grafana application via the grafana operator |

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.

|grafana-pod | |:-------------------------------------------------------------------:| | Confirming the grafana pod is running |

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.

|grafana-route | |:-------------------------------------------------------------------:| | Confirming the grafana route is working |

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! 🎉