Keptn
During the workshop, you will interact with the following components:
KeptnAppContext
KeptnTaskDefinition
KeptnEvaluationDefinition
KeptnMetricsProvider
KeptnMetric
AnalysisValueTemplate
AnalysisDefinition
Keptn in a Nutshell
KeptnAppContext
The KeptnAppContext custom resource works with the corresponding KeptnApp resource that has the same name and is located in the same namespace. It allows you to:
-
Add metadata and links to traces for a specific application. This enables you to enrich your traces with additional information that you can use to better understand and analyze the performance of your applications.
-
Define tasks and evaluations that run before or after the deployment of the KeptnApp.
Note
The KeptnApp is autogenerated based on the Kubernetes Recommended Labels and Annotations for Kubernetes Workloads.
apiVersion: lifecycle.keptn.sh/v1
kind: KeptnAppContext
metadata:
name: demo-app
namespace: demo-app-dev
spec:
preDeploymentTasks:
- maintenance-window-check
postDeploymentTasks:
- load-test
postDeploymentEvaluations:
- demoapp-heatlh-check
promotionTasks:
- promote
KeptnTaskDefinition
A KeptnTaskDefinition defines tasks that Keptn runs as part of the pre- and post-deployment phases of a KeptnApp or KeptnWorkload.
A KeptnTask
could be executed on each Workload or at the Application Level.
apiVersion: lifecycle.keptn.sh/v1alpha3
kind: KeptnTaskDefinition
metadata:
name: maintenance-window-check
namespace: demo-app-dev
spec:
retries: 3
timeout: 5m
python:
httpRef:
url: https://raw.githubusercontent.com/{{ .Values.repo.name }}/{{ .Values.repo.revision }}/tasks/checkmaintenance.py
parameters:
map:
url: https://raw.githubusercontent.com/{{ .Values.repo.name }}/{{ .Values.repo.revision }}/data/maintenance.json
To assign this KeptnTask to a KeptnApp, you need to add it to the KeptnAppContext
, as shown in the example above.
To assign the task to a specific workload, you need to add the following annotations to the deployment manifest:
keptn.sh/pre-deployment-tasks: <task-name>
keptn.sh/post-deployment-tasks: <task-name>
KeptnEvaluationDefinition
A KeptnEvaluationDefinition assigns target values to KeptnMetric queries. These are used as part of evaluation tasks that Keptn runs as part of the pre-analysis and post-analysis phases of a KeptnApp or workload.
apiVersion: lifecycle.keptn.sh/v1alpha3
kind: KeptnEvaluationDefinition
metadata:
name: demoapp-heatlh-check
namespace: demo-app-dev
spec:
objectives:
- keptnMetricRef:
name: demoapp-latency
namespace: demo-app-dev
evaluationTarget: "<1" # less than 1 second
KeptnMetricsProvider
A KeptnMetricsProvider resource defines an instance of a data provider (such as Prometheus, Thanos, Cortex, Dynatrace, or Datadog) that is used by one or more KeptnMetric resources.
apiVersion: metrics.keptn.sh/v1alpha3
kind: KeptnMetricsProvider
metadata:
name: prometheus
namespace: demo-app-dev
spec:
type: prometheus
targetServer: "http://prometheus-operated.monitoring.svc.cluster.local:9090"
KeptnMetric
A KeptnMetric represents a metric that is collected from a provider. Providing the metrics as a custom resource facilitates the reusability of this data across multiple components and allows using multiple observability platforms for different metrics at the same time.
apiVersion: metrics.keptn.sh/v1alpha3
kind: KeptnMetric
metadata:
name: demoapp-latency
namespace: demo-app-dev
spec:
provider:
name: prometheus
query: 'sum by (path) (rate(http_request_duration_seconds_sum{namespace="demo-app-dev", path="/"}[2m]) / rate(http_request_duration_seconds_count{namespace="demo-app-dev", path="/"}[2m]))'
fetchIntervalSeconds: 5
AnalysisValueTemplate
An AnalysisValueTemplate resource defines a Service Level Indicator (SLI), which identifies the data to be analyzed by a data source to use and the query to issue. One Analysis can use data from multiple AnalysisValueTemplates.
apiVersion: metrics.keptn.sh/v1
kind: AnalysisValueTemplate
metadata:
name: request-duration
namespace: demo-app-prod
spec:
provider:
name: prometheus
query: "{{ printf "sum by (path) (rate(http_request_duration_seconds_sum{namespace='demo-app-prod', path='/'}[1m]) / rate(http_request_duration_seconds_count{path='/'}[1m]))" }}"
AnalysisDefinition
An AnalysisDefinition resource defines the list of Service Level Objectives (SLOs) for an Analysis.
apiVersion: metrics.keptn.sh/v1
kind: AnalysisDefinition
metadata:
name: demo-app-analysis
namespace: demo-app-prod
spec:
objectives:
- analysisValueTemplateRef:
name: request-duration
keyObjective: true
target:
failure:
greaterThan:
fixedValue: 3
warning:
greaterThan:
fixedValue: 2
weight: 1
totalScore:
passPercentage: 90
warningPercentage: 75