0

I have a simple setup of 2 containers, one for configuration and one for gateway.

Below is the definitions of service and deployments. They get created fine but the gateway container isn't able to connect to the http://configuration:8888 and throws unknown host error.

The configuration server is running Nginx on port 8888.

I am able to access the configuration from a browser with URL http://configuration/actuator/.

I thought the pods in Kubernetes should be able to communicate fine as long as they are in the same network (host here). Not sure what is missing here.

apiVersion: v1
items:
- apiVersion: v1
  kind: Service
  metadata:
    name: configuration
  spec:
    ports:
    - port: 8888
      targetPort: 8888
    selector:
      app: configuration
  status:
    loadBalancer: {}
- apiVersion: apps/v1
  kind: Deployment
  metadata:
    labels:
      app: configuration
    name: configuration
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: configuration
    strategy:
      type: Recreate
    template:
      metadata:
        labels:
          app: configuration
      spec:
        hostNetwork: true
        containers:
        - env:
          - name: JVM_OPTS
            value: -Xss512k -XX:MaxRAM=128m
          image: <image>
          name: configuration
          resources: {}
          volumeMounts:
          - mountPath: /data
            name: configuration-claim0
        restartPolicy: Always
        volumes:
        - name: configuration-claim0
          persistentVolumeClaim:
            claimName: configuration-claim0
  status: {}
- apiVersion: apps/v1
  kind: Deployment
  metadata:
    labels:
      app: gateway
    name: gateway
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: gateway
    strategy:
      type: Recreate
    template:
      metadata:
        labels:
          app: gateway
      spec:
        hostNetwork: true
        containers:
        - env:
          - name: JVM_OPTS
            value: -Xss512k -XX:MaxRAM=128m
          **- name: SPRING_CLOUD_CONFIG_URI
            value: http://configuration:8888**
          - name: SPRING_PROFILES_ACTIVE
            value: container
          image: <image>
          name: gateway
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
sg1973
  • 91
  • 6

1 Answers1

0

You are using:
hostNetwork: true

So you can reference the service using: http://localhost:8888.

Otherwise, remove hostNetwork: true

Marco Caberletti
  • 1,353
  • 1
  • 10
  • 13