简体   繁体   English

为 go 应用程序的 EKS 集群中的 Kube.netes pod 设置调试器

[英]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.

相关问题 EKS 集群中的 Pod 创建失败并出现 FailedScheduling 错误 - Pod creation in EKS cluster fails with FailedScheduling error AWS EKS NodeGroup“创建失败”:实例未能加入 kubernetes 集群 - AWS EKS NodeGroup "Create failed": Instances failed to join the kubernetes cluster 在大规模扩展期间无法通过 kubectl 访问 EKS 集群 - EKS cluster not reachable through kubectl during major scale up 如何使用 Fargate 创建 AWS Kube.netes 集群 (EKS)? - How to create a AWS Kubernetes cluster (EKS) using Fargate? EKS pod 到 RDS 连接 - EKS pod to RDS connectivity EKS 节点与 EKS Fargate pod 之间的通信 - Communication between EKS node and EKS Fargate pod 如何通过 terraform 修复新配置的 EKS 集群上的 kube.netes_config_map 资源错误? - How to fix kubernetes_config_map resource error on a newly provisioned EKS cluster via terraform? EKS 上的 Airflow 是否需要 Trigger Pod - Is Triggerer Pod needed for Airflow on EKS 您当前的用户或角色无权访问此 EKS 集群上的 Kube.netes 对象 - Your current user or role does not have access to Kubernetes objects on this EKS cluster Pod 在 AWS EKS 集群中终止,因为即使有足够的资源也达到了 Pod 限制 - Pods terminating in AWS EKS cluster because the pod limit is reached even with enought resources
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM