stakater / Reloader

A Kubernetes controller to watch changes in ConfigMap and Secrets and do rolling upgrades on Pods with their associated Deployment, StatefulSet, DaemonSet and DeploymentConfig – [✩Star] if you're using it!
https://docs.stakater.com/reloader/
Apache License 2.0
7.55k stars 505 forks source link

Reloader and Pod with initContainer problem #139

Closed jrcjoro closed 4 years ago

jrcjoro commented 4 years ago

My fluend-configmap does not get reloaded with initContainer?

I have this fluentd daemonset deployment:

 apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd
  namespace: kube-system
  labels:
    k8s-app: fluentd-logging
    version: v1
  annotations:
    configmap.reloader.stakater.com/reload: "fluentd-configmap"
spec:
  selector:
    matchLabels:
      k8s-app: fluentd-logging
  template:
    metadata:
      labels:
        k8s-app: fluentd-logging
        version: v1
    spec:
      serviceAccount: fluentd
      serviceAccountName: fluentd
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
      initContainers:
      - name: config-fluentd
        image: busybox
        imagePullPolicy: IfNotPresent
        command: ["/bin/sh","-c"]
        args:
        - cp /fluentd/etc2/fluent.conf /fluentd/etc/fluent.conf;
#          cp /fluentd/etc2/kubernetes.conf /fluentd/etc/kubernetes.conf;
        volumeMounts:
        - name: config-path
          mountPath: /fluentd/etc
        - name: config-source
          mountPath: /fluentd/etc2
      containers:
      - name: fluentd
        image: fluent/fluentd-kubernetes-daemonset:v1-debian-syslog
        env:
          - name:  SYSLOG_HOST
            value: "10.32.121.202"
          - name:  SYSLOG_PORT
            value: "514"
          - name:  SYSLOG_PROTOCOL
            value: "udp"            
        resources:
          limits:
            memory: 200Mi
            ephemeral-storage: 500Mi
          requests:
            cpu: 100m
            memory: 200Mi
            ephemeral-storage: 100Mi
        volumeMounts:
        - name: varlog
          mountPath: /var/log
        - name: varlibdockercontainers
          mountPath: /var/lib/docker/containers
          readOnly: true
        - name: config-path
          mountPath: /fluentd/etc
        - name: config-source 
          mountPath: /test
          readOnly: true
      terminationGracePeriodSeconds: 30
      volumes:
      - name: varlog
        hostPath:
          path: /var/log
      - name: varlibdockercontainers
        hostPath:
          path: /var/lib/docker/containers
      - name: config-source
        configMap:
          name: fluentd-configmap
      - name: config-path
        emptyDir: {}

I used /test mount above to check that configmap was changed, but Pod was not reloaded because /fluentd/etc/fluent.conf was still old version. Any help what I'm doing wrong here?

rasheedamir commented 4 years ago

@jrcjoro can you plz share Reloader logs? does it detect the change in configmap

jrcjoro commented 4 years ago

Sorry, my mistake, I tried to set reloader deployment only into kube-system namespace together with fluentd. Now when I changed it back to default it works:

$ kubectl logs reloader-reloader-64cdcc9557-gqx2x time="2020-05-15T10:55:10Z" level=info msg="Environment: Kubernetes" time="2020-05-15T10:55:10Z" level=info msg="Starting Reloader" time="2020-05-15T10:55:10Z" level=warning msg="KUBERNETES_NAMESPACE is unset, will detect changes in all namespaces." time="2020-05-15T10:55:10Z" level=info msg="Starting Controller to watch resource type: secrets" time="2020-05-15T10:55:10Z" level=info msg="Starting Controller to watch resource type: configMaps" time="2020-05-15T10:57:33Z" level=info msg="Changes detected in 'fluentd-configmap' of type 'CONFIGMAP' in namespace 'kube-system'" time="2020-05-15T10:57:33Z" level=info msg="Updated 'fluentd' of type 'DaemonSet' in namespace 'kube-system'" time="2020-05-15T11:06:45Z" level=info msg="Changes detected in 'fluentd-configmap' of type 'CONFIGMAP' in namespace 'kube-system'" time="2020-05-15T11:06:45Z" level=info msg="Updated 'fluentd' of type 'DaemonSet' in namespace 'kube-system'"

Is it possible to run reloader in other namespace than default?