Kaptain.
Telegram /
LinkedIn /
Email /
GIT /
RSS /
GPG /
Заказ печатных плат

№ 11971 В разделе
Sysadmin
от April 11th, 2023,
В подшивках: Kubernetes
You have some url to REST API, which processing some DB requests. So you want to separate reading (get) and writing (post) requests because reading is a fast operation using whole DB cluster, and writing may be long and writes only to master DB server. Or just because you have different applications for reading and writing data. This means you have 2 different k8s services with different applications.
In kubernetes you need to create ingress resource with 2 path to 2 services marked as _post and _get, also add rewrite and conditions for every service into annotations.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/configuration-snippet: |
internal;
rewrite ^ $original_uri break;
nginx.ingress.kubernetes.io/server-snippet: |
location /api/file {
if ( $request_method = GET) {
set $target_destination '/api/file/_get';
}
if ( $request_method = POST) {
set $target_destination '/api/file/_post';
}
set $original_uri $uri;
rewrite ^ $target_destination last;
}
name: simple-two-route
namespace: test
spec:
ingressClassName: nginx
rules:
- host: blindage.org
http:
paths:
- backend:
service:
name: service-post
port:
number: 80
path: /api/file/_post
pathType: Exact
- backend:
service:
name: service-get
port:
number: 80
path: /api/file/_get
pathType: Exact
You can divide traffic more by adding more conditions and paths.
Fortune cookie: Sodomy, fellatio, cunnilingus, pederasty, Father, why do these words sound so nasty? -- Hair
Leave a Reply