[리소스 로깅과 모니터링] 쿠버네티스 애플리케이션 로그 관리

IMKUNYOUNG·2023년 9월 2일
0

쿠버네티스

목록 보기
59/64

Kubernetes 애플리케이션 로그 확인

  • 로그는 컨테이너 단위로 로그 확인 가능
  • 싱글 컨테이너 포드의 경우 포드까지만 지정하여 로그 확인
  • 멀티 컨테이너의 경우 포드 뒤에 컨테이너 이름까지 전달하여 로그 확인
  • kubectl logs <pod name> <옵션: container name>


kubeapi가 정상 동작하지 않는 경우

  • 쿠버네티스에서 돌아가는 리소스들은 모두 docker를 사용
  • 따라서 docker의 로깅 기능 사용
  • docker ps -a 를 사용하여 조회 가능
  • docker logs <container id> 를 사용하여 로그 확인 가능
imkunyoung@cloudshell:~ (k8s-inflearn)$ kubectl get pods
NAME                                            READY   STATUS    RESTARTS   AGE
admin-page                                      1/1     Running   0          3d22h
front-end                                       1/1     Running   0          3d23h
jhipster-prometheus-operator-77c8f847cb-sr7sx   1/1     Running   0          2d15h
mariadb-5bfcbc8dd5-vm69q                        1/1     Running   0          25h
nginx-sidecar                                   3/3     Running   0          2m17s

imkunyoung@cloudshell:~ (k8s-inflearn)$ kubectl describe pod nginx-sidecar
Name:             nginx-sidecar
Namespace:        default
Priority:         0
Service Account:  default
Node:             gke-artbridge-default-pool-65403ed8-7zvx/10.128.0.3
Start Time:       Mon, 11 Sep 2023 00:37:52 +0000
Labels:           <none>
Annotations:      <none>
Status:           Running
IP:               10.40.0.22
IPs:
  IP:  10.40.0.22
Containers:
  nginx:
    Container ID:   containerd://ba128080089f3d0522bb38a9ab11aa976ffd423223418fcaa300d4134407702f
    Image:          nginx
    Image ID:       docker.io/library/nginx@sha256:6926dd802f40e5e7257fded83e0d8030039642e4e10c4a98a6478e9c6fe06153
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Mon, 11 Sep 2023 00:37:52 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/log/nginx from varlognginx (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-rmk6t (ro)
  sidecar-access:
    Container ID:  containerd://8cb491b6f7266ca6393b4924a26df4feb827b48bd79dc882bf559b7e0932a9c3
    Image:         busybox
    Image ID:      docker.io/library/busybox@sha256:3fbc632167424a6d997e74f52b878d7cc478225cffac6bc977eedfe51c7f4e79
    Port:          <none>
    Host Port:     <none>
    Args:
      /bin/sh
      -c
      tail -n+1 -f /var/log/nginx/access.log
    State:          Running
      Started:      Mon, 11 Sep 2023 00:37:53 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/log/nginx from varlognginx (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-rmk6t (ro)
  sidecar-error:
    Container ID:  containerd://94076408866fbb6f0a13bbef69444ebbc9eb042e1095f5b28a9a5ca67cb53730
    Image:         busybox
    Image ID:      docker.io/library/busybox@sha256:3fbc632167424a6d997e74f52b878d7cc478225cffac6bc977eedfe51c7f4e79
    Port:          <none>
    Host Port:     <none>
    Args:
      /bin/sh
      -c
      tail -n+1 -f /var/log/nginx/error.log
    State:          Running
      Started:      Mon, 11 Sep 2023 00:37:53 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/log/nginx from varlognginx (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-rmk6t (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  varlognginx:
    Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:
    SizeLimit:  <unset>
  kube-api-access-rmk6t:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  116s  default-scheduler  Successfully assigned default/nginx-sidecar to gke-artbridge-default-pool-65403ed8-7zvx
  Normal  Pulling    116s  kubelet            Pulling image "nginx"
  Normal  Pulled     116s  kubelet            Successfully pulled image "nginx" in 129.733044ms (129.772648ms including waiting)
  Normal  Created    116s  kubelet            Created container nginx
  Normal  Started    116s  kubelet            Started container nginx
  Normal  Pulling    116s  kubelet            Pulling image "busybox"
  Normal  Pulled     116s  kubelet            Successfully pulled image "busybox" in 102.074255ms (102.096371ms including waiting)
  Normal  Created    115s  kubelet            Created container sidecar-access
  Normal  Started    115s  kubelet            Started container sidecar-access
  Normal  Pulling    115s  kubelet            Pulling image "busybox"
  Normal  Pulled     115s  kubelet            Successfully pulled image "busybox" in 128.089019ms (128.102345ms including waiting)
  Normal  Created    115s  kubelet            Created container sidecar-error
  Normal  Started    115s  kubelet            Started container sidecar-error  

imkunyoung@cloudshell:~ (k8s-inflearn)$ kubectl logs nginx-sidecar
Defaulted container "nginx" out of: nginx, sidecar-access, sidecar-error
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up

imkunyoung@cloudshell:~ (k8s-inflearn)$ kubectl logs nginx-sidecar nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh

imkunyoung@cloudshell:~ (k8s-inflearn)$ kubectl logs nginx-sidecar sidecar-access

imkunyoung@cloudshell:~ (k8s-inflearn)$ kubectl logs nginx-sidecar sidecar-error
2023/09/11 00:37:52 [notice] 1#1: using the "epoll" event method
2023/09/11 00:37:52 [notice] 1#1: nginx/1.25.2
2023/09/11 00:37:52 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14)
2023/09/11 00:37:52 [notice] 1#1: OS: Linux 5.15.109+
2023/09/11 00:37:52 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2023/09/11 00:37:52 [notice] 1#1: start worker processes
2023/09/11 00:37:52 [notice] 1#1: start worker process 29
2023/09/11 00:37:52 [notice] 1#1: start worker process 30




kubectl logs

0개의 댓글