nginx - Kubernetes 中的 SPRING_CLOUD_CONFIG_URI 设置
问题描述
我有 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
解决方案
您正在使用:
hostNetwork: true
因此,您可以使用以下方式引用该服务:http://localhost:8888
。
否则,删除hostNetwork: true
推荐阅读
- javascript - Ngrx 存储已更新但未显示
- node.js - GhostScript - 在将 Microsoft Print 转换为 PDF 文件时,ImageMagick 将 pdf 转换为图像到奇数字母
- javascript - 检测浏览器和版本 - 没有 Modernizr
- mysql - 从右表结果中获取多维数组
- android - Kotlinx Parcelize 类扩展
- inno-setup - 可执行文件不会执行
- elasticsearch - Apache Nifi - 联合搜索
- c# - 通过特定的电子邮件提供商/ Infusionsoft 通过 C# SDK 发送电子邮件
- c# - WPF - 在选项卡更改之前在选项卡中的当前活动元素上触发“LostFocus”
- javascript - 如何仅从 ISO 格式中获取日期的时间