-
-
Save adilshaikh165/4e70493354faa0671b22bc1f3f363b39 to your computer and use it in GitHub Desktop.
Setting Up the Prometheus Operator Promise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apiVersion: monitoring.platform/v1alpha1 | |
| kind: AppObservability | |
| metadata: | |
| name: example-app-monitoring | |
| namespace: default | |
| spec: | |
| appName: prometheus-example-app | |
| namespace: default | |
| metricsPort: 8080 | |
| metricsPath: "/metrics" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apiVersion: platform.kratix.io/v1alpha1 | |
| kind: Promise | |
| metadata: | |
| name: app-observability | |
| spec: | |
| requiredPromises: | |
| - name: promoperator | |
| api: | |
| apiVersion: apiextensions.k8s.io/v1 | |
| kind: CustomResourceDefinition | |
| metadata: | |
| name: appobservabilities.monitoring.platform | |
| spec: | |
| group: monitoring.platform | |
| names: | |
| kind: AppObservability | |
| plural: appobservabilities | |
| singular: appobservability | |
| scope: Namespaced | |
| versions: | |
| - name: v1alpha1 | |
| served: true | |
| storage: true | |
| schema: | |
| openAPIV3Schema: | |
| type: object | |
| properties: | |
| spec: | |
| type: object | |
| properties: | |
| appName: | |
| type: string | |
| description: "Name of the application to monitor" | |
| namespace: | |
| type: string | |
| description: "Namespace where the application is deployed" | |
| metricsPort: | |
| type: integer | |
| default: 8080 | |
| description: "Port where metrics are exposed" | |
| metricsPath: | |
| type: string | |
| default: "/metrics" | |
| description: "Path where metrics are exposed" | |
| required: | |
| - appName | |
| - namespace | |
| workflows: | |
| resource: | |
| configure: | |
| - apiVersion: platform.kratix.io/v1alpha1 | |
| kind: Pipeline | |
| metadata: | |
| name: app-observability | |
| spec: | |
| rbac: | |
| permissions: | |
| - apiGroups: [""] | |
| resources: ["namespaces"] | |
| verbs: ["get", "list", "create", "patch"] | |
| - apiGroups: ["monitoring.coreos.com"] | |
| resources: ["prometheuses", "podmonitors", "servicemonitors"] | |
| resourceNamespace: "*" | |
| verbs: ["*"] | |
| - apiGroups: [""] | |
| resources: ["services", "endpoints", "serviceaccounts"] | |
| resourceNamespace: "*" | |
| verbs: ["*"] | |
| - apiGroups: ["rbac.authorization.k8s.io"] | |
| resources: ["roles", "rolebindings"] | |
| resourceNamespace: "*" | |
| verbs: ["*"] | |
| - apiGroups: [""] | |
| resources: ["persistentvolumeclaims"] | |
| resourceNamespace: "*" | |
| verbs: ["*"] | |
| containers: | |
| - name: setup-app-observability | |
| image: ghcr.io/syntasso/kratix-pipeline-utility:v0.0.1 | |
| command: [sh, -c] | |
| args: | |
| - | | |
| export APP_NAME=$(yq eval '.spec.appName' /kratix/input/object.yaml) | |
| export APP_NAMESPACE=$(yq eval '.spec.namespace' /kratix/input/object.yaml) | |
| export METRICS_PORT=$(yq eval '.spec.metricsPort // 8080' /kratix/input/object.yaml) | |
| export METRICS_PATH=$(yq eval '.spec.metricsPath // "/metrics"' /kratix/input/object.yaml) | |
| echo "Setting up observability for app: ${APP_NAME} in namespace: ${APP_NAMESPACE}" | |
| kubectl get namespace "${APP_NAMESPACE}" || kubectl create namespace "${APP_NAMESPACE}" | |
| cat <<EOF | kubectl apply -f - | |
| apiVersion: v1 | |
| kind: ServiceAccount | |
| metadata: | |
| name: prometheus-${APP_NAME} | |
| namespace: ${APP_NAMESPACE} | |
| EOF | |
| cat <<EOF | kubectl apply -f - | |
| apiVersion: rbac.authorization.k8s.io/v1 | |
| kind: Role | |
| metadata: | |
| name: prometheus-${APP_NAME} | |
| namespace: ${APP_NAMESPACE} | |
| rules: | |
| - apiGroups: [""] | |
| resources: ["pods", "services", "endpoints"] | |
| verbs: ["get", "list", "watch"] | |
| - apiGroups: [""] | |
| resources: ["configmaps"] | |
| verbs: ["get"] | |
| EOF | |
| cat <<EOF | kubectl apply -f - | |
| apiVersion: rbac.authorization.k8s.io/v1 | |
| kind: RoleBinding | |
| metadata: | |
| name: prometheus-${APP_NAME} | |
| namespace: ${APP_NAMESPACE} | |
| roleRef: | |
| apiGroup: rbac.authorization.k8s.io | |
| kind: Role | |
| name: prometheus-${APP_NAME} | |
| subjects: | |
| - kind: ServiceAccount | |
| name: prometheus-${APP_NAME} | |
| namespace: ${APP_NAMESPACE} | |
| EOF | |
| cat <<EOF | kubectl apply -f - | |
| apiVersion: monitoring.coreos.com/v1 | |
| kind: Prometheus | |
| metadata: | |
| name: prometheus-${APP_NAME} | |
| namespace: ${APP_NAMESPACE} | |
| spec: | |
| serviceAccountName: prometheus-${APP_NAME} | |
| podMonitorSelector: | |
| matchLabels: | |
| app: ${APP_NAME} | |
| resources: | |
| requests: | |
| memory: 400Mi | |
| cpu: 100m | |
| limits: | |
| memory: 800Mi | |
| cpu: 200m | |
| EOF | |
| cat <<EOF | kubectl apply -f - | |
| apiVersion: monitoring.coreos.com/v1 | |
| kind: PodMonitor | |
| metadata: | |
| name: ${APP_NAME}-podmonitor | |
| namespace: ${APP_NAMESPACE} | |
| labels: | |
| app: ${APP_NAME} | |
| spec: | |
| selector: | |
| matchLabels: | |
| app.kubernetes.io/name: ${APP_NAME} | |
| podMetricsEndpoints: | |
| - port: web | |
| path: ${METRICS_PATH} | |
| EOF | |
| cat <<EOF | kubectl apply -f - | |
| apiVersion: v1 | |
| kind: Service | |
| metadata: | |
| name: prometheus-${APP_NAME} | |
| namespace: ${APP_NAME} | |
| spec: | |
| selector: | |
| prometheus: prometheus-${APP_NAME} | |
| ports: | |
| - name: web | |
| port: 9090 | |
| targetPort: 9090 | |
| type: ClusterIP | |
| EOF | |
| echo "Observability setup completed for ${APP_NAME}" | |
| echo "Prometheus available at: prometheus-${APP_NAME}.${APP_NAMESPACE}.svc.cluster.local:9090" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apiVersion: platform.kratix.io/v1alpha1 | |
| kind: Promise | |
| metadata: | |
| name: promoperator | |
| spec: | |
| api: | |
| apiVersion: apiextensions.k8s.io/v1 | |
| kind: CustomResourceDefinition | |
| metadata: | |
| name: promoperators.monitoring.platform | |
| spec: | |
| group: monitoring.platform | |
| names: | |
| kind: PromOperator | |
| plural: promoperators | |
| singular: promoperator | |
| scope: Namespaced | |
| versions: | |
| - name: v1alpha1 | |
| served: true | |
| storage: true | |
| schema: | |
| openAPIV3Schema: | |
| type: object | |
| properties: | |
| spec: | |
| type: object | |
| properties: | |
| version: | |
| type: string | |
| default: "master" | |
| description: "Version of prometheus-operator to install" | |
| dependencies: [] | |
| workflows: | |
| promise: | |
| configure: | |
| - apiVersion:რ | |
| System: platform.kratix.io/v1alpha1 | |
| kind: Pipeline | |
| metadata: | |
| name: promoperator-install | |
| spec: | |
| rbac: | |
| permissions: | |
| - apiGroups: ["apiextensions.k8s.io"] | |
| resources: ["customresourcedefinitions"] | |
| resourceNamespace: "*" | |
| verbs: ["*"] | |
| - apiGroups: ["rbac.authorization.k8s.io"] | |
| resourceNamespace: "*" | |
| resources: ["clusterroles", "clusterrolebindings", "roles", "rolebindings"] | |
| verbs: ["*"] | |
| - apiGroups: ["storage.k8s.io"] | |
| resources: ["storageclasses"] | |
| resourceNamespace: "*" | |
| verbs: ["get", "list", "watch"] | |
| - apiGroups: [""] | |
| resources: ["nodes"] | |
| resourceNamespace: "*" | |
| verbs: ["get", "list", "watch"] | |
| - apiGroups: [""] | |
| resources: ["serviceaccounts", "services", "endpoints", "configmaps", "secrets"] | |
| resourceNamespace: "*" | |
| verbs: ["*"] | |
| - apiGroups: ["apps"] | |
| resources: ["deployments", "replicasets"] | |
| resourceNamespace: "*" | |
| verbs: ["*"] | |
| - apiGroups: [""] | |
| resources: ["events"] | |
| resourceNamespace: "*" | |
| verbs: ["*"] | |
| - apiGroups: ["monitoring.coreos.com"] | |
| resources: ["prometheuses", "prometheusrules", "servicemonitors", "podmonitors", "alertmanagers", "thanosrulers"] | |
| resourceNamespace: "*" | |
| verbs: ["*"] | |
| - apiGroups: ["monitoring.coreos.com"] | |
| resources: ["prometheusagents", "scrapeconfigs"] | |
| resourceNamespace: "*" | |
| verbs: ["*"] | |
| - apiGroups: [""] | |
| resources: ["pods", "namespaces"] | |
| resourceNamespace: "*" | |
| verbs: ["get", "list", "watch"] | |
| - apiGroups: ["apps"] | |
| resources: ["statefulsets", "daemonsets"] | |
| resourceNamespace: "*" | |
| verbs: ["*"] | |
| - apiGroups: ["networking.k8s.io"] | |
| resources: ["networkpolicies"] | |
| resourceNamespace: "*" | |
| verbs: ["get", "list", "watch"] | |
| containers: | |
| - name: install-prometheus-operator | |
| image: ghcr.io/syntasso/kratix-pipeline-utility:v0.0.1 | |
| command: [sh, -c] | |
| args: | |
| - | | |
| echo "Getting latest Prometheus Operator version..." | |
| LATEST=$(curl -s https://api.github.com/repos/prometheus-operator/prometheus-operator/releases/latest | yq eval '.tag_name' -) | |
| echo "Installing Prometheus Operator version: ${LATEST}" | |
| curl -sL https://github.com/prometheus-operator/prometheus-operator/releases/download/${LATEST}/bundle.yaml | kubectl create -f - | |
| echo "Prometheus Operator installation completed" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apiVersion: apps/v1 | |
| kind: Deployment | |
| metadata: | |
| labels: | |
| app.kubernetes.io/name: prometheus-example-app | |
| name: prometheus-example-app | |
| spec: | |
| replicas: 1 | |
| selector: | |
| matchLabels: | |
| app.kubernetes.io/name: prometheus-example-app | |
| template: | |
| metadata: | |
| labels: | |
| app.kubernetes.io/name: prometheus-example-app | |
| spec: | |
| containers: | |
| - name: prometheus-example-app | |
| image: quay.io/brancz/prometheus-example-app:v0.3.0 | |
| ports: | |
| - name: web | |
| containerPort: 8080 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment