apiVersion: operator.victoriametrics.com/v1beta1
kind: VMRule
metadata:
  name: alerts-k8s.rules.containerresource
spec:
  groups:
  - name: k8s.rules.container_resource
    params: {}
    rules:
    - annotations: {}
      expr: |-
        kube_pod_container_resource_requests{resource="memory",job="kube-state-metrics"}  * on (namespace,pod,cluster)
        group_left() max by (namespace,pod,cluster) (
          (kube_pod_status_phase{phase=~"Pending|Running"} == 1)
        )
      labels: {}
      record: cluster:namespace:pod_memory:active:kube_pod_container_resource_requests
    - annotations: {}
      expr: |-
        sum by (namespace,cluster) (
            sum by (namespace,pod,cluster) (
                max by (namespace,pod,container,cluster) (
                  kube_pod_container_resource_requests{resource="memory",job="kube-state-metrics"}
                ) * on (namespace,pod,cluster) group_left() max by (namespace,pod,cluster) (
                  kube_pod_status_phase{phase=~"Pending|Running"} == 1
                )
            )
        )
      labels: {}
      record: namespace_memory:kube_pod_container_resource_requests:sum
    - annotations: {}
      expr: |-
        kube_pod_container_resource_requests{resource="cpu",job="kube-state-metrics"}  * on (namespace,pod,cluster)
        group_left() max by (namespace,pod,cluster) (
          (kube_pod_status_phase{phase=~"Pending|Running"} == 1)
        )
      labels: {}
      record: cluster:namespace:pod_cpu:active:kube_pod_container_resource_requests
    - annotations: {}
      expr: |-
        sum by (namespace,cluster) (
            sum by (namespace,pod,cluster) (
                max by (namespace,pod,container,cluster) (
                  kube_pod_container_resource_requests{resource="cpu",job="kube-state-metrics"}
                ) * on (namespace,pod,cluster) group_left() max by (namespace,pod,cluster) (
                  kube_pod_status_phase{phase=~"Pending|Running"} == 1
                )
            )
        )
      labels: {}
      record: namespace_cpu:kube_pod_container_resource_requests:sum
    - annotations: {}
      expr: |-
        kube_pod_container_resource_limits{resource="memory",job="kube-state-metrics"}  * on (namespace,pod,cluster)
        group_left() max by (namespace,pod,cluster) (
          (kube_pod_status_phase{phase=~"Pending|Running"} == 1)
        )
      labels: {}
      record: cluster:namespace:pod_memory:active:kube_pod_container_resource_limits
    - annotations: {}
      expr: |-
        sum by (namespace,cluster) (
            sum by (namespace,pod,cluster) (
                max by (namespace,pod,container,cluster) (
                  kube_pod_container_resource_limits{resource="memory",job="kube-state-metrics"}
                ) * on (namespace,pod,cluster) group_left() max by (namespace,pod,cluster) (
                  kube_pod_status_phase{phase=~"Pending|Running"} == 1
                )
            )
        )
      labels: {}
      record: namespace_memory:kube_pod_container_resource_limits:sum
    - annotations: {}
      expr: |-
        kube_pod_container_resource_limits{resource="cpu",job="kube-state-metrics"}  * on (namespace,pod,cluster)
        group_left() max by (namespace,pod,cluster) (
         (kube_pod_status_phase{phase=~"Pending|Running"} == 1)
         )
      labels: {}
      record: cluster:namespace:pod_cpu:active:kube_pod_container_resource_limits
    - annotations: {}
      expr: |-
        sum by (namespace,cluster) (
            sum by (namespace,pod,cluster) (
                max by (namespace,pod,container,cluster) (
                  kube_pod_container_resource_limits{resource="cpu",job="kube-state-metrics"}
                ) * on (namespace,pod,cluster) group_left() max by (namespace,pod,cluster) (
                  kube_pod_status_phase{phase=~"Pending|Running"} == 1
                )
            )
        )
      labels: {}
      record: namespace_cpu:kube_pod_container_resource_limits:sum
