반응형
K8s + Elastic Search pod 구축하기
Elastic Search 란?
* 실시간 검색/분석 기능 제공, 분산환경에 저장 되어있는 로그를 통합으로 수집합으로써 통합 데이터 저장소의 역할을 할 수 있고 로그의 라이프 사이클을 관리하여 효과적인 디스크 관리를 지원.
* MSA 환경에서 Telemetry는 더더욱 중요해지고 있고, Telemetry는 로깅, 모니터링, 추적 기능을 포괄하여 분산 트랜잭션 환경에서 효과적인 유지보수를 수행할 수 있도록 지원해주는 도구. 자동화된 수집 체계를 구성하는 것이 중요하다.
* 마스터 노드: 클러스터 관리, 인덱스 관리, 필요한 경우 새 마스터 선택을 담당
* Data 노드: 데이터 저장 전용인 반면 클라이언트 Pod는 수신 트래픽을 나머지 Pod로 전달하는 것 외에는 역할이 없다.
* Ingest 노드: 데이터 변환을 위한 노드
* Tribe 노드: 다중 클러스터 관리
* Client 노드: 복잡한 데이터의 조회 및 집계를 포함할 경우 사용하는 노드 등이 있다.
Elastic Search 설치
1) Namespace 생성
* $ vi elasticsearch-pv.yaml
apiVersion: v1
kind: Namespace
metadata:
name: elasticsearch
2) YAML 파일 적용 및 Namespace 확인
* $ kubectl apply -f elasticsearch-pv.yaml
* $ kubectl get namespace
3) Elasticsearch master node 생성
3-1) Master node configmap 생성
$ vi elasticsearch-master-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
namespace: elasticsearch
name: elasticsearch-master-config
labels:
app: elasticsearch
role: master
data:
elasticsearch.yml: |-
cluster.name: ${CLUSTER_NAME}
node.name: ${NODE_NAME}
discovery.seed_hosts: ${NODE_LIST}
cluster.initial_master_nodes: ${MASTER_NODES}
network.host: 0.0.0.0
node:
master: true
data: false
ingest: false
xpack.security.enabled: false
xpack.monitoring.collection.enabled: false
3-2) Master node service 생성
$ vi elasticsearch-master-service.yaml
apiVersion: v1
kind: Service
metadata:
namespace: elasticsearch
name: elasticsearch-master
labels:
app: elasticsearch
role: master
spec:
ports:
- port: 9300
name: transport
selector:
app: elasticsearch
role: master
3-3) Master node deployment 생성
$ vi elasticsearch-master-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: elasticsearch
name: elasticsearch-master
labels:
app: elasticsearch
role: master
spec:
replicas: 1
selector:
matchLabels:
app: elasticsearch
role: master
template:
metadata:
labels:
app: elasticsearch
role: master
spec:
containers:
- name: elasticsearch-master
image: docker.elastic.co/elasticsearch/elasticsearch:7.3.0
env:
- name: CLUSTER_NAME
value: elasticsearch
- name: NODE_NAME
value: elasticsearch-master
- name: NODE_LIST
value: elasticsearch-master,elasticsearch-data,elasticsearch-client
- name: MASTER_NODES
value: elasticsearch-master
- name: "ES_JAVA_OPTS"
value: "-Xms256m -Xmx256m"
ports:
- containerPort: 9300
name: transport
volumeMounts:
- name: config
mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
readOnly: true
subPath: elasticsearch.yml
- name: storage
mountPath: /data
volumes:
- name: config
configMap:
name: elasticsearch-master-config
- name: "storage"
emptyDir:
medium: ""
initContainers:
- name: increase-vm-max-map
image: busybox
command: ["sysctl", "-w", "vm.max_map_count=262144"]
securityContext:
privileged: true
3-4) Master node 생성 및 확인
$ kubectl apply -f elasticsearch-master-configmap.yaml -f elasticsearch-master-service.yaml -f elasticsearch-master-deployment.yaml
$ kubectl get pods -n elasticsearch (Running 확인)
4) Elasticsearch Data node 생성
4-1) Data config 생성
$ vi elasticsearch-data-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
namespace: elasticsearch
name: elasticsearch-data-config
labels:
app: elasticsearch
role: data
data:
elasticsearch.yml: |-
cluster.name: ${CLUSTER_NAME}
node.name: ${NODE_NAME}
discovery.seed_hosts: ${NODE_LIST}
cluster.initial_master_nodes: ${MASTER_NODES}
network.host: 0.0.0.0
node:
master: false
data: true
ingest: false
xpack.security.enabled: false
xpack.monitoring.collection.enabled: false
4-2) Data service 생성
$ vi elasticsearch-data-service.yaml
apiVersion: v1
kind: Service
metadata:
namespace: elasticsearch
name: elasticsearch-data
labels:
app: elasticsearch
role: data
spec:
ports:
- port: 9300
name: transport
selector:
app: elasticsearch
role: data
4-3) Data statefulset 생성
$ vi elasticsearch-data-statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
namespace: elasticsearch
name: elasticsearch-data
labels:
app: elasticsearch
role: data
spec:
serviceName: "elasticsearch-data"
selector:
matchLabels:
app: elasticsearch-data
role: data
replicas: 1
template:
metadata:
labels:
app: elasticsearch-data
role: data
spec:
containers:
- name: elasticsearch-data
image: docker.elastic.co/elasticsearch/elasticsearch:7.3.0
env:
- name: CLUSTER_NAME
value: elasticsearch
- name: NODE_NAME
value: elasticsearch-data
- name: NODE_LIST
value: elasticsearch-master,elasticsearch-data,elasticsearch-client
- name: MASTER_NODES
value: elasticsearch-master
- name: "ES_JAVA_OPTS"
value: "-Xms300m -Xmx300m"
ports:
- containerPort: 9300
name: transport
volumeMounts:
- name: config
mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
readOnly: true
subPath: elasticsearch.yml
- name: elasticsearch-data-persistent-storage
mountPath: /data/db
volumes:
- name: config
configMap:
name: elasticsearch-data-config
initContainers:
- name: increase-vm-max-map
image: busybox
command: ["sysctl", "-w", "vm.max_map_count=262144"]
securityContext:
privileged: true
volumeClaimTemplates:
- metadata:
name: elasticsearch-data-persistent-storage
annotations:
volume.beta.kubernetes.io/storage-class: "gp2"
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: standard
resources:
requests:
storage: 10Gi
4-4) 적용 및 확인
$ kubectl apply -f elasticsearch-data-configmap.yaml -f elasticsearch-data-service.yaml -f elasticsearch-data-statefulset.yaml
$ kubectl get pods -n elasticsearch
(master , data 2개 pod가 Running 이어야하는데 data는 pending 일 것이다. PV와 연결이 안되었기 때문)
5) Elasticsearch PV 생성
$ vi elasticsearch-persistentvolume.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
namespace: elasticsearch
name: elasticsearch-pv
labels:
name: elasticsearch
spec:
storageClassName: standard
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
# PVC이름은 elasticsearch-data-statefulset의 volumeClaimTemplates의 name + pod명
claimRef:
namespace: elasticsearch
name: elasticsearch-data-persistent-storage-elasticsearch-data-0
persistentVolumeReclaimPolicy: Delete
hostPath:
path: /data/db
type: DirectoryOrCreate
6) Elasticsearch Client node 생성
6-1) Client configmap 생성
$ vi elasticsearch-client-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
namespace: elasticsearch
name: elasticsearch-client-config
labels:
app: elasticsearch
role: client
data:
elasticsearch.yml: |-
cluster.name: ${CLUSTER_NAME}
node.name: ${NODE_NAME}
discovery.seed_hosts: ${NODE_LIST}
cluster.initial_master_nodes: ${MASTER_NODES}
network.host: 0.0.0.0
node:
master: false
data: false
ingest: true
xpack.security.enabled: false
xpack.monitoring.collection.enabled: false
6-2) Client service 생성
$ vi elasticsearch-client-service.yaml
apiVersion: v1
kind: Service
metadata:
namespace: elasticsearch
name: elasticsearch-client
labels:
app: elasticsearch
role: client
spec:
ports:
- port: 9200
name: client
- port: 9300
name: transport
selector:
app: elasticsearch
role: client
6-3) Client deployment 생성
$ vi elasticsearch-client-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: elasticsearch
name: elasticsearch-client
labels:
app: elasticsearch
role: client
spec:
replicas: 1
selector:
matchLabels:
app: elasticsearch
role: client
template:
metadata:
labels:
app: elasticsearch
role: client
spec:
containers:
- name: elasticsearch-client
image: docker.elastic.co/elasticsearch/elasticsearch:7.3.0
env:
- name: CLUSTER_NAME
value: elasticsearch
- name: NODE_NAME
value: elasticsearch-client
- name: NODE_LIST
value: elasticsearch-master,elasticsearch-data,elasticsearch-client
- name: MASTER_NODES
value: elasticsearch-master
- name: "ES_JAVA_OPTS"
value: "-Xms256m -Xmx256m"
ports:
- containerPort: 9200
name: client
- containerPort: 9300
name: transport
volumeMounts:
- name: config
mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
readOnly: true
subPath: elasticsearch.yml
- name: storage
mountPath: /data
volumes:
- name: config
configMap:
name: elasticsearch-client-config
- name: "storage"
emptyDir:
medium: ""
initContainers:
- name: increase-vm-max-map
image: busybox
command: ["sysctl", "-w", "vm.max_map_count=262144"]
securityContext:
privileged: true
7) 적용 및 확인
$ kubectl apply -f elasticsearch-client-configmap.yaml -f elasticsearch-client-service.yaml -f elasticsearch-client-deployment.yaml
$ kubectl get svc -n elasticsearch -o wide
8) Service 생성 확인
$ kubectl get pods -n elasticsearch
Master , Client , Data node Running 확인
$ curl http://10.108.23.153:9200/_cluster/health?pretty
Cluster , status , node 생성 등 확인.
참고문헌
반응형
'개발인생 > Kubernetes' 카테고리의 다른 글
install) kubernetes + GitLab (yaml 파일로 배포) (0) | 2023.02.07 |
---|---|
install) kubernetes + Nexus3 (yaml 배포) (0) | 2023.02.07 |
install) Kubernetes + nas storage (NFS 서버) (0) | 2023.01.27 |
install) kubernetes + LoadBalancer(metal LB) 구축 (0) | 2023.01.27 |
install) Ubuntu 22.04+K8s 1.26+CRIO 1.26+Calico 3.25 (0) | 2023.01.18 |