Deploy Keptn using Kubernetes(K8s)

Digital business and technology
Reading Time: 3 minutes

In this blog we will quickly go through the steps to deploy Keptn with the help of replication controllers in Kubernetes !! So lets dive in 🙂

What is Keptn?

Keptn is an open source control plane to build cloud-native, industry-driven continous delivery systems. According to Dynatrace, Keptn augments any standard Kubernetes cluster to support delivery based on automated quality gates and self-healing operations workflows.

Deploy Keptn using K8s

Now let’s deploy Keptn in Kubernetes.

Pre-requisites

For deploying Keptn in kubernetes we require the following :-

  • Basic Knowledge about Kubernetes and replication controller.
  • Basic knowledge about yaml files.

Code Block

Copy the code for the replication controller in your yaml file and save it as keptn-rc.yaml.

apiVersion: v1

kind: ReplicationController

metadata:

#contains 2 things object name and label

  name: keptn-rc

spec:

#contains no. of replicas and pods spec

  replicas: 3

  selector:

    app: keptn-app
  
  template:

  #pods spec

    metadata:

      name: keptn-pod

      labels:

        app: keptn-app
    
    spec:

      containers:

      - name: keptn-container

        image: gardnera/thekindkeptn:0.0.15

        ports:

        - containerPort: 80

Here we are creating a replication controller with the following specs:

  • Metadata of replication controller: keptn-rc
  • Replica of keptn pods: 3
  • Container name: keptn-container
  • Keptn image: gardnera/thekindkeptn:0.0.15
  • Port for running: 80

By default only 3 pods of Keptn will be running on nodes. To scale up or down the pods use the following command.

Code Implementation

- Deploy keptn rc with (default 3 replicas) following command.

kubectl create -f keptn-rc.yaml


- Get output of running pods using this command.

kubectl get po -o wide


- Scale Up / Scale Down the pods using this command.

kubectl scale rc keptn-rc --replicas=5

kubectl scale rc keptn-rc --replicas=1


- Delete keptn-rc after deployment

kubectl delete -f keptn-rc.yaml

FUN PART 🙂

If you don’t want to execute the above steps, I have a script made for you that does that 🙂

Just execute as bash main.sh.

echo "Please enter the number of pods you want to deploy for Keptn"

read count

echo $count

#Start keptn: with 3 nodes

kubectl create -f keptn-rc.yaml && kubectl scale rc keptn-rc --

replicas=$count

#Check output:

kubectl get po -o wide

echo 

while true; do    

    read -p "Do you want to scalup Pods? [y for Yes  ;  n for No  ;  q  for 

Quit] " yn

    echo ""

    case $yn in

        [Yy]* ) echo "Enter number of pods to scale up" 

                read scale_count

        echo "Pods scaled up to $scale_count" && kubectl scale rc keptn-rc --

replicas=$scale_count ; break;;

        [Nn]* ) break ;;

        [Qq]* ) exit 0;;

        * ) echo "Please provide a yes or no answer."

    esac

done

echo

while true; do    

    read -p "Do you want to scaldown Pods? [y for Yes  ;  n for No  ;  q  for 

Quit] " yn

    echo ""

    case $yn in

        [Yy]* ) echo "Enter number of pods to scale down" 

                read scale_count

        echo "Pods scaled down to $scale_count" && kubectl scale rc keptn-rc 

--replicas=$scale_count ; break;;

        [Nn]* ) break ;;

        [Qq]* ) exit 0;;

        * ) echo "Please provide a yes or no answer."

    esac

done

echo 

while true; do    

    read -p "Do you want to delete this Deployment? [y for Yes  ;  n for No  

;  q  for Quit] " yn

    echo ""

    case $yn in

        [Yy]* ) kubectl delete -f keptn-rc.yaml ; break;;

        [Nn]* ) break ;;

        [Qq]* ) exit 0;;

        * ) echo "Please provide a yes or no answer."

    esac

done

Output

Running and scaling up Keptn pods with the above command.

Scale up pods

Running and scaling down Keptn pods with the above command.

Scale down pods

Conclusion

In this blog I have tried to cover Keptn deployment using Kubernetes(K8s). I have tried my best to provide you with the source code as well as a script that does all that steps for you.

Please like and subscribe the blog to get more informative blogs like this !!

References

Keptn Docs: https://keptn.sh/docs/quickstart/

Written by 

Rishabh Verma is Google Certified Professional DevOps Engineer. He is always charged up for new things & learnings. He is dedicated to his work and believes in quality output. He loves to take deep dives into cloud technologies & different tools.

Leave a Reply