EKS에서 Opentelemetry로
내 코드가 잘 동작하는지 모니터링하기
신재현
백엔드 개발자
인덴트코퍼레이션
오늘은 무엇을 하나요?
헨즈온 환경 구축 하기 OpenTelemetry는 무엇인가요? 서비스 배포&모니터링 하기 리소스 정리
헨즈온 환경 구축하기
헨즈온 환경 구축하기
1. EKS 접속을 위한 IAM 생성
2. Cloud9 생성 및 인증 정보 설정
3. EKS 생성
4. Helm으로 grafana, jaeger 설치
IAM role 생성하기
1. 아래 링크를 눌러 IAM role을 생성합니다.
https://console.aws.amazon.com/iam/home#/roles$new?
step=review&commonUseCase=EC2%2BEC2&selectedUseCase=EC2&po
licies=arn:aws:iam::aws:policy%2FAdministratorAccess
2. role 이름을 적는 폼이 나올때 까지 Next 버튼을 눌러주세요
3. role 이름을 cday-apm-handson으로 입력하고 Create role 버튼을 눌러주세요
Cloud9 생성
1. Cloud9 콘솔에 접속하셔서 Create Environment 버튼을 클릭합니다.
2. 이름은 aws-cloud9-apm 으로 나머지는 수정없이 Cloud9 생성을 완료합니다.
3. Cloud9이 생성될 때 까지 기다립니다.
Cloud9 환경 설정
4. Cloud9이 뜨면 R로 시작하는 프로필 버튼을 클릭 > manage EC2 Instance 클릭
Cloud9 환경 설정
5. Cloud9 인스턴스 선택 > Actions 클릭 > Security 클릭 > Modify Iam role 클릭
Cloud9 환경 설정
6. 방금 만든 cday-apm-handson role 선택후 저장
Cloud9 환경 설정
7. Cloud9 설정 > AWS 설정 > Credentials > AWS 임시 토큰 사용 비활성화
Cloud9 환경 설정
8. 좌측 사이드바의 AWS로고 클릭시 우측 하단에 ec2:instance 라고 뜨는지 확인
EKS 개발 환경 구축
1. 헨즈온 레포 다운로드
git clone https://github.com/wesky93/cday-2021-apm-handson.git
cd cday-2021-apm-handson/
EKS 개발 환경 구축
2. SSH 키 생성 및 EC2에 SSH키 등록
ssh-keygen
# enter 3번 하기
aws ec2 import-key-pair 
--region ap-northeast-2 
--key-name "cday-handson" 
--public-key-material file://~/.ssh/id_rsa.pub
EKS 개발 환경 구축
3. eksctl 설치
curl --silent 
--location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" 
| tar xz -C /tmp
sudo mv -v /tmp/eksctl /usr/local/bin
# 설치 확인
eksctl version
EKS 개발 환경 구축
4. kubectl 설치
# kubectl 다운로드
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
# kubectl 설치
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
# 설치 확인
kubectl version --client
EKS 개발 환경 구축
5. AWS IAM Authenticator
curl -o aws-iam-authenticator 
https://amazon-eks.s3.us-west-2.amazonaws.com/1.19.6/2021-01-05/bin/linux/amd64/aws-iam-authenticator
chmod +x ./aws-iam-authenticator
mkdir -p $HOME/bin 
&& cp ./aws-iam-authenticator $HOME/bin/aws-iam-authenticator 
&& export PATH=$PATH:$HOME/bin
echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc
aws-iam-authenticator help
EKS 개발 환경 구축
6. Helm 설치
curl -fsSL -o get_helm.sh 
https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
EKS 클러스터 생성
eksctl create cluster 
--name apm-cluster 
--region ap-northeast-2 
--with-oidc 
--ssh-access=true 
--ssh-public-key ~/.ssh/id_rsa.pub 
--managed
# eks 접속
kubectl get nodes
Helm repo 추가
helm repo add grafana https://grafana.github.io/helm-charts
helm repo add incubator https://charts.helm.sh/incubator
helm repo add jaegertracing https://jaegertracing.github.io/helm-charts
helm repo update
Helm chart 설치
# grafana 설치
helm install grafana grafana/grafana 
--set adminPassword="cday-handson" 
--set service.type=LoadBalancer
# jaeger 설치
helm install jaeger jaegertracing/jaeger-operator 
--set rbac.clusterRole=true
Grafana 접속
# grafana 주소 확인 및 접속
kubectl get all -n default | grep service/grafana
# ID : admin PW : cday-handson
An observability framework for cloud-native software
APM
APM 솔루션
Image caption 1 Image caption 2 Image caption 3
Image caption 4 Image caption 5 Image caption 6
서비스 배포 & 모니터링
썸네일 서비스 배포
kubectl apply -f k8s/
# 썸네일 서비스 주소 확인
kubectl get all -n default | grep service/thumbnail-app-srv
<썸네일 서비스 주소>/docs 로 접속
1. crop, resize, smartcrop 에 각각 아래 값을 넣어서 결과를 확인 합니다.
URL_1 : https://images.chosun.com/resizer/a5YP6FNZMLmdoSmJCXiQJcN25Fw=/
540x799/smart/cloudfront-ap-northeast-1.images.arcpublishing.com/chosun/
CFCFB3LGQ75OBNIYD36LN74FHQ.jpg
URL_2 : https://naver.com
Width : 200
Height: 200
썸네일 서비스 테스트
1. Grafana 에서 설정 > 데이터 소스 > 데이터 소스 추가 > jaeger 선택
2. 아래 주소를 url에 입력후 save&test 클릭
URL : jaeger-query.default.svc.cluster.local:16686
Grafana에 jaeger 데이터소스 추가
1. crop 과 smart crop요청을 비교해봅니다.
2. 각 span의 메타데이터를 확인 합니다.
3. namespace가 default인 요청만 찾아봅니다.
4. 에러가 발생한 요청만 찾아봅니다.
Grafana explore 에서 요청 쿼리해보기
리소스 정리하기
K8S 리소스 정리
kubectl delete -f k8s/
helm uninstall grafana
helm uninstall jaeger
# 삭제 됬는지 확인
kubectl get all -n default
# EKS 삭제
eksctl delete cluster --name apm-cluster --region ap-northeast-2
AWS 리소스 정리
1. Cloud9 삭제
https://ap-northeast-2.console.aws.amazon.com/cloudformation/home?
region=ap-northeast-2#/stacks?filteringStatus=active&filteringText=aws-
cloud9-aws-cloud9-apm&viewNested=true&hideStacks=false&stackId=
2. EC2 key-pair 삭제
3. IAM 삭제
감사합니다!
May the trace with you!

Aws 커뮤니티데이 APM 헨즈온

  • 1.
    EKS에서 Opentelemetry로 내 코드가잘 동작하는지 모니터링하기 신재현 백엔드 개발자 인덴트코퍼레이션
  • 2.
    오늘은 무엇을 하나요? 헨즈온환경 구축 하기 OpenTelemetry는 무엇인가요? 서비스 배포&모니터링 하기 리소스 정리
  • 3.
  • 4.
    헨즈온 환경 구축하기 1.EKS 접속을 위한 IAM 생성 2. Cloud9 생성 및 인증 정보 설정 3. EKS 생성 4. Helm으로 grafana, jaeger 설치
  • 5.
    IAM role 생성하기 1.아래 링크를 눌러 IAM role을 생성합니다. https://console.aws.amazon.com/iam/home#/roles$new? step=review&commonUseCase=EC2%2BEC2&selectedUseCase=EC2&po licies=arn:aws:iam::aws:policy%2FAdministratorAccess 2. role 이름을 적는 폼이 나올때 까지 Next 버튼을 눌러주세요 3. role 이름을 cday-apm-handson으로 입력하고 Create role 버튼을 눌러주세요
  • 6.
    Cloud9 생성 1. Cloud9콘솔에 접속하셔서 Create Environment 버튼을 클릭합니다. 2. 이름은 aws-cloud9-apm 으로 나머지는 수정없이 Cloud9 생성을 완료합니다. 3. Cloud9이 생성될 때 까지 기다립니다.
  • 7.
    Cloud9 환경 설정 4.Cloud9이 뜨면 R로 시작하는 프로필 버튼을 클릭 > manage EC2 Instance 클릭
  • 8.
    Cloud9 환경 설정 5.Cloud9 인스턴스 선택 > Actions 클릭 > Security 클릭 > Modify Iam role 클릭
  • 9.
    Cloud9 환경 설정 6.방금 만든 cday-apm-handson role 선택후 저장
  • 10.
    Cloud9 환경 설정 7.Cloud9 설정 > AWS 설정 > Credentials > AWS 임시 토큰 사용 비활성화
  • 11.
    Cloud9 환경 설정 8.좌측 사이드바의 AWS로고 클릭시 우측 하단에 ec2:instance 라고 뜨는지 확인
  • 12.
    EKS 개발 환경구축 1. 헨즈온 레포 다운로드 git clone https://github.com/wesky93/cday-2021-apm-handson.git cd cday-2021-apm-handson/
  • 13.
    EKS 개발 환경구축 2. SSH 키 생성 및 EC2에 SSH키 등록 ssh-keygen # enter 3번 하기 aws ec2 import-key-pair --region ap-northeast-2 --key-name "cday-handson" --public-key-material file://~/.ssh/id_rsa.pub
  • 14.
    EKS 개발 환경구축 3. eksctl 설치 curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp sudo mv -v /tmp/eksctl /usr/local/bin # 설치 확인 eksctl version
  • 15.
    EKS 개발 환경구축 4. kubectl 설치 # kubectl 다운로드 curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" # kubectl 설치 sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl # 설치 확인 kubectl version --client
  • 16.
    EKS 개발 환경구축 5. AWS IAM Authenticator curl -o aws-iam-authenticator https://amazon-eks.s3.us-west-2.amazonaws.com/1.19.6/2021-01-05/bin/linux/amd64/aws-iam-authenticator chmod +x ./aws-iam-authenticator mkdir -p $HOME/bin && cp ./aws-iam-authenticator $HOME/bin/aws-iam-authenticator && export PATH=$PATH:$HOME/bin echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc aws-iam-authenticator help
  • 17.
    EKS 개발 환경구축 6. Helm 설치 curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 chmod 700 get_helm.sh ./get_helm.sh
  • 18.
    EKS 클러스터 생성 eksctlcreate cluster --name apm-cluster --region ap-northeast-2 --with-oidc --ssh-access=true --ssh-public-key ~/.ssh/id_rsa.pub --managed # eks 접속 kubectl get nodes
  • 19.
    Helm repo 추가 helmrepo add grafana https://grafana.github.io/helm-charts helm repo add incubator https://charts.helm.sh/incubator helm repo add jaegertracing https://jaegertracing.github.io/helm-charts helm repo update
  • 20.
    Helm chart 설치 #grafana 설치 helm install grafana grafana/grafana --set adminPassword="cday-handson" --set service.type=LoadBalancer # jaeger 설치 helm install jaeger jaegertracing/jaeger-operator --set rbac.clusterRole=true
  • 21.
    Grafana 접속 # grafana주소 확인 및 접속 kubectl get all -n default | grep service/grafana # ID : admin PW : cday-handson
  • 22.
    An observability frameworkfor cloud-native software
  • 23.
  • 24.
    APM 솔루션 Image caption1 Image caption 2 Image caption 3 Image caption 4 Image caption 5 Image caption 6
  • 26.
    서비스 배포 &모니터링
  • 27.
    썸네일 서비스 배포 kubectlapply -f k8s/ # 썸네일 서비스 주소 확인 kubectl get all -n default | grep service/thumbnail-app-srv <썸네일 서비스 주소>/docs 로 접속
  • 28.
    1. crop, resize,smartcrop 에 각각 아래 값을 넣어서 결과를 확인 합니다. URL_1 : https://images.chosun.com/resizer/a5YP6FNZMLmdoSmJCXiQJcN25Fw=/ 540x799/smart/cloudfront-ap-northeast-1.images.arcpublishing.com/chosun/ CFCFB3LGQ75OBNIYD36LN74FHQ.jpg URL_2 : https://naver.com Width : 200 Height: 200 썸네일 서비스 테스트
  • 29.
    1. Grafana 에서설정 > 데이터 소스 > 데이터 소스 추가 > jaeger 선택 2. 아래 주소를 url에 입력후 save&test 클릭 URL : jaeger-query.default.svc.cluster.local:16686 Grafana에 jaeger 데이터소스 추가
  • 30.
    1. crop 과smart crop요청을 비교해봅니다. 2. 각 span의 메타데이터를 확인 합니다. 3. namespace가 default인 요청만 찾아봅니다. 4. 에러가 발생한 요청만 찾아봅니다. Grafana explore 에서 요청 쿼리해보기
  • 31.
  • 32.
    K8S 리소스 정리 kubectldelete -f k8s/ helm uninstall grafana helm uninstall jaeger # 삭제 됬는지 확인 kubectl get all -n default # EKS 삭제 eksctl delete cluster --name apm-cluster --region ap-northeast-2
  • 33.
    AWS 리소스 정리 1.Cloud9 삭제 https://ap-northeast-2.console.aws.amazon.com/cloudformation/home? region=ap-northeast-2#/stacks?filteringStatus=active&filteringText=aws- cloud9-aws-cloud9-apm&viewNested=true&hideStacks=false&stackId= 2. EC2 key-pair 삭제 3. IAM 삭제
  • 34.