<p>We are currently providing our software as a software-as-a-service on Amazon EC2 machines. Our software is a microservice-based application with around 20 different services.
For bigger customers we use dedicated installations on a dedicated set of VMs, the number of VMs (and number of instances of our microservices) depending on the customer's requirements. A common requirement of any larger customer is that our software needs access to the customer's datacenter (e.g., for LDAP access). So far, we solved this using Amazon's virtual private gateway feature.</p>

<p>Now we want to move our SaaS deployments to Kubernetes. Of course we could just create a Kubernetes cluster across an individual customer's VMs (e.g., using kops), but that would offer little benefit.
Instead, perspectively, we would like to run a single large Kubernetes cluster on which we deploy the individual customer installations into dedicated namespaces, that way increasing resource utilization and lowering cost compared to the fixed allocation of machines to customers that we have today.
From the Kubernetes side of things, our software works fine already, we can deploy multiple installations to one cluster just fine. An open topic is however the VPN access. What we would need is a way to allow <strong>all</strong> pods in a customer's namespace access to the customer's VPN, but not to any other customers' VPNs.</p>

<p>When googleing for the topic, I found approaches that add a VPN client to the individual container (e.g., <a href="https://caveofcode.com/2017/06/how-to-setup-a-vpn-connection-from-inside-a-pod-in-kubernetes/" rel="noreferrer">https://caveofcode.com/2017/06/how-to-setup-a-vpn-connection-from-inside-a-pod-in-kubernetes/</a>) which is obviously not an option). 
Other approaches seem to describe running a VPN <em>server</em> inside K8s (which is  also not what we need). 
Again others (like the "Strongswan IPSec VPN service", <a href="https://www.ibm.com/blogs/bluemix/2017/12/connecting-kubernetes-cluster-premises-resources/" rel="noreferrer">https://www.ibm.com/blogs/bluemix/2017/12/connecting-kubernetes-cluster-premises-resources/</a> ) use DaemonSets to "configure routing on each of the worker nodes". This also does not seem like a solution that is acceptable to us, since that would allow all pods (irrespective of the namespace they are in) on a worker node access to the respective VPN... and would also not work well if we have dozens of customer installations each requiring its own VPN setup on the cluster.</p>

<p>Is there any approach or solution that provides what we need, .i.e., VPN access for the pods in a specific namespace only?
Or are there any other approaches that could still satisfy our requirement (lower cost due to Kubernetes worker nodes being shared between customers)?</p>

<p>For LDAP access, one option might be to setup a kind of LDAP proxy, so that only this proxy would need to have VPN access to the customer network (by running this proxy on a small dedicated VM for each customer, and then configuring the proxy as LDAP endpoint for the application). However, LDAP access is only one out of many aspects of connectivity that our application needs depending on the use case.</p>

<p>If your IPSec concentrator support VTI, it's possible route the traffic using firewall rules. For example, PFSense suports it: <a href="https://www.netgate.com/docs/pfsense/vpn/ipsec/ipsec-routed.html" rel="nofollow noreferrer">https://www.netgate.com/docs/pfsense/vpn/ipsec/ipsec-routed.html</a>. </p>

<p>Using VTI, you can direct traffic using some kind of policy routing: <a href="https://www.netgate.com/docs/pfsense/routing/directing-traffic-with-policy-routing.html" rel="nofollow noreferrer">https://www.netgate.com/docs/pfsense/routing/directing-traffic-with-policy-routing.html</a></p>

<p>However, i can see two big problems here:</p>

<ul>
<li><p>You cannot have two IPSEC tunnels with the conflicted networks. For example, your kube network is 192.168.0.0/24 and you have two customers: A (172.12.0.0/24) and B (172.12.0.0/12). Unfortunelly, this can happen (unless your customer be able to NAT those networks).</p></li>
<li><p>Find the ideals criteria for rule match (to allow the routing), since your source network are always the same. Use mark packages (using iptables mangle or even through application) can be a option, but you will still get stucked on the first problem.</p></li>
</ul>

<p>A similar scenario is founded on WSO2 (API gateway provider) architecture. They solved it using reverse-proxy in each network (sad but true) <a href="https://docs.wso2.com/display/APICloud/Expose+your+On-Premises+Backend+Services+to+the+API+Cloud#ExposeyourOn-PremisesBackendServicestotheAPICloud-ExposeyourservicesusingaVPN" rel="nofollow noreferrer">https://docs.wso2.com/display/APICloud/Expose+your+On-Premises+Backend+Services+to+the+API+Cloud#ExposeyourOn-PremisesBackendServicestotheAPICloud-ExposeyourservicesusingaVPN</a></p>

<p>Regards,</p>

<p>UPDATE:</p>

<p>I don't know if you use GKE. If yes, maybe use Alias-IP can be an option: <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/alias-ips" rel="nofollow noreferrer">https://cloud.google.com/kubernetes-engine/docs/how-to/alias-ips</a>. The PODs IPs will be routable from VPC. So, you can apply some kind of routing policy based on their CIDR.</p>
