您可以通过使用Logtail采集Windows容器上的应用信息。本文介绍如何使用Logtail收集Windows容器日志。

前提条件

添加Windows节点的Logtail

  1. 通过kubectl连接Kubernetes集群
  2. 在kube-system下的configmap的alibaba-log-configuration中,添加以下条目。
    win-log-config-path: C:\Program Files (x86)\Alibaba\Logtail\conf\{your region}\ilogtail_config.json
    说明 请根据集群所在的地域,将{your region}修改成对应的值。
  3. 执行以下命令部署Windows节点的DaemonSet。
    apiVersion: extensions/v1beta1
    kind: DaemonSet
    metadata:
      labels:
        k8s-app: win-logtail-ds
      name: win-logtail-ds
      namespace: kube-system
    spec:
      selector:
        matchLabels:
          k8s-app: logtail-ds
          kubernetes.io/cluster-service: "true"
          version: v1.0
      template:
        metadata:
          annotations:
            scheduler.alpha.kubernetes.io/critical-pod: ""
          labels:
            k8s-app: logtail-ds
            kubernetes.io/cluster-service: "true"
            version: v1.0
        spec:
          containers:
          - env:
            - name: ALIYUN_LOGTAIL_CONFIG
              valueFrom:
                configMapKeyRef:
                  key: win-log-config-path
                  name: alibaba-log-configuration
            - name: ALIYUN_LOGTAIL_USER_ID
              valueFrom:
                configMapKeyRef:
                  key: log-ali-uid
                  name: alibaba-log-configuration
            - name: ALIYUN_LOGTAIL_USER_DEFINED_ID
              valueFrom:
                configMapKeyRef:
                  key: log-machine-group
                  name: alibaba-log-configuration
            - name: ALICLOUD_LOG_DOCKER_ENV_CONFIG
              value: "true"
            - name: ALICLOUD_LOG_ECS_FLAG
              value: "true"
            - name: ALICLOUD_LOG_DEFAULT_PROJECT
              valueFrom:
                configMapKeyRef:
                  key: log-project
                  name: alibaba-log-configuration
            - name: ALICLOUD_LOG_ENDPOINT
              valueFrom:
                configMapKeyRef:
                  key: log-endpoint
                  name: alibaba-log-configuration
            - name: ALICLOUD_LOG_DEFAULT_MACHINE_GROUP
              valueFrom:
                configMapKeyRef:
                  key: log-machine-group
                  name: alibaba-log-configuration
            - name: ALIYUN_LOG_ENV_TAGS
              value: _node_name_|_node_ip_
            - name: _node_name_
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: spec.nodeName
            - name: _node_ip_
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: status.hostIP
            - name: cpu_usage_limit
              value: "1.0"
            - name: mem_usage_limit
              value: "512"
            - name: max_bytes_per_sec
              value: "20971520"
            - name: send_request_concurrency
              value: "20"
            image: registry.cn-hangzhou.aliyuncs.com/log-service/winlogtail:ltsc2019-1.0.0.10
            imagePullPolicy: IfNotPresent
            name: logtail
            resources:
              limits:
                memory: 512Mi
              requests:
                cpu: 100m
                memory: 256Mi
            securityContext:
              privileged: false
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
            volumeMounts:
            - mountPath: '\\\\.\pipe\docker_engine'
              name: sock
            - mountPath: 'c:\ProgramData\docker'
              name: root
              readOnly: true
            - mountPath: 'c:\logtail_host'
              name: root-c
              readOnly: true
          nodeSelector:
            beta.kubernetes.io/os: windows
          terminationGracePeriodSeconds: 30
          tolerations:
          - effect: NoSchedule
            key: os
            operator: Equal
            value: windows
          volumes:
          - hostPath:
              path: '\\\\.\pipe\docker_engine'
            name: sock
          - hostPath:
              path: 'c:\ProgramData\docker'
            name: root
          - hostPath:
              path: 'c:\'
            name: root-c
    注意 目前Logtail仅限于支持采集Stdout的输出至日志服务,后续会支持对日志文件的采集。

示例说明

在Windows节点上添加Logtail后,使用以下应用模板部署添加的Logtail。
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: logtail-test
  name: logtail-test
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: logtail-test
      name: logtail-test
    spec:
      containers:
      - name: nanoserver
        image: mcr.microsoft.com/windows/servercore:1809
        command: ["powershell.exe"]
        args: ["ping -t 127.0.0.1 -w 10000"]
        env:
      ######### 配置环境变量 ###########
        - name: aliyun_logs_logtail-stdout
          value: stdout
        - name: aliyun_logs_logttail-tags
          value: tag1=v1
      #################################
      nodeSelector:
        beta.kubernetes.io/os: windows
      tolerations:
      - effect: NoSchedule
        key: os
        operator: Equal
        value: windows

成功部署示例应用后,您可查看日志信息。详细步骤,请参见查询分析日志