Score:1

Kubernetes StatefulSet with PodAffinity

ru flag

I have a k8s cluster with the following problem: We have a stateful set with filebeat, which collects logs of our microservices locally on the nodes via volumes and pushes them to our open search. The problem is that not all services write these logs, more precisely only services with the pod label type: microservice. Thus, the filebeat pods run completely pointlessly on many nodes. My idea was to restrict the Deamon Set so that the pods are only started on nodes where at least one pod with the label type: microservice is running. I came across podAffinity, but the whole thing is very poorly documented for Deamon Sets and I'm not even sure if it's possible.

So far I have built this yaml as a test:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: my-daemonset
  namespace: default
spec:
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      affinity:
        podAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: type
                    operator: In
                    values:
                      - microservice
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: my-container
          image: test-image

However, it continues to create as many pods as I have nodes, but none are assigned to a node anymore, even if the label would fit. Can anyone help me here or is this not possible at all.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.