SlideShare a Scribd company logo
1 of 21
Network Policy in Kubernetes
with Calico
Matt Dupre
Physical Network
Physical / Cloud Network
Server Server Server Server
Physical Network
Server Server Server Server
Physical Network
Server Server Server Server
Physical Network
NetworkPolicy to the rescue!
https://kubernetes.io/docs/concepts/services-
networking/networkpolicies/
NetworkPolicy to the rescue!
kind: Namespace
apiVersion: v1
metadata:
name: production
annotations:
network-policy: |
{
"ingress": {
"Isolation": "DefaultDeny"
}
}
Enable Network Policy
kind: NetworkPolicy
apiVersion: extensions/v1beta1
metadata:
namespace: production
spec:
podSelector:
matchLabels: {}
ingress:
- from:
- podSelector:
matchLabels: {}
Allow Desired Traffic
apiVersion: extensions/v1beta1
kind: NetworkPolicy
metadata:
name: test-network-policy
namespace: default
spec:
podSelector:
matchLabels:
role: db
ingress:
- from:
- namespaceSelector:
matchLabels:
project: users
ports:
- protocol: tcp
port: 6379
role: frontend
role: user-auth
role: main-logic
role: database
role: frontend
role: user-auth
role: main-logic
role: database
“allow from web to
TCP 80”
“allow from role: frontend”
“allow from role: user-auth”
“allow from role:
user-auth”
“allow from role:
main-logic”
“allow from role: frontend”
podSelector:
role: user-auth
ingress:
- from:
- podSelector:
role: frontend
ports:
- port: 8001
protocol: tcp
role: frontend
role: user-auth
“allow from role: frontend”
Network
FabricRouting
10.0.0.1
192.168.1.2
192.168.1.1
Routing
10.0.0.2
192.168.1.3
192.168.1.4
Demo!
kubectl apply -f
http://docs.projectcalico.org/v2.1/getting-
started/kubernetes/installation/hosted/kubea
dm/1.6/calico.yaml
Network performance?
- Impact of policy is minimal
- Conntrack
- Selectors / ipsets
- Rule traversal
Extensions
- Egress
- CIDRs
- Blacklists
projectcalico.org
github.com/projectcalico
@projectcalico
slack.projectcalico.org
We’re Hiring!

More Related Content

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Featured

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
Simplilearn
 

Featured (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

Network Policy in Kubernetes with Calico

Editor's Notes

  1. Hi everyone Thank you all for coming, and also thanks to our hosts Kinvolk. Please yell at me if I’m not speaking loudly enough! I’m a software engineer at Tigera. I’ve always been in networking, and for the past few years I’ve been a developer on Project Calico. For anyone who hasn’t encountered it yet, it’s an open source project focused on providing simple, scalable and secure communications for cloud native workloads. Today I’m going to speak a bit about network policy for Kubernetes. I’ll start with a quick spin through why you should care, and then get into a demo and some details of how it all works. I’ll give some time for questions at the end.
  2. So, what’s the problem? Once upon a time, applications were simple. (Well, some of them…?) In previous generations of web application architectures, the network was the thing that connected users to your application. Now the application you want to build doesn’t run on a single machine. Computers have gotten faster, but our ambitions have outstripped Moore’s Law.
  3. Now the network is part of the composition of the application itself. If any of these component applications is compromised, then all data stored could be vulnerable, potentially very broadly - cluster, organisation etc. My colleague, Mike Stowe, spoke about that here a few weeks ago at the CoreOS meetup.
  4. But how how can we do that? We’ve got physical firewalls, so we can just put them between our applications. (This isn’t intended to illustrate a sensible network architecture, just the effect.)
  5. But we want to use Kubernetes. For the sake of my curiosity, how many people here are already using Kubernetes? Show of hands? In production? Plans Cool, so
  6. We’ve got multiple nodes in our cluster running pods. So can we use physical firewalls similarly?
  7. But really a k8s cluster doesn’t look like that.
  8. They’re slow.
  9. And then they’ll give up anyway because there are too many rules: one set per pod! Now. There is one thing we could do - categorize the nodes by what application they run. I mention this because it possible, I don’t endorse it. There are some things we could do: Affinity Multiple clusters Taints and tolerations to force pods onto certain nodes Doing this in some places might be a pragmatic solution for compliance say, but it’s awful. It’s slow and inflexible - you throw out many of the benefits of Kubernetes, or indeed any cloud native orchestrator. The orchestrator should be doing the scheduling, not a network security engineer. Speed, flexibility, utilization.
  10. It’s still in beta, strictly, but it’s been in for about a year and mostly seems pretty stable now. The one thing to watch out for is named ports, which afaik nobody has implemented and might be removed.
  11. Key points. What does this apply to? What does that mean for traffic? NetworkPolicies always define allowed traffic. That’s why we need to disable all traffic to use them, by annotating the namespaces. Ingress only Podselector(s) for from
  12. Here’s a slightly different one. This one is a namespaceselector instead. Also an example of specifying a port, which in practice you’d usually want to do.
  13. Kubernetes uses labels to select which pods in your application to replicate, and which pods should belong to a given micro-service. Your application’s pods are already labeled according to what their role is in your application, and this lines up really well with how the network should secure your application. This diagram shows four micro-services, made up of replicated Kubernetes pods. In this example, the developer has chosen to use “role” as the label used to group his services, but there isn’t anything special about this - any label could be used.
  14. And looking at this diagram, it is easy to see what the necessary network policy should be.
  15. Let’s take a closer look at an example of how we might actually define some of this policy using the Kubernetes API. The “user-auth” service in this example app takes incoming requests from the frontend, and validates them against the database’s list of valid users. As such, it needs to accept incoming connections from any of our replicated frontend pods. The Kubernetes object on the left describes this relationship. This “NetworkPolicy” selects all the “user-auth” pods, and allows incoming traffic from “frontend” pods to TCP port 8001. This is really powerful, because we’re describing network security in an easy to understand way, and we’re using Kubernetes labels. Because policy is defined in terms of labels, If I scale my frontend to handle a sudden spike in traffic, my network policy will automatically be applied to all of the new pods with no extra effort required. It just works.
  16. As I mentioned at the start, I work on project Calico, so obviously I’m going to use it here. There are now a number of implementations: Weave and Romana are some other examples. I’ll do a quick demo, and we’ll look briefly into how things work
  17. Calico uses the Linux kernel to enforce network policy on each and every pod in your cluster. The Calico distributed firewall is dynamic, automatic, and enforces security rules in front of each workload in your cluster. The network fabric here is swappable. For example, you could be using one of the backends provided by canal, or your own custom fabric.
  18. Sorry I’m not actually showing you this bit - this laptop is new to me and it turns out airplane mode is mapped to print screen so I couldn’t grab a screenshow?! Anyway, you install this yaml file, which sets up the various components and configurations. I’ve had to go for something simple here, since I didn’t have access to the cluster I wanted to use, or the time to set it up.
  19. - don’t worry about it - connection based, and overlay / fabric has much more impact anyway - how do we get it efficient? - selectors very efficient - iptables performance mostly depends on the number and type of rules traversed for a packet - minimal representation on nodes (unused policies not written) - you probably don't need this, but order of policies (can be explicit for Calico ones, or alphabetical) will give the processing order - honestly, if you're really pushing it, kube-proxy is probably more concerning. We have a big k8s user who are finding it consumes 10s of thousands of rules, when we're only in thousands in a large setup.
  20. The NetworkPolicy API as it stands is relatively restrictive. The underlying Calico engine (we do policy across multiple orchestrators, so we implement a superset of function) supports a few more things. You can actually use these with K8s, by using the very similar calico policy API to configure them.
  21. Thank organisers / hosts / audience