2026-01-09 08:54:07 -03:00
# services/logging/opensearch-ism-job.yaml
apiVersion : batch/v1
kind : Job
metadata :
2026-01-09 09:00:25 -03:00
name : opensearch-ism-setup-3
2026-01-09 08:54:07 -03:00
namespace : logging
spec :
backoffLimit : 3
ttlSecondsAfterFinished : 3600
template :
spec :
restartPolicy : OnFailure
2026-01-09 08:58:48 -03:00
nodeSelector :
node-role.kubernetes.io/worker : "true"
2026-01-09 09:00:25 -03:00
hardware : rpi5
2026-01-09 08:58:48 -03:00
affinity :
nodeAffinity :
requiredDuringSchedulingIgnoredDuringExecution :
nodeSelectorTerms :
- matchExpressions :
- key : hardware
operator : In
2026-01-09 09:00:25 -03:00
values :
- rpi5
2026-01-09 08:54:07 -03:00
containers :
- name : apply
image : alpine:3.20
command : [ "/bin/sh" , "-c" ]
args :
- |
set -euo pipefail
apk add --no-cache curl >/dev/null
OS_URL="http://opensearch-master.logging.svc.cluster.local:9200"
for attempt in $(seq 1 60); do
if curl -s -o /dev/null -w "%{http_code}" "${OS_URL}" | grep -q "200"; then
break
fi
sleep 5
done
if ! curl -s -o /dev/null -w "%{http_code}" "${OS_URL}" | grep -q "200"; then
echo "OpenSearch did not become ready in time" >&2
exit 1
fi
policy='{"policy":{"description":"Delete logs after 180 days","schema_version":1,"default_state":"hot","states":[{"name":"hot","actions":[],"transitions":[{"state_name":"delete","conditions":{"min_index_age":"180d"}}]},{"name":"delete","actions":[{"delete":{}}],"transitions":[]}]}}'
curl -sS -X PUT "${OS_URL}/_plugins/_ism/policies/logging-180d" \
-H 'Content-Type : application/json' \
-d "${policy}" >/dev/null
kube_template='{"index_patterns":["kube-*"],"priority":200,"template":{"settings":{"index.number_of_shards":1,"index.number_of_replicas":0,"index.refresh_interval":"30s","plugins.index_state_management.policy_id":"logging-180d"},"mappings":{"properties":{"@timestamp":{"type":"date"}}}}}'
curl -sS -X PUT "${OS_URL}/_index_template/kube-logs" \
-H 'Content-Type : application/json' \
-d "${kube_template}" >/dev/null
journal_template='{"index_patterns":["journald-*"],"priority":200,"template":{"settings":{"index.number_of_shards":1,"index.number_of_replicas":0,"index.refresh_interval":"30s","plugins.index_state_management.policy_id":"logging-180d"},"mappings":{"properties":{"@timestamp":{"type":"date"}}}}}'
curl -sS -X PUT "${OS_URL}/_index_template/journald-logs" \
-H 'Content-Type : application/json' \
-d "${journal_template}" >/dev/null