Running android container over GKE - adb is not attached to device

8/2/2019

I'm trying to run android emulator container, over GKE. For this, I'm using budtmo/docker-android open source.

First, I tried to run it locally over docker:

$ sudo  docker run --privileged -d -p 6080:6080 -p 5554:5554 -p 4723:4723 -p 5555:5555 -e DEVICE="Samsung Galaxy S6" --name android-container budtmo/docker-android-x86-8.1

Then I connected to the device, using:

$ adb connect localhost:5555

And I saw the device:

>> $ adb devices
List of devices attached
localhost:5555  device

works great!

Now I'm trying to do same thing over GKE:

This is the pod:

apiVersion: v1
kind: Pod
metadata:
  name: android
  labels:
    app: android
spec:
  containers:
  - name: android
    image: budtmo/docker-android-x86-8.1
    securityContext:
      privileged: true   
    ports:
    - containerPort: 6080
    - containerPort: 5554
    - containerPort: 5555
    - containerPort: 4723
    env:
    - name: DEVICE
      value: "Samsung Galaxy S6"

This is the service:

apiVersion: v1
kind: Service
metadata:
  name: android-service
spec:
  ports:
  - port: 6080
    name: serving
    protocol: TCP
  - port: 5555
    name: srv
    protocol: TCP
  - port: 5554
    name: srv2
    protocol: TCP
  - port: 4723
    name: novnc
    protocol: TCP
  selector:
    app: android
  type: LoadBalancer
  loadBalancerIp: "35.X.X.X"

Then I'm trying to connect to the emulator (from my computer), but after it claims it connected, I don't see any devices attached :

>> $ adb connect 35.X.X.X:5555
connected to 35.X.X.X:5555
>> $ adb devices
List of devices attached
*empty*

I also tried to connect locally from the GKE terminal:

adb connect 35.X.X.X:5555
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
connected to 35.X.X.X:5555

Then again:

>> $ adb devices
List of devices attached
*empty*     

Any idea what is the problem, and how can I fix it?

-- Yagel
adb
android
google-cloud-platform
google-kubernetes-engine
kubernetes

1 Answer

8/9/2019

Reproduced your steps with the only difference: I havent specified loadBalancerIp under service:

---
apiVersion: v1
kind: Pod
metadata:
  name: android
  labels:
    app: android
spec:
  containers:
  - name: android
    image: budtmo/docker-android-x86-8.1
    securityContext:
      privileged: true
    ports:
    - containerPort: 6080
    - containerPort: 5554
    - containerPort: 5555
    - containerPort: 4723
    env:
    - name: DEVICE
      value: "Samsung Galaxy S6"

---
apiVersion: v1
kind: Service
metadata:
  name: android-service
spec:
  ports:
  - port: 6080
    name: serving
    protocol: TCP
  - port: 5555
    name: srv
    protocol: TCP
  - port: 5554
    name: srv2
    protocol: TCP
  - port: 4723
    name: novnc
    protocol: TCP
  selector:
    app: android
  type: LoadBalancer

Result is everything works as expected with provided yaml:

kubectl get po,svc
NAME          READY   STATUS    RESTARTS   AGE
pod/android   1/1     Running   0          14m

NAME                      TYPE           CLUSTER-IP   EXTERNAL-IP     PORT(S)                                                       AGE
service/android-service   LoadBalancer   10.0.1.238   *.*.*.54   6080:31952/TCP,5555:30822/TCP,5554:30806/TCP,4723:30248/TCP   14m

From local pc:

adb connect *.*.*.54:5555
already connected to *.*.*.54:5555

adb devices
List of devices attached
*.*.*.54:5555   offline
emulator-5554   device
localhost:5555  device
-- VKR
Source: StackOverflow