1

I've created a daemonset which adds a systemd unit and timer file to every host in the cluster.

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: logclean-updater
spec:
  selector:
    matchLabels: 
      name: logclean-updater
    spec:
      containers:
      - name: logclean-updater
        image: alpine
        command: ["/bin/sh", "-c"]
        args: [
              "
              while true; do
                echo '[Unit]\n
                Description=Clean journal files\n
                [Service]\n
                ExecStart=/usr/bin/journalctl --vacuum-size=1M\n
                SystemCallFilter=@default @file-system @basic-io @system-service\n
                \n
                [Install]\n
                WantedBy=multi-user.target\n
                ' > /systemd/cleanjournal.service;
                echo '[Unit]\n

                [Timer]\n
                OnCalendar=hourly\n
                \n
                [Install]\n
                WantedBy=multi-user.target\n
                ' > /systemd/cleanjournal.timer;
                sleep 60;\n
              done\n
              "
              ]
        volumeMounts:
        - name: systemdpath
          mountPath: /systemd
      volumes:
      - name: systemdpath
        hostPath:
          path: /usr/lib/systemd/system

cleanjournal.timer and cleanjournal.service appear on the node as they should.

But the first time the timer is not started, so now I need to manually call

systemctl start cleanjournal.timer

Is it possible do that from within the container? Or more general, can we call commands from a container on the host system?

2
  • So you're looking for a container escape vulnerability?
    – BMitch
    Oct 14 at 13:12
  • looking for a timer which cleans log files on host on daily basis and when a new node joins the cluster it gets added there automatically too Oct 14 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.