Integrate KLT with your applications
Use Kubernetes annotations and labels to integrate the Keptn Lifecycle Toolkit into your Kubernetes cluster.
The Keptn Lifecycle Toolkit monitors manifests that have been applied against the Kubernetes API and reacts if it finds a workload with special annotations/labels. This is a four-step process:
- Annotate your workload(s)
- Create a
KeptnAppcustom resource that references those workloads
- Create the
KeptnTaskDefinitions you need
- Enable the target namespace by annotating it
For this, you should annotate your Workload with (at least) the following annotations:
keptn.sh/app: myAwesomeAppName keptn.sh/workload: myAwesomeWorkload keptn.sh/version: myAwesomeWorkloadVersion
Alternatively, you can use Kubernetes Recommended Labels to annotate your workload:
app.kubernetes.io/part-of: myAwesomeAppName app.kubernetes.io/name: myAwesomeWorkload app.kubernetes.io/version: myAwesomeWorkloadVersion
Note the following:
- The Keptn Annotations/Labels take precedence over the Kubernetes recommended labels.
- If the Workload has no version annotation/labels and the pod has only one container, the Lifecycle Toolkit takes the image tag as version (if it is not “latest”).
This process is demonstrated in the Keptn Lifecycle Toolkit: Installation and KeptnTask Creation in Mintes video.
Pre- and post-deployment checks
Further annotations are necessary to run pre- and post-deployment checks:
keptn.sh/pre-deployment-tasks: verify-infrastructure-problems keptn.sh/post-deployment-tasks: slack-notification,performance-test
The value of these annotations are
These CRDs contain re-usable “functions”
that can execute before and after the deployment.
In this example, before the deployment starts,
a check for open problems in your infrastructure is performed.
If everything is fine, the deployment continues and afterward,
a slack notification is sent with the result of the deployment
and a pipeline to run performance tests is invoked.
Otherwise, the deployment is kept in a pending state
until the infrastructure is capable of accepting deployments again.
A more comprehensive example can be found in our examples folder, where we use Podtato-Head to run some simple pre-deployment checks.
To run the example, use the following commands:
cd ./examples/podtatohead-deployment/ kubectl apply -f .
Afterward, you can monitor the status of the deployment using
kubectl get keptnworkloadinstance -n podtato-kubectl -w
The deployment for a Workload stays in a
state until the respective pre-deployment check is completed.
Afterwards, the deployment starts and when it is marked
the post-deployment checks start.