gpt4 book ai didi

docker - 使用 intellij 在 kubernetes 中远程调试容器

转载 作者:行者123 更新时间:2023-12-04 16:04:07 24 4
gpt4 key购买 nike

我尝试使用主机以附加模式远程调试应用程序:192.168.99.100和端口 5005 ,但它告诉我它是 unable to open the debugger port . IP是192.268.99.100 (集群通过 minikube 在本地托管)。
kubectl describe service catalogservice 的输出

Name:                     catalogservice
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=catalogservice
Type: NodePort
IP: 10.98.238.198
Port: web 31003/TCP
TargetPort: 8080/TCP
NodePort: web 31003/TCP
Endpoints: 172.17.0.6:8080
Port: debug 5005/TCP
TargetPort: 5005/TCP
NodePort: debug 32003/TCP
Endpoints: 172.17.0.6:5005
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>

这是 pods service.yml:
apiVersion: v1
kind: Service
metadata:
name: catalogservice
spec:
type: NodePort
selector:
app: catalogservice
ports:
- name: web
protocol: TCP
port: 31003
nodePort: 31003
targetPort: 8080
- name: debug
protocol: TCP
port: 5005
nodePort: 32003
targetPort: 5005

在这里我公开了容器端口
spec:
containers:
- name: catalogservice
image: elps/myimage
ports:
- containerPort: 8080
name: app
- containerPort: 5005
name: debug

我构建图像的方式:
FROM openjdk:11
VOLUME /tmp
EXPOSE 8082
ADD /target/catalogservice-0.0.1-SNAPSHOT.jar catalogservice-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n", "-jar", "catalogservice-0.0.1-SNAPSHOT.jar"]

当我执行 nmap -p 5005 192.168.99.100我收到
PORT     STATE  SERVICE
5005/tcp closed avt-profile-2

当我执行 nmap -p 32003 192.168.99.100我收到
PORT     STATE  SERVICE
32003/tcp closed unknown

当我执行 nmap -p 31003 192.168.99.100我收到
PORT     STATE  SERVICE
31003/tcp open unknown

当我执行 kubectl get services我收到
NAME              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                          AGE
catalogservice NodePort 10.108.195.102 <none> 31003:31003/TCP,5005:32003/TCP 14m
minikube service customerservice --url返回
http://192.168.99.100:32004

最佳答案

作为使用 NodePort 的替代方法在 Service您也可以使用 kubectl port-forward 访问您的 Pod 中的调试端口.

kubectl port-forward allows using resource name, such as a pod name, to select a matching pod to port forward to since Kubernetes v1.10.



您需要在部署 yaml 中为 Pod 公开调试端口
spec:
containers:
...
ports:
...
- containerPort: 5005

然后通过以下方式获取您的 Pod 的名称
kubectl get pods

然后向该 Pod 添加端口转发
kubectl port-forward podname 5005:5005

在 IntelliJ 中,您将能够连接到

主持人: localhost
端口: 5005

关于docker - 使用 intellij 在 kubernetes 中远程调试容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53836493/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com