我正在尝试创建一个垂直复制的服务-

在这个体系结构中,请求转到主节点。为此,我可以用库伯内特斯的入口。
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: example.com
http:
paths:
- path: /
backend:
serviceName: master-node
servicePort: http现在,我的要求是,如果主被关闭,那么请求应该转到从节点。我可以通过创建三条路径/master、/slave-1、/slave-2来实现这一点。但是约束条件是请求路径必须保持相同的。因此,路径必须始终是/。
如何创建一个入口,如果master-node关闭,那么所有请求都应该转发给slave-1-node。
我想实现以下的目标-
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: example.com
http:
paths:
- path: /
priority: 1
backend:
serviceName: master-node
servicePort: http
- host: example.com
http:
paths:
- path: /
priority: 2
backend:
serviceName: slave-1-node
servicePort: http
- host: example.com
http:
paths:
- path: /
priority: 3
backend:
serviceName: slave-2-node
servicePort: http发布于 2022-10-08 13:24:42
我不知道如何使用入口资源来完成这一任务,但是如果您在服务前面部署了一个haproxy吊舱,那么您的体系结构就会像这样:

使用像这样的want配置,您将得到您想要的行为:
global
log stdout format raw local0
maxconn 4000
user haproxy
group haproxy
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout connect 10s
timeout client 1m
timeout server 1m
frontend example_fe
bind 0.0.0.0:8080
default_backend example_be
backend example_be
option httpchk GET /healthz
server alpha example-alpha:80 check
server beta example-beta:80 check backup
server gamma example-gamma:80 check backup这将向alpha发送所有请求,只要它运行。如果alpha脱机,请求将转到beta,如果beta没有运行,请求将转到gamma。我发现这篇文章在寻找关于如何设置它的信息时很有用。
您可以创建运行haproxy的部署:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: haproxy
name: haproxy
spec:
replicas: 1
selector:
matchLabels:
app: haproxy
template:
metadata:
labels:
app: haproxy
spec:
containers:
- image: docker.io/haproxy:latest
name: haproxy
ports:
- containerPort: 8080
name: http
volumeMounts:
- mountPath: /usr/local/etc/haproxy
name: haproxy-config
volumes:
- configMap:
name: haproxy-config-ddc898c5f5
name: haproxy-config指向该部署的服务:
apiVersion: v1
kind: Service
metadata:
labels:
app: haproxy
name: haproxy
spec:
ports:
- name: http
port: 80
targetPort: http
selector:
app: haproxy然后把母老虎指向那个服务处:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example
spec:
rules:
- host: example.com
http:
paths:
- backend:
service:
name: haproxy
port:
name: http
path: /
pathType: Prefix如果您想尝试这一点的话,我已经组装了一个完整的配置这里。
https://stackoverflow.com/questions/73996233
复制相似问题