aquasecurity trivy 에 대한 공식대시보드 추가 실습 진행
aquasecurity trivy 설치
helm repo add aqua <https://aquasecurity.github.io/helm-charts/> helm repo update helm pull aqua/trivy-operator --untar vi values.yaml
- 아래의 항목을 수정하여 배포한다.
serviceMonitor: # enabled determines whether a serviceMonitor should be deployed enabled: true trivy: ignoreUnfixed: truehelm install trivy-operator aqua/trivy-operator \\ --namespace trivy-system \\ --create-namespace \\ --values ./values.yamlprometheus상에서 trivy-operator가 올라왔는지 확인
prometheus dashboard 임포트
Dashboard 확인
Nginx 파드 배포 / 프로메테우스 확인 / 그라파타 대시보드 확인
nginx 설치
# helm repo add bitnami <https://charts.bitnami.com/bitnami> # 파라미터 파일 생성 : 서비스 모니터 방식으로 nginx 모니터링 대상을 등록하고, export 는 9113 포트 사용, nginx 웹서버 노출은 AWS CLB 기본 사용 cat <<EOT > ~/nginx-values.yaml metrics: enabled: true service: port: 9113 serviceMonitor: enabled: true namespace: monitoring interval: 10s EOT # 배포 helm install nginx bitnami/nginx --version 13.2.23 -f nginx-values.yaml # CLB에 ExternanDNS 로 도메인 연결 kubectl annotate service nginx "external-dns.alpha.kubernetes.io/hostname=nginx.$KOPS_CLUSTER_NAME" # 확인 kubectl get pod,svc,ep kubectl get servicemonitor -n monitoring nginx kubectl get servicemonitor -n monitoring nginx -o json | jq # nginx 파드내에 컨테이너 갯수 확인 kubectl get pod -l app.kubernetes.io/instance=nginx kubectl describe pod -l app.kubernetes.io/instance=nginx # 접속 주소 확인 및 접속 echo -e "Nginx WebServer URL = http://nginx.$KOPS_CLUSTER_NAME" curl -s http://nginx.$KOPS_CLUSTER_NAME kubectl logs deploy/nginx -f # 반복 접속 while true; do curl -s http://nginx.$KOPS_CLUSTER_NAME -I | head -n 1; date; sleep 1; done프로메테우스 상 메트릭 확인
그라파나 상 추가된 대시보드 확인
configmap도 없는 상황
kops config 를 수정하여 해결해보려 했으나 실패
kops edit cluster spec: kubeProxy: metricsBindAddress: 0.0.0.0:10249이를 해결하기 위해 찾아 보았으나 그나마 적절한 정답은 kube-proxy mainfest파일을 직접 건드리는 것 (https://kubernetes.io/docs/reference/command-line-tools-reference/kube-proxy/)
sudo vi /etc/kubernetes/manifests/kube-proxy.manifest
spec: containers: - args: - --log-file=/var/log/kube-proxy.log - --also-stdout - /usr/local/bin/kube-proxy - --conntrack-max-per-core=131072 - --hostname-override=i-0ea9c3c46f95cf7f9 - --kubeconfig=/var/lib/kube-proxy/kubeconfig - --master=https://127.0.0.1 - --oom-score-adj=-998 - --v=2 - --metrics-bind-address=0.0.0.0:10249
- 위와 같이 —metrics-bind-address=0.0.0.0:10249를 포함시켜준다
아래와 같이 listen ip가 127.0.0.1에서 *으로 변경됨을 볼 수 있다.
한개가 변경됨을 확인할 수 있음 (down → up)