ktimoney | 90fcec9 | 2022-04-29 15:46:50 +0100 | [diff] [blame^] | 1 | apiVersion: v1 |
| 2 | kind: ConfigMap |
| 3 | metadata: |
| 4 | name: elasticsearch-init-script |
| 5 | namespace: logging |
| 6 | data: |
| 7 | setup_certs.sh: | |
| 8 | #!/bin/bash |
| 9 | ELASTIC_HOME=/usr/share/elasticsearch |
| 10 | # If the ca directory already exists, delete it |
| 11 | if [ -d /certs-dir/ca ]; then |
| 12 | rm -rf /certs-dir/ca |
| 13 | fi |
| 14 | # If the elasticsearch directory already exists, delete it |
| 15 | if [ -d /certs-dir/elasticsearch ]; then |
| 16 | rm -rf /certs-dir/elasticsearch |
| 17 | fi |
| 18 | echo "Creating CA"; |
| 19 | $ELASTIC_HOME/bin/elasticsearch-certutil ca --silent --pem -out /certs-dir/ca.zip; |
| 20 | unzip -o /certs-dir/ca.zip -d /certs-dir; |
| 21 | echo "Creating certs"; |
| 22 | echo -ne \ |
| 23 | "instances:\n"\ |
| 24 | " - name: elasticsearch\n"\ |
| 25 | " dns:\n"\ |
| 26 | " - elasticsearch\n"\ |
| 27 | " - elasticsearch.logging\n"\ |
| 28 | " - elasticsearch.est.tech\n"\ |
| 29 | " - localhost\n"\ |
| 30 | " ip:\n"\ |
| 31 | " - 127.0.0.1\n"\ |
| 32 | " - 192.168.49.2\n"\ |
| 33 | > /certs-dir/instances.yml; |
| 34 | $ELASTIC_HOME/bin/elasticsearch-certutil cert --silent --pem -out /certs-dir/certs.zip --in /certs-dir/instances.yml \ |
| 35 | --ca-cert /certs-dir/ca/ca.crt --ca-key /certs-dir/ca/ca.key; |
| 36 | unzip -o /certs-dir/certs.zip -d /certs-dir; |
| 37 | |
| 38 | echo "Removing zip files" |
| 39 | rm -f /certs-dir/ca.zip |
| 40 | rm -f /certs-dir/certs.zip |
| 41 | echo "Setting file permissions" |
| 42 | chmod 750 /certs-dir/ca |
| 43 | chmod 750 /certs-dir/elasticsearch |
| 44 | chmod 640 /certs-dir/ca/* |
| 45 | chmod 640 /certs-dir/elasticsearch/* |
| 46 | echo "All done!"; |
| 47 | --- |
| 48 | apiVersion: v1 |
| 49 | kind: ConfigMap |
| 50 | metadata: |
| 51 | name: elasticsearch-config |
| 52 | namespace: logging |
| 53 | data: |
| 54 | elasticsearch.yml: | |
| 55 | discovery.type: single-node |
| 56 | cluster.name: "docker-cluster" |
| 57 | network.host: 0.0.0.0 |
| 58 | node.name: elasticsearch |
| 59 | ingest.geoip.downloader.enabled: false |
| 60 | xpack.license.self_generated.type: basic |
| 61 | xpack.security.enabled: true |
| 62 | xpack.security.http.ssl.enabled: true |
| 63 | xpack.security.http.ssl.key: certs/elasticsearch/elasticsearch.key |
| 64 | xpack.security.http.ssl.certificate: certs/elasticsearch/elasticsearch.crt |
| 65 | xpack.security.http.ssl.certificate_authorities: certs/ca/ca.crt |
| 66 | xpack.security.http.ssl.verification_mode: certificate |
| 67 | xpack.security.transport.ssl.enabled: true |
| 68 | xpack.security.transport.ssl.key: certs/elasticsearch/elasticsearch.key |
| 69 | xpack.security.transport.ssl.certificate: certs/elasticsearch/elasticsearch.crt |
| 70 | xpack.security.transport.ssl.certificate_authorities: certs/ca/ca.crt |
| 71 | xpack.security.transport.ssl.verification_mode: certificate |
| 72 | --- |
| 73 | apiVersion: apps/v1 |
| 74 | kind: Deployment |
| 75 | metadata: |
| 76 | name: elasticsearch |
| 77 | namespace: logging |
| 78 | spec: |
| 79 | selector: |
| 80 | matchLabels: |
| 81 | component: elasticsearch |
| 82 | template: |
| 83 | metadata: |
| 84 | labels: |
| 85 | component: elasticsearch |
| 86 | spec: |
| 87 | containers: |
| 88 | - name: elasticsearch |
| 89 | imagePullPolicy: IfNotPresent |
| 90 | image: docker.elastic.co/elasticsearch/elasticsearch:8.1.2 |
| 91 | env: |
| 92 | - name: ELASTIC_PASSWORD |
| 93 | value: "secret" |
| 94 | ports: |
| 95 | - containerPort: 9200 |
| 96 | name: http |
| 97 | protocol: TCP |
| 98 | resources: |
| 99 | limits: |
| 100 | cpu: 500m |
| 101 | memory: 4Gi |
| 102 | requests: |
| 103 | cpu: 500m |
| 104 | memory: 4Gi |
| 105 | volumeMounts: |
| 106 | - name: elasticsearch-storage |
| 107 | mountPath: /usr/share/elasticsearch/data |
| 108 | readOnly: false |
| 109 | - name: elasticsearch-certs |
| 110 | mountPath: /usr/share/elasticsearch/config/certs |
| 111 | readOnly: true |
| 112 | - name : config |
| 113 | mountPath: /usr/share/elasticsearch/config/elasticsearch.yml |
| 114 | subPath: elasticsearch.yml |
| 115 | readOnly: false |
| 116 | initContainers: |
| 117 | - name: init-elasticsearch |
| 118 | image: docker.elastic.co/elasticsearch/elasticsearch:8.1.2 |
| 119 | imagePullPolicy: IfNotPresent |
| 120 | command: ['/bin/bash', '-c', '/usr/share/elasticsearch/bin/setup_certs.sh'] |
| 121 | volumeMounts: |
| 122 | - name: elasticsearch-certs |
| 123 | mountPath: "/certs-dir" |
| 124 | - name: elasticsearch-cert-init |
| 125 | mountPath: /usr/share/elasticsearch/bin/setup_certs.sh |
| 126 | subPath: setup_certs.sh |
| 127 | volumes: |
| 128 | - name: elasticsearch-storage |
| 129 | hostPath: |
| 130 | # Ensure the file directory is created. |
| 131 | path: /var/elasticsearch/data |
| 132 | type: DirectoryOrCreate |
| 133 | - name: elasticsearch-certs |
| 134 | hostPath: |
| 135 | # Ensure the file directory is created. |
| 136 | path: /var/elasticsearch/config/certs |
| 137 | type: DirectoryOrCreate |
| 138 | - name: config |
| 139 | configMap: |
| 140 | name: elasticsearch-config |
| 141 | - name: elasticsearch-cert-init |
| 142 | configMap: |
| 143 | name: elasticsearch-init-script |
| 144 | defaultMode: 0755 |
| 145 | --- |
| 146 | apiVersion: v1 |
| 147 | kind: Service |
| 148 | metadata: |
| 149 | name: elasticsearch |
| 150 | namespace: logging |
| 151 | labels: |
| 152 | service: elasticsearch |
| 153 | spec: |
| 154 | type: NodePort |
| 155 | selector: |
| 156 | component: elasticsearch |
| 157 | ports: |
| 158 | - port: 9200 |
| 159 | targetPort: 9200 |
| 160 | --- |
| 161 | apiVersion: networking.istio.io/v1alpha3 |
| 162 | kind: Gateway |
| 163 | metadata: |
| 164 | name: esgateway |
| 165 | spec: |
| 166 | selector: |
| 167 | istio: ingressgateway # use istio default ingress gateway |
| 168 | servers: |
| 169 | - port: |
| 170 | number: 443 |
| 171 | name: https |
| 172 | protocol: HTTPS |
| 173 | tls: |
| 174 | mode: PASSTHROUGH |
| 175 | hosts: |
| 176 | - elasticsearch.est.tech |
| 177 | --- |
| 178 | apiVersion: networking.istio.io/v1alpha3 |
| 179 | kind: VirtualService |
| 180 | metadata: |
| 181 | name: esvirtualservice |
| 182 | spec: |
| 183 | hosts: |
| 184 | - "elasticsearch.est.tech" |
| 185 | gateways: |
| 186 | - esgateway |
| 187 | tls: |
| 188 | - match: |
| 189 | - port: 443 |
| 190 | sniHosts: |
| 191 | - elasticsearch.est.tech |
| 192 | route: |
| 193 | - destination: |
| 194 | host: elasticsearch.logging.svc.cluster.local |
| 195 | port: |
| 196 | number: 9200 |
| 197 | --- |