You inherit a kubeadm cluster that was bootstrapped with the default flannel overlay. Pod-to-pod traffic works. Then a new team starts shipping workloads that need to talk to a database VLAN outside the cluster, the security review asks where the NetworkPolicy enforcement is, and the egress controller you bolted on doesn’t even see east-west traffic. Three months later you are wedged between a CNI that doesn’t enforce policy and an overlay that doesn’t route to the rest of the network. The fix is not “add an admission controller” — it’s swap the CNI for one that does both jobs, before the cluster has too much state for a clean migration.
What’s happening
Most kubeadm clusters get bootstrapped with whatever CNI the docs of the day suggested — flannel, weave, kube-router. Those are fine for a sandbox. In production you want three things the default CNIs don’t all give you: real NetworkPolicy enforcement (most defaults silently no-op the policy resources), BGP peering with your top-of-rack so pod IPs are routable from outside the cluster (no overlay tax, no double encapsulation), and a path forward for egress rules, IPv6, and eBPF acceleration. Calico in BGP mode covers all three. The trade-off is that BGP requires your physical network to be willing to peer — if you’re on a flat L2 segment with no router participation, you’ll fall back to IP-in-IP or VXLAN, and at that point Cilium is usually a better choice. This article assumes a routed environment (each node sits on its own /29 or /30, the upstream router speaks BGP, AS numbers are coordinated).
How to verify
Check whether your current CNI enforces NetworkPolicy at all:
kubectl create ns netpol-test
kubectl run web --image=nginx -n netpol-test
kubectl expose pod web --port=80 -n netpol-test
kubectl apply -n netpol-test -f - <<'YAML'
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: deny-all
spec:
podSelector: {}
policyTypes: ["Ingress"]
YAML
kubectl run -n netpol-test --rm -it --restart=Never \
--image=curlimages/curl curl-test -- curl -m 3 web
If the deny-all policy is in force, the curl times out. If it returns the nginx welcome page, your CNI is ignoring the policy — that’s a finding. Inspect the active CNI binary on a node:
ls /opt/cni/bin/
cat /etc/cni/net.d/*.conflist
Confirm the kubeadm --pod-network-cidr was set at init time (Calico will need to match it):
grep podSubnet /etc/kubernetes/manifests/kube-controller-manager.yaml \
|| grep -- --pod-network-cidr /etc/kubernetes/kubeadm-config.yaml
If you don’t see the pod CIDR, run kubeadm config view and confirm the cluster init parameters.
The fix
Save the script as /root/install-calico-bgp.sh and run it once from the first control-plane node. It downloads Calico 3.28, configures the operator with BGP mode (encapsulation off), creates a BGPConfiguration and per-node BGPPeer resources for your upstream router, enables NetworkPolicy enforcement, installs calicoctl for cluster operations, and verifies that route advertisement is happening. Edit the variables at the top: pod CIDR, service CIDR, node ASN, ToR ASN, ToR peer IPs.
#!/usr/bin/env bash
set -euo pipefail
### Calico 3.28 installer for kubeadm cluster with BGP routing
### Run once from any control-plane node after kubeadm init
### Assumes: pod CIDR already set at kubeadm init time, nodes have routable IPs
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
if ! command -v kubectl >/dev/null; then
echo "kubectl not found — run on a control-plane node."
exit 1
fi
# === EDIT BEFORE RUNNING ===
POD_CIDR="10.244.0.0/16" # must match kubeadm --pod-network-cidr
SERVICE_CIDR="10.96.0.0/12" # default kubeadm service CIDR
NODE_ASN="65001" # ASN advertised by Calico-running nodes
TOR_ASN="65000" # ASN of your top-of-rack switch
TOR_PEERS=("10.10.0.1" "10.10.0.2") # one or two ToR peer IPs
CALICO_VERSION="v3.28.2"
# ===========================
echo "==> Verifying cluster reachable"
kubectl cluster-info
echo "==> Confirming no existing CNI installed"
if kubectl get pods -n kube-system | grep -qE 'flannel|weave|kube-router|cilium'; then
echo "ERROR: another CNI appears to be installed. Remove it first."
echo " kubectl delete -n kube-system ds <cni-daemonset>"
echo " rm /etc/cni/net.d/*"
exit 1
fi
echo "==> Installing Tigera operator"
kubectl create -f "https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests/tigera-operator.yaml"
echo "==> Waiting for operator pod"
for i in {1..60}; do
if kubectl -n tigera-operator get pod -l name=tigera-operator \
-o jsonpath='{.items[0].status.phase}' 2>/dev/null | grep -q Running; then
break
fi
sleep 5
done
echo "==> Applying Installation custom resource"
cat <<EOF | kubectl apply -f -
apiVersion: operator.tigera.io/v1
kind: Installation
metadata:
name: default
spec:
calicoNetwork:
bgp: Enabled
ipPools:
- blockSize: 26
cidr: ${POD_CIDR}
encapsulation: None
natOutgoing: Disabled
nodeSelector: all()
nodeAddressAutodetectionV4:
kubernetes: NodeInternalIP
registry: quay.io
flexVolumePath: None
cni:
type: Calico
ipam:
type: Calico
---
apiVersion: operator.tigera.io/v1
kind: APIServer
metadata:
name: default
spec: {}
EOF
echo "==> Waiting for calico-system to come up"
for i in {1..60}; do
READY=$(kubectl -n calico-system get pods --no-headers 2>/dev/null \
| awk '{print $2}' | grep -c -E '^[0-9]+/[0-9]+$' || true)
RUNNING=$(kubectl -n calico-system get pods --no-headers 2>/dev/null \
| awk '$3=="Running"' | wc -l || true)
TOTAL=$(kubectl -n calico-system get pods --no-headers 2>/dev/null | wc -l || true)
if [[ "$TOTAL" -gt 0 && "$RUNNING" -eq "$TOTAL" ]]; then
echo " calico-system: $RUNNING/$TOTAL pods Running"
break
fi
sleep 5
done
echo "==> Installing calicoctl"
curl -L "https://github.com/projectcalico/calico/releases/download/${CALICO_VERSION}/calicoctl-linux-amd64" \
-o /usr/local/bin/calicoctl
chmod 755 /usr/local/bin/calicoctl
calicoctl version || true
echo "==> Creating BGPConfiguration (cluster-wide)"
cat <<EOF | calicoctl apply -f -
apiVersion: projectcalico.org/v3
kind: BGPConfiguration
metadata:
name: default
spec:
logSeverityScreen: Info
nodeToNodeMeshEnabled: false
asNumber: ${NODE_ASN}
serviceClusterIPs:
- cidr: ${SERVICE_CIDR}
listenPort: 179
EOF
echo "==> Creating BGPPeer resources for ToR uplinks"
for peer in "${TOR_PEERS[@]}"; do
peer_safe="${peer//./-}"
cat <<EOF | calicoctl apply -f -
apiVersion: projectcalico.org/v3
kind: BGPPeer
metadata:
name: tor-${peer_safe}
spec:
peerIP: ${peer}
asNumber: ${TOR_ASN}
keepOriginalNextHop: true
EOF
done
echo "==> Enabling per-node BGP password (optional but recommended)"
echo " Create a secret called 'bgp-password' in kube-system if you want MD5 auth"
echo "==> Disabling kube-proxy iptables NAT for pod-source preservation"
echo " (optional — only if you want pod IPs preserved end-to-end)"
echo "==> Applying baseline GlobalNetworkPolicy: kube-system allow-all + deny-all default"
cat <<EOF | calicoctl apply -f -
apiVersion: projectcalico.org/v3
kind: GlobalNetworkPolicy
metadata:
name: default-deny-egress-non-cluster
spec:
selector: all()
types:
- Egress
egress:
- action: Allow
destination:
nets:
- ${POD_CIDR}
- ${SERVICE_CIDR}
- action: Allow
protocol: UDP
destination:
ports: [53]
- action: Allow
protocol: TCP
destination:
ports: [53]
EOF
echo "==> Verifying BGP sessions"
sleep 10
calicoctl node status || true
echo "==> Confirming pod CIDR advertisement"
echo " From a ToR / upstream router, run:"
echo " show ip route bgp | include ${POD_CIDR%.*}"
echo
echo "==> Re-running NetworkPolicy enforcement test"
kubectl delete ns netpol-test --ignore-not-found
kubectl create ns netpol-test
kubectl run web --image=nginx -n netpol-test
kubectl wait --for=condition=ready pod/web -n netpol-test --timeout=60s
kubectl expose pod web --port=80 -n netpol-test
kubectl apply -n netpol-test -f - <<'YAML'
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: deny-all-ingress
spec:
podSelector: {}
policyTypes: ["Ingress"]
YAML
sleep 5
set +e
kubectl run -n netpol-test --rm -i --restart=Never --image=curlimages/curl \
curl-test -- curl -m 3 -sf web >/dev/null 2>&1
RC=$?
set -e
if [[ $RC -ne 0 ]]; then
echo " NetworkPolicy enforcement: PASS (curl correctly blocked)"
else
echo " NetworkPolicy enforcement: FAIL (curl reached pod with deny-all in place)"
fi
kubectl delete ns netpol-test --ignore-not-found
echo
echo "========================================"
echo "Calico BGP install complete"
echo "========================================"
echo
echo "Verify cluster:"
echo " kubectl get pods -n calico-system"
echo " calicoctl node status"
echo " calicoctl get bgpconfiguration -o yaml"
echo " calicoctl get bgppeer -o wide"
echo
echo "Watch BGP route count on a node:"
echo " ip route show proto bird | wc -l"
echo
echo "If BGP sessions never come up, check:"
echo " - Firewall on each node allows TCP/179 to/from \${TOR_PEERS[*]}"
echo " - ToR is configured to peer with this AS (${NODE_ASN})"
echo " - calico-node logs: kubectl -n calico-system logs -l k8s-app=calico-node -c calico-node"
Make it executable and run from one control-plane node:
chmod 700 /root/install-calico-bgp.sh
/root/install-calico-bgp.sh
The script is idempotent for the operator/install steps — re-running won’t break a working cluster, but it does re-apply the GlobalNetworkPolicy. Before merging this into prod, confirm the BGP sessions come up from each node (calicoctl node status should show Established for every peer), confirm the pod CIDR appears in the routing table of your ToR (show ip route bgp on the switch side), and run the NetworkPolicy test in a non-default namespace to validate enforcement end-to-end. The most common gotcha on first deploy is forgetting to disable the node-to-node mesh once you have a ToR peer — leave the mesh on and every node will try to peer with every other node, which scales badly past a dozen nodes. The script disables it; the operational rule is “ToR fabric does the BGP, nodes never peer with each other.”
We run Kubernetes clusters on our managed cloud compute under Managed Cloud Ops with CNI choice, BGP peering with your fabric, and policy auditing handled in our monitoring plane — start a scoping call when you want to stop running the control plane yourself.