Skip to main content

elastic-search

ben.wangzLess than 1 minute

elastic-search

prepare

  1. k8s is ready
  2. argocd is ready and logged in
  3. ingress is ready
  4. cert-manager is ready
    • the clusterissuer named self-signed-ca-issuer is ready

installation

  1. prepare elastic-search.yaml
    • minimal
      apiVersion: argoproj.io/v1alpha1
      kind: Application
      metadata:
        name: elastic-search
      spec:
        syncPolicy:
          syncOptions:
          - CreateNamespace=true
        project: default
        source:
          repoURL: https://charts.bitnami.com/bitnami
          chart: elasticsearch
          targetRevision: 19.21.2
          helm:
            releaseName: elastic-search
            values: |
              global:
                kibanaEnabled: false
              clusterName: elastic
              image:
                registry: docker.io
                pullPolicy: IfNotPresent
              security:
                enabled: false
              service:
                type: ClusterIP
              ingress:
                enabled: true
                annotations:
                  cert-manager.io/cluster-issuer: self-signed-ca-issuer
                  nginx.ingress.kubernetes.io/rewrite-target: /$1
                hostname: elastic-search.dev.geekcity.tech
                ingressClassName: nginx
                path: /?(.*)
                tls: true
              master:
                masterOnly: false
                replicaCount: 1
                persistence:
                  enabled: false
              data:
                replicaCount: 0
                persistence:
                  enabled: false
              coordinating:
                replicaCount: 0
              ingest:
                enabled: true
                replicaCount: 0
                service:
                  enabled: false
                  type: ClusterIP
                ingress:
                  enabled: false
              metrics:
                enabled: false
                image:
                  registry: docker.io
                  pullPolicy: IfNotPresent
              volumePermissions:
                enabled: false
                image:
                  registry: docker.io
                  pullPolicy: IfNotPresent
              sysctlImage:
                enabled: true
                registry: docker.io
                pullPolicy: IfNotPresent
              kibana:
                elasticsearch:
                  hosts:
                    - '{{ include "elasticsearch.service.name" . }}'
                  port: '{{ include "elasticsearch.service.ports.restAPI" . }}'
        destination:
          server: https://kubernetes.default.svc
          namespace: application
      
      
  2. apply to k8s
    • kubectl -n argocd apply -f elastic-search.yaml
      
  3. sync by argocd
    • argocd app sync argocd/elastic-search
      

tests

  • elastic-search.dev.geekcity.tech should be resolved to nginx-ingress
    • for example, add $K8S_MASTER_IP elastic-search.dev.geekcity.tech to /etc/hosts
  • make a REST api call
    • curl -k "https://elastic-search.dev.geekcity.tech:32443/?pretty"
      
  • add single document
    • curl -k -H "Content-Type: application/json" \
          -X POST "https://elastic-search.dev.geekcity.tech:32443/books/_doc?pretty" \
          -d '{"name": "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470}'
      
  • bulk add documents
    • curl -k -H "Content-Type: application/x-ndjson" \
          -X POST "https://elastic-search.dev.geekcity.tech:32443/books/_bulk?pretty" \
          -d '{ "index" : { "_index" : "books" } }
      {"name": "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585}
      { "index" : { "_index" : "books" } }
      {"name": "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328}
      { "index" : { "_index" : "books" } }
      {"name": "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227}
      { "index" : { "_index" : "books" } }
      {"name": "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268}
      { "index" : { "_index" : "books" } }
      {"name": "The Handmaids Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311}
      '
      
  • search all documents with index named books
    • curl -k -X GET "https://elastic-search.dev.geekcity.tech:32443/books/_search?pretty"
      
  • search with match query
    • curl -k -H "Content-Type: application/json" \
          -X GET "https://elastic-search.dev.geekcity.tech:32443/books/_search?pretty" \
          -d '{"query": {"match": {"name": "brave"}}}'