Get started with Keptn — Multi-stage delivery with Quality Gates(Demo)-Part 1

In this article, we will set up a Keptn environment for us. We will do a multi-stage delivery with Quality Gates. This article will cover everything from scratch and is for the person who has just started to explore the Keptn project. My objective is to provide you with a step-by-step guide so that you can bring up Keptn for yourself and try running your use cases for POC.
Start with provisioning a Kubernetes cluster
I am going to use Azure Kubernetes Service (AKS) for this demo. You may use any other Cloud providers or your local Kubernetes as well. Keptn recommends a cluster with at least 8vCPUs and 30 GB of memory. I have performed this demo with 2vCpu and 7GB RAM (DS2_v2) since it was a lightweight demo. Azure users refer to the chart below:-

Please refer to this Microsoft Azure document for more details on how to create AKS and connect to it. Click Here
I have created an Azure Kubernetes Service with the name “keptn-aks-eastus” for the demo.

Setup your repository for Keptn project
You should have a repository created because Keptn project will be created with Git upstream. You need the below information post-creating the repository.
GIT_USER=gitusername
GIT_TOKEN=gittoken
GIT_REMOTE_URL=remoteurl
I will be using Github for repository management. I have created a repository with the name “keptn-poc”

Connect to your Kubernetes
Since I am using Azure Kubernetes Service (AKS) I would need to connect to this resource with my terminal.
#login to your azure
az login
#set your azure subscription id
az account set — subscription <your-subscription-id>
#get your kubernetes resource
az aks get-credentials — resource-group <your-resource-group-name> <your-kubernetes-name>

Let’s start configuring your cluster
Let’s get started with Keptn now
Start with authenticating the Keptn CLI. This will authenticate and connect you to Keptn CLI with all the permission required to create/delete/update Keptn project using CLI.
KEPTN_ENDPOINT=http://$(kubectl -n keptn get ingress api-keptn-ingress -ojsonpath='{.spec.rules[0].host}')/apiKEPTN_API_TOKEN=$(kubectl get secret keptn-api-token -n keptn -ojsonpath='{.data.keptn-api-token}' | base64 --decode)KEPTN_BRIDGE_URL=http://$(kubectl -n keptn get ingress api-keptn-ingress -ojsonpath='{.spec.rules[0].host}')/bridgekeptn auth --endpoint=$KEPTN_ENDPOINT --api-token=$KEPTN_API_TOKEN

Let us try to access our Keptn bridge before we proceed. You can try opening the KEPTN_BRIDGE_URL
but you will be asked for the credentials.

You can fetch these credentials very easily using the Keptn command.
keptn configure bridge --output

Get username and password using the commands returned as a response. Use these credentials to login into the bridge dashboard. You would see a dashboard with “no project exists” on the screen.

Create a Keptn project
- Download a sample application
We will use a sample project “pod-tato-head” to deploy at multi-stage for this demo. Download the project and change the directory to ./podtato-head/delivery/keptn.
git clone https://github.com/codeWithUtkarsh/podtato-head.git
cd podtato-head/delivery/keptn
The Keptn directory contains resources that we will need going ahead in the demo.
2. Create a Keptn project
keptn create project pod-tato-head --shipyard=./shipyard.yaml --git-user=$GIT_USER --git-token=$GIT_TOKEN --git-remote-url=$GIT_REMOTE_URL
$GIT_USER, $GIT_TOKEN, $GIT_REMOTE_URL
are your repository credentials where your Keptn project will be created. We have already created a repository at the beginning of the article with the name “keptn-poc” for this purpose.
keptn create project pod-tato-head --shipyard=./shipyard.yaml --git-user=codeWithUtkarsh --git-remote-url=https://github.com/codeWithUtkarsh/keptn-poc --git-token=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

Once your command runs successfully you can verify the project created on the Keptn bridge dashboard. Ref below image.

To create the project we have used a Shipyard.yaml file that contains the environment description/blueprint. I have used the below Shipyard file for this demo.
apiVersion: "spec.keptn.sh/0.2.0"
kind: "Shipyard"
metadata:
name: "shipyard-sockshop"
spec:
stages:
- name: "hardening"
sequences:
- name: "delivery"
tasks:
- name: "deployment"
properties:
deploymentstrategy: "blue_green_service"
- name: "test"
properties:
teststrategy: "performance"
- name: "evaluation"
- name: "release"
- name: "production"
sequences:
- name: "delivery"
triggeredOn:
- event: "hardening.delivery.finished"
tasks:
- name: "deployment"
properties:
deploymentstrategy: "blue_green_service"
- name: "release"
In the above Shipyard file, we have defined the deployment description. There will be two stages - name: “hardening”
and — name: “production".
In each stage, we define the sequence. In the hardening stage, there is one sequence name: “delivery”.
The delivery sequence has four tasks.
tasks:
- name: "deployment"
properties:
deploymentstrategy: "blue_green_service"
- name: "test"
properties:
teststrategy: "performance"
- name: "evaluation"
- name: "release"
There is another stage name: “production”
which is only triggered when the “hardening“
stage is finished.
triggeredOn:
- event: "hardening.delivery.finished"
3. Onboard a Service
Now that we have created the project we need to create/Onboard service. But before that let's create a .tgz file of the helm file we have.
cd helm-charts
tar cfvz ./helloservice.tgz ./helloservice
cd ..
The above file will create a tgz file that we will use while onboarding the service.


Next, we will add a JMeter script for testing and JMeter configuration.
keptn add-resource --project=pod-tato-head --stage=hardening --service=helloservice --resource=jmeter/load.jmx --resourceUri=jmeter/load.jmxkeptn add-resource --project=pod-tato-head --stage=hardening --service=helloservice --resource=jmeter/jmeter.conf.yaml --resourceUri=jmeter/jmeter.conf.yaml

We have done setting up Keptn. Now, All we need to do is to trigger this deployment with some details and that will start the sequence defined in Shipyard.yaml file.
keptn trigger delivery --project="pod-tato-head" --service=helloservice --image="gabrieltanner/hello-server" --tag=v0.1.1
The above command will trigger the Keptn project “pod-tato-head” service “helloservice” and deploy docker image of application “gabrieltanner/hello-server” of tag “v0.1.1”.


That was it for the demo. If you face any issue connect with me on LinkedIn or write to me at utkarshkviim@gmail.com