1

I've got an InfluxDB as database service in the default namespace. It's service is called influxdb and works fine with chronograf to visualize the data.

Now i'd like to connect with an other deployment from the namspace test to this service. It's a python application. The normal python Influxdb Lib uses Requests to connect to the db.

Architecture Overview

Istio is also installed.

Namspace: Default

  • Influxdb Deployment
  • Influxdb Service
  • Chronograf Deployment (visualise influxdb)
  • Chronograf Service to Ingress(for external web access)

Namespace: test

  • Python App which should connect to influxdb for processing etc.
  • Influxdb Service (which points to influxdb.default.svc.cluster.local)

Therefore i created a service in the Namespace test which points to the service of influxdb in the default namespace.

apiVersion: v1
kind: Service
metadata:
  name: influxdb
  labels:
    app: pythonapp
  namespace: test
spec:
  type: ExternalName
  externalName: influxdb.default.svc.cluster.local
  ports:
    - port: 8086
      name: http
    - port: 8088
      name: http-flux

And now deployed the python app which points to the influxdb Service. Which keeps getting a http connection error.

2020-07-03 13:02:05 - db.meterdb [meterdb.__init__:57] - ERROR - Oops, something wen't wrong during init of db. message: HTTPConnectionPool(host='influxdb', port=8086): Max retries exceeded with url: /query?q=SHOW+DATABASES (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6863ed6310>: Failed to establish a new connection: [Errno 111] Connection refused'))
2020-07-03 13:02:05 - db.meterdb [meterdb.check_connection:113] - ERROR - can't reach db server... message: HTTPConnectionPool(host='influxdb', port=8086): Max retries exceeded with url: /ping (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6863e57650>: Failed to establish a new connection: [Errno 111] Connection refused'))

When I visualise the traffic with kiali I see, that the Python app tries to connect to the influxdb service, but which is unknown with http traffic.

I don't know how to get it work to use the created influxdb Service.

Connection settings for python influxdb Client library. Link to python influxdb lib

  • host=influxdb
  • port=8086

Traffic from Kiali

How can i route the traffik to the right service ? It seems to me, that it routes the traffik to an unknown service because it's http and not tcp.

1 Answers1

2

You don't need the

kind: Service
metadata:
  name: influxdb
  labels:
    app: pythonapp
  namespace: test

Just access the service directly in your python request:

requests.get('influxdb.default.svc.cluster.local:8086')

And this can be more configurable.

# Kubernetes deployment
      containers:
      - name: pythonapp
        env:
        - name: DB_URL
          value: influxdb.default.svc.cluster.local:8086
# python
DB = os.environ['DB_URL']
requests.get(DB)
RammusXu
  • 1,180
  • 1
  • 7
  • 21
  • Thanks for the answer. this solved my problem. Leave the Service away and directly point to the influxdb in the default namespace. – David Stäheli Jul 06 '20 at 06:44