Skip to content

Commit

Permalink
Fix #106. Automating Kibana DataView creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ricsanfre committed Jan 7, 2025
1 parent a824fbb commit 8dc4ba3
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: kibana-config-data
data:
wait-for-kibana.sh: |
#!/bin/sh
# Wait for Kibana to be available & healthy
echo "Testing connection to Kibana"
until $(curl -k -X GET http://${KIBANA_URL}:${KIBANA_PORT}/_cluster/health); do sleep 5; done
until [ "$(curl -k -X GET http://${KIBANA_URL}:${KIBANA_PORT}/_cluster/health | wc -l)" == "0" ]
do sleep 5
done
create-data-view.sh: |
#!/bin/sh
#Import data view
echo "Importing data_view..."
curl -u elastic:${ELASTICSEARCH_PASSWORD} \
-X POST http://${KIBANA_URL}:${KIBANA_PORT}/api/data_views/data_view \
-H 'Content-Type: application/json; Elastic-Api-Version=2023-10-31' \
-H 'kbn-xsrf: string' \
-d '
{
"data_view": {
"name": "fluentd",
"title": "fluentd-*",
"timeFieldName": "@timestamp"
}
}
'
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: batch/v1
kind: Job
metadata:
name: kibana-config-job
spec:
parallelism: 1
completions: 1
template:
spec:
restartPolicy: Never
initContainers:
- name: wait-for-kibana
image: alpine/curl:latest
imagePullPolicy: IfNotPresent
env:
- name: KIBANA_URL
value: efk-kb-http
- name: KIBANA_PORT
value: "5601"
command: ["/bin/sh","/kibana/wait-for-kibana.sh"]
volumeMounts:
- name: kibana-config-data
mountPath: /kibana/
containers:
- name: kibana-config-job
image: alpine/curl:latest
env:
- name: ELASTICSEARCH_PASSWORD
valueFrom:
secretKeyRef:
name: efk-es-elastic-user
key: elastic
- name: KIBANA_URL
value: efk-kb-http
- name: KIBANA_PORT
value: "5601"
command: ["/bin/sh","/kibana/create-data-view.sh"]
volumeMounts:
- name: kibana-config-data
mountPath: /kibana/
volumes:
- name: kibana-config-data
configMap:
name: kibana-config-data
defaultMode: 0777
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

resources:
- kibana-configuration-cm.yaml
- kibana-configuration-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ resources:
components:
- ../../components/authentication
- ../../components/ingress
- ../../components/istio
- ../../components/istio
- ../../components/kibana-config

0 comments on commit 8dc4ba3

Please sign in to comment.