You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

K8s集群中无法连接Android模拟器Pod的5555端口问题排查

问题解决:Kubernetes中Android模拟器5555端口仅localhost可访问的问题

问题描述

在Kubernetes集群的test命名空间部署了包含Android模拟器的Pod,模拟器容器暴露5555端口用于adb连接,但出现以下异常:

  • Pod IP为172.30.113.239,从集群内其他Pod或本Pod使用该IP访问5555端口时,均提示连接拒绝
  • 同Pod内另一个容器的8000端口可正常访问
  • 仅在模拟器容器内使用localhost访问5555端口才能成功

Deployment配置片段:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/managed-by: Helm
    service: android-emulator
  name: android-emulator
  namespace: test
spec:
  replicas: 1
  selector:
    matchLabels:
      service: android-emulator
  template:
    metadata:
      labels:
        service: android-emulator
    spec:
      containers:
      - command:
        - /bin/sh
        - -c
        - cd /opt/android-sdk-linux;emulator -avd avd30 -no-window  -memory 4096 -cores
          4;sleep 99999
        env:
        - name: resources
          value: 4c4Gig8Gis
        image: test/android30:v1.1.0
        imagePullPolicy: IfNotPresent
        name: android-emulator
        securityContext:
          privileged: true
        ports:
        - containerPort: 5555
          protocol: TCP     
      - env:
        - name: resources
          value: 2c4Gig8Gis
        - name: serviceName
          value: scrcpy
        image: test/scrcpy-web:1.0.0
        imagePullPolicy: IfNotPresent
        name: testtest-android-emulator-scrcpy
        ports:
        - containerPort: 8000
          protocol: TCP
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      terminationGracePeriodSeconds: 30

问题根源

Android模拟器默认会将adb服务绑定到127.0.0.1(仅本地回环地址),导致只能在容器内部通过localhost访问,无法通过容器IP或外部Pod访问。

解决方案

修改Android模拟器的启动命令,添加-adb-host 0.0.0.0参数,让adb服务监听容器的所有网卡地址:

更新Deployment中android-emulator容器的command字段:

command:
- /bin/sh
- -c
- cd /opt/android-sdk-linux;emulator -avd avd30 -no-window -memory 4096 -cores 4 -adb-host 0.0.0.0;sleep 99999

验证步骤

  1. 应用更新后的Deployment:
kubectl apply -f your-deployment.yaml -n test
  1. 等待Pod重启完成后,从同Pod的另一个容器执行:
telnet 172.30.113.239 5555

或者从集群内其他Pod执行:

adb connect 172.30.113.239:5555

确认连接成功。

额外排查点

如果添加-adb-host 0.0.0.0后仍无法访问,可检查:

  • 容器内是否有防火墙规则限制5555端口
  • 模拟器启动后是否正确加载该参数,进入容器查看进程命令:
kubectl exec -it <pod-name> -c android-emulator -n test -- ps aux | grep emulator

内容的提问来源于stack exchange,提问作者mosakashaka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 21:27:40