前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >二进制安装k8s集群(17)-安装kubectl-debug

二进制安装k8s集群(17)-安装kubectl-debug

作者头像
TA码字
发布2020-04-01 14:59:44
8010
发布2020-04-01 14:59:44
举报
文章被收录于专栏:TA码字TA码字

上一篇文章里我们主要介绍安装k8s集群内的基础服务nginx-ingress-controller,这里我们介绍一下k8s的pod调试工具。在k8s的容器环境中,去排查问题是避免不了的,这就需要在pod里有各种工具,例如top,ps,pidstat,vmstat,nslookup,netstat,tcpdump,dig,traceroute等。可是有些pod里就没有这些工具(当然从制作image的角度来说确实是不应该把和应用自身无关的tools放到image里),这无疑给我们调试排查问题带来巨大的困难。kubectl-debug就是为了解决这个问题的,它不是k8s官方工具,是个人项目,但是用起来却比较方便,这里我们用0.1.1本版。kubectl-debug具体原理不在这里详细展开,有兴趣的同学可以到github的项目里看一下(https://github.com/aylei/kubectl-debug)。

下载binary:

这里在github下载有时候会很慢,甚至断掉。

mkdir -p /opt/sw/kubernetes/kube-pod-debug
cd /opt/sw/kubernetes/kube-pod-debug

wget https://github.com/aylei/kubectl-debug/releases/download/v0.1.1/kubectl-debug_0.1.1_linux_amd64.tar.gz
tar -zxvf kubectl-debug_0.1.1_linux_amd64.tar.gz

cp kubectl-debug /usr/bin
whereis kubectl-debug

在私有harbor repo中创建public project:

以前文章里介绍过如何搭建私有的harbor repo,可以参考。

创建debug-agent镜像,并push到上面步骤的repo project里:

docker pull aylei/debug-agent:latest
docker images|grep debug
docker tag aylei/debug-agent:latest 172.20.11.41:1034/infra-pub/kubectl-debug-agent:latest
docker push 172.20.11.41:1034/infra-pub/kubectl-debug-agent:latest

创建debug-tool镜像,并push到上面步骤的repo project里:

docker pull nicolaka/netshoot:latest
docker images|grep nicolaka
docker tag nicolaka/netshoot:latest 172.20.11.41:1034/infra-pub/kubectl-debug-container:latest
docker push 172.20.11.41:1034/infra-pub/kubectl-debug-container:latest

创建kube-debug配置文件:

对于配置文件里的参数比较多,就不逐一在这里详述,有兴趣的同学可以去github上(https://github.com/aylei/kubectl-debug#configuration)看一下kubectl-debug的参数配置文档。

cat > ~/.kube/debug-config << EOF
# debug agent listening port(outside container), default to 10027
agentPort: 10027

# whether using agentless mode
# default to false
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: 172.20.11.41:1034/infra-pub/kubectl-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 false
portForward: true
# image of the debug tool container, default as nicolaka/netshoot:latest
image: 172.20.11.41:1034/infra-pub/kubectl-debug-container:latest
# start command of the debug container, default ['bash']
command:
- '/bin/bash'
- '-l' 
EOF

使用kubectl-debug工具调试pod:

请注意,当开始对一个pod debug的时候,kubectl-debug会在目标pod所在的node创建2个items。一个是debug-agent,它的本质是一个pod。另一个是debug-tool container,它的本质是docker container,不是pod。当然,在退出kubectl-debug的target pod的时候这两个items都会被销毁。

调试pod:

我们以集群中的coredns的pod为例子进行调试,当debug进入之后我们就可以用预置在debug-tool container里的curl,ping,tracroute,nslookup等诸多工具了。

kubectl get pods -n kube-system
kubectl-debug deployment-coredns-c58b8b7fc-kp2j8 --namespace kube-system

查看debug-agent pod和debug-tool container:

kubectl get pods --all-namespaces=true
docker ps|grep debug-container

退出debug:

exit
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-11-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 TA码字 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档