我为httpd pod创建了nodeport服务,为tomcat pod创建了cluster IP服务,它们位于nginx LB后面的相同名称空间中。当http和tomcat服务不是同一类型时,应用程序会出现一个奇怪的问题。当我将两者都更改为cluster IP或者都更改为NodePort时,一切都会正常工作……
流量是这样的:
HTTP and HTTPS traffic -> LB -> Ingress -> Httpd -> Tomcat
HTTPS virtual host custom port traffic -> LB -> Tomcat
TCP traffic -> LB -> Tomcat
在HTTPD和Tomcat之间有什么问题吗?尽管我可以从外部telnet到httpd和tomcat pod,但是由于某些原因,应用程序的功能中断了(一些静态和jsp页面会被处理)。
httpd-service:
apiVersion: v1
kind: Service
metadata:
name: httpd
labels:
app: httpd-service
namespace: test-web-dev
spec:
type: NodePort
selector:
app: httpd
ports:
- name: port-80
port: 80
protocol: TCP
targetPort: 80
- name: port-443
port: 443
protocol: TCP
targetPort: 443
sessionAffinity: "ClientIP"
sessionAffinityConfig:
clientIP:
timeoutSeconds: 10800
externalTrafficPolicy: Localtocmat-service:
apiVersion: v1
kind: Service
metadata:
name: tomcat7
namespace: test-web-dev
annotations:
spec:
selector:
app: tomcat7 # Metadata label of the deployemnt pod template or pod metadata label
ports:
- name: port-8080 # Optional when its just only one port
protocol: TCP
port: 8080
targetPort: 8080
- name: port-8262
protocol: TCP
port: 8262
targetPort: 8262
sessionAffinity: "ClientIP"
sessionAffinityConfig:
clientIP:
timeoutSeconds: 10800入口lb:
apiVersion: v1
kind: ConfigMap
metadata:
name: tcp-services
namespace: ingress-nginx
data:
1234: "test-web-dev/httpd:1234"
8262: "test-web-dev/tomcat7:8262"
---
apiVersion: v1
kind: Service
metadata:
name: ingress-nginx
namespace: ingress-nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
spec:
externalTrafficPolicy: Local
type: LoadBalancer
selector:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
ports:
- name: http
port: 80
protocol: TCP
targetPort: http
- name: https
port: 443
protocol: TCP
targetPort: https
- name: port-1234
port: 1234
protocol: TCP
targetPort: 1234
- name: port-8262
port: 8262
protocol: TCP
targetPort: 8262发布于 2020-12-16 11:05:40
回答我自己的问题。
当服务需要暴露在集群之外时,如因特网,需要NodePort服务。
当服务需要像前端到后端那样进行内部通信时,就会使用ClusterIP服务。
在我的例子中,用户需要从外部连接到httpd和tomcat (特定的应用程序端口),因此tomcat和httpd都必须是nodeport类型的服务。配置tomcat has集群IP将中断应用程序,因为无法从互联网访问tomcat应用程序端口。
https://stackoverflow.com/questions/65272950
复制相似问题