Dapr进阶-01-Debug dapr

本文详细介绍了在 CentOS 8 上安装 Go 语言环境,并使用 Dapr 进行源码调试,包括设置 GOPROXY 为国内镜像,构建 debug 模式的镜像,自定义部署 Dapr 并启用 debug 功能,以及如何调试控制面和微服务组件。

1. 安装golang

CentOS 8 安装golang_敦格-CSDN博客CentOS 8 安装golanghttps://shuaihj.blog.csdn.net/article/details/123018041

2. 以debug模式编译源码

Debug daprd on Kubernetes | Dapr DocsHow to debug the Dapr sidecar (daprd) on your Kubernetes clusterhttps://docs.dapr.io/developing-applications/debugging/debug-k8s/debug-daprd/

2.1. 下载dapr源码

git clone https://github.com/dapr/dapr.git

2.2. 目录定位

cd dapr

2.3. 修改Dockerfile中的GOPROXY为国内镜像源

vi ./docker/Dockerfile-debug
  • 关键参数如下 
GOPROXY=https://goproxy.cn,direct
  • 结果 

2.4. 编译

make release GOOS=linux GOARCH=amd64 DEBUG=1

3. 生成debug模式的dapr镜像到你自己的docker库

3.1. 登录你的docker hub

docker login

3.2. 提前下载gcr.io的docker镜像

gcr.io/distroless/static:nonroot

国内无法访问gcr.io的解决办法_敦格-CSDN博客国内无法访问gcr.io的解决办法https://shuaihj.blog.csdn.net/article/details/123022325

3.3. 验证本地docker镜像

docker images | grep static

3.4. Build 并 Push到docker hub

export DAPR_TAG=dev
export DAPR_REGISTRY=k8schina
make docker-push DEBUG=1

3.5. 验证docker hub

4. 安装debug模式的的dapr

4.1. 创建values.yaml文件

vi values.yaml
global:
  registry: docker.io/k8schina
  tag: "dev-linux-amd64"
  logAsJson: true
dapr_operator:
  debug:
    enabled: true
dapr_sidecar_injector:
  hostNetwork: true
  debug:
    enabled: true
dapr_placement:
  debug:
    enabled: true
dapr_sentry:
  debug:
    enabled: true

4.2. 卸载旧版本

helm uninstall dapr --namespace dapr-system

4.3. 安装debug版本

  • 必须 进入dapr源码目录
cd dapr
  • 自定义安装 
helm install dapr charts/dapr \
--namespace dapr-system \
--create-namespace \
--values values.yaml \
--wait

4.4. 验证

docker images | grep dev

5. Debug Dapr 控制面组件

5.1. 查看要debug的控制面pod

kubectl get pods -n dapr-system -o wide

5.2. debug监控你的控制面pod

kubectl port-forward dapr-operator-7878f94fcd-6bfx9 40000:40000 -n dapr-system

6. Debug 微服务的 daprd sidecar

Debug daprd on Kubernetes | Dapr DocsHow to debug the Dapr sidecar (daprd) on your Kubernetes clusterhttps://docs.dapr.io/developing-applications/debugging/debug-k8s/debug-daprd/

6.1. 配置你的deployment为可debug

dapr.io/enable-debug: "true"
apiVersion: v1
kind: Namespace
metadata:
  name: dapr-demo
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: service01
  namespace: dapr-demo
  labels:
    app: service01
spec:
  replicas: 2
  selector:
    matchLabels:
      app: service01
  template:
    metadata:
      labels:
        app: service01
      annotations:
        dapr.io/enabled: "true"
        dapr.io/app-id: "service01"
        dapr.io/app-port: "80"
        dapr.io/sidecar-liveness-probe-delay-seconds: "10"
        dapr.io/sidecar-readiness-probe-delay-seconds: "10"
        dapr.io/log-as-json: "true"
        dapr.io/enable-debug: "true"
    spec:
      containers:
        - name: service01
          image: docker.io/k8schina/service01:v1
          ports:
            - containerPort: 80
          imagePullPolicy: Always
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: service02
  namespace: dapr-demo
  labels:
    app: service02
spec:
  replicas: 1
  selector:
    matchLabels:
      app: service02
  template:
    metadata:
      labels:
        app: service02
      annotations:
        dapr.io/enabled: "true"
        dapr.io/app-id: "service02"
        dapr.io/app-port: "80"
        dapr.io/sidecar-liveness-probe-delay-seconds: "10"
        dapr.io/sidecar-readiness-probe-delay-seconds: "10"
        dapr.io/log-as-json: "true"
        dapr.io/enable-debug: "true"
    spec:
      containers:
        - name: service02
          image: docker.io/k8schina/service02:v1
          ports:
            - containerPort: 80
          imagePullPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: service02
  namespace: dapr-demo
spec:
  type: NodePort
  selector:
    app: service02
  ports:
    - port: 80
      targetPort: 80
      nodePort: 30006

6.2. 部署你的微服务

kubectl apply -f http://k8schina.corecore.cn/DaprDemo.yaml

6.3. 查看要debug的微服务pod

kubectl get pods -n dapr-demo -o wide

6.4. debug监控你的目标pod

kubectl port-forward dapr-operator-7878f94fcd-6bfx9 40000:40000 -n dapr-demo

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

敦格

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值