레이블이 grafana인 게시물을 표시합니다. 모든 게시물 표시
레이블이 grafana인 게시물을 표시합니다. 모든 게시물 표시

change grafana pod localtime

# grafana timezone 이 UTC 로 되어 있다.
kubectl exec monitoring-grafana-aaa -it -- date
Wed Mar  6 07:35:45 UTC 2024

# 그래서 로그가 UTC 로 기록된다.
kubectl logs --tail=3 monitoring-grafana-aaa | rg -i "t="
... t=2024-03-06T07:45:00.515393518Z ...

# 이를 KST 로 변경하기 위해 deployment 에서
env > TZ 의 값을 Asia/Seoul 로 변경하면된다.

# 또는 아래와 같이 노드의 timezone 을 container 의 /etc/localtime 을 마운트되도록 설정한다.
kubectl edit deploy monitoring-grafana

spec > template > spec > containers > env > volumeMounts
volumeMounts:
- mountPath: /etc/localtime
  name: localtime-volume

spec > template > spec > containers > env > volumes
volumes:
- hostPath:
    path: /usr/share/zoneinfo/Asia/Seoul
  name: localtime-volume

# pod 가 다시 시작하고 나면 KST 로 변경되어 있다.
kubectl exec monitoring-grafana-aaa -it -- date
Wed Mar  6 16:45:55 KST 2024

# 이제 로그도 KST 로 기록된다.
kubectl logs --tail=3 monitoring-grafana-aaa | rg -i "t="
... t=2024-03-06T16:54:49.939479809+09:00 ...

# k8tz 을 사용하면 pod 에 편한게 적용할 수 있다.
# 배포되면 기본 k8tz 네임스페이스에 service,deployment,pod 등이 뜬다.
# install k8tz
helm repo add k8tz https://k8tz.github.io/k8tz/
helm install k8tz k8tz/k8tz --set timezone=Asia/Seoul

# deploy 등을 재시작해보자.
# 새로 뜨는 파드는 k8tz container 를 사이드카로 해서 locatime 이 반영된다. 

# k8tz 명령어를 사용하는 경우
# install k8tz cli command 
wget -c https://github.com/k8tz/k8tz/releases/download/v0.16.0/k8tz_0.16.0_darwin_amd64.tar.gz -O - | tar zx
./k8tz version

# 수동으로 현재 네임스페이스의 모든 deployment 에 반영하기
kubectl get deploy -oyaml | k8tz inject --timezone=Asia/Seoul -| kubectl apply -f -

# 참고로 prometheus, grafana 등은 k8tz 타임이 적용되지 않았고
# env > TZ 값이나 hostPath Volume 마운트를 해야 된다.
 

k8s grafana iframe

k8s grafana 그래프 하나를 share > embed(iframe) 으로 공유할때
브라우저에서 iframe 로딩이 안된다.
이경우 grafana.ini 설정에 다음 설정을 추가해야 한다.
[security]
allow_embedding = true

추가로 로그인 없이 익명사용자로 접근하기 위해서 다음 설정도 필요하다.
요 설정이 없으면 grafana 로그인 화면으로 보인다.
[auth.anonymous]
enabled = true

위 설정으로 grafana 적용(pod재시작)했다.

로컬에 index.html 에
grafana iframe 과
youtube 동영상 하나 공유 링크(iframe) 
로 2개의 iframe을 추가했다.

브라우저로 보면 youtube iframe 은 보이지만 grafana iframe은 보이지 않는다.
x-frame-options 으로 인해 iframe 과 현재 호스트(localhost)가 달라서 콘솔에 다음과 같은 에러가 발생했다.

Refused to display 'http://grafana.ysoftman.test/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.

아래와 같은 크롬 익스텐션으로 브라우저에서 x-frame-headers 을 무시하면 되긴 한다.

원인은 k8s grafana ingress 별다른 설정이 없어 ngnix 가 디폴트로 X-Frame-Options: sameorigin 로 처리되기 때문이다.

X-Frame-Options ALLOW-FROM=url 로 특정 url 요청을 허용하도록 하면 될것 같았는데,
ALLOW-FROM 는 obsolete 로 최신브라우저에선 동작하지 않는다.

ingress 설정으로 다음과 같이 X-Frame-Options 헤더를 의미없는 값으로 설정하면 보인다.
하지만 브라우져 콘솔에 invalid 에러가 발생한다.
annotations:
  nginx.ingress.kubernetes.io/configuration-snippet: |
    more_set_headers "X-Frame-Options: _for_ysoftman"

다음과 같이 하면 X-Frame-Options 헤더를 응답에서 제외할 수 있다.
annotations:
  nginx.ingress.kubernetes.io/configuration-snippet: |
    more_clear_headers "X-Frame-Options";


#####


만약 csp(Content-Security-Policy)문제인 경우
csp 의 frame-src 지시자로 iframe url 을 제어한다.
csp는 html 에서 다음과 같이 사용할 수 있지만 서버 응답헤더로 설정을 권장한다.
<meta http-equiv="Content-Security-Policy" content="frame-src http://*">

nginx 응답 헤더 추가를 위해 ingress 에 다음과 같이 설정한다.
annotations:
  nginx.ingress.kubernetes.io/configuration-snippet: |
    more_set_headers "Content-Security-Policy: frame-src http://*;";

참고로 frame-ancestors(iframe 를 호출 하는 상위) 경우는 meta 태그로 명시하지 못한다고 한다.
frame-ancestors specifies the sources that can embed the current page. This directive applies to <frame>, <iframe>, <embed>, and <applet> tags. This directive can't be used in <meta> tags and applies only to non-HTML resources.