
현재 k8s 자동 프로비저닝 툴을 개발 중입니다.
kubelet log가 쌓이는 경로를 바꾸고 싶어요!
v1.31.1 기준
1, 2번은 systemd 파일을 직접 변경해하는 방식으로 진행한다.
3번은 kubelet을 직접 실행하는 방식으로 진행한다.
kube-log-runner를 사용하는 방법root@temp-cp-node-1:/usr/lib/systemd/system/kubelet.service.d# cat 10-kubeadm.conf
# Note: This dropin only works with kubeadm and kubelet v1.11+
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
EnvironmentFile=-/etc/default/kubelet
ExecStart=
ExecStart=/usr/bin/kube-log-runner -log-file=/data/log/kubelet.log -also-stdout=false \
/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS
root@temp-cp-node-1:~# cat /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf
# Note: This dropin only works with kubeadm and kubelet v1.11+
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
EnvironmentFile=-/etc/default/kubelet
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS
StandardOutput=append:/data/log/kubelet.log
StandardError=append:/data/log/kubelet.log
StandardOutput, StandardError를 추가하면 아래 정의한 경로로 지속하여 추가된다.
StandardOutput=append:/data/log/kubelet.log
StandardError=append:/data/log/kubelet.log
test@temp-cp-node-1:~$ sudo ./kube-log-runner -log-file=/data/log/kubelet.log -also-stdout=false /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --container-runtime-endpoint=unix:///run/containerd/containerd.sock --pod-infra-container-image=registry.k8s.io/pause:3.10 --root-dir=/data/kubelet --v=2 --runtime-request-timeout=15m --resolv-conf=/run/systemd/resolve/resolv.conf --node-ip=10.10.40.82 --node-labels=[세부 설정]/role=master,[세부 설정]/clusterid=kubernetes,[세부 설정]/ansible_host=192.168.88.24
2024/10/25 01:14:02 Running command:
Command env: (log-file=/data/log/kubelet.log, also-stdout=false, redirect-stderr=true)
Run from directory:
Executable path: /usr/bin/kubelet
Args (comma-delimited): /usr/bin/kubelet,--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf,--kubeconfig=/etc/kubernetes/kubelet.conf,--config=/var/lib/kubelet/config.yaml,--container-runtime-endpoint=unix:///run/containerd/containerd.sock,--pod-infra-container-image=registry.k8s.io/pause:3.10,--root-dir=/data/kubelet,--v=2,--runtime-request-timeout=15m,--resolv-conf=/run/systemd/resolve/resolv.conf,--node-ip=10.10.40.82,--node-labels=[세부 설정]/role=master,[세부 설정]/clusterid=kubernetes,[세부 설정]/ansible_host=192.168.88.24
2024/10/25 01:14:02 Now listening for interrupts
...