Windows节点上使用logtail

环境要求

  • 创建Linux托管集群,添加OS为Windows的节点池来使用Windows节点
  • 集群已经部署了日志组件

添加Windows节点的logtail

  • 在kube-system下的configmap alibaba-log-configuration中添加item
## 根据集群所在的region,写入对应的值
win-log-config-path: C:\Program Files (x86)\Alibaba\Logtail\conf\{your region}\ilogtail_config.json
  • 部署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的输出至日志服务,后续会支持对日志文件的采集

部署完成后可以使用如下应用去验证是否可用:

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
上一篇:云原生架构下日志服务数据预处理


下一篇:阿里云云安全中心入选Gartner CWPP全球市场指南 为客户提供一体化安全解决方案