英文:
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("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
}
I think I can check these logs via kubectl logs
, but I cannot see them, even use kubectl logs --v 6 <kubeapi server pod> | grep "going to delete"
or kubectl logs --v 4 <kubeapi server pod> | grep "DeleteCollection"
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论