Notice
Recent Posts
Recent Comments
Link
Archives
Today
Total
관리 메뉴

윤서율의 블로그

k8sgpt로 쿠버네티스 클러스터 관리 도움받기 본문

DevOps

k8sgpt로 쿠버네티스 클러스터 관리 도움받기

Yoon Seo-yul 2023. 8. 2. 01:29

회사에서 내부 전파용으로 작성했던 백서를 오랜만에 다시 읽어보니 밖으로 전파해도 문제없다 판단되어 블로그에 포스팅합니다. k8sgpt에 대해서 간단히 설명하고, 사용 방법을 가이드합니다

Publication date: March, 2023

 

 

Abstract

k8sgpt명령어로 kubernetes 클러스터를 스캔하고 문제를 진단 및 분류하기 위한 도구

Introduction (Background)

kubernetes k8sgpt는 NLP를 사용하여 쿠버네티스 클러스터의 로그와 다른 데이터를 분석하여 문제를 식별하고 진단하는 도구이다. 쿠버네티스 클러스터에서 발생할 수 있는 일반적인 문제들을 인식할 수 있는 내장 분석기들을 지원하여 파드 충돌, 서비스 실패, 인그레스의 잘못된 구성 등의 문제들을 찾아줄 수 있다.

분석기에 SRE 경험을 코드화하고 AI로 풍부한 정보를 바탕으로 가장 관련성이 높은 정보를 추출하는 데 도움을 준다.

 

장점과 특징

kubernetes k8sgpt는 문제가 발견되면 자연어로 이해하기 쉬운 설명을 제공한다. 또한, AI를 통해 관련 정보를 더욱 풍부하게 만들어줍니다. 예를 들어, 공식 문서나 튜토리얼 링크를 제공하거나, 문제의 원인과 해결 방법을 제시하거나, 추가적인 질문을 하여 문제를 좁혀나갈 수 있도록 지시한다.

 

설치 및 사용 방법

kubernetes k8sgpt는 CLI와 Operator 두 가지 방식으로 설치할 수 있다. CLI는 brew나 rpm, deb, apk 등의 패키지 매니저를 통해 설치할 수 있으며, Operator는 Helm이나 Kustomize 등의 도구로 설치할 수 있다.

현재 기본 AI 제공자는 OpenAI이며, OpenAI에서 API 키를 생성하여 k8sgpt에 설정해야 한다. 그 후에는 k8sgpt analyze 명령어로 클러스터를 스캔하고, --explain이나 --with-doc 옵션으로 자세한 설명이나 문서를 얻을 수 있다.

자세한 내용은 아래 핸즈온에서 살펴 볼 수 있다.

 

예시와 활용 사례

kubernetes k8sgpt는 다양한 리소스와 네임스페이스에 대해 분석할 수 있으며, 필터 옵션으로 원하는 항목만 선택할 수 있다. 또한, JSON 형식으로 출력하여 다른 도구와 연동을 지원한다.

활용 예시로는 파드 충돌이나 서비스 실패 등의 문제를 찾고, 그 원인과 해결 방법을 알려주는 것이 있다.

Conclusion

핸즈온

핸즈온은 Mac OS환경에서 CLI를 이용하여 진행한다.

1. k8sgpt 설치

brew tap k8sgpt-ai/k8sgpt
brew install k8sgpt

2. Open AI 사용을 위한 api key 발급 받기

k8sgpt generate

명령어 실행하면 브라우저가 실행되고, Open AI 로그인 후 api key를 발급 받습니다.

위에서 발급되는 secret key를 k8sgpt에 설정

k8sgpt auth --password {MY_SERCRET_KEY}
  1. k8sgpt 기능 설정하기.

k8sgpt는 활성화된 필터를 바탕으로 동작한다. 아래 명령어로 필터 리스트를 확인 할 수 있다.

k8sgpt filters list

# 아래 값이 기본 적용되어 있습니다.
Active:
> Pod
> ReplicaSet
> PersistentVolumeClaim
> Service
> Ingress
Unused:
> HorizontalPodAutoScaler
> PodDisruptionBudget 
  1. k8sgpt로 분석하기
k8sgpt analyze
# 상세 설명 얻기
k8sgpt analyze --explain

 

예시

k8sgpt analyze --explain --filter=Service --namespace=apim --output=yaml --anonymize

서비스를 대상으로 분석했을때, svc-loadflash-response에 문제가 있음을 알고, 해결 방법을 제시

실제로 해당 파드가 없어서 앱 지정 label 이 잘못됨

 

익명화 중요함

--anonymize 옵션을 사용

> Anonymization

With this option, the data is anonymized before being sent to the AI Backend. During the analysis execution, k8sgpt retrieves sensitive data (Kubernetes object names, labels, etc.). This data is masked when sent to the AI backend and replaced by a key that can be used to de-anonymize the data when the solution is returned to the user.

1. Error reported during analysis: ```bash Error: HorizontalPodAutoscaler uses StatefulSet/fake-deployment as ScaleTargetRef which does not exist. ```
Payload sent to the AI backend:
Error: HorizontalPodAutoscaler uses StatefulSet/tGLcCRcHa1Ce5Rs as ScaleTargetRef which does not exist.
Payload returned by the AI:
The Kubernetes system is trying to scale a StatefulSet named tGLcCRcHa1Ce5Rs using the HorizontalPodAutoscaler, but it cannot find the StatefulSet. The solution is to verify that the StatefulSet name is spelled correctly and exists in the same namespace as the HorizontalPodAutoscaler.
Payload returned to the user:
The Kubernetes system is trying to scale a StatefulSet named fake-deployment using the HorizontalPodAutoscaler, but it cannot find the StatefulSet. The solution is to verify that the StatefulSet name is spelled correctly and exists in the same namespace as the HorizontalPodAutoscaler.
Anonymization does not currently apply to events.

Additional Resources

official web site

k8sgpt github

k8sgpt slack

user blog post

Contribution

Yoon Seo-yul