流程:
客户端访问--->ingress七层代理---->service四层代理---->deployment
详细情况:https://www.cnblogs.com/yangmeichong/p/17664552.html
1.Ingress七层代理
---可在其基础上添加灰度发布
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-myapp
namespace: default
# 注解:可能其它版本不能用,1.25版本换方法
#annotations:
# 将创建的ingress规则交给ingress-nginx-controller这2个pod
# kubernetes.io/ingress.class: "nginx"
spec:
# 代替上面的注解
ingressClassName: nginx
rules:
- host: tomcat.lucky.com
http:
paths:
- backend:
service:
name: tomcat
port:
number: 8080
path: /
pathType: Prefix
2.service四层代理
apiVersion: v1
kind: Service
metadata:
name: tomcat
namespace: default
spec:
selector:
app: tomcat
release: canary
ports:
- name: http
targetPort: 8080
port: 8080
- name: ajp
targetPort: 8009
port: 8009
3.deployment控制器
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-deploy
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: tomcat
release: canary
template:
metadata:
labels:
app: tomcat
release: canary
spec:
containers:
- name: tomcat
image: tomcat:8.5.34-jre8-alpine
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 8080
name: ajp
containerPort: 8009