0

我有 2 个容器的简单设置,一个用于配置,一个用于网关。

下面是服务和部署的定义。它们创建得很好,但网关容器无法连接到http://configuration:8888并引发未知主机错误。

配置服务器在端口上运行 Nginx 8888

我可以从带有 URL 的浏览器访问配置http://configuration/actuator/

我认为 Kubernetes 中的 pod 应该能够很好地通信,只要它们在同一个网络中(这里是主机)。不确定这里缺少什么。

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
4

1 回答 1

0

您正在使用:
hostNetwork: true

因此,您可以使用以下方式引用该服务:http://localhost:8888

否则,删除hostNetwork: true

于 2021-11-12T11:52:52.423 回答