React Native and Kubernetes

32 Views Asked by At

Having this Kubernetes configuration, trying to hit the endpoint sanction.dev from React Native Android and iOS simulators but unsuccessful. Getting the: Network error

apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: auth
  template:
    metadata:
      labels:
        app: auth
    spec:
      containers:
        - name: auth
          image: dockerhub/sanction-auth
---
apiVersion: v1
kind: Service
metadata:
  name: auth-srv
spec:
  selector:
    app: auth
  ports:
    - name: auth
      port: 3000
      targetPort: 3000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
  rules:
    - host: sanction.dev
      http:
        paths:
          - path: /api/auth/?(.*)
            pathType: ImplementationSpecific
            backend:
              service:
                name: auth-srv
                port:
                  number: 3000

And this is my /etc/hosts mapping:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
# 127.0.0.1     localhost
255.255.255.255 broadcasthost
::1             localhost

127.0.0.1 sanction.dev

What is the reason React Native cannot hit the Kubernetes endpoint?

1

There are 1 best solutions below

0
bitcloud On

The Problem is that an android simulator simulates the full system in an virtual environment. So it is a VM with its own network context and its own 127.0.0.1.

I guess that you want to access the host computer which is running a kubernetes cluster and the simulator as well. To make that possible you need to configure the ip of the host system in the android vm.

There are a couple of methods to choose from:

  • You could simply use the external IP address of you host system running the kubernetes cluster.
  • You could use the ip of the host system of the virtual network connecting the simulator to the host system. A quick google search indicates that 10.0.2.2 should be the IP address of the host system if you want to reach it in the simulator
  • using adb you could add a tunnel in the android simulator to tunnel localhost connections to a host port e.g. adb reverse tcp:3000 tcp:3000

Concerning ios, it seems that the ios simulator uses the host system network directly, so localhost should be possible.

In both cases, you should verify that the exposed service is accessible on the host system itself before trying to access it from inside a simulated environment.