Ubuntu – How to pass flags when starting a systemd service

dockerjujukubernetesservicessystemd

Note a similar question has been asked:
How to pass flags when starting 'service'?

But I read a while back that Linux switched from init.d to systemd, and since that Q&A are 6 years old I thought it might refer to init.d

My question is:
How do you pass flags/arguments when starting a systemd service? Let's say I do systemctl restart Kubelet, that means I have the Kubelet Service running, well how could I see and modify what Flags/Arguements are passed to that service? (Such as –anonymous-auth=false)

Also here's some Context:
I'm close to scheduling my CNCF Kubernetes Certification Exam, the exam is performance-based and covers some nitty gritty stuff that's usually abstracted away from a Cluster Admin.

Something I learned is that there are 7 core Binary's that makeup Kubernetes: [docker, etcd, kube-apiserver, kube-controller-manager, kube-scheduler, kube-proxy, and kubelet]

Some of these Kubernetes control plane binaries are "self hosted"/run as pods on Kubernetes, and you pass args/flags like –service-cluster-ip-range=10.0.0.0/16

The following URL has an example of some core
binaries being run as Docker containers on Kubernetes, and the flags being passed in as Arguments in the YAML specification.
https://kubernetes.io/docs/setup/scratch/#scheduler-pod-template

Other Core Kubernetes Binaries like Kubelet and Docker aren't well suited for self hosting and are instead run as Linux System Daemons, and they run using systemd and are managed with systemctl and journalctl. Anyways I've had to login to a node and do systemctl restart docker.service and systemctl restart kubelet.service before, but I don't actually know how to see or modify what flags/Arguments are passed to them.

Best Answer

From here this can be done like so:

  1. Create an arguments file say /etc/.argconf

    ARG1=-o
    ARG2=--verbose
    
  2. And your .service file:

    EnvironmentFile=/etc/.argconf
    ExecStart=/usr/bin/prog $ARG1 $ARG2
    

Another method from that same post is as seen below:

[Unit]
Description=Test passing multiple arguments

[Service]
Environment="SCRIPT_ARGS=%I"
ExecStart=/tmp/test.py $SCRIPT_ARGS

And the name of the file has to be myservice@.service take note of the @ as this is required when passing arguments in this fashion to a service. You then run that service like so:

sudo systemctl start myservice@"arg1 arg2 arg3".service
Related Question