gpt4 book ai didi

spring-boot - Minikube springboot收到请求并且无法正确响应

转载 作者:行者123 更新时间:2023-12-02 12:34:12 24 4
gpt4 key购买 nike

我从kubernetes和docker开始,并面临一个问题。

在将其转换为docker镜像(使用minikube的docker)后,在minikube上部署了springboot应用程序。该应用程序处于在线状态,正在接收请求,正如您在以下屏幕截图中所见,但未按预期进行答复。

例如,当我正常部署该应用程序时(像往常一样在我的计算机上)一切正常,我可以在所有html页面上运行,但是一旦部署到minikube中,它就无法正确答复。 (所有的工作部分都是 Spring 的图标的接收)

用于部署应用程序的YAML:

apiVersion: apps/v1
kind: Deployment
metadata:
name: esse-deployment-1
labels:
app: esse
spec:
replicas: 1
selector:
matchLabels:
app: esse-1
template:
metadata:
labels:
app: esse-1
spec:
containers:
- image: mysql:5.7
name: esse-datasource
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: esse_password
- image: esse_application
name: esse-app-1
imagePullPolicy: Never
ports:
- containerPort: 8080
volumes:
- name: esse-1-mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-persistent-storage-claim
---

apiVersion: v1
kind: Service
metadata:
name: esse-service-1
spec:
selector:
app: esse-1
ports:
- protocol: TCP
port: 8080
type: NodePort

----

kind: PersistentVolume
apiVersion: v1
metadata:
name: mysql-persistent-storage
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/home/docker/data"

---

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mysql-persistent-storage-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 200Mi

Docker文件构造镜像:
FROM openjdk:8
ADD ESSE_Application.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

App log
Result in brower

最佳答案

我可以看到您有.yml文件来定义部署和服务,但是看不到“Ingress”。为了告诉kubernetes应该有一个指向您服务的外部url,需要一个kind: Route的.yml文件。一个最小的Ingress资源示例:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: test
servicePort: 80

**请不要从字面上理解此代码,我只是想在此处草拟一些示例代码,可能与您的命名/数据不完全匹配:)

关于spring-boot - Minikube springboot收到请求并且无法正确响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57255738/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com