Drone

DNS resolution issue with Kubernetes native

Hello,

I’m facing to a strange issue with the last version of Drone with Kubernetes mode.

Here is the simple pipeline :

kind: pipeline
name: default

services:
  - name: nats
    image: nats-streaming
    commands:
      - -cid
      - libmed
  - name: postgres
    image: postgres
    environement:
      POSTGRES_PASSWORD: password
steps:
  - name: build
    image: golang
    environment:
      DB_PASSWORD: password
      DB_NAME: postgres
      DB_HOST: postgres
      NATS_URL: nats://nats:4222
    commands:
      - go build
      - go test

The Drone itself has been of course deployed with :
- name: DRONE_KUBERNETES_ENABLED
value: “true”
- name: DRONE_KUBERNETES_NAMESPACE
value: “drone”
- name: DRONE_KUBERNETES_SERVICE_ACCOUNT
value: “drone”

The services are spawned but when my tests begins :
2019/04/08 18:31:54 connecting to PostgreSQL database
2019/04/08 18:31:54 error when trying to connect to PostgreSQL : dial tcp: lookup postgres on
10.96.0.10:53: no such host

10.96.0.10 is the K8s DNS server.
I’ve I missed something ?

With kubernetes native you need to define ports for your service. See https://docs.drone.io/examples/service/nats/

Good point!

But it seems the syntax has changed :

default: Service "nats" is invalid: [spec.ports[0].name: Required value, spec.ports[1].name: Required value]

With the syntax used in your sample.

I’ve tried with a K8s syntax:

`services:

  • name: nats
    image: nats-streaming
    commands:
    • -cid
    • libmed
      ports:
    • port: 4222
      name: nats
    • port: 8222
      name: monitoring`

But same result.

Not sure, but we have a thread that you can use to help debug issues with the Kubernetes runtime and recommend changes/ improvements. See Contributing to Drone for Kubernetes

The code seems clear.
I will take a look tomorrow.

Thank you.

Thanks! Please let me know what you find and how I can help :slight_smile:

Ok, I’ve checked :

  • drone-yaml code : everything looks good
  • drone-runtime code : everything looks good

The spec.ports[0].name and spec.ports[0].name is well filled via func toService(spec *engine.Spec, step *engine.Step) *v1.Service on util.go.

If I take my .chrono.yml file, I translate them with drone-yaml into a json file and I use this json file through drone-runtime and pointing to my current Kubernetes cluster, everything run fine…

But fail on my drone server deployed with the latest docker image available yesterday.

The only suspect could be the old version of k8s.io/client-go (v9) you use, incompatible with my cluster version (v1.13.4).
The only suggestion I can do is to try to build a a docker version that use k8s.io/client-go v11.0.0 (the last available)…

P.S. This only fail for service(s) that had more than one listen port (because in this case, the port name is mandatory in K8s)

I have the same issue.

Having

services:
  - name: mongo
    image: mongo:4
    command: [--smallfiles]
    ports:
      - 27017
  - name: mailcatcher
    image: schickling/mailcatcher
    ports:
      - name: smtp
        port: 1025
      - name: api
        port: 1080

Mongo service works fine, while mailcatcher fails with

default: Service “mailcatcher” is invalid: [spec.ports[0].name: Required value, spec.ports[1].name: Required value]