Skip to main content
Version: v0.38 Stable

Network policy

Supported Configurations
Running the control plane as a container with:
note

This feature is disabled by default.

By default, workloads created by vCluster are able to communicate with other workloads in the control plane cluster through their cluster IPs. Configure network policies when you want to isolate namespaces and do not want the pods running inside the cluster to have access to other workloads in the control plane cluster.

Enabling this creates Kubernetes NetworkPolicy resources in the host namespace that control how vCluster pods (both control plane and workloads) communicate with each other and with other pods on the control plane cluster.

Prerequisites​

Network policies are implemented by the network plugin (CNI). To use network policies, you must be using a networking solution which supports NetworkPolicy. Creating a NetworkPolicy resource without a controller that implements it will have no effect. Some CNIs accept NetworkPolicy resources without enforcing them, so confirm enforcement directly rather than assuming it from CNI support alone.

Coverage is limited to the primary pod interface

NetworkPolicy governs the primary pod network interface, including a VM's primary interface through its virt-launcher Pod. It doesn't cover Multus secondary interfaces or direct underlay network attachments. Host-network Pod traffic is undefined in the Kubernetes NetworkPolicy spec and CNI-dependent. Most CNIs ignore it, but confirm your CNI's actual behavior rather than assuming either way. See network and endpoint isolation for the controls those paths need.

Enable network isolation​

Set policies.networkPolicy.enabled to create NetworkPolicies that isolate the cluster:

vcluster.yaml
policies:
networkPolicy:
enabled: true

This creates Kubernetes NetworkPolicies resources in the host namespace that:

  • Allow traffic between pods within the cluster
  • Block traffic from other namespaces
  • Permit DNS (port 1053) and API server communication
note

The Kubernetes NetworkPolicies resources are managed by vCluster. Manual changes to these resources will be overwritten.

Example of NetworkPolicies resources created in the host namespace
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: vc-work-{name}
namespace: vcluster-{name}
labels:
app: vcluster
chart: vcluster-0.31.0
heritage: Helm
release: {name}
spec:
# Pod selector matching cluster workloads pods.
podSelector:
matchLabels:
vcluster.loft.sh/managed-by: {name}
policyTypes:
- Egress
- Ingress
egress:
# Allow egress to vcluster DNS and control plane.
- ports:
- port: 1053
protocol: UDP
- port: 1053
protocol: TCP
- port: 8443
protocol: TCP
to:
- podSelector:
matchLabels:
release: {name}
# Allow egress to other vcluster workloads, including coredns when not embedded.
- to:
- podSelector:
matchLabels:
vcluster.loft.sh/managed-by: {name}
# Allow public egress.
- to:
- ipBlock:
cidr: 0.0.0.0/0
except:
- 100.64.0.0/10
- 127.0.0.0/8
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
ingress:
# Allow ingress from vcluster control plane.
- from:
- podSelector:
matchLabels:
release: {name}
# Allow ingress from other vcluster workloads.
- from:
- podSelector:
matchLabels:
vcluster.loft.sh/managed-by: {name}
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: vc-cp-{name}
namespace: vcluster-{name}
labels:
app: vcluster
chart: vcluster-0.31.0
heritage: Helm
release: {name}
spec:
# Pod selector matching cluster control plane pods.
podSelector:
matchLabels:
release: {name}
policyTypes:
- Egress
- Ingress
egress:
# Allow egress to host kube-dns.
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: 'kube-system'
podSelector:
matchLabels:
k8s-app: kube-dns
# Allow egress to host control plane.
- ports:
- port: 443
protocol: TCP
- port: 8443
protocol: TCP
- port: 6443
protocol: TCP
# Allow egress to vcluster control plane peers, including etcd peers, when using etcd as the backend in HA mode.
- to:
- podSelector:
matchLabels:
release: {name}
# Allow egress connections to vcluster workloads.
- to:
- podSelector:
matchLabels:
vcluster.loft.sh/managed-by: {name}
# Allow egress to vcluster platform.
- to:
- podSelector:
matchLabels:
app: loft
namespaceSelector: {}
ingress:
# Allow ingress from vcluster control plane peers, including etcd peers, when using etcd as the backend in HA mode.
- from:
- podSelector:
matchLabels:
release: {name}
# Allow ingress for vcluster workloads.
- ports:
- port: 1053
protocol: UDP
- port: 1053
protocol: TCP
- port: 8443
protocol: TCP
from:
- podSelector:
matchLabels:
vcluster.loft.sh/managed-by: {name}
# Allow ingress from vcluster snapshot.
- from:
- podSelector:
matchLabels:
app: vcluster-snapshot
# Allow ingress from vcluster platform.
- from:
- podSelector:
matchLabels:
app: loft
namespaceSelector: {}

Example configurations​

Custom ingress and egress rules​

DNS port in clusters

Cluster DNS runs on port 1053, not the standard port 53. Custom egress rules that allow DNS traffic must target port 1053 or DNS resolution silently fails. UDP packets are dropped with no error in pod logs.

ports:
- port: 1053
protocol: UDP
- port: 1053
protocol: TCP

Control inbound and outbound traffic with specific ports and IP addresses for vCluster control plane and workloads:

vcluster.yaml
policies:
networkPolicy:
enabled: true

workload:
ingress:
# Allow ingress from anywhere to specific ports
- ports:
- port: 6060
- port: 444

egress:
# Allow egress to a specific address and port
- to:
- ipBlock:
cidr: 172.19.10.23/32
ports:
- port: 7777
protocol: TCP

publicEgress:
# Disable convenience common public egress rule.
enabled: false

controlPlane:
ingress:
# Allow ingress traffic from anywhere to the cluster control plane api
- ports:
- port: 8443

egress:
# Allow egress traffic to a specific address
- to:
- ipBlock:
cidr: 172.19.10.23/32
note

ingress and egress config sections follow the same schema as PodNetworkPolicy

Add custom labels​

Apply labels to generated NetworkPolicies for easier management:

vcluster.yaml
policies:
networkPolicy:
enabled: true
labels:
environment: production
team: platform
annotations:
description: "Network isolation for production vCluster"

Project-scoped isolation with Platform​

For Platform users needing project-level network boundaries, combine policies.networkPolicy with VirtualClusterTemplates:

project-isolated-template.yaml
apiVersion: management.loft.sh/v1
kind: VirtualClusterTemplate
metadata:
name: project-isolated
spec:
template:
helmRelease:
chart:
version: 0.26.0
values: |
policies:
networkPolicy:
enabled: true
labels:
vcluster.io/project: "{{ .Values.loft.project }}"

This automatically:

  • Isolates clusters by project
  • Allows communication within the same project
  • Enforces network boundaries for CI/CD pipelines

Migration from v0.30 config​

workload and controlPlane configuration sections are introduced to allow defining additional ingress/egress rules for the specific components.

vcluster.yaml (v0.30 and earlier)
policies:
networkPolicy:
enabled: true

extraControlPlaneRules:
- ports:
- port: 8443


extraWorkloadRules:
- ports:
- port: 6060


outgoingConnections:
ipBlock:
cidr: 172.19.10.23/32
vcluster.yaml (v0.31)
policies:
networkPolicy:
enabled: true

controlPlane:
egress:
- ports:
- port: 8443

workload:
egress:
- ports:
- port: 6060

publicEgress:
cidr: 172.19.10.23/32

Config reference​

Deprecated FieldNew Field
extraControlPlaneRulescontrolPlane.egress
extraWorkloadRulesworkload.egress
outgoingConnections.ipBlockworkload.publicEgress

For every field under policies.networkPolicy, see the policies reference.