🧀 Service Route Advertisement
About 403 words
Calico can advertise Kubernetes Service ClusterIPs and ExternalIPs to external networks through BGP (Border Gateway Protocol). The following steps and examples show how to configure it:
Basic Steps
1. Enable Service Route Advertisement
- Modify Calico's BGPConfiguration:
kubectl edit bgpconfiguration defaultAdd or modify the following:
apiVersion: projectcalico.org/v3
kind: BGPConfiguration
metadata:
name: default
spec:
logSeverityScreen: Info
nodeToNodeMeshEnabled: true
serviceClusterIPs:
- cidr: 10.96.0.0/12 # Replace with your ClusterIP CIDR
serviceExternalIPs:
- cidr: 192.168.1.0/24 # Replace with your ExternalIP range
asNumber: 64512 # Your AS number2. Configure a BGP Peer If External Router Communication Is Needed
kubectl apply -f - <<EOF
apiVersion: projectcalico.org/v3
kind: BGPPeer
metadata:
name: my-external-router
spec:
peerIP: 192.168.1.1 # External router IP
asNumber: 64513 # External router AS number
EOF3. Verify the Configuration
# Check BGP peer status
calicoctl get bgppeer
# Check node BGP status
calicoctl node statusComplete Example
Scenario: Advertise a Particular Service's ExternalIP to an External Network
- Create a test Service:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 9376
externalIPs:
- 192.168.1.100- Configure Calico to advertise the ExternalIP:
kubectl apply -f - <<EOF
apiVersion: projectcalico.org/v3
kind: BGPConfiguration
metadata:
name: default
spec:
serviceExternalIPs:
- cidr: 192.168.1.0/24
EOF- Verify on the external router:
show ip route 192.168.1.100You should see BGP routes from the Calico nodes.
Advanced Configuration
Fine-Grained Control Through Annotations
Add annotations to particular Services to control route advertisement:
apiVersion: v1
kind: Service
metadata:
name: my-service
annotations:
projectcalico.org/exportBgpServiceRoutes: "true" # Explicitly enable
# projectcalico.org/exportBgpServiceRoutes: "false" # Explicitly disable
spec:
# ...Using Calico's ServiceAdvertisement Resource (Calico v3.22+)
apiVersion: projectcalico.org/v3
kind: ServiceAdvertisement
metadata:
name: advertise-my-service
spec:
services: ["my-service"]
aggregation: /32
communities: ["64512:100"]Things to Keep in Mind
- Ensure your network devices have the correct BGP peers configured
- Advertising many Services in a large cluster may affect network performance
- Use route aggregation in production to reduce routing-table size
- For LoadBalancer Services, Calico can also integrate with MetalLB
Troubleshooting
Check BGP session status:
calicoctl node statusInspect advertised routes:
calicoctl get serviceadvertisementInspect BIRD configuration on the Calico node:
birdc show protocols birdc show route
This configuration advertises Kubernetes Service IP addresses to external networks over BGP for more flexible network integration.