[英]Set up debugger for Kubernetes pod in EKS cluster for go applications
I am trying to set up a debugger for my application which is running inside my Kube.netes pod in the EKS cluster.我正在尝试为在 EKS 集群中的 Kube.netes pod 中运行的应用程序设置调试器。
I have one through many articles but they all talk about setting up a debugger for local env.我有很多文章,但他们都在谈论为本地环境设置调试器。
I am using helm charts and EKS for the Kube.netes cluster.我正在为 Kube.netes 集群使用 helm 图表和 EKS。 Please help me with this problem.
请帮我解决这个问题。
I tried Dockerfile changes to install delve but CMD and ENTRYPOINT command both are failing with我尝试了 Dockerfile 更改来安装 delve 但 CMD 和 ENTRYPOINT 命令都失败了
exec: "go": executable file not found in $PATH
My docker file looks like我的 docker 文件看起来像
Stage 1: Compile the Golang application第一阶段:编译 Golang 应用程序
FROM golang:1.18-alpine AS builder
WORKDIR /application
COPY . /application
RUN GOOS=linux GOARCH=amd64 go build -v -x -o app --ldflags '-extldflags "-static"'
Stage 2: Move only the compiled code to container第 2 阶段:仅将编译后的代码移动到容器中
FROM alpine:latest
WORKDIR /application
COPY --from=builder /application/app /application
RUN apk add --no-cache delve
# let's start delve as the entrypoint
ENTRYPOINT ["/usr/bin/dlv", "debug", ".", "--listen=:40000", "--accept-multiclient", "--headless=true", "--api-version=2" , "exec" , "./app" ]
Not an expert in Go but in the second stage you are copying the files from first stage to the second one.不是Go的专家,但在第二阶段,您正在将文件从第一阶段复制到第二阶段。
Those files could be the executable or source code这些文件可以是可执行文件或源代码
In the second stage you have installed the delve but when you are adding the Entry point or CMD it's showing error of this在第二阶段,您已经安装了delve ,但是当您添加入口点或 CMD 时,它显示此错误
exec: "go": executable file not found in $PATH
it's due to the second stage is alpine won't have Go installed by default and as you have not copied Go binary from the first to the second stage so showing a path error or missing error as dlv might be requiring it in background.这是因为第二阶段是alpine默认情况下不会安装Go并且因为您没有将Go二进制文件从第一阶段复制到第二阶段所以显示路径错误或丢失错误,因为dlv可能在后台需要它。
What you can do is install it with in first stage and move to second stage你可以做的是在第一阶段安装它并移动到第二阶段
RUN CGO_ENABLED=0 go install github.com/go-delve/delve/cmd/dlv@latest
stage 2第二阶段
COPY --from=builder /go/bin/dlv /usr/bin/dlv
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.