【问题标题】:Configuring Azure log analytics配置 Azure 日志分析
【发布时间】:2026-02-01 05:10:01
【问题描述】:

我正在关注此文档 https://docs.microsoft.com/en-us/azure/aks/tutorial-kubernetes-monitor,使用以下 yaml 文件在 AKS 上配置监控解决方案

apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
 name: omsagent
spec:
 template:
  metadata:
   labels:
    app: omsagent
    agentVersion: 1.4.0-12
    dockerProviderVersion: 10.0.0-25
  spec:
   containers:
     - name: omsagent
       image: "microsoft/oms"
       imagePullPolicy: Always
       env:
       - name: WSID
         value: <WSID>
       - name: KEY
         value: <KEY>
       securityContext:
         privileged: true
       ports:
       - containerPort: 25225
         protocol: TCP
       - containerPort: 25224
         protocol: UDP
       volumeMounts:
        - mountPath: /var/run/docker.sock
          name: docker-sock
        - mountPath: /var/opt/microsoft/omsagent/state/containerhostname
          name: container-hostname
        - mountPath: /var/log
          name: host-log
        - mountPath: /var/lib/docker/containers/
          name: container-log
       livenessProbe:
        exec:
         command:
         - /bin/bash
         - -c
         - ps -ef | grep omsagent | grep -v "grep"
        initialDelaySeconds: 60
        periodSeconds: 60
   nodeSelector:
    beta.kubernetes.io/os: linux
   # Tolerate a NoSchedule taint on master that ACS Engine sets.
   tolerations:
    - key: "node-role.kubernetes.io/master"
      operator: "Equal"
      value: "true"
      effect: "NoSchedule"
   volumes:
    - name: docker-sock
      hostPath:
       path: /var/run/docker.sock
    - name: container-hostname
      hostPath:
       path: /etc/hostname
    - name: host-log
      hostPath:
       path: /var/log
    - name: container-log
      hostPath:
       path: /var/lib/docker/containers/

这会失败并出现错误

error: error converting YAML to JSON: yaml: line 65: mapping values are not allowed in this context

我已经使用 yaml 验证器验证了该文件在语法上是正确的,不知道有什么问题?

这是 Kubernetes 1.7 版 1.9 版也会发生这种情况

【问题讨论】:

    标签: azure kubernetes yaml azure-log-analytics


    【解决方案1】:

    那个 yaml 文件对我有用:

    [root@jasoncli@jasonye aksoms]# vi oms-daemonset.yaml
    [root@jasoncli@jasonye aksoms]# kubectl create -f oms-daemonset.yaml 
    daemonset "omsagent" created
    [root@jasoncli@jasonye aksoms]# kubectl get daemonset
    NAME       DESIRED   CURRENT   READY     UP-TO-DATE   AVAILABLE   NODE SELECTOR                 AGE
    omsagent   1         1         0         1            0           beta.kubernetes.io/os=linux   1m
    

    请使用此命令kubectl version 检查您的kubectl 客户端版本,这是我的输出:

    [root@jasoncli@jasonye aksoms]# kubectl version
    Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.5", GitCommit:"cce11c6a185279d037023e02ac5249e14daa22bf", GitTreeState:"clean", BuildDate:"2017-12-07T16:16:03Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
    Server Version: version.Info{Major:"1", Minor:"7", GitVersion:"v1.7.7", GitCommit:"8e1552342355496b62754e61ad5f802a0f3f1fa7", GitTreeState:"clean", BuildDate:"2017-09-28T23:56:03Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
    

    您可以运行以下命令az aks install-cli在本地安装kubectl客户端。

    更多关于安装kubernetes命令行客户端的信息,请参考这个article

    【讨论】:

    • 这对你有用吗?如果您需要更多帮助,请告诉我:)