0

I'm new in Kubernetes and I have problem with accessing to running service from another machine in my local network. Running minikube on Centos 9 Below are my configurations:

  1. mongo-express.yaml
kind: Deployment
metadata:
  name: mongo-express
  labels:
    app: mongo-express
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo-express
  template:
    metadata:
      labels:
        app: mongo-express
    spec:
      containers:
        - name: mongo-express
          image: mongo-express
          ports:
            - containerPort: 8081
          env:
            - name: ME_CONFIG_MONGODB_ADMINUSERNAME
              valueFrom:
                secretKeyRef:
                  name: mongodb-secret
                  key: mongo-root-username
            - name: ME_CONFIG_MONGODB_ADMINPASSWORD
              valueFrom:
                secretKeyRef:
                  name: mongodb-secret
                  key: mongo-root-password
            - name: ME_CONFIG_MONGODB_SERVER
              valueFrom:
                configMapKeyRef:
                  name: mongodb-configmap
                  key: database_url
---
apiVersion: v1
kind: Service
metadata:
  name: mongo-express-service
spec:
  selector:
    app: mongo-express
  type: NodePort
  ports:
    - protocol: TCP
      port: 8081
      targetPort: 8081
      nodePort: 30000

$ minikube service mongo-express-service command output:

|-----------|-----------------------|-------------|---------------------------|
| NAMESPACE |         NAME          | TARGET PORT |            URL            |
|-----------|-----------------------|-------------|---------------------------|
| default   | mongo-express-service |        8081 | http://192.168.49.2:30000 |
|-----------|-----------------------|-------------|---------------------------|

$ kubectl get service command output:

NAME                    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes              ClusterIP   10.96.0.1        <none>        443/TCP          4d13h
mongo-express-service   NodePort    10.100.148.37    <none>        8081:30000/TCP   3s
mongodb-service         ClusterIP   10.105.122.101   <none>        27017/TCP        2m30s

My network interfaces:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
    link/ether 94:de:80:b8:24:30 brd ff:ff:ff:ff:ff:ff
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 94:de:80:b8:24:30 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.80/24 brd 192.168.0.255 scope global noprefixroute br0
       valid_lft forever preferred_lft forever
    inet6 2601:2c2:502:2f40:d188:581e:2837:cfe7/64 scope global dynamic noprefixroute
       valid_lft 345587sec preferred_lft 345587sec
    inet6 fe80::8763:4506:5db7:afaa/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
4: br-a8f04f55d768: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:f1:0f:7d:cb brd ff:ff:ff:ff:ff:ff
    inet 192.168.49.1/24 brd 192.168.49.255 scope global br-a8f04f55d768
       valid_lft forever preferred_lft forever
    inet6 fe80::42:f1ff:fe0f:7dcb/64 scope link
       valid_lft forever preferred_lft forever

The local ip for minikube host is 192.168.0.80. On host I'm able to ping service 192.168.49.2, but I'm able to ping and access it from any other machine in my local network. Any ideas what I'm doing wrong and how can I fix it.

1 Answers1

0

In order to access to the app you need to use node address and node port, double check your service details and firewall rules:

http://<public-node-ip>:<node-port>

Proceed with the following steps:

  1. Display service information and notice the NodePort value

kubectl describe services mongo-express-service

  1. List the pods running Mongo application

kubectl get pods --selector="YOURSERVICESELECTORMATCHLABEL" --output=wide

  1. Get public IP of one of your nodes running a Mongo pod.

kubectl cluster-info

  1. On your chosen node, create a firewall rule that allows TCP traffic on your node port. For example, if your Service has a NodePort value of 31568, create a firewall rule that allows TCP traffic on port 31568

  2. Finally access with the URL as stated at the beginning:

curl http://<public-node-ip>:<node-port>

Note: Cluster IPs differ than addresses in Network interfaces

jmvcollaborator
  • 2,141
  • 1
  • 6
  • 17
  • This steps still not fixed issue. I can access to service UI (http://192.168.49.2:30000) from host (192.168.0.80) but cannot from any other machine in my local network. The firewall rule for port 30000 added. – Hasan Humbatov May 19 '23 at 19:08