Skip to content

Commit 8161e14

Browse files
authored
Merge pull request #13664 from mburke5678/Exposing-elasticsearch-service-with-route
Exposing elasticsearch service with a route
2 parents 3bf9380 + b9a5ec9 commit 8161e14

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

modules/efk-logging-elasticsearch-exposing.adoc

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,58 @@ You have access to Elasticsearch using your {product-title} token, and
1313
you can provide the external Elasticsearch and Elasticsearch Ops
1414
hostnames when creating the server certificate (similar to Kibana).
1515

16+
.Prerequisite
17+
18+
Set cluster logging to the unmanaged state.
19+
1620
.Procedure
1721

18-
. To access Elasticsearch as a reencrypt route, define the following variables:
22+
. Use the following command to get name of the ElasticSearch pod:
1923
+
2024
----
21-
openshift_logging_es_allow_external=True
22-
// openshift_logging_es_hostname=elasticsearch.example.com
25+
ESPOD=$( oc get pods -l component=elasticsearch -o name | sed -e "s/pod\///" )
2326
----
2427

25-
. To log in to Elasticsearch remotely, the request must contain three HTTP headers:
28+
. Use the following command to extract CA certificate to a file:
2629
+
2730
----
28-
Authorization: Bearer $token
29-
X-Proxy-Remote-User: $username
30-
X-Forwarded-For: $ip_address
31+
oc exec $ESPOD -- cat /etc/openshift/elasticsearch/secret/admin-ca > ./admin-ca
3132
----
3233

33-
. You must have access to the project in order to be able to access to the logs. For example:
34+
. Create the route object for the ElasticSearch service as an yaml file:
3435
+
3536
----
36-
$ oc login <user1>
37-
$ oc new-project <user1project>
38-
$ oc new-app <httpd-example>
37+
apiVersion: route.openshift.io/v1
38+
kind: Route
39+
metadata:
40+
name: elasticsearch
41+
namespace: openshift-logging
42+
spec:
43+
host:
44+
to:
45+
kind: Service
46+
name: elasticsearch
47+
tls:
48+
termination: reencrypt
49+
caCertificate: |-
3950
----
4051

41-
. You need to get the token of this ServiceAccount to be used in the request:
52+
. Use the following commands to add the CA certificate to the object YAML file:
4253
+
4354
----
44-
$ token=$(oc whoami -t)
55+
cat ./admin-ca | sed -e "s/^/ /" >> my_es_route.yaml
56+
echo " destinationCACertificate: |-" >> my_es_route.yaml
57+
cat ./admin-ca | sed -e "s/^/ /" >> my_es_route.yaml
4558
----
4659

47-
. Using the token previously configured, you should be able access Elasticsearch through the exposed route:
60+
. Use the following command to create the service:
4861
+
4962
----
50-
$ curl -k -H "Authorization: Bearer $token" -H "X-Proxy-Remote-User: $(oc whoami)" -H "X-Forwarded-For: 127.0.0.1" https://es.example.test/project.my-project.*/_search?q=level:err | python -mjson.tool
63+
oc create -f my_es_route.yaml
5164
----
5265

66+
. Check the ElasticSearch service is exposed:
67+
+
68+
----
69+
curl --silent --insecure -H "Authorization: Bearer $( oc whoami -t )" "https://$( oc get route elasticsearch -o jsonpath='{.spec.host}' ):443/.operations.*/_search" | jq
70+
----

0 commit comments

Comments
 (0)