클라우드/Kubernetes
[RKE2] KTCloud 서버 ElasticSearch 설치
세브웁스
2024. 12. 31. 20:00
반응형
최소사양 : Server : 2Core/ 4GB Agent : 2Core / 2GB
KT cloud 1번 서버 ( Master Node )
# swap 끄기
sudo swapoff -a
sudo sed -i -e '/swap/d' /etc/fstab
# rke2 다운로드
[root@hyun-test ~]# curl -sfL <https://get.rke2.io> | sh -
# rke2 서비스 등록 및 사용
systemctl enable rke2-server.service
systemctl start rke2-server.service
journalctl -u rke2-server -f
# 명령어 환경변수 등록 & 별칭 등록
mkdir ~/.kube/
cp /etc/rancher/rke2/rke2.yaml ~/.kube/config
export PATH=$PATH:/ var/lib/rancher/rke2/bin/
echo 'export PATH=/usr/local/bin:/var/lib/rancher/rke2/bin:$PATH' >> ~/.bashrc
echo 'source <(kubectl completion bash)' >>~/.bashrc
echo 'alias k=kubectl' >>~/.bashrc
echo 'complete -F __start_kubectl k' >>~/.bashrc
source ~/.bashrc
KT cloud 2번 서버 ( Worker Node )
# rke2 다운로드
[root@hyun-test2 tmp] curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE="agent" sh -
[root@hyun-test2 tmp] systemctl enable rke2-agent.service
[root@hyun-test2 tmp] mkdir -p /etc/rancher/rke2/
# rke2 연동 (마스터 서버와 연동)
# 9345 , 6443 두개의 포트 통신 허용 (방화벽 허용)
[root@hyun-test tmp] cat /var/lib/rancher/rke2/server/node-token
# 마스터 서버 연동용 config 파일 생성 및 내용 기입
[root@hyun-test2 tmp] mkdir -p /etc/rancher/rke2/
# 마스터 서버의 파일에서 가져와서 등록 (마스터IP, 토큰(랜덤) )
[root@hyun-test2 tmp]# cat /etc/rancher/rke2/config.yaml
server: https://172.27.0.224:9345
token: xxxxx
[root@hyun-test2 tmp] systemctl start rke2-agent.service
# 로그 확인
[root@hyun-test2 tmp] journalctl -u rke2-agent -f
# rke2 서비스 시작 & 로그 보기
[root@hyun-test2 tmp] systemctl start rke2-agent.service
[root@hyun-test2 tmp] journalctl -u rke2-agent -f
# 설정파일 경로
/tmp/filebeat-7.17.1-linux-x86_64/filebeat.yml
/tmp/elastic/pvall.yaml
/tmp/elastic/kib_values.yaml
/tmp/elastic/ela_values.yaml
PV 생성
# PV 적용
[root@hyun-test ~]# k apply -f pvall.yaml
Helm 설치
[root@hyun-test ~]# wget https://get.helm.sh/helm-v3.7.0-linux-amd64.tar.gz
[root@hyun-test ~]# tar -zxvf helm-v3.7.0-linux-amd64.tar.gz
[root@hyun-test ~]# sudo mv linux-amd64/helm /usr/local/bin/helm
[root@hyun-test ~]# helm version
Elastic Search 생성
Elastic Search 버전 정보 : 7.17.7
# yaml 파일 기반으로 elasticsearch 설치
helm install elasticsearch elastic/elasticsearch -n elk --values ela_values.yaml
# 사용하는 포트 확인
[root@hyun-test elastic]# k get svc -n elk
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
elasticsearch-master NodePort 10.43.70.121 <none> 9200:30000/TCP,9300:30846/TCP 21m
# ElasticSearch 홈페이지 접속 정상 확인
IP : 마스터 노드 IP
ID : elastic
Passwd : Password1!
Kibana 버전 정보 : 7.17.7
💡 Kibana 버전 정보 : 7.17.7
# helm을 사용하여 kibana 설치
[root@hyun-test elastic]# helm install kibana elastic/kibana -n elk --values kib_values.yaml
# pod 정상 실행 확인
[root@hyun-test elastic]# kubectl get pods --namespace=elk -l release=kibana -w
NAME READY STATUS RESTARTS AGE
kibana-kibana-bf9b84946-hqfss 0/1 Running 0 9s
kibana-kibana-bf9b84946-hqfss 1/1 Running 0 91s
# 서비스 확인
[root@hyun-test elastic]# k get svc -n elk
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
elasticsearch-master NodePort 10.43.70.121 <none> 9200:30000/TCP,9300:30846/TCP 63m
elasticsearch-master-headless ClusterIP None <none> 9200/TCP,9300/TCP 63m
kibana-kibana NodePort 10.43.176.67 <none> 5601:30010/TCP 8m24s
# Kibana 접속
# 접속 경로는 위의 서비스 확인 명령어를 통해 확인
Filebeat 설치
# 서버에서 파일 다운로드 cd /tmp wget <https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.17.7-linux-x86_64.tar.gz> tar -xvf /tmp/filebeat-7.17.7-linux-x86_64.tar.gz
Filebeat 는 모니터링이 필요한 서버에 설치 (nginx 설치된 서버라 가정)
Filebeat 버전 정보 : 7.17.7
# /etc/hosts 파일에 등록
$ cat /etc/hosts
172.27.0.97 elasticsearch-master
# filebeat.yml 파일 수정
# /var/log/nginx 경로는 nginx 로그 경로
filebeat.inputs:
- type: filestream
paths:
- /var/log/nginx/*.log
output.elasticsearch:
hosts: ["elasticsearch-master:30000"]
protocol: "https"
username: "elastic"
password: "Password1!"
ssl.certificate_authorities: ["/tmp/filebeat-7.17.1-linux-x86_64/ca.crt"]
# 위 코드의 ca 파일은 elasticsearch pod 안에 존재
[root@hyun-test filebeat-7.17.1-linux-x86_64]# k get pod -n elk
NAME READY STATUS RESTARTS AGE
elasticsearch-master-0 1/1 Running 2 (28m ago) 3d23h
[root@hyun-test filebeat-7.17.1-linux-x86_64]# k exec -it -n elk elasticsearch-master-0 /bin/bash
# 해당 내용 카피하여 filebeat 설치된 서버에 파일 생성 및 내용 추가
elasticsearch@elasticsearch-master-0:~/config/certs$ cat /usr/share/elasticsearch/config/certs/ca.crt
# Filebeat 설치된 경로로 가서 filebeat 실행
cd /tmp/filebeat-7.17.1-linux-x86_64
./filebeat -e -c filebeat.yml
Filebeat - Elasticsearch 연동 확인
트러블슈팅
# 리소스 사용량 제한 에러
[root@hyun-test elastic]# k describe pod elasticsearch-master-0 -n elk
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 8m12s default-scheduler 0/1 nodes are available: pod has unbound immediate PersistentVolumeClaims. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling..
Warning FailedScheduling 8m11s default-scheduler 0/1 nodes are available: 1 Insufficient cpu. preemption: 0/1 nodes are available: 1 No preemption victims found for incoming pod..
Warning FailedScheduling 3m10s default-scheduler 0/1 nodes are available: 1 Insufficient cpu. preemption: 0/1 nodes are available: 1 No preemption victims found for incoming pod..
[root@hyun-test elastic]# k describe node hyun-test
Allocated resources:
(Total limits may be over 100 percent, i.e., overcommitted.)
Resource Requests Limits
-------- -------- ------
cpu 1675m (83%) 200m (10%)
memory 2610Mi (71%) 192Mi (5%)
ephemeral-storage 0 (0%) 0 (0%)
hugepages-1Gi 0 (0%) 0 (0%)
hugepages-2Mi 0 (0%) 0 (0%)
# cpu 사용량이 여유롭지 못함
# 스케일업으로 cpu 확보 또는 워커노드에 파드 배포
# 파드 변화상태 조회시 계속해서 CrashLoopBackoff 발생
[root@hyun-test elastic]# kubectl get pods --namespace=elk -l app=elasticsearch-master -w
NAME READY STATUS RESTARTS AGE
elasticsearch-master-0 0/1 Init:0/1 0 19s
elasticsearch-master-0 0/1 PodInitializing 0 20s
elasticsearch-master-0 0/1 RunContainerError 0 21s
elasticsearch-master-0 0/1 RunContainerError 1 (1s ago) 22s
elasticsearch-master-0 0/1 CrashLoopBackOff 1 (9s ago) 30s
elasticsearch-master-0 0/1 RunContainerError 2 (1s ago) 43s
elasticsearch-master-0 0/1 CrashLoopBackOff 2 (8s ago) 50s
[root@hyun-test elastic]# k describe -n elk pod elasticsearch-master-0
Error: failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error setting cgroup config for procHooks process: unable to set memory limit to 1 (current usage: 2977792, peak usage: 3280896): unknown
Warning BackOff 12s (x7 over 72s) kubelet Back-off restarting failed container elasticsearch in pod elasticsearch-master-0_elk(6db64879-fb34-4e18-852d-ae949ec391d7)
# 해결법
yaml 파일에 오타 수정
resources:
requests:
cpu: "256m"
memory: "1Gi"
limits:
cpu: "512m"
memory: "512m"
# m 으로 표시시 장애 발생 -> 1Gi로 수정
resources:
requests:
cpu: "256m"
memory: "1Gi"
limits:
cpu: "512m"
memory: "1Gi"
[root@hyun-test elastic]# k get pod -n elk -w
NAME READY STATUS RESTARTS AGE
elasticsearch-master-0 0/1 Running 0 80s
elasticsearch-master-0 1/1 Running 0 111s
Elasticsearch에 Filebeat 로그 출력되지 않는 현상
# 로그가 없어서 생긴 문제
# 시간이 지난 후 로그가 생기면 자연스러운 해결(2분 이상 기다려 볼 것)
반응형