Get Started with Keptn Development locally - Part 1
In this article, we’re going to talk about something a little bit different than what you’re used to seeing on my storyboard, and it is Keptn.
Keptn is an event-based control plane for continuous delivery and even automated operations in the cloud native context, there’s a lot to learn about Keptn, which I’m not going to share in detail right now because my focus for this article is going to get up and running with a local development environment for Keptn.
Let’s get started, so I’m in the Keptn GitHub repository which is github.com/keptn/keptn. When you scroll down in the README you will find a QuickStart for developing Keptn, which is based on k3d.
Now in case you don’t know k3d, k3d is a lightweight wrapper to run k3s which is a minimal Kubernetes distribution by Rancher labs. It’s super lightweight and it is based on docker; so you need docker for this. I mean to get started basically, ensure you have all the requirements installed, so you would check if you have docker installed.
oem@meha:~$ docker --version
Docker version 20.10.12, build 20.10.12-0ubuntu2~20.04.1FYI I have docker version 20.10.12 and you should also have kubectl installed which is the Kubernetes command line interface.
oem@meha:~$ kubectl version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.3", GitCommit:"c92036820499fedefec0f847e2054d824aea6cd1", GitTreeState:"clean", BuildDate:"2021-10-27T18:41:28Z", GoVersion:"go1.16.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.3", GitCommit:"c92036820499fedefec0f847e2054d824aea6cd1", GitTreeState:"clean", BuildDate:"2021-10-27T18:35:25Z", GoVersion:"go1.16.9", Compiler:"gc", Platform:"linux/amd64"}Last but not least, the helm is the command line interface for the Kubernetes package manager.
oem@meha:~$ helm version
version.BuildInfo{Version:"v3.7.0", GitCommit:"eeac83883cb4014fe60267ec6373570374ce770b", GitTreeState:"clean", GoVersion:"go1.16.8"}Note: I prefer minikube instead of k3d as of now.
To get started we are going to install minikube, the latest minikube stable release on x86–64 Linux using binary download:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64sudo install minikube-linux-amd64 /usr/local/bin/minikube
Just make sure you have the docker engine installed and not the docker desktop because I think the docker desktop and fiddling around with the configuration on windows could be a little bit more difficult, but alright.
I already have it installed, if you don’t have it installed, it will download it, and it’s really just a CLI tool that is being put into your /usr/bin/minikube directory.
It will ask you for your password because it’s going to use sudo, so yeah, that’s fine. It’s time to create a cluster called minikube.
oem@meha:~$ minikube start
😄 minikube v1.24.0 on Ubuntu 20.04
✨ Using the docker driver based on user configuration
👍 Starting control plane node minikube in cluster minikube
🚜 Pulling base image ...
🔥 Creating docker container (CPUs=2, Memory=2200MB) ...
🐳 Preparing Kubernetes v1.22.3 on Docker 20.10.8 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
🔎 Verifying Kubernetes components...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟 Enabled addons: storage-provisioner, default-storageclass
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by defaultThis will download some docker images and then create a Kubernetes cluster in docker for you. Take some time depending on your computer and speaking about that you should have at least two (better four) CPUs and eight-gigabyte memory for this.
Okay, this was actually rather quick and if you’re wondering what’s happening, it’s starting the control plane node. You can also see this by saying:
oem@meha:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane,master 3m46s v1.22.3At this point, you already have access to Kubernetes.
Get Meha Bhalodiya’s stories in your inbox
Join Medium for free to get updates from this writer.
So now, we can install Keptn and the first command would be to install the Keptn CLI and this will install the latest version of the CLI, and I don’t want that I want to have a specific version, so I’m just going to write:
oem@meha:~$ curl -sL https://get.keptn.sh | bash
The newest version of Keptn is 0.16.0 and will be used automatically
Determined target architecture x86_64
Downloading keptn 0.16.0 for OS linux with architecture amd64 from GitHub: https://github.com/keptn/keptn/releases/download/0.16.0/keptn-0.16.0-linux-amd64.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 26.0M 100 26.0M 0 0 1823k 0 0:00:14 0:00:14 --:--:-- 2354k
Unpacking archive keptn-0.16.0-linux-amd64.tar.gz in current directory ...
keptn-0.16.0-linux-amd64
-rwxr-xr-x 1 oem oem 61650492 Jun 7 17:06 keptn-0.16.0-linux-amd64
Moving keptn binary to /usr/local/bin
Trying to run mv keptn-0.16.0-linux-amd64 /usr/local/bin/keptn with sudo...
[sudo] password for oem:
Keptn CLI installation completed successfully!
You can check the Keptn CLI installation by running:
keptn --help
To install Keptn in your cluster, please follow the documentation at https://keptn.sh/docs/ or execute:
keptn install
Learn more on how to use Keptn in our tutorials at https://tutorials.keptn.sh/
Welcome aboard!Note: I am using Keptn 0.16.0 version. There are chances of deprecation of some commands in the newer releases.
FYI if you want to install any specific version of Keptn, then use the below command:
curl -sL https://get.keptn.sh | KEPTN_VERSION=<version> bashFurther, we can actually install the Keptn control plane into your Kubernetes cluster which is done via the keptn install command. I will say,
keptn install --helpNote:
keptn installcommand is deprecated since 0.17.x release.
It will print me some of the parameters. I want to take, --use-case flag, and set it to continuous-delivery so this will just make things easier for me in development. I will do it and it will ask me if this is the correct cluster.
oem@meha:~$ keptn install -n keptn --use-case=continuous-delivery
Please confirm that the provided cluster information is correct:
Cluster: minikube
Is this all correct? (y/n)
y
Istio is required for the continuous-delivery use case, but could not be found in your cluster in namespace istio-system.
Please install Istio as described in the Istio docs: https://istio.io/latest/docs/setup/getting-started/
Installing Keptn ...
Helm Chart used for Keptn installation: https://charts.keptn.sh/packages/keptn-0.16.0.tgz
Existing Keptn installation found in namespace keptn
Do you want to overwrite this installation? (y/n)
y
Start upgrading Helm Chart keptn in namespace keptn
Found existing installation, overwriting...
Finished upgrading Helm Chart keptn in namespace keptn
Keptn control plane has been successfully set up on your cluster.
Installing execution plane services for continuous-delivery use case.
Start upgrading Helm Chart helm-service in namespace keptn
Finished upgrading Helm Chart helm-service in namespace keptn
Start upgrading Helm Chart jmeter-service in namespace keptn
Finished upgrading Helm Chart jmeter-service in namespace keptn
---------------------------------------------------
* To quickly access Keptn, you can use a port-forward and then authenticate your Keptn CLI:
- kubectl -n keptn port-forward service/api-gateway-nginx 8080:80
- keptn auth --endpoint=http://localhost:8080/api --api-token=$(kubectl get secret keptn-api-token -n keptn -ojsonpath={.data.keptn-api-token} | base64 --decode)
* Alternatively, follow the instructions provided at: https://keptn.sh/docs/0.16.x/operate/install/#authenticate-keptn-cli
* To expose Keptn on a public endpoint, please continue with the installation guidelines provided at:
- https://keptn.sh/docs/0.16.x/operate/install#install-keptnFor the people, who are using any greater version than 0.16.0, you need to install core Keptn control plane components and expose them via a LoadBalancer and install some standard Keptn execution plane components using helm by,
helm install keptn keptn --repo=https://charts.keptn.sh \
-n keptn --create-namespace \
--set=apiGatewayNginx.type=LoadBalancer \
--set=continuousDelivery.enabled=true \
--waithelm install jmeter-service keptn/jmeter-service -n keptnhelm install helm-service keptn/helm-service -n keptn
This is installing Keptn and if you want to watch it, you can use a Kubernetes IDE of your choice or you could just say,
oem@meha:~$ kubectl get pods -n keptn
NAME READY STATUS RESTARTS AGE
api-gateway-nginx-575b669549-vvlwx 0/1 ContainerCreating 0 19s
api-service-587459fb-d2zn6 0/1 ContainerCreating 0 20s
approval-service-694569596-wrpg7 0/1 ContainerCreating 0 19s
bridge-fb8564c8f-x27nf 0/1 ContainerCreating 0 19s
helm-service-59c88584c9-gkbbs 0/2 ContainerCreating 0 19s
jmeter-service-77fd6d7967-b5h6v 0/2 ContainerCreating 0 19s
keptn-mongo-74bf4c476f-789mr 0/1 ContainerCreating 0 19s
keptn-nats-0 0/2 ContainerCreating 0 20s
lighthouse-service-89c5687bb-lsfkm 0/1 ContainerCreating 0 20s
mongodb-datastore-667685bc5d-bqwg7 0/1 ContainerCreating 0 20s
remediation-service-65df9f98bd-5nd52 0/1 ContainerCreating 0 20s
resource-service-7c98c668c-w6snh 0/1 ContainerCreating 0 20s
secret-service-7798f4f484-xfvk7 0/1 ContainerCreating 0 20s
shipyard-controller-859bcb5dd5-2jp46 0/1 ContainerCreating 0 19s
statistics-service-7b995b9477-hdh2h 0/2 ContainerCreating 0 20s
webhook-service-766b556b87-w5d5b 0/1 ContainerCreating 0 20sYou can watch it right now, it’s in the state of ContainerCreating which means it’s pulling images from Docker Hub, it’s configuring those containers, so there are going to be a lot of things going on and you could also take a look at services:
oem@meha:~$ kubectl -n keptn get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
api-gateway-nginx ClusterIP 10.98.238.85 <none> 80/TCP 35s
api-service ClusterIP 10.100.33.110 <none> 8080/TCP 35s
approval-service ClusterIP 10.102.13.14 <none> 8080/TCP 35s
bridge ClusterIP 10.110.192.41 <none> 8080/TCP 35s
configuration-service ClusterIP 10.106.58.29 <none> 8080/TCP 35s
helm-service ClusterIP 10.103.197.179 <none> 8080/TCP 35s
jmeter-service ClusterIP 10.96.247.162 <none> 8080/TCP 35s
job-executor-service ClusterIP 10.97.187.221 <none> 8080/TCP 35s
keptn-mongo ClusterIP 10.108.231.52 <none> 27017/TCP 35s
keptn-nats ClusterIP None <none> 4222/TCP,6222/TCP,8222/TCP,7777/TCP,7422/TCP,7522/TCP 35s
lighthouse-service ClusterIP 10.108.224.241 <none> 8080/TCP 35s
mongodb-datastore ClusterIP 10.110.19.32 <none> 8080/TCP 35s
remediation-service ClusterIP 10.104.69.38 <none> 8080/TCP 35s
secret-service ClusterIP 10.102.113.99 <none> 8080/TCP 35s
shipyard-controller ClusterIP 10.97.140.59 <none> 8080/TCP 35s
statistics-service ClusterIP 10.110.24.203 <none> 8080/TCP 35s
webhook-service ClusterIP 10.102.199.242 <none> 8080/TCP 35sMost importantly, you wouldn’t be able to authenticate with your Keptn control plane, so it basically tells you (read the output when you have performed keptn install) how to access it if you don’t use --endpoint-service-type=LoadBalancer , but if you use the default which is ClusterIP then it will also tell you to port forward.
oem@meha:~$ kubectl -n keptn port-forward service/api-gateway-nginx 8080:80
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080
Handling connection for 8080
Handling connection for 8080
Handling connection for 8080Note: You need to keep the
port-forwardopen. Run thekeptn authcommand in the new window of the terminal.
It should automatically authenticate now by executing the below command.
oem@meha:~$ keptn auth --endpoint=http://localhost:8080/api --api-token=$(kubectl get secret keptn-api-token -n keptn -ojsonpath={.data.keptn-api-token} | base64 --decode)
Starting to authenticate
Successfully authenticated against http://localhost:8080/api
Bridge URL: http://localhost:8080/bridgeYeah, looks good! Successfully authenticated! We can also use keptn status and we can see the API.
oem@meha:~$ keptn status
Starting to authenticate
Successfully authenticated against http://localhost:8080/api
Bridge URL: http://localhost:8080/bridgeSo I want to go to my Keptn bridge, and it will now ask you for a password and username, and you can just get the output of that by saying,
oem@meha:~$ keptn configure bridge --output
You can get your login credentials e.g. by using the following kubectl commands:
Username - kubectl get secret -n keptn bridge-credentials -o jsonpath="{.data.BASIC_AUTH_USERNAME}" | base64 --decode
Password - kubectl get secret -n keptn bridge-credentials -o jsonpath="{.data.BASIC_AUTH_PASSWORD}" | base64 --decode
The URL to your Keptn Bridge can be retrieved using 'keptn status'It basically tells you how to get those; those are encoded in a config map actually in a secret in Kubernetes. The username is usually keptn and the password is randomly generated in this case.
There we go! We have our Keptn bridge up and running. Now, we can start developing if we want to. If you have any questions please let me know in the comments below.
Reference: https://youtu.be/zVFLxaa2xkw
Shoutout to Christian Kreuzberger for being so supportive!
Go through Part 2 for more on Keptn development.








