【发布时间】:2020-01-27 23:34:20
【问题描述】:
我是 Kubernetes 和 kubectl 的新手。我基本上在我的本地主机中运行 GRPC 服务器。我想在我的 mac 上使用 kubectl 在 kubernetes 上运行的 spring boot 应用程序中使用这个端点。如果我在 application.yml 中设置以下配置并在 kubernetes 中运行,它不起作用。如果我在 IDE 中运行,相同的配置也可以工作。
grpc:
client:
local-server:
address: static://localhost:6565
negotiationType: PLAINTEXT
我看到有些人建议端口转发,但它是相反的(当我想使用本地主机中已经存在于 kubernetes 中的端口时,它可以工作,就像从本地主机上的浏览器在 kubernetes 中运行的 tomcat 服务器一样)
apiVersion: apps/v1
kind: Deployment
metadata:
name: testspringconfigvol
labels:
app: testspring
spec:
replicas: 1
selector:
matchLabels:
app: testspringconfigvol
template:
metadata:
labels:
app: testspringconfigvol
spec:
initContainers:
# taken from https://gist.github.com/tallclair/849601a16cebeee581ef2be50c351841
# This container clones the desired git repo to the EmptyDir volume.
- name: git-config
image: alpine/git # Any image with git will do
args:
- clone
- --single-branch
- --
- https://github.com/username/fakeconfig
- /repo # Put it in the volume
securityContext:
runAsUser: 1 # Any non-root user will do. Match to the workload.
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
volumeMounts:
- mountPath: /repo
name: git-config
containers:
- name: testspringconfigvol-cont
image: username/testspring
ports:
- containerPort: 8080
volumeMounts:
- mountPath: /usr/local/lib/config/
name: git-config
volumes:
- name: git-config
emptyDir: {}
简单来说我需要什么:
在我的本地主机中有一些服务器的端口:
localhost:6565、localhost:6566,我需要在我的 kubernetes 中以某种方式访问这些端口。那么我应该在 application.yml 配置中设置什么?会不会是一样的localhost:6565、localhost:6566 或how-to-get-this-ip:6565、how-to-get-this-ip:6566。
【问题讨论】:
-
抱歉,哪个
localhost?物理主机本身、Mac 或 Minikube VM 的 Docker 和 pod 各自单独路由localhost到它们自己,所以说某些东西在“本地主机上”运行是非常含糊的。 (相应地,localhost上的 pod 外调用将返回到 pod,而不是其他任何地方。) -
grpc 服务器位于物理主机上,可在端口 6565 和 6566 上使用。我正在尝试从 minikube 中的 pod 访问它们。上面配置中的地址值我没有改过。
-
所以基本上我试图从 minikube 内部访问在主机操作系统上运行的服务。 @大卫迷宫
标签: spring-boot docker kubernetes localhost portforwarding