MindCloud调试工具
一、工具介绍
MindCloud调试工具,单一二进制,无其它环境依赖。
该工具主要功能包括:
- 远程断点调试容器
- 挂载主机路径(挂载nginx配置,在主机路径上修改该文件可以使修改持久化)
- 新增端口映射(pprof等工具需要端口映射才能访问)
链接
工具默认使用环境上MEFCenter安装目录的容器yaml作为输入。使用参数(
-mef_idr=-
)可使用标准输入
二、远程断点调试容器
调试工具使用dlv(地址)进行断点调试。实现原理是通过挂载dlv和带符号表的二进制到容器,修改启动命令并创建端口映射,使得开发者通过网络连接远程机器上的容器,实现断点调试。
使用指导
1、获取dlv,编译调试二进制
断点调试需要编译时保留符号表,编译命令实例如下
1
|
go build -o edge-manager --gcflags="-N -l" main.go |
2、将dlv,调试二进制上传到执行环境的同一个目录,并上传调试工具
需要确保dlv,edge-manager有执行权限
3、修改容器配置,启动dlv
如下命令可以生成dlv调试配置yaml
1
|
./center_debug_tool -m edge-manager -d -debug_port 30099 -debug_dir /root/debug |
或者直接使用如下命令使得配置生效
1
|
./center_debug_tool -m edge-manager -d -debug_port 30099 -debug_dir /root/debug | kubectl apply -f - |
该配置在MindCloud重启后会被重启,如果想在重启MEFCenter之后继续生效请将上述命令输出重定向到
{安装路径}/mind-cloud/images/{component}/image-config/{component}.yaml
./center_debug_tool -d -debug_port 30099 -debug_dir /home/gwx/dlv -m edge-manager -p 30098:9090 > dlv.yaml
apiVersion: v1 kind: Service metadata: name: ascend-edge-manager-debug-external-30099 namespace: mef-center labels: app: ascend-edge-manager spec: externalTrafficPolicy: Local ports: - name: ascend-edge-manager-debug-port-30099 port: 30099 targetPort: 30099 protocol: TCP nodePort: 30099 selector: app: ascend-edge-manager type: NodePort --- apiVersion: v1 kind: Service metadata: name: ascend-edge-manager-debug-external-30098 namespace: mef-center labels: app: ascend-edge-manager spec: externalTrafficPolicy: Local ports: - name: ascend-edge-manager-debug-port-30098 port: 9090 targetPort: 9090 protocol: TCP nodePort: 30098 selector: app: ascend-edge-manager type: NodePort --- apiVersion: apps/v1 kind: Deployment metadata: creationTimestamp: null name: ascend-edge-manager namespace: mef-center spec: replicas: 1 selector: matchLabels: app: ascend-edge-manager strategy: {} template: metadata: creationTimestamp: null labels: app: ascend-edge-manager spec: automountServiceAccountToken: false containers: - args: - 'LD_LIBRARY_PATH=/home/MEFCenter/lib:${LD_LIBRARY_PATH} /home/MEFCenter/dlv exec /home/MEFCenter/edge-manager --headless --api-version=2 --listen=:30099 --accept-multiclient --check-go-version=false -- -port=8101 -wsPort=10000 -maxClientNum=1024 ' command: - /bin/bash - -c - -- env: - name: KUBE_CLIENT_QPS value: "1000" - name: KUBE_CLIENT_BURST value: "100" - name: installed-module value: '{[''edge-manager'', ''cert-manager'', ''nginx-manager'', ''alarm-manager'']}' - name: API_SERVER_ENDPOINT value: 51.38.66.39:6443 - name: LOG_UPLOAD_CONCURRENCY value: "10" - name: POD_IP valueFrom: fieldRef: fieldPath: status.podIP - name: NODE_IP valueFrom: fieldRef: fieldPath: status.hostIP image: ascend-edge-manager:v1 imagePullPolicy: Never name: ascend-edge-manager resources: limits: cpu: "6" memory: 10000Mi requests: cpu: 500m memory: 500Mi securityContext: allowPrivilegeEscalation: false capabilities: drop: - ALL readOnlyRootFilesystem: true seccompProfile: type: RuntimeDefault volumeMounts: - mountPath: /var/log/mindx-edge/edge-manager name: edge-manager-log - mountPath: /var/log_backup/mindx-edge/edge-manager name: edge-manager-log-backup - mountPath: /etc/localtime name: localtime - mountPath: /home/data/config/ name: edge-manager-config - mountPath: /home/data/public-config/ name: public-config - mountPath: /home/data/inner-root-ca/ name: root-ca - mountPath: /home/MEFCenter/mef_logcollect name: log-collect-dir - mountPath: /home/MEFCenter/edge-manager name: edge-manager-debug - mountPath: /home/MEFCenter/dlv name: dlv-debug nodeSelector: mef-center-node: "" volumes: - hostPath: path: /var/mef-center-log/edge-manager type: Directory name: edge-manager-log - hostPath: path: /var/mef-center-log-backup/edge-manager type: Directory name: edge-manager-log-backup - hostPath: path: /etc/localtime name: localtime - hostPath: path: /usr/local/MEF-Center/mef-config/edge-manager name: edge-manager-config - hostPath: path: /usr/local/MEF-Center/mef-config/root-ca/cert name: root-ca - hostPath: path: /usr/local/MEF-Center/mef-config/public-config name: public-config - hostPath: path: /var/mef_logcollect name: log-collect-dir - hostPath: path: /home/gwx/dlv/edge-manager name: edge-manager-debug - hostPath: path: /home/gwx/dlv/dlv name: dlv-debug status: {}
最后确认一下容器是否正常启动
4、在GOLAND 上配置调试
配置
连接远程dlv
打个断点,触发调用,能够看到作用域内所有的变量
三、挂载主机路径
示例:
主机路径下添加如下文件
1
|
echo 123 > /root/debug/hello |
挂载
1
|
./center_debug_tool -m nginx-manager -v /root/debug/hello:/home/MEFCenter/hello | kubectl apply -f - |
测试
1
|
docker exec -it $(docker ps -a | grep k8s_ascend-nginx-manager | awk -F' ' '{print $1}') cat /home/MEFCenter/hello |
输出:123,我们的文件已成功挂载
四、端口映射
示例:
在容器中提供pprof接口时,需要配置端口映射外部才能外部访问
1
|
func main() { |
2
|
go func() { |
3
|
engine := gin.New() |
4
|
pprof.Register(engine) |
5
|
if err := engine.Run(":9090"); err != nil { |
6
|
panic(err) |
7
|
} |
8
|
}() |
9
|
|
10
|
... |
11
|
} |
1
|
./center_debug_tool -m edge-manager -p 30099:9090 -v /root/debug/edge-manager:/home/MEFCenter/edge-manager | kubectl apply -f - |
外部可以访问到容器内的pporf服务
参考链接:
本文来自博客园,作者:易先讯,转载请注明原文链接:https://www.cnblogs.com/gongxianjin/p/17871562.html