- Set up a separate nginx server
- Set up a proxy from the nginx instance exposing a port and proxying traffic from the destination service
- From kubernetes, set up a service and an endpoint for that service that tunnels traffic to the proxy instance
Creating a proxy service
From the proxy instance, create a proxy
- after installing nginx, create a config file
Save this as /etc/nginx/conf.d/proxy.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| server {
listen 5080;
location / {
proxy_pass http://192.168.100.81:8310;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
send_timeout 60s;
}
}
|
Reload nginx once saved
Kubernetes instance
Kubernetes service and endpoint
1
2
3
4
5
6
7
8
9
10
| apiVersion: v1
kind: Service
metadata:
name: external-service
namespace: prod
spec:
ports:
- protocol: TCP
port: 5080
targetPort: 5080
|
Endpoint
1
2
3
4
5
6
7
8
9
10
| apiVersion: v1
kind: Endpoints
metadata:
name: external-service
namespace: prod
subsets:
- addresses:
- ip: 192.169.100.20 # remote proxy ip
ports:
- port: 5080 # remote proxy port
|
You can then use the . annotation to access the proxy.
1
| curl http://external-service.prod.svc.cluster.local:5080/
|