diff --git a/benchmark/benchmark.sh b/benchmark/benchmark.sh new file mode 100755 index 0000000..9333ec7 --- /dev/null +++ b/benchmark/benchmark.sh @@ -0,0 +1,70 @@ +#!/bin/bash - +#=============================================================================== +# +# FILE: benchmark.sh +# +# USAGE: ./benchmark.sh +# +# DESCRIPTION: Runs a benchmark against the kubenab-Server +# +# OPTIONS: --- +# REQUIREMENTS: go, docker, openssl +# BUGS: --- +# NOTES: --- +# AUTHOR: Francesco Emanuel Bennici +# ORGANIZATION: +# CREATED: 28.09.2019 00:32:08 +# REVISION: --- +#=============================================================================== + +set -o nounset # Treat unset variables as an error + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +tmp=$(mktemp -d) +curr=$(pwd) + +## ===> Compile `kubenab` <=== + +echo "[i] Generating Self-Signed Certificates" +openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \ + -keyout ${tmp}/tls.key -out ${tmp}/tls.crt -extensions san -config \ + <(echo "[req]"; + echo distinguished_name=req; + echo "[san]"; + echo subjectAltName=DNS:localhost,IP:127.0.0.1 + ) \ + -subj "/CN=localhost" + + +echo "[i] Compiling kubenab" +cd ${DIR}/../ +docker build -t temp/build:kubenab . +id=$(docker run -p 8443:443 \ + -v ${tmp}:/etc/admission-controller/tls \ + -d --env "DOCKER_REGISTRY_URL=jfrog" --env "REPLACE_REGISTRY_URL=false" \ + temp/build:kubenab) +cd ${curr} + +## ==> Benchmark <==# + +echo "[i] Installing bombardier" +go get -u github.com/codesenberg/bombardier + +echo "###########################" +echo "### Starting bombardier ###" +echo -e "###########################\n" + +echo -e "==> Mutate Webhook\n\n" +bombardier -c 125 -n 10000000 --insecure --latencies \ + --fasthttp --body $(cat ${DIR}/mutate_body) \ + --print 'i,p,r' --method POST https://localhost:8443/mutate + +echo -e "\n\n==> Validate Webhook\n\n" +bombardier -c 125 -n 10000000 --insecure --latencies \ + --fasthttp --body $(cat ${DIR}/validate_body) \ + --print 'i,p,r' --method POST https://localhost:8443/validate + + +## Cleaning Up +docker rm --force --volumes ${id} +rm -rf ${tmp} diff --git a/benchmark/mutate_body b/benchmark/mutate_body new file mode 100644 index 0000000..f62c22c --- /dev/null +++ b/benchmark/mutate_body @@ -0,0 +1 @@ +{"kind":"AdmissionReview","apiVersion":"admission.k8s.io/v1beta1","request":{"uid":"eae55fa6-d3f5-41f2-bafe-ecb34af1a2d0","kind":{"group":"","version":"v1","kind":"Pod"},"resource":{"group":"","version":"v1","resource":"pods"},"requestKind":{"group":"","version":"v1","kind":"Pod"},"requestResource":{"group":"","version":"v1","resource":"pods"},"namespace":"nginx","operation":"CREATE","userInfo":{"username":"system:serviceaccount:kube-system:replicaset-controller","uid":"76e1a4a5-f75a-40fe-a7a0-876619472d2f","groups":["system:serviceaccounts","system:serviceaccounts:kube-system","system:authenticated"]},"object":{"kind":"Pod","apiVersion":"v1","metadata":{"generateName":"nginx-69844dfc86-","creationTimestamp":null,"labels":{"pod-template-hash":"69844dfc86","test":"kubenab"},"ownerReferences":[{"apiVersion":"apps/v1","kind":"ReplicaSet","name":"nginx-69844dfc86","uid":"5ddf2df2-66e4-4287-869a-e349b0777966","controller":true,"blockOwnerDeletion":true}]},"spec":{"volumes":[{"name":"default-token-mc7dh","secret":{"secretName":"default-token-mc7dh"}}],"containers":[{"name":"nginx","image":"nginx","resources":{},"volumeMounts":[{"name":"default-token-mc7dh","readOnly":true,"mountPath":"/var/run/secrets/kubernetes.io/serviceaccount"}],"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"IfNotPresent"}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","serviceAccountName":"default","serviceAccount":"default","securityContext":{},"schedulerName":"default-scheduler","tolerations":[{"key":"node.kubernetes.io/not-ready","operator":"Exists","effect":"NoExecute","tolerationSeconds":300},{"key":"node.kubernetes.io/unreachable","operator":"Exists","effect":"NoExecute","tolerationSeconds":300}],"priority":0,"enableServiceLinks":true},"status":{}},"oldObject":null,"dryRun":false,"options":{"kind":"CreateOptions","apiVersion":"meta.k8s.io/v1"}}} diff --git a/benchmark/validate_body b/benchmark/validate_body new file mode 100644 index 0000000..30deaf2 --- /dev/null +++ b/benchmark/validate_body @@ -0,0 +1 @@ +{"kind":"AdmissionReview","apiVersion":"admission.k8s.io/v1beta1","request":{"uid":"1f19a6d5-949a-4379-a0f9-a34e52faee18","kind":{"group":"","version":"v1","kind":"Pod"},"resource":{"group":"","version":"v1","resource":"pods"},"requestKind":{"group":"","version":"v1","kind":"Pod"},"requestResource":{"group":"","version":"v1","resource":"pods"},"name":"nginx-69844dfc86-n5vbr","namespace":"nginx","operation":"CREATE","userInfo":{"username":"system:serviceaccount:kube-system:replicaset-controller","uid":"76e1a4a5-f75a-40fe-a7a0-876619472d2f","groups":["system:serviceaccounts","system:serviceaccounts:kube-system","system:authenticated"]},"object":{"kind":"Pod","apiVersion":"v1","metadata":{"name":"nginx-69844dfc86-n5vbr","generateName":"nginx-69844dfc86-","namespace":"nginx","uid":"7be27643-cdb7-438b-a32f-47e5844ad7a8","creationTimestamp":"2019-09-27T22:30:55Z","labels":{"pod-template-hash":"69844dfc86","test":"kubenab"},"ownerReferences":[{"apiVersion":"apps/v1","kind":"ReplicaSet","name":"nginx-69844dfc86","uid":"5ddf2df2-66e4-4287-869a-e349b0777966","controller":true,"blockOwnerDeletion":true}]},"spec":{"volumes":[{"name":"default-token-mc7dh","secret":{"secretName":"default-token-mc7dh","defaultMode":420}}],"containers":[{"name":"nginx","image":"kubenab/nginx","resources":{},"volumeMounts":[{"name":"default-token-mc7dh","readOnly":true,"mountPath":"/var/run/secrets/kubernetes.io/serviceaccount"}],"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"IfNotPresent"}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","serviceAccountName":"default","serviceAccount":"default","securityContext":{},"imagePullSecrets":[{"name":"regsecret"}],"schedulerName":"default-scheduler","tolerations":[{"key":"node.kubernetes.io/not-ready","operator":"Exists","effect":"NoExecute","tolerationSeconds":300},{"key":"node.kubernetes.io/unreachable","operator":"Exists","effect":"NoExecute","tolerationSeconds":300}],"priority":0,"enableServiceLinks":true},"status":{"phase":"Pending","qosClass":"BestEffort"}},"oldObject":null,"dryRun":false,"options":{"kind":"CreateOptions","apiVersion":"meta.k8s.io/v1"}}}