Skip to main content
Version: v1.4

Installing Kubernetes Operators

Overview

Welcome to Nova Control Plane's guide on managing Kubernetes Operators! Nova provides a simplified way to manage Kubernetes Operators across different clusters. This guide will walk you through the steps to install and manage Kubernetes Operators using Nova. We'll use the Prometheus Operator as an example, but the principles can be applied to other operators as well. This guide is based on the official Prometheus Operator documentation.

Note: The examples provided are for illustrative purposes. In a real-world setup, make sure to customize the SchedulePolicy, deployment, CRDs, and values according to your specific needs.

Prerequisites

Before proceeding, you'll need to set labels on the resources you're applying. We've created a helper script for this purpose. Download it and save it as add_labels.sh and make it executable with chmod +x add_labels.sh.

Steps to Install Operators

1. Define Your SchedulePolicy

Start by defining a SchedulePolicy tailored to your specific clusters and namespaces. This sets the stage for deploying your Operator.

apiVersion: policy.elotl.co/v1alpha1
kind: SchedulePolicy
metadata:
name: prometheus-operator-policy
spec:
namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: default
clusterSelector:
matchLabels:
kubernetes.io/metadata.name: wlc-1
resourceSelectors:
labelSelectors:
- matchLabels:
nova.elotl.co/policy: prometheus-operator-policy

Apply the policy:

kubectl create -f example-operator-policy.yaml

2. Install Prometheus Operator and Resources

Use the following one-liner to download, label, and apply all the necessary Prometheus Operator resources. This command uses the script add_labels.sh, to add the appropriate labels for Nova management:

LATEST=$(curl -s https://api.github.com/repos/prometheus-operator/prometheus-operator/releases/latest | jq -cr .tag_name)
curl -sL https://github.com/prometheus-operator/prometheus-operator/releases/download/${LATEST}/bundle.yaml | \
./add_labels.sh -l nova.elotl.co/policy=prometheus-operator-policy | \
kubectl create -f -

3. Verify the Operator is Running

After applying the one-liner, you can verify that the Prometheus Operator is running successfully:

kubectl get deploy

Wait for the Prometheus Operator's to show running pods.

Congratulations! You've successfully installed the Prometheus Operator and its resources in your wlc-1 cluster using Nova, and all of this was done with a convenient one-liner.

4. Deploying Prometheus

Now we need to setup RBAC for our Prometheus and deploy Prometheus itself. First, save this as prom-rbac.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
labels:
nova.elotl.co/policy: prometheus-operator-policy
name: prometheus
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
nova.elotl.co/policy: prometheus-operator-policy
name: prometheus
rules:
- apiGroups: [""]
resources:
- nodes
- nodes/metrics
- services
- endpoints
- pods
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources:
- configmaps
verbs: ["get"]
- apiGroups:
- networking.k8s.io
resources:
- ingresses
verbs: ["get", "list", "watch"]
- nonResourceURLs: ["/metrics"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
nova.elotl.co/policy: prometheus-operator-policy
name: prometheus
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: prometheus
subjects:
- kind: ServiceAccount
name: prometheus
namespace: default

And run:

kubectl create -f prom-rbac.yaml

This will setup RBAC needed by Prometheus deployment.

With that out of the way, we can finally deploy Prometheus itself!

Save this as prometheus.yaml:

apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
labels:
nova.elotl.co/policy: prometheus-operator-policy
name: prometheus
spec:
serviceAccountName: prometheus
serviceMonitorSelector:
matchLabels:
team: frontend
resources:
requests:
memory: 400Mi
enableAdminAPI: false

Run:

kubectl create -f prometheus.yaml

And thats it! You now have a running Prometheus stack inside your wlc-1 cluster!

Learn more about our SchedulePolicies and how you can deploy operators across multiple clusters in our Tutorials section.

Reminder: Customize According to Your Needs

As mentioned before, the examples provided here are solely for illustrative purposes. For your specific needs, make sure to adapt the SchedulePolicy, Operator deployment, CRDs, and custom resources.