Launch Your First OpenShift Operator

Hands-On Lab

 

Length

01:30:00

Difficulty

Intermediate

Launch your first operator You have been tasked with creating a Prometheus operator using only CLI in a 3-node OpenShift cluster running OKD v3.11.0. Using the templates provided in the examples, launch a 2-node Prometheus operator.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Deploy your first operator

  • create a new namespace named operation
$ oc new-project titans
  • create a Prometheus Operator subscription object definition named operator-sub.yml:
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  generateName: prometheus-
  namespace: operation
spec:
  source: rh-operators
  name: prometheus
  startingCSV: prometheusoperator.0.22.2
  channel: preview
  • Using the operator-sub.yml object definition, subscribe the operation namespace to the Prometheus operator:
$ oc create -f operator-sub.yml
  • create a prometheus-example operator definition:

prometheus-example.yml

apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
  name: prometheus-example
  labels:
    prometheus: k8s
  namespace: titans
spec:
  replicas: 2
  version: v2.3.2
  serviceAccountName: prometheus-k8s
  securityContext: {}
  serviceMonitorSelector:
    matchExpressions:
      - key: k8s-app
        operator: Exists
  ruleSelector:
    matchLabels:
      role: prometheus-rulefiles
      prometheus: k8s
  alerting:
    alertmanagers:
      - namespace: monitoring
        name: alertmanager-main
        port: web
  • create the operator using prometheus-example.yml:
$ oc create -f prometheus-example.yml