Skip to content

Namespace network isolation with Calico #175

@danielhartnell

Description

@danielhartnell

Hey @the-smooth-operator and @ziegeer,

apiVersion: projectcalico.org/v3
kind: NetworkPolicy
metadata:
  name: deny-most
  namespace: prod
spec:
  selector: role != 'proxy'
  types:
  - Ingress
  - Egress
  ingress:
  - action: Allow
    source:
      namespaceSelector: name == 'prod'
  - action: Deny
    source:
      namespaceSelector: name != 'prod'
  egress:
  - action: Allow

This policy should provide namespace network isolation. Sorry that got lost in the transition. Maybe it'll save you a little time. The policy can only be applied with calicoctl I believe. In order to do that, I had to run calicoctl as a pod in the cluster itself which is documented here:

https://docs.projectcalico.org/v3.5/usage/calicoctl/install#installing-calicoctl-as-a-kubernetes-pod

I think that the current cluster has Calico available in policy only mode but I'm not sure I fully understood the state of Calico in the cluster.

Cheers!
Daniel

Update: I forgot. You'll want to read the docs on Calico policies. You can do some pretty neat stuff including using the namespaceSelector and selector for this. I can't remember exactly what I was doing here but you'll just need to make sure that the namespace and pod labels match whatever you have in the policy here. May take a bit of experimenting but it shouldn't be too bad to get it all working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions