본문 바로가기

개발하자

Kubernetes에서 배포 로그를 가져오는 방법은?

반응형

Kubernetes에서 배포 로그를 가져오는 방법은?

나는 Kubernetes 클러스터(v1.15.2)에서 InputDB 배포를 생성하고 있으며, 이것은 나의 yaml 파일이다:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: monitoring-influxdb
  namespace: kube-system
spec:
  replicas: 1
  template:
    metadata:
      labels:
        task: monitoring
        k8s-app: influxdb
    spec:
      containers:
      - name: influxdb
        image: registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-influxdb-amd64:v1.5.2
        volumeMounts:
        - mountPath: /data
          name: influxdb-storage
      volumes:
      - name: influxdb-storage
        emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  labels:
    task: monitoring
    # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)
    # If you are NOT using this as an addon, you should comment out this line.
    kubernetes.io/cluster-service: 'true'
    kubernetes.io/name: monitoring-influxdb
  name: monitoring-influxdb
  namespace: kube-system
spec:
  ports:
  - port: 8086
    targetPort: 8086
  selector:
    k8s-app: influxdb

그리고 이것이 포드의 상태입니다:

$ kubectl get deployment -n kube-system
NAME                   READY   UP-TO-DATE   AVAILABLE   AGE
coredns                1/1     1            1           163d
kubernetes-dashboard   1/1     1            1           164d
monitoring-grafana     0/1     0            0           12m
monitoring-influxdb    0/1     0            0           11m

30분을 기다렸는데도 포드가 아직 없는데, 명령줄에서 배포 로그는 어떻게 확인하나요? 나는 지금 Kubernetes 대시보드에 접속할 수 없었다. 포드 로그를 가져오기 위해 명령어를 검색하고 있는데 지금은 사용 가능한 포드가 없습니다. 이미 노드에 레이블을 추가하려고 했습니다:

kubectl label nodes azshara-k8s03 k8s-app=influxdb

다음은 제가 배포한 내용입니다:

$ kubectl describe deployments monitoring-influxdb -n kube-system
Name:                   monitoring-influxdb
Namespace:              kube-system
CreationTimestamp:      Wed, 04 Mar 2020 11:15:52 +0800
Labels:                 k8s-app=influxdb
                        task=monitoring
Annotations:            kubectl.kubernetes.io/last-applied-configuration:
                          {"apiVersion":"extensions/v1beta1","kind":"Deployment","metadata":{"annotations":{},"name":"monitoring-influxdb","namespace":"kube-system"...
Selector:               k8s-app=influxdb,task=monitoring
Replicas:               1 desired | 0 updated | 0 total | 0 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  1 max unavailable, 1 max surge
Pod Template:
  Labels:  k8s-app=influxdb
           task=monitoring
  Containers:
   influxdb:
    Image:        registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-influxdb-amd64:v1.5.2
    Port:         <none>
    Host Port:    <none>
    Environment:  <none>
    Mounts:
      /data from influxdb-storage (rw)
  Volumes:
   influxdb-storage:
    Type:        EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:
    SizeLimit:   <unset>
OldReplicaSets:  <none>
NewReplicaSet:   <none>
Events:          <none>

로그를 가져오는 또 다른 방법은 다음과 같습니다:

$ kubectl -n kube-system logs -f deployment/monitoring-influxdb
error: timed out waiting for the condition

이 명령에 대한 출력이 없습니다:

kubectl logs --selector k8s-app=influxdb

kube-system 네임스페이스에 내 포드가 모두 있습니다:

~/Library/Mobile Documents/com~apple~CloudDocs/Document/k8s/work/heapster/heapster-deployment ⌚ 11:57:40
$ kubectl get pods -n kube-system
NAME                                  READY   STATUS    RESTARTS   AGE
coredns-569fd64d84-5q5pj              1/1     Running   0          46h
kubernetes-dashboard-6466b68b-z6z78   1/1     Running   0          11h
traefik-ingress-controller-hx4xd      1/1     Running   0          11h



배포에 대한 개요를 파악할 수 있습니다. 여기에 정보가 있을 수도 있습니다.

자세한 로그를 보려면 먼저 포드를 가져옵니다: 그런 다음 포드 로그를 요청합니다:




kubectl logs deployment/<name-of-deployment> # logs of deployment
kubectl logs -f deployment/<name-of-deployment> # follow logs



클러스터 로그를 보는 데 도움이 될 수 있는 두 가지 훌륭한 도구에 대한 참조를 추가합니다:

  1. "무거운" 타사 로깅 솔루션을 사용하지 않고 터미널의 로그를 보려면 클러스터를 제어하는 데 도움이 되는 훌륭한 CLI 도구를 사용하는 것을 고려해 보겠습니다.

  2. CLI에만 바인딩되어 있지 않고 여전히 로컬에서 실행을 원하는 경우 에 대해 권장합니다.




시도해 볼 수 있습니다:

kubectl get events -n <your_namespace>

반응형