Skip to content

slashpai/prometheus-operator-examples

Repository files navigation

prometheus-operator-examples

Disclaimer: The configs in this repo should be treated as examples only. This is not tested in production cluster. These examples can serve as a starting point for creating production ready configs.

For each example config, check README page in respective folder.

Examples are created in default namespace

Pre-requisites

Create kind cluster or minikube cluster (examples in this repo are tested with kind cluster)

Create a playground kubernetes cluster

kind cluster

This will create a multi-node kind cluster with one control plane node and two worker nodes

 kind create cluster --name multi-node --config kind-config.yaml

or

minikube (not fully tested for all examples)

minikube start --nodes 3 -p multi-node --kubernetes-version=v1.27.3 --memory=6g --bootstrapper=kubeadm --extra-config=kubelet.authentication-token-webhook=true --extra-config=kubelet.authorization-mode=Webhook --extra-config=scheduler.bind-address=0.0.0.0 --extra-config=controller-manager.bind-address=0.0.0.0

Configure prometheus-operator

git clone https://github.com/prometheus-operator/prometheus-operator.git
cd prometheus-operator
# install crds
kubectl create -f example/prometheus-operator-crd-full
# deploy prometheus-operator
kubectl create -f example/rbac/prometheus-operator

You should see prometheus-operator pod running

kubectl get pods
NAME                                  READY   STATUS     RESTARTS   AGE
prometheus-operator-bcbbc87bd-mmbrl   1/1     Running    0          3m47s

Create Prometheus stack

From this repo path:

kubectl create -f prometheus_only_stack

You should see prometheus pods running after a while

prometheus-prometheus-0               2/2     Running   0          3m20s
prometheus-prometheus-1               2/2     Running   0          3m20s

Helpful Commands

  • Access Prometheus UI

    kubectl -n default port-forward svc/prometheus-operated 9090&

Notes

For most of the examples, app deployed is prometheus-example-app. You can deploy a different app adjust configs accordingly (mainly the port number).

Port-forward the app deployed to see more metrices generated by the prometheus-example-app. Otherwise you will see only version metric and automatically generated timeseries only in prometheus when you query.

If app is deployed as a pod:

kubectl port-forward pod/<pod-name> 8080

If service exists/deployed as a Deployment and exposed it through service

kubectl port-forward svc/<service-name> 8080