使用intellij的kubernetes中的远程调试容器

时间:2018-12-18 15:42:18

标签: docker intellij-idea kubernetes

我尝试使用主机@include('emails.table', [ __('order.reference') => $order->reference, __('order.total') => @price($order->total), ]) 和端口192.168.99.100以附加模式远程调试应用程序,但是它告诉我它是5005。 IP为unable to open the debugger port(集群通过minikube在本地托管)。

192.268.99.100的输出

kubectl describe service catalogservice

这是pods service.yml:

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>

在这里,我暴露了容器端口

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

3 个答案:

答案 0 :(得分:3)

除了在request.PATH_INFO中使用NodePort之外,还可以使用kubectl port-forward访问Service中的调试端口。

Pod允许使用资源名称(例如Pod名称)来选择匹配的Pod,以将其移植到Kubernetes v1.10以后的版本。

您需要在Pod的Deployment Yaml中公开调试端口

kubectl port-forward

然后通过获取您的Pod的名称

spec:
  containers:
    ...
    ports:
      ...
      - containerPort: 5005

,然后向该Pod添加端口转发

kubectl get pods

在IntelliJ中,您将可以连接到

主持人:kubectl port-forward podname 5005:5005

端口:localhost

答案 1 :(得分:1)

或者,您可以使用Code Cloud Intellij插件。 另外,如果您使用Fabric8,它会提供fabric8:debug目标。

答案 2 :(得分:0)

您最初发布为的Yaml出现了滑动:

    - containerPort: 5050
      name: debug

应该是:

    - containerPort: 5005
      name: debug

在配置IntelliJ调试器时,您还需要使用32003的外部端口。通过这些更改,它应该可以工作。

您可能还想考虑如何使其更加灵活。在过去的when I've done this中,我使用了一个不同的form for the docker start command,它允许您通过一个名为REMOTE_DEBUG的环境变量来打开和关闭远程调试,对于您来说,它是:

CMD if [ "x$REMOTE_DEBUG" = "xfalse" ] ; then java $JAVA_OPTS -jar catalogservice-0.0.1-SNAPSHOT.jar ; else java $JAVA_OPTS -agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n -jar catalogservice-0.0.1-SNAPSHOT.jar ; fi

您可能会发现自己想set the env var $JAVA_OPTS来限制JVM内存的使用以避免issues in k8s

相关问题