Skip to content

Commit

Permalink
[kubernetes] add kubelogs option
Browse files Browse the repository at this point in the history
If your cluster is completely broken you can't gather
logs using kubectl / the API, so add an option to easily
copy logs from the most critical pods.

Signed-off-by: Etienne Champetier <e.champetier@ateme.com>
  • Loading branch information
champtar authored and TurboTurtle committed Dec 13, 2024
1 parent 37456a9 commit 279ea13
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion sos/report/plugins/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class Kubernetes(Plugin):
forbidden_paths = [
"/etc/kubernetes/pki",
]
kube_system_logs = [
"/var/log/pods/kube-system_etcd-*",
"/var/log/pods/kube-system_kube-apiserver-*",
"/var/log/pods/kube-system_kube-controller-manager-*",
"/var/log/pods/kube-system_kube-scheduler-*",
]
resources = [
'events',
'deployments',
Expand Down Expand Up @@ -88,8 +94,10 @@ class Kubernetes(Plugin):
desc='collect all namespace output separately'),
PluginOpt('describe', default=False,
desc='collect describe output of all resources'),
PluginOpt('kubelogs', default=False,
desc='copy some kube-system pod logs without using the API'),
PluginOpt('podlogs', default=False,
desc='capture stdout/stderr logs from pods'),
desc='capture stdout/stderr logs from pods using the API'),
PluginOpt('podlogs-filter', default='', val_type=str,
desc='only collect logs from pods matching this pattern')
]
Expand All @@ -113,6 +121,9 @@ def setup(self):

self.add_forbidden_path(self.forbidden_paths)

if self.get_option('kubelogs'):
self.add_copy_spec(self.kube_system_logs)

self.add_env_var([
'KUBECONFIG',
'KUBERNETES_HTTP_PROXY',
Expand Down

0 comments on commit 279ea13

Please sign in to comment.