Evaluations

Understand Keptn evaluations and how to use them

A KeptnEvaluationDefinition resource contains a list of objectives, each of which checks whether a defined KeptnMetric resource meets a defined target value. The example app-pre-deploy-eval.yaml file specifies the app-pre-deploy-eval-2 evaluation as follows:

apiVersion: lifecycle.keptn.sh/v1alpha3
kind: KeptnEvaluationDefinition
metadata:
  name: app-pre-deploy-eval-2
  namespace: podtato-kubectl
spec:
  objectives:
    - keptnMetricRef:
        name: available-cpus
        namespace: podtato-kubectl
      evaluationTarget: ">1"

The evaluationTarget is set to be >1, so this evaluation ensures that more than 1 CPU is available before the workload or application is deployed.

This evaluation references the KeptnMetric resource that is named available-cpus. This is defined in the example metric.yaml file:

apiVersion: metrics.keptn.sh/v1beta1
kind: KeptnMetric
metadata:
  name: available-cpus
  namespace: podtato-kubectl
spec:
  provider:
    name: my-provider
  query: "sum(kube_node_status_capacity{resource='cpu'})"
  fetchIntervalSeconds: 10

To run an evaluation on one of your Workloads (Deployments, StatefulSets, DaemonSets, or ReplicaSets, you must:

  • Annotate your workloads to identify the KeptnEvaluationDefinition resource you want to run pre- and post-deployment for the specific workloads.
  • Manually edit all KeptnApp resources to specify the KeptnEvaluationDefinition to be run pre- and post-deployment evaluations for the KeptnApp itself.

See Pre- and post-deployment checks for details.

Note the following:

  • One KeptnEvaluationDefinition resource can include multiple objective fields that reference additional metrics. In this example, you might want to also query available memory, disk space, and other resources that are required for the deployment.
  • The KeptnMetric resources that are referenced in a KeptnEvaluationDefinition resource
    • can be defined on different namespaces in the cluster
    • can query different instances of different types of metric providers
  • All objectives within a KeptnEvaluationDefinition resource are evaluated in order. If the evaluation of any objective fails, the KeptnEvaluation itself fails.
  • You can define multiple evaluations for each stage (pre- and post-deployment). These evaluations run in parallel so the failure of one evaluation has no effect on whether other evaluations are completed.
  • The results of each evaluation is written to a KeptnEvaluation resource.