commit aa1dd9bc42c602e0372400396fe9252b394f9d62 Author: Simon Belmas <22192134+simbelmas@users.noreply.github.com> Date: Wed Mar 27 17:09:26 2024 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..20d6167 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +yamls/** diff --git a/README.md b/README.md new file mode 100644 index 0000000..1b986ab --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Test heavy load on cluster + +Log in cluster. + +## nodes configuration +oc label node worker-0 wkloadtype=fakeload +oc adm taint node worker-0 wkloadtype=fakeload:NoSchedule + +## Deploy workload + +~~~ +deploy_wkload.sh {number of deployment} [-d] +~~~ \ No newline at end of file diff --git a/app_template.yaml b/app_template.yaml new file mode 100644 index 0000000..421cd53 --- /dev/null +++ b/app_template.yaml @@ -0,0 +1,204 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + labels: + app.kubernetes.io/part-of: fakeworkload + name: ${current_ns} + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: fakeworkload + namespace: ${current_ns} + labels: &deploy_labels + app.kubernetes.io/part-of: fakeworkload + app.kubernetes.io/name: ${current_ns} +spec: + replicas: 2 + revisionHistoryLimit: 2 + progressDeadlineSeconds: 2000 + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 25% + maxSurge: 25% + selector: + matchLabels: *deploy_labels + template: + metadata: + creationTimestamp: null + labels: *deploy_labels + spec: + securityContext: + runAsNonRoot: true + seccompProfile: + type: RuntimeDefault + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: wkloadtype + operator: In + values: + - fakeload + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + podAffinityTerm: + labelSelector: + matchExpressions: + - key: app.kubernetes.io/name + operator: In + values: + - ${current_ns} + topologyKey: kubernetes.io/hostname + tolerations: + - key: wkloadtype + operator: Equal + value: fakeload + effect: "NoSchedule" + containers: + - image: quay.io/simbelmas/nginx:stable + resources: + requests: + memory: "1Mi" + cpu: "1m" + limits: + memory: "20Mi" + command: + - bash + - -e + - -c + - |- + lc() + { + ( + pids="" + cpus=\${1:-1} + seconds=\${2:-60} + echo loading \$cpus CPUs for \$seconds seconds + trap 'for p in \$pids; do kill \$p; done' 0 + for ((i=0;i/var/www/index.html < + ${current_ns} + +

${current_ns}

+ + + EOF + image: quay.io/simbelmas/nginx:stable + imagePullPolicy: IfNotPresent + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: ['ALL'] + name: generate-web + volumeMounts: + - mountPath: /var/www + name: web + volumes: + - emptyDir: {} + name: web + +--- +apiVersion: v1 +kind: Service +metadata: + labels: &svc_labels + app.kubernetes.io/part-of: fakeworkload + app.kubernetes.io/name: ${current_ns} + name: fakeworkload-${current_ns} + namespace: ${current_ns} +spec: + ports: + - name: http + port: 80 + protocol: TCP + targetPort: 8080 + selector: *svc_labels + sessionAffinity: ClientIP + type: ClusterIP + +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: fakeworkload-${current_ns} + namespace: ${current_ns} + labels: + app.kubernetes.io/part-of: fakeworkload + app.kubernetes.io/name: ${current_ns} +spec: + ingressClassName: openshift-default + rules: + - host: ${current_ns}.${route_domain} + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: fakeworkload-${current_ns} + port: + number: 80 + diff --git a/deploy_wkload.sh b/deploy_wkload.sh new file mode 100755 index 0000000..ffb6e1f --- /dev/null +++ b/deploy_wkload.sh @@ -0,0 +1,39 @@ +#!/bin/zsh -e +script_dir="$(dirname "$(readlink -f "$0")")" +manifests_dir=${script_dir}/yamls + + +ns_prefix=wkload- + +if [[ "$1" =~ '^[0-9]+$' ]] ; then + nb_ns="$1" +else + echo First paramater nor given or not number, assuming 1 >&2 + nb_ns=1 +fi + +# Namesspaces Cleanup +if [[ "$2" == "-d" ]] ; then + oc delete --wait ns -l app.kubernetes.io/part-of=fakeworkload || echo No namespace to delete continuing +fi + +# yamls Cleanup +if [ -d "${manifests_dir}" ] ; then + rm -rf "${manifests_dir}" +fi + +## Generate yamls +echo Template generation .... +mkdir "${manifests_dir}" +route_domain="$(oc get ingresses.config.openshift.io cluster -o jsonpath='{.spec.domain}')" +start=1 +while [[ "${start}" -le "${nb_ns}" ]] ; do + current_ns=${ns_prefix}$(printf "%05d" "${start}") + start=$((start + 1)) + eval "cat >${manifests_dir}/${current_ns}.yaml <