Prometheus가 수집한 metric data를 EBS Volume에 저장하기 위해 EBS Volume을 자동 생성 관리하는 EKS Add-on EBS-CSI-Driver를 설치해야 한다.
eksctl create iamserviceaccount \
--name ebs-csi-controller-sa \
--namespace kube-system \
--cluster my-cluster \
--attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy \
--approve \
--role-only \
--role-name AmazonEKS_EBS_CSI_DriverRole
cat <<EOF > kms-key-for-encryption-on-ebs.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"kms:CreateGrant",
"kms:ListGrants",
"kms:RevokeGrant"
],
"Resource": ["custom-key-arn"],
"Condition": {
"Bool": {
"kms:GrantIsForAWSResource": "true"
}
}
},
{
"Effect": "Allow",
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
],
"Resource": ["custom-key-arn"]
}
]
}
EOF
aws iam create-policy \
--policy-name KMS_Key_For_Encryption_On_EBS_Policy \
--policy-document file://kms-key-for-encryption-on-ebs.json
aws iam attach-role-policy \
--policy-arn arn:aws:iam::111122223333:policy/KMS_Key_For_Encryption_On_EBS_Policy \
--role-name AmazonEKS_EBS_CSI_DriverRole
Prometheus를 배포하던 pod가 중지되거나 삭제될 시 그동안 수집했던 데이터들이 전부 휘발된다.
그러므로 pod가 중지되거나 삭제되어도 volume이 남아있을 수 있도록 설정해야 한다.
# storageClass.yml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: monitor-sc
# annotations:
# storageclass.kubernetes.io/is-default-class: "true"
provisioner: kubernetes.io/aws-ebs
parameters:
type: gp2
fsType: ext4
reclaimPolicy: Retain
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer
# Add storageClass
kubectl apply -f storageClass.yml
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
alertmanager:
enabled: true
alertmanagerSpec:
storage:
volumeClaimTemplate:
spec:
storageClassName: monitor-sc
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 10Gi
grafana:
defaultDashboardsEnabled: true
adminPassword: admin
persistence:
enabled: true
storageClassName: monitor-sc
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 10Gi
prometheus:
prometheusSpec:
retention: 5y
# retentionSize: "1TiB"
storageSpec:
volumeClaimTemplate:
spec:
storageClassName: monitor-sc
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 100Gi
# deploy prometheus-grafana-stack using helm
helm install prometheus -n monitoring prometheus-community/kube-prometheus-stack -f values.yaml
# grafana-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: monitoring
name: grafana-ingress
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: prometheus-grafana
port:
number: 80
# ingress
kubectl apply -f grafana-ingress.yaml
pvc와 values를 수정 후 적용하면 된다.
kubectl get pvc -n monitoring
결과로 나온 pvc를 수정
kubectl edit pvc <prometheus-pvc> -n monitoring
Storage 증설 후 :wq
values 파일에서 storage 증설 후
# upgrade prometheus-grafana-stack using helm
helm upgrade -i prometheus -n monitoring prometheus-community/kube-prometheus-stack -f values.yaml