apiVersion: operator.victoriametrics.com/v1beta1
kind: VMRule
metadata:
  name: alerts-kube-state-metrics
  namespace: cozy-monitoring
spec:
  groups:
  - name: kube-state-metrics
    rules:
    - alert: DeploymentGenerationMismatch
      expr: max(kube_deployment_status_observed_generation != kube_deployment_metadata_generation) by (namespace, deployment)
      for: 15m
      labels:
        severity_level: "4"
      annotations:
        plk_protocol_version: "1"
        description: Observed deployment generation does not match expected one for
          deployment {{$labels.namespace}}/{{$labels.deployment}}
        summary: Deployment is outdated
    - alert: KubeStateMetricsDown
      expr: absent(up{job="kube-state-metrics"} == 1)
      for: 5m
      labels:
        severity_level: "3"
      annotations:
        plk_protocol_version: "1"
        plk_markup_format: markdown
        description: |-
          There are no metrics about cluster resources for 5 minutes.
  
          Most alerts an monitroing panels aren't working.
  
          To debug the problem:
          1. Check kube-state-metrics pods: `kubectl -n d8-monitoring describe pod -l app=kube-state-metrics`
          2. Check its logs: `kubectl -n d8-monitoring describe deploy kube-state-metrics`
        summary: >
          Kube-state-metrics is not working in the cluster.
  - name: kubernetes.rules
    rules:
     - alert: KubePodCrashLooping
       expr: |
         max_over_time(kube_pod_container_status_waiting_reason{reason="CrashLoopBackOff", job="kube-state-metrics"}[5m]) >= 1
       annotations:
         description: 'Pod {{ $labels.namespace }}/{{ $labels.pod }} ({{ $labels.container
           }}) is in waiting state (reason: "CrashLoopBackOff").'
         runbook_url: https://github.com/kubernetes-monitoring/kubernetes-mixin/tree/master/runbook.md#alert-name-kubepodcrashlooping
         summary: Pod is crash looping.
       for: 15m
       labels:
         severity: warning
