为什么我无法通过kubectl logs命令在Kubernetes的klog中看到日志?

huangapple go评论63阅读模式
英文:

why I cannot see the logs in k8s klog via kubectl logs?

问题

我在k8s中看到了一些源代码:

	// 立即删除,或者不支持优雅删除
	klog.V(6).Infof("going to delete %s from registry: ", name)
	if _, _, err := e.Delete(ctx, accessor.GetName(), deleteValidation, options); err != nil && !apierrors.IsNotFound(err) {
	klog.V(4).Infof("Delete %s in DeleteCollection failed: %v", accessor.GetName(), err)
		errs <- err
		return
	}

我认为我可以通过 kubectl logs 来检查这些日志,但是我无法看到它们,即使使用 kubectl logs --v 6 <kubeapi server pod> | grep "going to delete" 或者 kubectl logs --v 4 <kubeapi server pod> | grep "DeleteCollection",我仍然无法看到应该由 klog 输出的日志。我该如何检查这些日志?

英文:

I saw some source codes in k8s:

	// delete immediately, or no graceful deletion supported
	klog.V(6).Infof(&quot;going to delete %s from registry: &quot;, name)
	if _, _, err := e.Delete(ctx, accessor.GetName(), deleteValidation, options); err != nil &amp;&amp; !apierrors.IsNotFound(err) {
	klog.V(4).Infof(&quot;Delete %s in DeleteCollection failed: %v&quot;, accessor.GetName(), err)
		errs &lt;- err
		return
	}

I think I can check these logs via kubectl logs, but I cannot see them, even use kubectl logs --v 6 &lt;kubeapi server pod&gt; | grep &quot;going to delete&quot; or kubectl logs --v 4 &lt;kubeapi server pod&gt; | grep &quot;DeleteCollection&quot; I still cannot see the logs that should be output by klog.
How can I check these logs?

答案1

得分: 0

答案是:
--v=4参数添加到kube api server配置文件中以启用日志详细程度。

文件路径:/etc/kubernetes/manifests/kube-apiserver.yaml

apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubeadm.kubernetes.io/kube-apiserver.advertise-address.endpoint: 192.168.49.2:8443
  creationTimestamp: null
  labels:
    component: kube-apiserver
    tier: control-plane
  name: kube-apiserver
  namespace: kube-system
spec:
  containers:
  - command:
    - kube-apiserver
    - --advertise-address=192.168.49.2
    - --allow-privileged=true
    - --v=4
    .......

然后运行kubectl log --v=4命令。

英文:

The answer is:
add --v=4 arg to kube api server config file to enable the log verbosity.

File path: /etc/kubernetes/manifests/kube-apiserver.yaml

apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubeadm.kubernetes.io/kube-apiserver.advertise-address.endpoint: 192.168.49.2:8443
  creationTimestamp: null
  labels:
    component: kube-apiserver
    tier: control-plane
  name: kube-apiserver
  namespace: kube-system
spec:
  containers:
  - command:
    - kube-apiserver
    - --advertise-address=192.168.49.2
    - --allow-privileged=true
    - --v=4
    .......

then kubectl log --v=4

huangapple
  • 本文由 发表于 2022年7月25日 15:43:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/73105600.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定