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?
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:
adb reverse tcp:3000 tcp:3000Concerning 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.