安装kube-debug
下载kubectl-debug的安装包
链接: https://pan.baidu.com/s/1MMzryo7H-3OK0B2tJMHpRw 密码: o39o
官网地址https://github.com/aylei/kubectl-debug
tar zxvf kubectl-debug_0.1.1_linux_amd64.tar.gz kubectl-debug
mv kubectl-debug /usr/local/bin/
kubectl debug -h
配置config文件
cat > ~/.kube/debug-config << EOF
# debug agent listening port(outside container)
# default to 10027
agentPort: 10027
# whether using agentless mode
# default to true
agentless: true
# namespace of debug-agent pod, used in agentless mode
# default to 'default'
agentPodNamespace: default
# prefix of debug-agent pod, used in agentless mode
# default to 'debug-agent-pod'
agentPodNamePrefix: debug-agent-pod
# image of debug-agent pod, used in agentless mode
# default to 'aylei/debug-agent:latest'
agentImage: aylei/debug-agent:latest
# daemonset name of the debug-agent, used in port-forward
# default to 'debug-agent'
debugAgentDaemonset: debug-agent
# daemonset namespace of the debug-agent, used in port-forwad
# default to 'default'
debugAgentNamespace: kube-system
# whether using port-forward when connecting debug-agent
# default true
portForward: true
# image of the debug container
# default as showed
image: nicolaka/netshoot:latest
# start command of the debug container
# default ['bash']
command:
- '/bin/bash'
- '-l'
# private docker registry auth kuberntes secret
# default RegistrySecretName is kubectl-debug-registry-secret
# default namspace is default
RegistrySecretName: my-debug-secret
RegistrySecretNamespace: debug
# in agentless mode, you can set the agent pod's resource limits/requests:
# default is not set
agentCpuRequests: ""
agentCpuLimits: ""
agentMemoryRequests: ""
agentMemoryLimits: ""
# in fork mode, if you want the copied pod retains the labels of the original pod, you can change this params
# format is []string
# If not set, this parameter is empty by default (Means that any labels of the original pod are not retained, and the labels of the copied pods are empty.)
forkPodRetainLabels: []
# You can disable SSL certificate check when communicating with image registry by
# setting registrySkipTLSVerify to true.
registrySkipTLSVerify: false
# You can set the log level with the verbosity setting
verbosity : 0
EOF
# 以下命令都可以
kubectl debug haozhuo-hm-dp-0 -c haozhuo-hm -n test
kubectl-debug haozhuo-hm-dp-0 -c haozhuo-hm -n test
退出kube-debug之后pod会自动删除
也可以使用自己制作事先安装好工具的镜像
kubectl-debug haozhuo-hm-dp-0 -c haozhuo-hm -n test --agentless=false --image registry.cn-hangzhou.aliyuncs.com/xjm_public/centos:7.4.1708
出现的问题
装了agent_daemonset 就报错如下
error: pod ran to completion
Predicate PodFitsHostPorts failed
Error from server (BadRequest): container “debug-agent” in pod “debug-agent-pod-6462e1b9-f719-11ea-82ea-005056b7c84c” is not available
可参考文档
https://github.com/aylei/kubectl-debug/blob/master/docs/zh-cn.md
https://aleiwu.com/post/kubectl-debug-intro/