Using IP Pools
About 531 words
Calico IP pools can assign independent IP address spaces to different teams.
Scenario
Suppose a Kubernetes cluster needs separate IP ranges for two teams: development and testing:
- The development team uses 10.0.1.0/24
- The testing team uses 10.0.2.0/24
- Pods use 10.0.0.0/24 by default
Step 1: Create Multiple IP Pools
First, create three IP pool definition files:
default-pool.yaml:
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
name: default-pool
spec:
cidr: 10.0.0.0/24
blockSize: 26
ipipMode: Never
natOutgoing: truedev-pool.yaml:
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
name: dev-pool
spec:
cidr: 10.0.1.0/24
blockSize: 26
ipipMode: Never
natOutgoing: truetest-pool.yaml:
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
name: test-pool
spec:
cidr: 10.0.2.0/24
blockSize: 26
ipipMode: Never
natOutgoing: trueApply these configurations:
calicoctl apply -f default-pool.yaml
calicoctl apply -f dev-pool.yaml
calicoctl apply -f test-pool.yamlStep 2: Verify IP Pool Creation
calicoctl get ippools -o wideThe output should resemble:
NAME CIDR NAT IPIPMODE DISABLED
default-pool 10.0.0.0/24 true Never false
dev-pool 10.0.1.0/24 true Never false
test-pool 10.0.2.0/24 true Never falseStep 3: Assign IP Pools to Different Teams
Method 1: Namespace Annotations
Annotate the development team's namespace:
kubectl create namespace dev-team
kubectl annotate namespace dev-team \
cni.projectcalico.org/ipv4pools='["dev-pool"]'Annotate the testing team's namespace:
kubectl create namespace test-team
kubectl annotate namespace test-team \
cni.projectcalico.org/ipv4pools='["test-pool"]'Method 2: Pod Annotations for Finer-Grained Control
Create a Pod for the development team:
apiVersion: v1
kind: Pod
metadata:
name: dev-app
namespace: dev-team
annotations:
cni.projectcalico.org/ipv4pools: '["dev-pool"]'
spec:
containers:
- name: dev-app
image: nginxCreate a Pod for the testing team:
apiVersion: v1
kind: Pod
metadata:
name: test-app
namespace: test-team
annotations:
cni.projectcalico.org/ipv4pools: '["test-pool"]'
spec:
containers:
- name: test-app
image: nginxStep 4: Verify IP Allocation
Check the IP addresses assigned to the Pods:
kubectl get pods -n dev-team -o wide
kubectl get pods -n test-team -o wideDevelopment Pods should receive IPs from 10.0.1.0/24, and testing Pods from 10.0.2.0/24.
Step 5: Create a Network Policy (Optional)
For stronger isolation, create a NetworkPolicy restricting communication between teams:
dev-team-policy.yaml:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: dev-team-isolation
namespace: dev-team
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
ingress:
- from:
- namespaceSelector:
matchLabels:
team: dev
egress:
- to:
- namespaceSelector:
matchLabels:
team: devAdd labels to the namespaces:
kubectl label namespace dev-team team=dev
kubectl label namespace test-team team=testAdvanced Example: Node-Specific IP Pools
To make particular nodes use particular IP pools:
- Add labels to the nodes:
kubectl label node <node-name> pool-group=high-perf- Create a dedicated IP pool:
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
name: high-perf-pool
spec:
cidr: 10.0.3.0/24
nodeSelector: pool-group == "high-perf"
ipipMode: Never
natOutgoing: true- Apply the configuration:
calicoctl apply -f high-perf-pool.yamlPods scheduled onto nodes labeled pool-group=high-perf will then automatically receive IPs from 10.0.3.0/24.
Clean Up
Delete the example resources:
kubectl delete namespace dev-team test-team
calicoctl delete ippool default-pool dev-pool test-pool