Dapr进阶-01-Debug dapr

Dapr进阶-01-Debug dapr,第1张

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/994017.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存