当前位置:网站首页>GoLand IDE and delve debug Go programs in kubernetes cluster
GoLand IDE and delve debug Go programs in kubernetes cluster
2022-06-28 07:19:00 【nangonghen】
1 summary :
On the local computer ide Remote debugging in go Program ,IDE by goland-2019.3,go Program exposed http Interface for GET /ip,go The procedure is based on pod The form runs in kubernetes In the cluster . When the client request reaches the destination go The program , The local IDE Breakpoint takes effect .
2 delve:
2.1 brief introduction
delve Is a go Program mode tool (git clone https://github.com/go-delve/delve.git), Is an easy-to-use binary program , Can be used to start the target go Program , Get into dlv After the environment, various built-in commands can be used to debug the target go Program .
2.2 Download binaries
# The downloaded file is located at $GOPATH/bin/ Under the table of contents
go get -u github.com/go-delve/delve/cmd/dlv
2.3 Operation mode
The way 1:
$GOPATH/bin/dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec / The goal is go Binary --continue
The way 2:
# Start the target first go Program , obtain pid Run the following command again
dlv attach The goal is go programmatic pid --headless --listen=:2345 --api-version=2 --accept-multiclient
2.4 Other instructions
2.4.1 Compile target go The program needs to take parameters -gcflags=“all=-N -l”
2.4.2 recommend B One of the stations delve Easy tutorial for .
https://www.bilibili.com/video/BV1pb411i7nw?from=search&seid=1674747649731508669
3 go Program :
https://github.com/gzlj/http-demo
go Program exposed http Interface for :GET /ip
4 Make docker Mirror image :
4.1 compile go Program
#cd $GOPATH/src/github.com/gzlj/http-demo/cmd/gracehttp-demo
# Compile target go The program needs to take parameters -gcflags="all=-N -l"
go build -gcflags="all=-N -l" -o main
4.2 To write Dockerfile
# The target go Binary executable of the program main and dlv The executable file is placed in Dockerfile The catalog of 
4.3 perform docker build Command build mirror
docker build -t "192.168.1.70:5000/http:dlv" .
5 Deploy go Program to kubernetes colony
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
namespace: default
spec:
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- command:
- /dlv
- --listen=:2345
- --headless=true
- --api-version=2
- --accept-multiclient
- exec
- /main
- --continue
image: 192.168.1.70:5000/http:dlv
imagePullPolicy: Always
name: web
# The container needs SYS_PTRACE or Directly as a privilege container
securityContext:
capabilities:
add:
- SYS_PTRACE
---
apiVersion: v1
kind: Service
metadata:
labels:
app: web
name: web
namespace: default
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
- name: dlv
port: 2345
protocol: TCP
targetPort: 2345
type: NodePort
selector:
app: web

After successful deployment , Know the node 31883 Port mapped to container 2345 port (delve Port on which the program listens ).
6 goland Turn on remote debug Pattern
6.1 newly added go remote debug To configure
Click... In the menu bar Run —> Edit Configurations —> newly added —> Go Remote —> determine .

6.2 newly added go remote debug To configure
In the code /ip Interface http handler Method , Click on IDE The bug icon for the debug Run the code in .
7 Access target go Program and view IDE The endpoint of
With kubernetes node port Access to go programmatic /ip Interface
#192.168.1.71 yes kubernetes Cluster node ,31175 yes go programmatic service NodePort.
curl 192.168.1.71:31175/ip && echo


边栏推荐
- open62541直接导入NodeSet文件
- 推荐10个好用到爆的Jupyter Notebook插件,让你效率飞起
- 强化学习——格子世界
- Makefile
- 面经---测试工程师web端自动化---大厂面试题
- Wechat applets - basics takes you to understand the life cycle of applets (I)
- OPC 协议认识
- 全方位透析真实企业软件测试流程
- 《微信小程序-基础篇》带你了解小程序中的生命周期(一)
- Will Internet talents be scarce in the future? Which technology directions are popular?
猜你喜欢

Kubernetes cluster lossless upgrade practice
![[C language] detailed explanation of C language to obtain array length](/img/cf/75c314bb622b8a1745f43cc07cb02e.png)
[C language] detailed explanation of C language to obtain array length

Recommend 10 popular jupyter notebook plug-ins to make you fly efficiently

What is a consistent hash? What scenarios can it be applied to?

在idea中,get和set方法爆红可能是没有安装Lombok插件

Modifying MySQL port number under Linux

推荐几款0代码、免费、现学现用的可视化工具

Solving the longest palindrome substring by dynamic programming

什么是EC鼓风机(ec blower fan)?

Pfizer's new Guankou medicine has entered the Chinese market, and the listing of relevant products of domestic pharmaceutical enterprises is just around the corner
随机推荐
A small code editor can also run programs -- a summary of sublime Text3 running programs in various languages
Construction and exploration of vivo database and storage platform
js正则表达式系统讲解(全面的总结)
Libuv framework echo server C source code explanation (TCP part)
声网 VQA:将实时互动中未知的视频画质用户主观体验变可知
Recommend 10 popular jupyter notebook plug-ins to make you fly efficiently
Practice and exploration of vivo live broadcast application technology
Alibaba cloud server creates snapshots and rolls back disks
OPC 协议认识
DOM parsing of XML file case code sentence by sentence analysis
Leetcode+ 66 - 70 high precision, two sub topics
R language ggmap visual cluster
Code submission specification
Pfizer's new Guankou medicine has entered the Chinese market, and the listing of relevant products of domestic pharmaceutical enterprises is just around the corner
VM332 WAService. js:2 Error: _ vm. Changetabs is not a function
【Rust翻譯】從頭實現Rust异步執行器
《微信小程序-基础篇》带你了解小程序中的生命周期(一)
Evolution of vivo push platform architecture
The practice of event driven architecture in vivo content platform
Jetpack - defects of livedata component and Countermeasures