按照迁移服务至k8s章节的内容尝试了前端静态资源和动态服务单独服务用ingress代理都能够正常访问,
之后尝试两个服务的ingress合在一起以path区分代理,path: / 是代理到前端静态web 另一个path:/corpApi 是代理到eureka服务。
apply之后前端仍能够正常访问,但是后端的eureka管理页面无法正常显示报错Whitelabel Error Page。
看报错应该也是代理到了eureka服务里但是没显示出正常访问 / 的服务监控情况页面。
另外还有一个问题,如果spring-boot服务使用eureka或者nacos作为微服务注册中心,那原先服务是使用eureka服务器的IP和端口作为key:eureka.client.service-url.defaultZone的值,在k8s体系内是仍然使用域名+/path的方式来访问还是可以直接用service直接内部转发?
#eureka-deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: eureka-server
spec:
selector:
matchLabels:
app: eureka-server
replicas: 1
template:
metadata:
labels:
app: eureka-server
spec:
containers:
- name: eureka-server
image: 10.5.118.197/kubernetes/eureka-server:latest
ports:
- containerPort: 8888
---
#eureka-service
apiVersion: v1
kind: Service
metadata:
name: eureka-server
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8888
selector:
app: eureka-server
type: ClusterIP
---
#pcbook-deploy
apiVersion: apps/v1
kind: Deployment
metadata:
name: pcbook
spec:
selector:
matchLabels:
app: pcbook
replicas: 2
template:
metadata:
labels:
app: pcbook
spec:
containers:
- name: pcbook
image: 10.5.118.197/kubernetes/pcbook:latest
imagePullPolicy: Always
ports:
- containerPort: 80
---
#pcbook-service
apiVersion: v1
kind: Service
metadata:
name: pcbook
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: pcbook
type: ClusterIP
---
#ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-nginx
spec:
rules:
- host: springboot.test.com
http:
paths:
- path: /
backend:
serviceName: pcbook
servicePort: 80
- path: /corpApi
backend:
serviceName: eureka-server
servicePort: 80