initial commit

This commit is contained in:
Simon Belmas
2024-03-27 17:09:26 +01:00
commit aa1dd9bc42
5 changed files with 268 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
yamls/**

13
README.md Normal file
View File

@@ -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]
~~~

204
app_template.yaml Normal file
View File

@@ -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<cpus;i++)); do
while : ; do
:
done &
pids="\$pids $!"
done
sleep \$seconds
) &
}
#lc \$((1 + \$RANDOM % 3)) \$((120 + \$RANDOM % 421))
lc \$((1 + \$RANDOM % 3)) \$((120 + \$RANDOM % 600))
wait
echo Starting frontend
exec nginx -g "daemon off;"
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ['ALL']
name: front
volumeMounts:
- mountPath: /var/www/html
name: web
ports:
- containerPort: 8080
protocol: TCP
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 20
successThreshold: 1
failureThreshold: 3
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 30
successThreshold: 1
failureThreshold: 3
startupProbe:
httpGet:
path: /
port: 8080
periodSeconds: 10
successThreshold: 1
failureThreshold: 90
initContainers:
- command:
- bash
- -e
- -c
- |-
cat >/var/www/index.html <<EOF
<html>
<head><title>${current_ns}</title>
<body>
<h1>${current_ns}</h1>
</body>
</html>
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

39
deploy_wkload.sh Executable file
View File

@@ -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 <<EOF
$(<${script_dir}/app_template.yaml)
EOF"
done
oc apply -f "${manifests_dir}"
echo All Done!

View File

@@ -0,0 +1,11 @@
apiVersion: machineconfiguration.openshift.io/v1
kind: KubeletConfig
metadata:
name: set-max-pods
spec:
machineConfigPoolSelector:
matchLabels:
pools.operator.machineconfiguration.openshift.io/worker: ""
kubeletConfig:
podsPerCore: 0
maxPods: 500