远程debug kubenetes controller

最近在学习腾讯开源的istio sidecar方案lazyxds的时候,想要深入lazyxds的执行过程。除了笨拙的添加日志,然后打包部署查看外,lazyxds作为一种kubenetest controller的实现,也可以通过远程调试的方式进行查看,更加方便直观。

后续再补一些背景知识吧,先上干货。

前提

  • go version go1.16.3 darwin/amd64
  • Aeraki source code : https://github.com/aeraki-framework/aeraki
  • Docker version 20.10.7, build f0df350
  • minikube version: v1.19.0
  • goland

步骤

  1. 未添加delve的dockerfile

     FROM alpine:3.10
     COPY lazyxds /usr/local/bin/
     ENTRYPOINT ["/usr/local/bin/lazyxds", "-v", "4"]
    
  2. 添加delve的dockerfile

    FROM alpine:3.10
    FROM golang
    RUN go install github.com/go-delve/delve/cmd/dlv@latest
    RUN ls -al /go/bin/dlv
    COPY lazyxds /usr/local/bin/
    EXPOSE 40000
    ENTRYPOINT ["/go/bin/dlv","exec", "/usr/local/bin/lazyxds", "--listen=:40000", "--headless=true", "--api-version=2"]
    

注意 先把-v 4 参数去掉了

  1. 重新打包 & deploy到minikube中

    sudo make docker-build.lazyxds
    
  2. kubenetes dashboard找到要remote debug的pod

     pod: lazyxds-697687644f-j8cf2
     namespace: istio-system
    
image.png
  1. expose debug指定的40000端口

    kubectl port-forward lazyxds-697687644f-j8cf2  40000:40000 -n istio-system
    
    image.png
  2. goland 指定remote debug端口


    image.png
image.png

你可能感兴趣的:(远程debug kubenetes controller)