Manage release lifecycle
In this exercise, we will configure Keptn
to run deployment checks as part of your deployment.
Whether you are deploying your software with
Argo, Flux, another deployment engine, or even kubectl apply
,
Keptn can do the following:
-
Pre-deploy: Validate external dependencies, confirm that images are scanned, and so forth
-
Post-deploy: Execute tests, notify stakeholders, promote to the next stage
-
Automatically validate against your SLO (Service Level Objectives)
Keptn sits on top of the Kubernetes scheduler and can do the following:
- Trace the deployment from start to end
- Keptn is application aware, so can extend the deployment with tasks and evaluations that are run either before or after your whole application starts the deployment or at the individual workload level.
- Validate any Keptn metric, either pre- or post-deployment, using the metrics from the Keptn Metrics Server introduced in Getting started with Keptn metrics.
This means that you can be sure that the environment is healthy and has adequate resources before you begin the deployment. After the deployment succeeds, use Keptn metrics to confirm that your deployed software is really healthy – not just that the pods are running but validate against SLOs such as performance and user experience. You can also check for new logs that came in from a log monitoring solution.
Using this exercise
This exercise shows how to implement pre- and post-deployment evaluations and tasks for your application. It is based on the simplenode-dev example.
The steps to implement pre- and post-deployment orchestration are:
- Using this exercise
- Define evaluations to be performed pre- and post-deployment
- Define tasks to be performed pre- and post-deployment
- Integrate evaluations and tasks into the cluster
This is the third of three exercises in the Introducing Keptn series. You may want to complete the other exercises before doing this exercise although that is not required:
- In the Getting started with Keptn metrics exercise, you learn how to define and use Keptn metrics.
- In Standardize observability, you learn how to standardize access to the observability data for your cluster.
If you are installing Keptn on an existing cluster or in a local cluster you are creating for this exercise and did not previously set up your cluster for the Standardize observability exercise, you need to do the following:
- Follow the instructions in Install and update to install and enable Keptn on your cluster.
- Follow the instructions in
Annotate workload
to integrate Keptn into your Kubernetes cluster
by applying basic annotations to your
Deployment
resource. This also creates appropriate KeptnApp resources which aggregate workloads that are combined into the released product, regardless of the tools being used.
Define evaluations to be performed pre- and post-deployment
An evaluation
is a KeptnMetric that has a defined target value.
Evaluations are resources that are defined in a
KeptnEvaluationDefinition
yaml file.
In our example, evaluations are defined in the
keptn-evaluations.yaml
file.
For example, the definition of the evaluate-dependencies
evaluation
looks like this:
{% include “usecase-orchestrate.md_1.yaml” %}
You see that the available-cpus
metric is defined in the
keptn-metric.yaml
file.
The evaluationTarget
is set to be >4
,
so this evaluation makes sure that more than 4 CPUs are available.
You could include objectives and additional metrics in this evaluation.
Define tasks to be performed pre- and post-deployment
Tasks are resources that are defined in a
KeptnTaskDefinition
file.
In our example, the tasks are defined in the
keptn-tasks.yaml
file.
As an example,
we have a notify
task that composes some Markdown text
to be sent as Slack notifications
The KeptnTaskDefinition
looks like this:
{% include “usecase-orchestrate.md_2.yaml” %}
The code to be executed is expressed as a Deno script, which uses JavaScript syntax. It can be embedded in the definition file or pulled in from a remote webserver that is specified. For this example, the code to be executed is embedded in this file although, in practice, this script would probably be located on a remote webserver.
Note that, beginning with Keptn 0.8.0, you can also use Python 3 to define your task, or you can define a standard Kubernetes container that uses the image, runner, and runtime dependencies that you choose. For more information, see Working with Keptn tasks.
You can view the actual JavaScript code for the task in the repository. You see that “context” is important in this code. This refers to the context in which this code executes – for which application, for which version, for which workload.
Because the slack server that is required to execute this task is protected by a secret, the task definition also specifies that secret.
Integrate evaluations and tasks into the cluster
Follow the instructions in
Annotate workload
to integrate the evaluations and tasks you defined
into the cluster
by applying annotations to the Deployment
resource.
See the
simplenode-dev-deployment.yaml
file for an example.