Skip to content

Commit

Permalink
docs: edit lifecycle management getting started (keptn#2602)
Browse files Browse the repository at this point in the history
Signed-off-by: Meg McRoberts <[email protected]>
Co-authored-by: odubajDT <[email protected]>
Co-authored-by: Moritz Wiesinger <[email protected]>
Signed-off-by: vickysomtee <[email protected]>
  • Loading branch information
3 people authored and Vickysomtee committed Apr 22, 2024
1 parent 556e19d commit 21636aa
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 100 deletions.
143 changes: 89 additions & 54 deletions docs-new/docs/getting-started/lifecycle-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,92 @@ The Release Lifecycle Management tools run
pre/post-deployment tasks and checks
for your existing cloud-native deployments
to make them more robust.
For more information, see
[Release lifecycle management](../core-concepts/index.md#release-lifecycle-management).

This tutorial introduces these tools.

> This tutorial assumes you have already completed the
[Getting started with Keptn Observability](../getting-started/index.md)
[Getting started with Keptn Observability](observability.md)
exercise.
> Please ensure you've finished that before attempting this guide.
> Please ensure you've finished that before attempting this exercise.
## Keptn Pre and Post Deployment Tasks

When Keptn is successfully monitoring your deployments, it can also run arbitrary tasks and SLO evaluations:

- pre-deployment (before the Pod is scheduled)
- post-deployment (after the Pod is scheduled)

> Tasks and Evaluations can also run on a KeptnApp level.
See
[Annotations to KeptnApp](../guides/tasks.md#annotations-to-keptnapp).
When Keptn is successfully monitoring your deployments,
it can also run arbitrary tasks and SLO evaluations for you
either before or after your deployment runs.
This is specified with labels or annotations in the Pod template specs of your
[workloads](https://kubernetes.io/docs/concepts/workloads/)
([Deployments](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/),
[StatefulSets](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/),
[DaemonSets](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/),
and
[ReplicaSets](https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/)).

> Pre and post deployments can be run either on individual workloads
> or on a group of associated workloads that are grouped into
> a`KeptnApp` resource.
> For instructions about how to identify the workloads to combine into `KeptnApp` resource,
> see
> [annotations to KeptnApp](../guides/integrate.md#basic-annotations).
> [Auto app discovery](../guides/auto-app-discovery.md/)
> explains how a `KeptnApp` resource is created.
## Prerequisites: Deploy webhook sink

During this exercise, you will configure Keptn to trigger a webhook before and after a deployment has successfully completed.
During this exercise, you will configure Keptn to trigger a webhook
before and after a deployment has completed successfully.

For demo purposes, a place is required to send those request.
Install the [open source webhook.site tool](https://github.com/webhooksite/webhook.site/tree/master/kubernetes) now.
For demo purposes, a place is required to which those requests are sent.
To implement this:

This will provide a place, on cluster, to send (and view) web requests.
1. Install the
[open source webhook.site tool](https://github.com/webhooksite/webhook.site/tree/master/kubernetes).

> Note: If you have your own endpoint, you can skip this step.
This provides a place on your cluster to which web requests are sent
and from which they can be viewed.
If you have your own endpoint, you can skip this step.

```shell
kubectl apply -f https://raw.githubusercontent.com/webhooksite/webhook.site/master/kubernetes/namespace.yml
kubectl apply -f https://raw.githubusercontent.com/webhooksite/webhook.site/master/kubernetes/redis.deployment.yml
kubectl apply -f https://raw.githubusercontent.com/webhooksite/webhook.site/master/kubernetes/laravel-echo-server.deployment.yml
kubectl apply -f https://raw.githubusercontent.com/webhooksite/webhook.site/master/kubernetes/webhook.deployment.yml
kubectl apply -f https://raw.githubusercontent.com/webhooksite/webhook.site/master/kubernetes/service.yml
```
1. Execute the following commands to apply the web hook:

Wait until all pods are running in the `webhook` namespace then port-forward and view the webhook sink page:
```shell
kubectl apply -f https://raw.githubusercontent.com/webhooksite/webhook.site/master/kubernetes/namespace.yml
kubectl apply -f https://raw.githubusercontent.com/webhooksite/webhook.site/master/kubernetes/redis.deployment.yml
kubectl apply -f https://raw.githubusercontent.com/webhooksite/webhook.site/master/kubernetes/laravel-echo-server.deployment.yml
kubectl apply -f https://raw.githubusercontent.com/webhooksite/webhook.site/master/kubernetes/webhook.deployment.yml
kubectl apply -f https://raw.githubusercontent.com/webhooksite/webhook.site/master/kubernetes/service.yml
```

```shell
kubectl -n webhook wait --for=condition=Ready pods --all
kubectl -n webhook port-forward svc/webhook 8084
```
1. Wait until all Pods are running in the `webhook` namespace
then port-forward and view the webhook sink page:

```shell
kubectl -n webhook wait --for=condition=Ready pods --all
kubectl -n webhook port-forward svc/webhook 8084
```

Open a browser and go to `http://localhost:8084`
1. Open a browser and go to `http://localhost:8084`

You should see a page like this with a unique URL (your ID will be different).
1. You should see a page like this with a unique URL
(your ID will be different than the example).

![webhook.site page](assets/webhook.site.1.png)
![webhook.site page](assets/webhook.site.1.png)

Make a note of that unique URL.
1. Make a note of that unique URL.

### Verify Webhook Sink

Open a new browser table and go to your unique URL.
The page should remain blank, but when toggling back to `http://localhost:8084`, you should see a new entry.

Every request sent to that unique URL will be logged here.
Each request sent to that unique URL will be logged here.

![webhook.site entry](assets/webhook.site.2.png)

## Add a Post Deployment Task

Add a task which will trigger after a deployment.
Add a task that triggers after a successful deployment.

Change `UUID` to whatever value you have.
Apply this manifest:
Expand Down Expand Up @@ -98,11 +120,12 @@ spec:

### Verify it works

Verify that the KeptnTaskDefinition above actually works.
Verify that the `KeptnTaskDefinition` resource shown above actually works.

Trigger an on-demand task execution to verify that the job and pod function correctly.
Trigger an on-demand task execution
to verify that the job and Pod are working correctly.

In the following steps we will have Keptn orchestrate this for us automatically.
In the following steps we have Keptn orchestrate this for us automatically.

Apply this manifest:

Expand Down Expand Up @@ -131,23 +154,31 @@ NAME COMPLETIONS DURATION AGE
runsendevent1-***** 1/1 6s 2m
```

`kubectl -n keptndemo get pods` will show the successfully executed pod.
`kubectl -n keptndemo get pods` shows the successfully executed Pod.

The webhook sync should show this:

![webhook sync](assets/webhook.site.3.png)

Incidentally, this is exactly how you can use Keptn with [applications deployed outside of Kubernetes](../use-cases/non-k8s.md).
Incidentally, this is exactly how you can use Keptn with
[applications deployed outside of Kubernetes](../use-cases/non-k8s.md).

> Note: If you want to trigger this multiple times, you must change the KeptnTask name.
> Note: If you want to trigger this task multiple times,
> you must change the value of the `name` field
> in the `KeptnTask` resource each time.
> For example, change `runsendevent1` to `runsendevent2`.
> See
> [Redeploy/Restart an Application](../guides/restart-application-deployment.md/)
> for details.
>
> For example, by changing `runsendevent1` to `runsendevent2`

## Ask Keptn to trigger task after Deployment

Annotate the demo application `Deployment` manifest to have Keptn automatically trigger the task after every deployment.
Annotate the demo application `Deployment` manifest
to have Keptn automatically trigger the task after every deployment.

Recall the `Deployment` from the [Observability](../getting-started/observability.md#step-3-deploy-demo-application)
Recall the `Deployment` from the
[Observability](../getting-started/observability.md#step-3-deploy-demo-application)
Getting started guide.

Add a new label so the `labels` section looks like this:
Expand All @@ -160,7 +191,6 @@ labels:
app.kubernetes.io/version: 0.0.2
keptn.sh/post-deployment-tasks: "send-event"
...
```
Increase the version number to `0.0.2` and re-apply the manifest.
Expand Down Expand Up @@ -200,28 +230,33 @@ spec:
### What Happens Next?
1. The deployment will be applied
1. When the pods are running, Keptn will automatically create a `KeptnTask` resource for version `0.0.2` of this KeptnApp
1. The `KeptnTask` will create a Kubernetes Job
1. The Kubernetes Job will create a Pod
1. The pod will run curl and send a new event to the event sink
1. The deployment is applied.
1. When the Pods are running,
Keptn automatically creates a `KeptnTask` resource
for version `0.0.2` of this `KeptnApp`.
1. The `KeptnTask` creates a Kubernetes `Job`.
1. The Kubernetes `Job` creates a Kubernetes `Pod`.
1. The `Pod` runs `curl` and sends a new event to the event sink.
### Pre-deployment Tasks
Keptn Tasks can also be executed pre-deployment (before the pods are scheduled).
Do this by using the `keptn.sh/pre-deployment-tasks` label.
Keptn Tasks can also be executed pre-deployment (before the Pods are scheduled).
Do this by using the `keptn.sh/pre-deployment-tasks` label or annotation.
> Note: If a pre-deployment task fails, the pod will remain in a Pending state.
> Note: If a pre-deployment task fails, the `Pod` remains in a Pending state.
## Further Information
You can do a lot more with KeptnTasks.
You can do much more with `KeptnTask` resources.
See the
[Deployment tasks](../guides/tasks.md)
guide for more information.
page to find out more.
## What's next?
Keptn can also run pre and post deployment SLO evaluations.
Keptn can also run simple pre- and post-deployment SLO evaluations.
Continue the Keptn learning journey by adding evaluations.
See the
[Evaluations](../guides/evaluations.md)
for more information.
Loading

0 comments on commit 21636aa

Please sign in to comment.