Skip to content

Commit

Permalink
trying proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
ivukotic committed Dec 11, 2023
1 parent 3299b70 commit c168422
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dask_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ kubernetes:
- scheduler
- --port
- "8786"
- -bokeh-prefix
- daskboard
- --bokeh-port
- "8787"
resources:
Expand Down
80 changes: 80 additions & 0 deletions kube/nginx_proxy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
data:
nginx.conf: |
user nginx;
worker_processes 2;
error_log /var/log/nginx/error.log;
events {
worker_connections 10240;
}
http {
server {
listen 8080;
server_name localhost;
location ^~ /daskboard/ {
proxy_pass http://<dask-scheduler>:8787;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 86400;
}
}
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: n4dask
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 8080
volumeMounts:
- name: nginx-conf
mountPath: /etc/nginx # mount nginx-conf volume to /etc/nginx
resources:
requests:
cpu: "1"
memory: "1Gi"
limits:
cpu: "2"
memory: "2Gi"
volumes:
- name: nginx-conf
configMap:
name: nginx-conf
---
apiVersion: v1
kind: Service
metadata:
name: n4dask
spec:
type: NodePort
ports:
- port: 80
targetPort: 8080
nodePort: 30001
selector:
app: nginx
36 changes: 36 additions & 0 deletions kube/tests/foo.vtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
varnishtest "Testing URL rewriting, for real"

server s1 {
# rxreq
# txresp
# expect req.url == "/content/articles/my_post.html"

rxreq
txresp
expect req.url == "/servicexxx.af-jupyter/status"
} -start

varnish v1 -vcl+backend {

import std;
sub vcl_recv {

if (req.url ~ "/cmsa/post/") {
set req.url = regsuball(req.url, "/cmsa/post/", "/content/articles/");
}
if (req.url ~ "/dask-service/") {
set req.http.x-fuck = regsub(req.url, "^/dask-service/([a-zA-Z0-9 -]*).af-jupyter/(.*)", "\1");
set req.url = regsub(req.url, "/dask-service/([a-zA-Z0-9 -]*).af-jupyter/", "/");
set req.http.x-fuck=req.http.x-fuck+".af-jupyter";
}
}

} -start

client c1 {
# txreq -url "/cmsa/post/my_post.html"
# rxresp

txreq -url "/dask-service/servicexxx.af-jupyter/status/asdf"
rxresp
} -run
84 changes: 84 additions & 0 deletions kube/varnish_proxy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# to test:
# docker run --rm -it -P -v .\tests\foo.vtc:/etc/varnish/tests/foo.vtc varnish:latest varnishtest /etc/varnish/tests/foo.vtc
apiVersion: v1
kind: ConfigMap
metadata:
name: v4dask
namespace: af-jupyter
labels:
k8s-app: v4dask
data:
default.vcl: |-
vcl 4.1;
import std;
import goto;
# import dynamic;
# import directors;
backend default none;
sub vcl_recv {
if (req.url ~ "/dask-service/") {
set req.http.x-dask-service = regsub(req.url, "^/dask-service/([a-zA-Z0-9 -]*).af-jupyter/(.*)", "\1");
set req.http.x-dask-service = req.http.x-dask-service + ".af-jupyter";
set req.url = regsub(req.url, "/dask-service/([a-zA-Z0-9 -]*).af-jupyter/", "/");
}
}
sub vcl_backend_fetch {
set bereq.backend = goto.dns_backend(req.http.x-dask-service);
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: varnish4dask
namespace: af-jupyter
labels:
k8s-app: v4dask
spec:
replicas: 1
selector:
matchLabels:
k8s-app: v4dask
template:
metadata:
labels:
k8s-app: v4dask
spec:
containers:
- name: v4dask
image: varnish:latest
# args: ["-t", "3600"]
command: ["varnishd"]
args:
[
"-F",
"-f",
"/etc/varnish/default.vcl",
"-a",
"http=:6081,HTTP",
"-p",
"feature=+http2",
"-s",
"malloc,$VARNISH_SIZE",
]
ports:
- containerPort: 6081
hostPort: 8787
volumeMounts:
- name: config-volume
mountPath: /etc/varnish/
resources:
requests:
cpu: "1"
memory: "1Gi"
limits:
cpu: "2"
memory: "2Gi"
volumes:
- name: config-volume
configMap:
name: v4dask

0 comments on commit c168422

Please sign in to comment.