<p>I'm currently following this guide: <a href="https://dzone.com/articles/export-kubernetes-logs-to-azure-log-analytics-with" rel="nofollow noreferrer">https://dzone.com/articles/export-kubernetes-logs-to-azure-log-analytics-with</a> to install fluentbit on my system and send logs to a LogAnalytics workspace.</p>
<p>The guide is based on a previous version of Kubernetes, I'm currently running Kubernetes 1.18 and most of the code needed some small tweaks to adhere to this version (name secretKeyRef must consist of lower case letters only, apiVersion needed to be apps/v1 instead of extensions/v1beta1 etc.).</p>
<p>Now I want to deploy a DaemonSet that is based on the guide, running the code from the guide gives me the following output:</p>
<blockquote>
<p>error: error validating &quot;fluent-bit-ds.yaml&quot;: error validating data: [ValidationError(DaemonSet.spec.selector): unknown field &quot;k8s-app&quot; in io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector, ValidationError(DaemonSet.spec.template.spec): unknown field &quot;selector&quot; in io.k8s.api.core.v1.PodSpec]; if you choose to ignore these errors, turn validation off with --validate=false</p>
</blockquote>
<p>I've tried to add the k8s-app myself and also tried to add a spec.selector but that didn't work.</p>
<pre><code>apiVersion: apps/v1
kind: DaemonSet
metadata: 
  name: fluent-bit
  namespace: logging
  labels: 
    k8s-app: fluent-bit-logging
    version: v1
    kubernetes.io/cluster-service: &quot;true&quot;
spec:
  selector:
    k8s-app: fluent-bit-logging
  template:
    metadata:
      labels:
        k8s-app: fluent-bit-logging
        version: v1
        kubernetes.io/cluster-service: &quot;true&quot;
      annotations:
        prometheus.io/scrape: &quot;true&quot;
        prometheus.io/port: &quot;2020&quot;
        prometheus.io/path: /api/v1/metrics/prometheus
    spec:
      selector:
        matchLabels:
          name: fluent-bit-logging
      containers:
      - name: fluent-bit
        image: fluent/fluent-bit:1.5.0
        imagePullPolicy: Always
        ports:
          - containerPort: 2020
        env:
        - name: FLUENT_AZURE_WORKSPACE_ID
          valueFrom:
            secretKeyRef:
              name: log-analytics
              key: WorkSpaceID 
        - name: FLUENT_AZURE_WORKSPACE_KEY
          valueFrom:
            secretKeyRef:
              name: log-analytics 
              key: WorkSpaceKey
        volumeMounts:
        - name: varlog
          mountPath: /var/log
        - name: varlibdockercontainers
          mountPath: /var/lib/docker/containers
          readOnly: true 
        - name: fluent-bit-config
          mountPath: /fluent-bit/etc/
      terminationGracePeriodSeconds: 10
      volumes:
      - name: varlog
        hostPath: 
          path: /var/log
      - name: varlibdockercontainers
        hostPath:
          path: /var/lib/docker/containers
      - name: fluent-bit-config
        configMap:
          name: fluent-bit-config
      serviceAccountName: fluent-bit
      tolerations:
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
      - operator: &quot;Exists&quot;
        effect: &quot;NoExecute&quot;
      - operator: &quot;Exists&quot;
        effect: &quot;NoSchedule&quot;
</code></pre>
<p>Can anyone spot what I'm missing? I'm not very sufficient in Kubernetes yet, so this might be a simple solution to what I'm overlooking.</p>
<p>Thanks in Advance!</p>

chr0nk
<p>In DaemonSet, you must specify a pod selector (<code>spec.selector</code>) that matches the labels of the (<code>.spec.template.metadata.labels</code>). <a href="https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/#pod-selector" rel="nofollow noreferrer">Ref</a></p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd-elasticsearch
spec:
  selector:  # &lt;-------- this one
    matchLabels:
      name: fluentd-elasticsearch
  template:
    metadata:
      labels: # &lt;------ matches this one
        name: fluentd-elasticsearch
</code></pre>
<p>Fixes:</p>
<ul>
<li><code>spec.template.spec.selector</code> isn't a valid filed, remove this.</li>
<li><code>spec.selector</code> is consist of two fields, <code>matchLabels</code> and <code>matchExpressions</code>.</li>
</ul>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: DaemonSet
metadata: 
  name: fluent-bit
  namespace: logging
  labels: 
    k8s-app: fluent-bit-logging
    version: v1
    kubernetes.io/cluster-service: &quot;true&quot;
spec:
  selector:
    matchLabels: # &lt;------- added 
      k8s-app: fluent-bit-logging
  template:
    metadata:
      labels:
        k8s-app: fluent-bit-logging
        version: v1
        kubernetes.io/cluster-service: &quot;true&quot;
      annotations:
        prometheus.io/scrape: &quot;true&quot;
        prometheus.io/port: &quot;2020&quot;
        prometheus.io/path: /api/v1/metrics/prometheus
    spec:
      # selector: &lt;--- removed
       # matchLabels:
        #  name: fluent-bit-logging
      containers:
      - name: fluent-bit
        image: fluent/fluent-bit:1.5.0
        imagePullPolicy: Always
        ports:
          - containerPort: 2020
        env:
        - name: FLUENT_AZURE_WORKSPACE_ID
          valueFrom:
            secretKeyRef:
              name: log-analytics
              key: WorkSpaceID 
        - name: FLUENT_AZURE_WORKSPACE_KEY
          valueFrom:
            secretKeyRef:
              name: log-analytics 
              key: WorkSpaceKey
        volumeMounts:
        - name: varlog
          mountPath: /var/log
        - name: varlibdockercontainers
          mountPath: /var/lib/docker/containers
          readOnly: true 
        - name: fluent-bit-config
          mountPath: /fluent-bit/etc/
      terminationGracePeriodSeconds: 10
      volumes:
      - name: varlog
        hostPath: 
          path: /var/log
      - name: varlibdockercontainers
        hostPath:
          path: /var/lib/docker/containers
      - name: fluent-bit-config
        configMap:
          name: fluent-bit-config
      serviceAccountName: fluent-bit
      tolerations:
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
      - operator: &quot;Exists&quot;
        effect: &quot;NoExecute&quot;
      - operator: &quot;Exists&quot;
        effect: &quot;NoSchedule&quot;
</code></pre>
