예전에 Silicon Mac 환경에 K8s 설치해서 ElasticSearch까지 설치하는 가이드를 작성한 적이 있는데, 최근에 다시 실행을 해보니 bitnami 정책의 변경으로 인해 설치가 되지 않았다.
그래서 elastic 표준 chart를 이용해서 설치하는 방법을 정리해봤다.
helm repo 추가
helm repo add elastic https://helm.elastic.co
helm repo update
CRD 설치
- chart만으로 ElasticSearch와 Kibana, Beat, Agent같은 리소스를 관리하기가 어렵기 때문에, K8s의 자원으로 등록해서 관리하기 위해 CRD와 Operator를 설치하고 이걸 이용해서 관리함
- chart는 배포까지만 담당하고, CRD와 Operator는 배포 이후의 운영 안정성을 보장함
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
- CRD와 Operator는 원래 클러스터 전역으로 설치해야 해서 namespace를 응용과 분리하는 게 더 적절함 (여기 예제는 그냥 같은 namespace 이용)
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 확인하기
- 호스트명은 ingress manifest에 설정된 것과 동일한 값을 확인할 수 있음
- IP는 ingress가 할당한 값을 확인하게 됨
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