Openvpn – Kubernetes custom routes

kubernetesopenvpnroute

I started OpenVPN on my k8s cluster and now clients can directly connect to the ClusterIP services but i need masquerade for it because pods (except OpenVPN pod) do not know route to clients.

Is there possibility to add custom route to Kubernetes pods and direct traffic for specific IP range to OpenVPN service – ClusterIP?

Best Answer

Due to the fact that you have already connected OpenVPN Node to the Kubernetes cluster using ClusterIP services, which are managed by kube-proxy, it is recommended to route network packets via iptables. Now it's time to configure kube-proxy for transferring all requests to internal CNI network via OpenVPN Node:

kube-proxy — kubeconfig=./kube-config/config.yaml — bind-address=xx.xx.xx.xx — cluster-cidr=yy.yy.yy.yy/cc — proxy-mode=iptables — masquerade-all

xx.xx.xx.xx - your OpenVPN node IP address

yy.yy.yy.0/cc - Cluster CIDR

Ensure that OpenVPN Pod is configured to connect the Kubernetes network:

push “route yy.yy.0.0 255.255.0.0”

To create routes from your Node services to the OpenVPN gateway, consider using Site-to-site routing via OpenVPN explained in this Article.

Related Topic