Sto provando a creare un proxy nginx che inoltra le richieste a /<service>
a http://<service>
. Ho provato la seguente:Dynamic proxy_pass in nginx in un altro pod in Kubernetes
location ~ ^/(.+)$ {
set $backend "http://$1:80";
proxy_pass $backend;
}
ma non riesce dicendo qualcosa del tipo (quando si chiama /myservice
):
[error] 7741#0: *1 no resolver defined to resolve http://myservice
Dal myservice
non è accessibile dall'esterno ho provato ad installare go-dnsmasq come un sidecar nel stesso pod e provo a usarlo per la risoluzione DNS (come ho visto nell'esempio this) e cambiare la mia configurazione di nginx in questo modo:
location ~ ^/(.+)$ {
resolver 127.0.0.1:53;
set $backend "http://$1:80";
proxy_pass $backend;
}
Ma ora nginx fallisce con:
[error] 9#9: *734 myservice could not be resolved (2: Server failure), client: 127.0.0.1, server: nginx-proxy, request: "GET /myservice HTTP/1.1", host: "localhost:8080"
127.0.0.1 - xxx [30/May/2016:10:34:23 +0000] "GET /myservice HTTP/1.1" 502 173 "-" "curl/7.38.0" "-"
mio kubernetes pod si presenta così:
spec:
containers:
- name: nginx
image: "nginx:1.10.0"
ports:
- containerPort: 8080
name: "external"
protocol: "TCP"
- name: dnsmasq
image: "janeczku/go-dnsmasq:release-1.0.5"
args:
- --listen
- "0.0.0.0:53"
Esecuzione netstat -ntlp
nel contenitore dnsmasq mi dà:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN -
tcp 0 0 :::53 :::* LISTEN 1/go-dnsmasq
E in esecuzione nmap --min-parallelism 100 -sT -sU localhost
nel contenitore nginx:
Starting Nmap 6.47 (http://nmap.org) at 2016-05-30 10:33 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00055s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 1997 closed ports
PORT STATE SERVICE
53/tcp open domain
8080/tcp open http-proxy
53/udp open domain
Quindi sembra che dnsmasq e nginx siano effettivamente attivi e funzionanti? Cosa potrei fare di sbagliato?
grazie per questo! –
Questo è fantastico. Grazie. Non sono sicuro del motivo per cui 'kube-dns' come risolutore non funziona. – ZoidbergWill