我是Kubernetes和kubectl的新手。我基本上是在我的本地主机上运行一个GRPC服务器。我想在我的mac上使用kubectl在kubernetes上运行的spring启动应用程序中使用这个端点。如果我在application.yml中设置以下配置并在kubernetes中运行,它将无法工作。如果我在IDE中运行,也可以使用相同的配置。
grpc:
client:
local-server:
address: static://localhost:6565
negotiationType: PLAINTEXT我看到一些人建议使用port-forward,但情况正好相反(当我想从localhost使用kubernetes中已经存在的端口时,它就像tomcat服务器从localhost上的浏览器运行在kubernetes中一样)。
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。
发布于 2019-10-17 18:06:37
我们可以使用minikube命令minikube ssh "route -n | grep ^0.0.0.0 | awk '{ print \$2 }'"获取vmware主机ip。对我来说,它是Mac上的10.0.2.2。如果在Docker for mac上使用Kubernetes,那么它是host.docker.internal。
通过使用这些命令,我设法从kubernetes连接到主机上运行的服务。
发布于 2019-09-28 00:41:38
1)在您的application.properties定义中
server.port=80002)创建Dockerfile
# Start with a base image containing Java runtime (mine java 8)
FROM openjdk:8u212-jdk-slim
# Add Maintainer Info
LABEL maintainer="vaquar.khan@gmail.com"
# Add a volume pointing to /tmp
VOLUME /tmp
# Make port 8080 available to the world outside this container
EXPOSE 8080
# The application's jar file (when packaged)
ARG JAR_FILE=target/codestatebkend-0.0.1-SNAPSHOT.jar
# Add the application's jar to the container
ADD ${JAR_FILE} codestatebkend.jar
# Run the jar file
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/codestatebkend.jar"]3)确保docker工作正常
docker run --rm -p 8080:8080 4)
使用以下命令查找实例名称
kubectl get pods 然后
kubectl port-forward <pod-name> 8080:8080有用的链接:
https://stackoverflow.com/questions/58137971
复制相似问题