Software Workshop

예전에 Silicon Mac 환경에 K8s 설치해서 ElasticSearch까지 설치하는 가이드를 작성한 적이 있는데, 최근에 다시 실행을 해보니 bitnami 정책의 변경으로 인해 설치가 되지 않았다.

그래서 elastic 표준 chart를 이용해서 설치하는 방법을 정리해봤다.

helm repo 추가

helm repo add elastic https://helm.elastic.co
helm repo update

CRD 설치

kubectl create -f https://download.elastic.co/downloads/eck/3.1.0/crds.yaml
kubectl get crd | grep k8s.elastic.co

Operator 설치

helm install elastic-operator elastic/eck-operator \
    -n my_namespace \
    --create-namespace \
    --version 3.1.0 \
    --set installCRDs=false
kubectl -n my_namespace rollout status sts/elastic-operator

secret 생성

kubectl -n my_namespace create secret generic es-app-basic \
  --type=kubernetes.io/basic-auth \
  --from-literal=username=계정이름 \
  --from-literal=password=패스워드 \
  --from-literal=roles='superuser'

es-values.yml

eck-elasticsearch:
  enabled: true
  fullnameOverride: elasticsearch

  version: 9.1.0

  auth:
    fileRealm:
      - secretName: es-app-basic   # kubernetes.io/basic-auth (username/password/roles)

  http:
    tls:
      selfSignedCertificate:
        disabled: true

  nodeSets:
    - name: default
      count: 1
      config:
        node.store.allow_mmap: false
      podTemplate:
        spec:
          initContainers:
            - name: install-plugins
              command: ["sh","-c","bin/elasticsearch-plugin install --batch analysis-nori"]
          containers:
            - name: elasticsearch
              resources:
                requests: { cpu: "200m", memory: "1Gi" }
                limits:   { cpu: "1",   memory: "2Gi" }

ElasticSearch chart 설치

helm install es-kb-quickstart elastic/eck-stack \
    -n my_namespace \
    --create-namespace \
    -f es-values.yml

es-ingress.yml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: es-ingress
  namespace: my_namespace
  annotations:
    nginx.ingress.kubernetes.io/backend-protocol: "HTTP"  
    nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-body-size: "100m"
spec:
  ingressClassName: nginx
  rules:
    - host: es.k8s
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: elasticsearch-es-http 
                port:
                  number: 9200

ingress 생성

kubectl apply -f es-ingress.yml

등록된 호스트명과 IP 확인하기

hostname=$(kubectl get ingress es-ingress -n my_namespace -o json | jq -r ".spec.rules[0].host")
ip=$(kubectl get ingress es-ingress -n my_namespace -o json | jq -r ".status.loadBalancer.ingress[0].ip")
echo "$hostname: $ip"

/etc/hosts에 이 호스트명과 IP를 등록해주면 된다.

ready될 때까지 대기한 후에 endpoint 접근 테스트

echo "waiting for ready state..."
kubectl -n textmanager wait --for=condition=ready pod/elasticsearch-es-default-0 --timeout=5m && \
    curl -u 계정이름:패스워드 http://es.k8s/_cluster/health\?pretty