metricbeat/module/kubernetes/_meta/remote-debugger/README.md
This readme explain how to remote debug metricbeat running on docker/kubernetes from your laptop with your local IDE.
substitutePath.to is still pointing to our root folder.cd metricbeat
GOOS=linux GOARCH=amd64 go build -gcflags "-N -l" -o metricbeat main.go
docker build -t metricbeat-debugger-image -f Dockerfile.debug .
docker run -p 56268:56268 --network elastic-package-stack_default -v $(pwd)/metric.docker.yml:/usr/share/metricbeat/metricbeat.yml metricbeat-debugger-image -c /usr/share/metricbeat/metricbeat.yml -e
You can customize the metricbeat configuration by mounting a different file instead of $(pwd)/metric.docker.yml.
Steps from 0 to 2 (included) are the same as Steps to run on docker
substitutePath.to is still pointing to our root folder.cd metricbeat
GOOS=linux GOARCH=amd64 go build -gcflags "-N -l" -o metricbeat main.go
docker build -t metricbeat-debugger-image -f Dockerfile.debug .
kind load docker-image metricbeat-debugger-image:latest
deploy/kubernetes/metricbeat-kubernetes.yaml with these changescontainers:
- name: metricbeat
# image: docker.elastic.co/beats/metricbeat:8.2.0
image: metricbeat-debugger-image:latest
imagePullPolicy: Never
args: [
"-c", "/etc/metricbeat.yml",
"-e",
"--system.hostfs=/hostfs",
]
ports:
- containerPort: 56268
hostPort: 56268
protocol: TCP
Namely you need:
imagePullPolicy to pull the image from inside Kindports to expose the port in order to remote debug from laptopCompared to the docker example, here the metricbeat config is provided in the kubernetes manifest and mounted as a volume.
kubectl apply -f metricbeat-kubernetes.yaml
kubectl port-forward -n kube-system <pod-name> 56268:56268
where <pod-name> is the name of the pod running on k8s
In order to attach to the remote debugger running on docker container or a k8s pod you need to provide a file .vscode/launch.json on your local machine with some configurations.
You can use the following template, but remember to replace <absolute path> with the absolute path of the root folder of your project.
{
"version": "0.2.0",
"configurations": [
{
"name": "Connect to server",
"type": "go",
"request": "attach",
"mode": "remote",
"debugAdapter": "dlv-dap",
"port": 56268,
"host": "127.0.0.1",
"showLog": true,
"trace": "trace",
"cwd": "${workspaceFolder}",
"substitutePath": [
{
"from": "${workspaceFolder}",
"to": "<absolute path>"
}
]
}
]
}
More info at here