Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing iptables rules on Kubernetes nodes

I would like to implement my own iptables rules before Kubernetes (kube-proxy) start doing it's magic and dynamically create rules based on services/pods running on the node. The kube-proxy is running in --proxy-mode=iptables.

Whenever I tried to load rules when booting up the node, for example in the INPUT chain, the Kubernetes rules (KUBE-EXTERNAL-SERVICES and KUBE-FIREWALL) are inserted on top of the chain even though my rules were also with -I flag.

What am I missing or doing wrong?

If it is somehow related, I am using weave-net plugin for the pod network.

like image 689
Luminance Avatar asked Aug 15 '18 11:08

Luminance


People also ask

Does Kubernetes use iptables?

In iptables mode, kube-proxy creates iptables rules for kubernetes services which ensure that the request to the service gets routed (and load balanced) to the appropriate pods. These iptables rules also help answer the second question mentioned above.

What is the purpose of iptables with respect to securing Kubernetes environment?

Kubernetes networking uses iptables to control the network connections between pods (and between nodes), handling many of the networking and port forwarding rules. This way, clients do not need to keep track of IP addresses to connect to Kubernetes services.

Does kube proxy use iptables?

kube-proxy can run in three different modes: iptables (default mode) ipvs. userspace (“legacy” mode, not recommended anymore)

What are iptables rules?

Iptables is a Linux command line firewall that allows system administrators to manage incoming and outgoing traffic via a set of configurable table rules. Iptables uses a set of tables which have chains that contain set of built-in or user defined rules.


1 Answers

The most common practice is to put all custom firewall rules on the gateway(ADC) or into cloud security groups. The rest of the cluster security is implemented by other features, like Network Policy (It depends on the network providers), Ingress, RBAC and others.

Check out the articles about Securing a Cluster and Kubernetes Security - Best Practice Guide.

These articles can also be helpful to secure your cluster:

  • Hardening your cluster's security

  • The Ultimate Guide to Kubernetes Security

like image 161
VASャ Avatar answered Sep 21 '22 00:09

VASャ