Home > OS >  ElasticSearch Kubernetes Setup with Skaffold
ElasticSearch Kubernetes Setup with Skaffold

Time:02-11

I love elastic search so on my new project I have been trying to make it work on Kubernetes and skaffold

this is the yaml file I wrote:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: eks-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: eks
  template:
    metadata:
      labels:
        app: eks
    spec:
      containers:
        - name: eks
          image: elasticsearch:7.17.0
---
apiVersion: v1
kind: Service
metadata:
  name: eks-srv
spec:
  selector:
    app: eks
  ports:
    - name: db
      protocol: TCP
      port: 9200
      targetPort: 9200
    - name: monitoring
      protocol: TCP
      port: 9300
      targetPort: 9300

After I run skaffold dev it shows to be working by Kubernetes but after a few seconds it crashes and goes down.

I can't understand what I am doing wrong.

This is where the problem seems to occur

After I have updated my config files as Mr. Harsh Manvar it worked like a charm but currently I am facing another issue. The client side says the following....

Btw I am using ElasticSearch version 7.11.1 and Client side module "@elastic/elasticsearch^7.11.1"

enter image description here

CodePudding user response:

Here is example YAML file you should consider running if you are planning to run the single Node elasticsearch cluster on the Kubernetes

apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app: elasticsearch
    component: elasticsearch
    release: elasticsearch
  name: elasticsearch
  namespace: default
spec:
  podManagementPolicy: OrderedReady
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: elasticsearch
      component: elasticsearch
      release: elasticsearch
  serviceName: elasticsearch
  template:
    metadata:
      labels:
        app: elasticsearch
        component: elasticsearch
        release: elasticsearch
    spec:
      containers:
      - env:
        - name: cluster.name
          value: es_cluster
        - name: ELASTIC_PASSWORD
          value: xyz-xyz
        - name: discovery.type
          value: single-node
        - name: path.repo
          value: backup/es-backup
        - name: ES_JAVA_OPTS
          value: -Xms512m -Xmx512m
        - name: bootstrap.memory_lock
          value: "false"
        - name: xpack.security.enabled
          value: "true"
        image: elasticsearch:7.3.2
        imagePullPolicy: IfNotPresent
        name: elasticsearch
        ports:
        - containerPort: 9200
          name: http
          protocol: TCP
        - containerPort: 9300
          name: transport
          protocol: TCP
        resources:
          limits:
            cpu: 451m
            memory: 1250Mi
          requests:
            cpu: 250m
            memory: 1000Mi
        securityContext:
          privileged: true
          runAsUser: 1000
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: elasticsearch-data
      dnsPolicy: ClusterFirst
      initContainers:
      - command:
        - sh
        - -c
        - chown -R 1000:1000 /usr/share/elasticsearch/data
        - sysctl -w vm.max_map_count=262144
        - chmod 777 /usr/share/elasticsearch/data
        - chomod 777 /usr/share/elasticsearch/data/node
        - chmod g rwx /usr/share/elasticsearch/data
        - chgrp 1000 /usr/share/elasticsearch/data
        image: busybox:1.29.2
        imagePullPolicy: IfNotPresent
        name: set-dir-owner
        resources: {}
        securityContext:
          privileged: true
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: elasticsearch-data
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 10
  updateStrategy:
    type: OnDelete
  volumeClaimTemplates:
  - metadata:
      creationTimestamp: null
      name: elasticsearch-data
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 10Gi
      volumeMode: Filesystem

i would also recommand checking out the helm charts of the elasticsearch :

1 . https://github.com/elastic/helm-charts/tree/master/elasticsearch

2. https://github.com/helm/charts/tree/master/stable/elasticsearch

you can expose the above stateful set using the service and use the further with the application.

  • Related