KeptnTask
Keptn uses KeptnTask resources internally
to manage tasks (and their underlying Kubernetes Job resources)
that are run before and after deployment of your workloads
(pre- and post-deployment tasks).
You do not need to create this resource yourself except in special situations,
for instance when using Keptn to manage workloads outside the k8s cluster.
See the use case page for more details about this.
Synopsis
apiVersion: lifecycle.keptn.sh/v1
kind: KeptnTask
metadata:
name: <name-of-this-run>
spec:
taskDefinition: <name-of-KeptnTaskDefinition resource>
context:
appName: "<name-of-KeptnApp-resource>"
appVersion: "KeptnApp-version"
objectType: ""
taskType: ""
workloadName: "name-of-KeptnWorkload resource""
workloadVersion: "version-of-KeptnWorkload resource"
metadata:
<custom-info1>: "<custom-info1-value>"
<custom-info2>: "<custom-info2-value>"
...
parameters: <parameters to pass to job>
secureParameters: <secure parameters to pass to job>
checkType: ""
retries: <integer>
timeout: <duration-in-seconds>
Fields
- apiVersion -- API version being used.
- kind -- Resource type.
Must be set to
KeptnTask - metadata
- name -- Unique name of this run of the task.
This name must be modified each time you run this
KeptnTask, so a common practice is to add a number to the end of the string so you can increment the number for each run. Names must comply with the Kubernetes Object Names and IDs specification.
- name -- Unique name of this run of the task.
This name must be modified each time you run this
- spec - Defines the specification of this
KeptnTaskresource- taskDefinition (required) -- Name of the corresponding
KeptnTaskDefinitionresource. ThisKeptnTaskDefinitioncan be located in the same namespace or in the Keptn installation namespace. -
context (required) -- Contextual information about the task execution
- appName (required) -- Name of the
KeptnApp resource
for which the
KeptnTaskis being executed. - appVersion (required) -- Version of the
KeptnAppresource for which theKeptnTaskis being executed. -
metadata -- Additional key-value pairs with contextual information for the
KeptnTask. Keptn populates this field based on thespec.metadatafield of the KeptnWorkloadVersion and KeptnAppVersion resources.For example, the following lines reference the commit ID and user ID:
See Context metadata for information about setting user defined values for those fields.
-
objectType (required) -- Indicates whether this
KeptnTaskis being executed for aKeptnAppor aKeptnWorkloadresource. When populating this resource manually to run a task for a non-Kubernetes deployment, set this value to"": Keptn populates this field based on annotations to theKeptnWorkloadandKeptnAppresources. - taskType (required) -- Indicates whether this
KeptnTaskis part of the pre- or post-deployment phase. When populating this resource manually to run a task for a non-Kubernetes deployment, set this value to"": Keptn populates this field based on annotations to theKeptnWorkloadandKeptnAppresources. - workloadName (required) -- Name of the
KeptnWorkloadfor which theKeptnTaskis being executed. - workloadVersion (required) -- Version of the
KeptnWorkloadfor which theKeptnTaskis being executed.- parameters -- Parameters that are passed to the job
that executes the
KeptnTask. - secureParameters -- Secure parameters that are passed
to the job that executes the
KeptnTask. These are stored and accessed as KubernetesSecretsin the cluster. See Working with secrets for more information. - checkType -- Defines whether task is part of pre- or post-deployment phase.
Keptn populates this field based on annotations
to the
KeptnWorkloadandKeptnAppresources. - retries -- If errors occur,
this defines the number of attempts made
before the
KeptnTaskis considered to be failed. - timeout -- Specifies the time, in seconds,
to wait for the
KeptnTaskto complete successfully. If theKeptnTaskdoes not complete successfully in this timeframe, it is considered to be failed.
- parameters -- Parameters that are passed to the job
that executes the
- appName (required) -- Name of the
KeptnApp resource
for which the
- taskDefinition (required) -- Name of the corresponding
Usage
Applying this file causes Keptn to create a Job and a Pod
and run the associated KeptnTaskDefinition.
Use the following commands to show the current status of the jobs:
Each time you want to rerun the KeptnTask resource,
you must update the value of the metadata.name field.
A common practice is to just increment the value incrementally,
so helloworldtask-1 becomes helloworldtask-2, etc.
Example
For a full example of how to create a KeptnTask resource
to use for a deployment being done outside of Kubernetes, see
Keptn for Non-Kubernetes Applications.
Files
Differences between versions
The syntax of the KeptnTask resource changed significantly
in Keptn v0.8.0.