From a95210240a173cef033509b4e68f511feac3adb3 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Tue, 6 Apr 2021 15:25:11 +0800 Subject: [PATCH] fix issue #1380 --- .../debugging/_index.md | 7 ++ .../debugging/debug-k8s/_index.md | 7 ++ .../debug-k8s/debug-dapr-services.md | 108 ++++++++++++++++++ .../debugging/debug-k8s/debug-daprd.md | 96 ++++++++++++++++ 4 files changed, 218 insertions(+) create mode 100644 daprdocs/content/en/developing-applications/debugging/_index.md create mode 100644 daprdocs/content/en/developing-applications/debugging/debug-k8s/_index.md create mode 100644 daprdocs/content/en/developing-applications/debugging/debug-k8s/debug-dapr-services.md create mode 100644 daprdocs/content/en/developing-applications/debugging/debug-k8s/debug-daprd.md diff --git a/daprdocs/content/en/developing-applications/debugging/_index.md b/daprdocs/content/en/developing-applications/debugging/_index.md new file mode 100644 index 000000000..a8b68ee44 --- /dev/null +++ b/daprdocs/content/en/developing-applications/debugging/_index.md @@ -0,0 +1,7 @@ +--- +type: docs +title: "Debug" +linkTitle: "Debug" +weight: 50 +description: "How to debug Dapr application and Dapr itself" +--- \ No newline at end of file diff --git a/daprdocs/content/en/developing-applications/debugging/debug-k8s/_index.md b/daprdocs/content/en/developing-applications/debugging/debug-k8s/_index.md new file mode 100644 index 000000000..aef6df1f1 --- /dev/null +++ b/daprdocs/content/en/developing-applications/debugging/debug-k8s/_index.md @@ -0,0 +1,7 @@ +--- +type: docs +title: "Debug Dapr in Kubernetes mode" +linkTitle: "Kubernetes" +weight: 2000 +description: "How to debug Dapr on your Kubernetes cluster" +--- diff --git a/daprdocs/content/en/developing-applications/debugging/debug-k8s/debug-dapr-services.md b/daprdocs/content/en/developing-applications/debugging/debug-k8s/debug-dapr-services.md new file mode 100644 index 000000000..531231478 --- /dev/null +++ b/daprdocs/content/en/developing-applications/debugging/debug-k8s/debug-dapr-services.md @@ -0,0 +1,108 @@ +--- +type: docs +title: "Debug Dapr services on Kubernetes" +linkTitle: "Dapr services" +weight: 10000 +description: "How to debug Dapr services on your Kubernetes cluster" +--- + +## Overview + +Sometimes it is necessary to understand what's going on in Dapr Kubernetes services, including `dapr-sidecar-injector`, `dapr-operator`, `dapr-placement`, and `dapr-sentry`, especially when you diagnose your Dapr application and wonder if there's something gets wrong in Dapr itself, or when you contribute to Dapr relevant to Kubernetes support. + +If this is the case, Dapr has built-in Kubernetes debug support coming in to rescue. + +## Debug Dapr Kubernetes services + +Before read on, pls. refer [this guide]({{< ref kubernetes-deploy.md >}}) to learn how to deploy Dapr to your Kubernetes cluster. + +### 1. Build Dapr debugging binaries + +In order to debug Dapr Kubernetes services, it's required to rebuild all Dapr binaries and Docker images to disable compiler optimization. To do this, pls. execute the following commands: + +```bash +git clone https://github.com/dapr/dapr.git +cd dapr +make release GOOS=linux GOARCH=amd64 DEBUG=1 +``` + +In the above command, 'DEBUG' is specified to '1' to disable compiler optimization. 'GOOS=linux' and 'GOARCH=amd64' are also necessary since the binaries will be packaged into Linux-based Docker image in the next step. + +The binaries could be found under 'dist/linux_amd64/debug' sub-directory under the 'dapr' directory. + +### 2. Build Dapr debugging Docker images + +Use the following commands to package the debugging binaries into Docker images. Before this, you need to login your docker.io account, and if you don't have it yet, you may need to consider registering one from "https://hub.docker.com/". + +```bash +export DAPR_TAG=dev +export DAPR_REGISTRY= +docker login +make docker-push DEBUG=1 +``` + +Once the Dapr Docker images are built and pushed onto Docker hub, then you are ready to re-install Dapr in your Kubernetes cluster. + +### 3. Install Dapr debugging binaries + +If Dapr has already been installed in your Kubernetes cluster, uninstall it first: + +```bash +dapr uninstall -k +``` + +We will use 'helm' to install Dapr debugging binaries. For more information pls. check [Install with Helm]({{< ref "kubernetes-deploy.md#install-with-helm-advanced" >}}). In the following sections, we will use Dapr operator as an example to demonstrate how to configure, install, and debug Dapr services in a Kubernetes environment. + +First configure a values file with these options: + +```yaml +global: + registry: docker.io/ + tag: "dev-linux-amd64" +dapr_operator: + debug: + enabled: true + initialDelaySeconds: 3000 +``` + +{{% alert title="Notice" color="primary" %}} +If you need to debug the startup time of Dapr services, you need to consider configuring `initialDelaySeconds` to a very long time value, e.g. "3000" seconds. If this is not the case, configure it to a short time value, e.g. "3" seconds. +{{% /alert %}} + +Then step into 'dapr' directory which's cloned from GitHub in the beginning of this guide if you haven't, and execute the following command: + +```bash +helm install dapr charts/dapr --namespace dapr-system --values values.yml --wait +``` + +### 4. Forward debugging port + +To debug the target Dapr service (Dapr operator in this case), its pre-configured debug port needs to be visible to your IDE. In order to achieve this, we need to find the target Dapr service's pod first: + +```bash +$ kubectl get pods -n dapr-system -o wide + +NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES +dapr-dashboard-64b46f98b6-dl2n9 1/1 Running 0 61s 172.17.0.9 minikube +dapr-operator-7878f94fcd-6bfx9 1/1 Running 1 61s 172.17.0.7 minikube +dapr-placement-server-0 1/1 Running 1 61s 172.17.0.8 minikube +dapr-sentry-68c7d4c7df-sc47x 1/1 Running 0 61s 172.17.0.6 minikube +dapr-sidecar-injector-56c8f489bb-t2st9 1/1 Running 0 61s 172.17.0.10 minikube +``` + +Then use kubectl's `port-forward` command to expose the internal debug port to the external IDE: + +```bash +$ kubectl port-forward dapr-operator-7878f94fcd-6bfx9 40000:40000 -n dapr-system + +Forwarding from 127.0.0.1:40000 -> 40000 +Forwarding from [::1]:40000 -> 40000 +``` + +All done. Now you can point to port 40000 and start remote debug session from your favorite IDE. + +## Related links + +- [Overview of Dapr on Kubernetes]({{< ref kubernetes-overview >}}) +- [Deploy Dapr to a Kubernetes cluster]({{< ref kubernetes-deploy >}}) +- [Dapr Kubernetes Quickstart](https://github.com/dapr/quickstarts/tree/master/hello-kubernetes) diff --git a/daprdocs/content/en/developing-applications/debugging/debug-k8s/debug-daprd.md b/daprdocs/content/en/developing-applications/debugging/debug-k8s/debug-daprd.md new file mode 100644 index 000000000..10c11b1a3 --- /dev/null +++ b/daprdocs/content/en/developing-applications/debugging/debug-k8s/debug-daprd.md @@ -0,0 +1,96 @@ +--- +type: docs +title: "Debug daprd on Kubernetes" +linkTitle: "Dapr sidecar" +weight: 20000 +description: "How to debug Dapr sidecar (daprd) on your Kubernetes cluster" +--- + + +## Overview + +Sometimes it is necessary to understand what's going on in Dapr sidecar (daprd) side by side to your application, especially when you diagnose your Dapr application and wonder if there's something gets wrong in Dapr sidecar itself, or when you contribute to Dapr relevant to Kubernetes support. + +If this is the case, Dapr has built-in Kubernetes debug support coming in to rescue. + +## Build Dapr sidecar on Kubernetes + +Before read on, pls. refer [this guide]({{< ref kubernetes-deploy.md >}}) to learn how to deploy Dapr to your Kubernetes cluster. + +In order to debug Dapr Kubernetes services, it's required to rebuild and reinstall all Dapr binaries, pls. follow the instructions in [Debug Dapr services]({{< ref "debug-dapr-services.md">}}) to build and install Dapr into debug mode. + +## Install daprd in debug mode + +If Dapr has already been installed in your Kubernetes cluster, uninstall it first: + +```bash +dapr uninstall -k +``` + +We will use 'helm' to install Dapr debugging binaries. For more information pls. check [Install with Helm]({{< ref "kubernetes-deploy.md#install-with-helm-advanced" >}}). + +First configure a values file with these options: + +```yaml +global: + registry: docker.io/ + tag: "dev-linux-amd64" +``` + +Then step into 'dapr' directory which's cloned from GitHub in the beginning of this guide if you haven't, and execute the following command: + +```bash +helm install dapr charts/dapr --namespace dapr-system --values values.yml --wait +``` + +To enable debug mode for daprd, you need to put extra annotations `dapr.io/enable-debug` in your application's deployment file. Let's use [quickstarts/hello-kubernetes](https://github.com/dapr/quickstarts/tree/master/hello-kubernetes) as an example, modify 'deploy/node.yaml' like below: + +```diff +diff --git a/hello-kubernetes/deploy/node.yaml b/hello-kubernetes/deploy/node.yaml +index 23185a6..6cdb0ae 100644 +--- a/hello-kubernetes/deploy/node.yaml ++++ b/hello-kubernetes/deploy/node.yaml +@@ -33,6 +33,7 @@ spec: + dapr.io/enabled: "true" + dapr.io/app-id: "nodeapp" + dapr.io/app-port: "3000" ++ dapr.io/enable-debug: "true" + spec: + containers: + - name: node +``` + +The annotation `dapr.io/enable-debug` will hint Dapr injector to inject Dapr sidecar into the debug mode. You can also specify the debug port with annotation `dapr.io/debug-port`, otherwise the default port will be "40000". + +Deploy the application with the following command. For the complete guide, pls. refer to [Dapr Kubernetes Quickstart](https://github.com/dapr/quickstarts/tree/master/hello-kubernetes): + +```bash +kubectl apply -f ./deploy/node.yaml +``` + +Figure out the target application's pod name with the following command: + +```bash +$ kubectl get pods + +NAME READY STATUS RESTARTS AGE +nodeapp-78866448f5-pqdtr 1/2 Running 0 14s +``` + +Then use kubectl's `port-forward` command to expose the internal debug port to the external IDE: + +```bash +$ kubectl port-forward nodeapp-78866448f5-pqdtr 40000:40000 + +Forwarding from 127.0.0.1:40000 -> 40000 +Forwarding from [::1]:40000 -> 40000 +``` + +All done. Now you can point to port 40000 and start remote debug session to daprd from your favorite IDE. + +## Related links + +- [Overview of Dapr on Kubernetes]({{< ref kubernetes-overview >}}) +- [Deploy Dapr to a Kubernetes cluster]({{< ref kubernetes-deploy >}}) +- [Debug Dapr services on Kubernetes]({{< ref debug-dapr-services >}}) +- [Dapr Kubernetes Quickstart](https://github.com/dapr/quickstarts/tree/master/hello-kubernetes) \ No newline at end of file