EP 11 - Network Policies and Service Mesh: Which One Do You Need?
Malchiel Urias
DevOps Engineer || Site Reliability Engineer || Cloud Engineer || 4x AWS Certified || CEH Master
Networking in Kubernetes
Networking in all areas of Infrastructure Engineering (DevOps, SRE, Platform Engineering) is more crucial than most people assume. It is the backbone of everything. And in the world of Kubernetes, where multiple services need to talk to each other, it is more important than ever.
Kubernetes is created to foster micro-service computing. To do that, various services or applications running in pods need to be able to send packets of data to each other, hence the need for managing and securing networks.
Controlling and Managing Network Traffic
By default, Kubernetes has an “any-any” network traffic policy. This means that the default configuration of Kubernetes allows network traffic from any pod within the cluster to reach any other pod within the cluster. This might not sound like an issue at first because it is a good thing for pods to be reachable within the cluster, however, when you begin to work in an environment that needs strict privacy within namespaces or for certain pods, it becomes an overly permissive policy.
For instance, I have within my Kubernetes cluster production databases, Kafka brokers, and cost monitoring services that I do not want to be accessible by every pod or user who has access to my cluster. Hence, the default networking policy of my Kubernetes cluster is now a security and compliance concern for me. What do I do about this?
There are two main tools we can use to manage the traffic within our cluster, and today we will look at both of them, their feature, benefits, and advantages and try to determine which solution is best for you to implement in your cluster.
They are:
Network Policies
Network policies are a mechanism for controlling the pods and Kubernetes services. They comprise rules that either allow or deny traffic to and from a pod based on the result of evaluating certain criteria or conditions.
Network Policies function on the Network and Transport layers of the OSI model (Layer 3 and Layer 4), and as such, they control traffic using the IP address and port of the pods and also the namespaces.
Network policies are basic Kubernetes objects and come with the Kubernetes API. However, to implement network policies, you must have a CNI that supports the execution and enforcement of network policies. Kubernetes allows the specification of network policies but cannot implement them by default.
How it Works
Features
Some core features of Network Policies include:
Pros and Cons
领英推荐
Service Mesh
Service Meshes, on the other hand, also provide a means for controlling and managing network traffic, but they do this on Layer 7 (The Application Layer), and because of this, they can have advanced features like advanced load-balancing, throttling, authentication and authorisation of requests etc. They control traffic based on application headers and paths.
How it Works
The main idea behind the operations of service meshes is to distribute a set of proxies, which would be embedded into the pod as sidecars and used to intercept traffic to the pod.
Process:
Features
Some of the features that service meshes provide:
Pros and Cons
Differences
Which Do You Need In Your Cluster
The choice of whether to use Network Policies or Service Mesh all comes down to your specific use case. It is important, however, to avoid deploying a service mesh if you don’t need to to avoid introducing unnecessary complexity and latency.
Install Network Policies If:
Install a Service Mesh If:
In summary, choosing between Network Policies and a Service Mesh depends on your specific needs. For lightweight security and traffic control, Network Policies offer a simple, effective solution. However, if your microservices architecture requires advanced traffic management, observability, and security features, a Service Mesh is the right choice. Assess your cluster’s complexity and scale to determine which approach best fits your goals, and remember, combining both can provide robust control and flexibility for your Kubernetes environment.
Thanks for reading and Happy Engineering ????????