We have a lot of services set up by Nodeport and available from external via <node_ip>:<node_port>
.
It should be a common requirement that I would like to control the access to certain services, which means the requests from some of IPs may access to it, while others not.
We'd like to use iptables
to meet this requirement, which gets a lot of confusion since kubernetes use it to set up communication as well. Do we have any high-level guidance
to design/create iptable rule to control k8s service?
Specifically, I am confused in below areas:
nat and filter
are created by K8stelnet <node_ip>:<node_port>
should I REJECT on FORWARD
or INPUT
, or PREROUTING
directly?For my scenarios, I have below rules to be set up:
full access
to each othercertain
IPsall
IPsany other
services from all IPs (outside of cluster)k8s version: 1.9.5 network plugin: weave
Best Regards!
/triage support
Although you can change iptables on your K8s nodes, I wouldn't recommend making any changes since K8s (kube-proxy) is constantly changing the rules dynamically. In other words, Kubernetes manages (combined with the overlay) manages iptables for you.
To block traffic I would strongly suggest using NetworkPolicies. And/Or if you are using an overlay, you can use what that overlay provides. For example, Calico has its own Network Policy
Another way of controlling traffic in/out is to use a service-mesh like Istio.