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.

up vote 0 down vote accepted

From here this can be done like so:

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

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

    EnvironmentFile=/etc/.progconf
    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 myseervice@.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 myseervic@"arg1 arg2 arg3".service
  • Thank you for pointing me in the right direction and answering my quest, I guess I should have looked on other stack overflows 1st. – neokyle Sep 23 at 22:10

Just like how every implementation/flavor/distribution of Linux is a little different.
I learned that every implementation of Kuberntes is a little different.
And that there's different ways to implement systemd.

With all that variability I believe the best way to do this seems to be:
To use the find command to find where *.service is located

WorkerNodeBash# find / -name "*.service" | grep -i "kube"
WorkerNodeBash# nano /etc/systemd/system/kubelet.service

[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/kubernetes/kubernetes
After=containerd.service
Requires=containerd.service

[Service]
ExecStart=/usr/local/bin/kubelet \
  --config=/var/lib/kubelet/kubelet-config.yaml \
  --container-runtime=remote \
  --container-runtime-endpoint=unix:///var/run/containerd/containerd.sock \
  --image-pull-progress-deadline=2m \
  --kubeconfig=/var/lib/kubelet/kubeconfig \
  --network-plugin=cni \
  --register-node=true \
  --pod-manifest-path=/etc/kubernetes/manifests \
  --v=2
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

(The above comes from Kubernetes the hard way implementation, I've also done kubeadm and looked in this same file and saw no args, but thanks to learning how to use the find command I was able to search:
WorkerNodeBash# find / -type f -name "*.yaml" | grep "kube"
And I found a config file that mentioned KUBELET_EXTRA_ARGS=, and pass them in there.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.