docker - 使用intellij在kubernetes中远程调试容器
问题描述
我尝试使用 host:192.168.99.100
和 port以附加模式远程调试应用程序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>
这是 pod 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
在 a 中使用 a 的替代方法,Service
您还可以使用它kubectl port-forward
来访问Pod
.
kubectl port-forward
自 Kubernetes v1.10 起,允许使用资源名称(例如 pod 名称)来选择匹配的 pod 进行端口转发。
您需要在 Pod 的 Deployment yaml 中公开调试端口
spec:
containers:
...
ports:
...
- containerPort: 5005
然后通过以下方式获取您的 Pod 的名称
kubectl get pods
然后向该 Pod 添加端口转发
kubectl port-forward podname 5005:5005
在 IntelliJ 中,您将能够连接到
主持人:localhost
港口:5005
推荐阅读
- c# - 如何在 Unity2D 中制作跳跃动画?
- python - 是否可以为 python 创建嵌套的虚拟环境?
- javascript - Javascript vs python:具有两个递归分支的函数的不同输出
- html - 网格内卡片的对齐方式
- php - 使用空间点从 MySQL 获取半径范围内的所有用户
- google-cloud-platform - 如何仅从应用程序向 Cloud Run 发送请求?
- javascript - 如何在同一页面的一个 div 中显示多个链接
- java - 当我运行程序时,Jmenus 没有弹出
- python - Python,jsonpath_ng:异常:在令牌附近 1:4 解析错误?(?)
- r - 使用 igraph 分配网络旅行