Connect two CGWs
The previous tutorials each configure one side of a connection against a peer that exists elsewhere. This one builds both sides: two CGW releases in one Kubernetes cluster, connected by a certificate-authenticated, policy-based IPsec tunnel, with an eBGP session running inside that tunnel that exchanges a hundred routing prefixes, and with every exporter enabled.
It is a self-contained playground. Nothing in it touches the cluster network — the tunnel endpoints are dummy interfaces inside the pods, and the routes the two BIRD instances exchange never reach a pod's routing table.
Files
The snippets below are excerpts. Download the complete files:
- values-site-a.yamlOpens a file — the responder, and the side that carries the annotated comments
- values-site-b.yamlOpens a file — the initiator, a mirror of site A
- mkcerts.shOpens a file — builds the throwaway PKI and the Secrets that carry it into the releases
- values-support.yamlOpens a file — the
optional
cgw-supportrelease for the ServiceMonitor
Prerequisites
- A Kubernetes cluster. One node is enough, and no Multus or host networking is needed.
- Pods may request the
NET_ADMINcapability. Nothing here runs privileged or mounts a host path, so a restricted PodSecurity level is fine as long asNET_ADMINis allowed. helm,kubectlandopenssl3.x.- Pull access to
registry.cennso.com/cennso, the registry that also serves the chart. Both values files reference the image pull secretcennso-pull-secret, which has to exist in the namespace before the pods start.
No monitoring stack is needed to follow this tutorial — every check below reads the metrics directly from the exporters. Collecting them in Prometheus and viewing them in Grafana is an optional last step with prerequisites of its own.
Create the namespace and the pull secret
Both releases go into one namespace:
Build the PKI
The two CGWs authenticate the IPsec connection with X.509 certificates rather
than with a pre-shared key. That makes certificate handling observable: the
ipsec-exporter reports strongswan_cert_valid and
strongswan_cert_expire_secs for what strongSwan has loaded, so certificate
validation and an approaching expiry can be checked from the metrics. A
pre-shared key neither validates nor expires, and strongSwan loads no
certificate at all.
mkcerts.sh builds one self-signed root and one end-entity certificate per
site, signed by that root. The extended key usage is what makes a certificate
usable for IKE:
It writes the certificates and a secrets.yaml into pki/, which has to be
applied before the releases are installed — the values files reference these
Secrets by name:
The whole Secret is mounted as a directory, so every key in it becomes a file
name that strongSwan sees. That is why the leftcert= and : ECDSA lines
further down name these exact files.
Note
The site certificates are valid 30 days by default, so that
strongswan_cert_expire_secs reports a number worth reading instead of a
decade. Override it with LEAF_DAYS. Once they expire, the tunnel between the
sites stays down, and the IPSec X509 Certificates row of the dashboard shows
them as invalid.
To renew the certificates, reissue them and apply the Secrets again. The kubelet updates the mounted files in the running pods within about a minute. strongSwan reads them only once, so then have it load them on both sites:
ipsec rereadall loads the private key and the CA, and ipsec reload adds the
connections again, which loads the site certificate. Established SAs stay up
and no pod restarts.
Install site A, the responder
Site A waits for its peer (auto=add, right=%any), so it does not need to
know where site B runs:
The tunnel endpoints are the two pod IPs, while the protected subnets are the
dummy /32 addresses. Keeping the pod IPs out of the traffic selectors is what
stops the XFRM policies from capturing the pod's own cluster traffic — DNS, IKE
and the metric scrapes all stay outside the tunnel.
An init container creates that dummy interface and the route that steers
traffic for the peer endpoint into the IPsec policy. NET_ADMIN is enough; no
privileged container and no host mount, unlike the
route-based setup:
Site A also creates the ClusterIP service that site B dials, and enables the
iptables container. That ruleset is not there to filter — the chain policies
stay ACCEPT. Current kernels do not track a network namespace until a rule
actually asks for connection tracking, so without it the conntrack-exporter
would come up and report an empty table.
Install site B, the initiator
Site B is the mirror image, with two differences. It dials out as soon as strongSwan starts, and it addresses site A through the service name rather than a pod IP, which survives a pod restart:
Reaching site A through a ClusterIP means reaching it through a DNAT.
strongSwan sees that as a NAT and switches to UDP encapsulation; forceencaps=yes
in the shared sts-base section makes that unconditional, so the data path
also works on CNIs that do not forward plain ESP.
Note
right=cgw-a-ipsec is a short name, resolved by the pod's search
domain within its own namespace. It therefore depends on site A being
installed under the release name cgw-a in the same namespace. Use
cgw-a-ipsec.<namespace>.svc.cluster.local if you split the two releases up.
Both sides run an eBGP session between the tunnel endpoints, so the BGP traffic is carried by the IPsec SA and doubles as a payload generator for it. Each side originates one documentation prefix from RFC 5737, and the kernel protocol exports nothing:
Site B originates 100 more /32s from a second static protocol named bulk.
A session carrying a single prefix leaves the prefix counters at 1, which says
little about whether they work; with bulk the two directions are asymmetric —
101 exported here, 1 imported — so bird_protocol_prefix_import_count and
bird_protocol_prefix_export_count have something to report and it stays
obvious which direction is which.
Verify
The tunnel comes up within a few seconds. Site B initiates, so its status is the more interesting one:
Expect site-a[1]: ESTABLISHED and an installed CHILD_SA between
198.18.2.1/32 and 198.18.1.1/32. With certificate authentication the line
above it names both DNs — CN=site-b.cgw-test and CN=site-a.cgw-test —
instead of the @site-b/@site-a identities a PSK setup would show.
What strongSwan loaded of the PKI:
The data path, end to end through the tunnel:
The BGP session and what it carries:
site_a reaches state Established, and show route lists the locally
originated prefixes next to 203.0.113.0/24 learned from site A. None of them
appear in ip route inside the pod, which is what export none is for.
Every exporter can be scraped from inside the pod, through the debug
container that shares its network namespace:
To watch the encrypted packets on the wire:
Site A also records its own traffic with the PCAP collector: dumpcap writes
eth0 into a ring of two 10 MB files below /data/, named after
pcap.env.FILENAME. There is no rclone to upload them, so they stay in the
pod. The debug container mounts the same directory read-only, so that is
where to list them and copy them out:
The captures show IKE on UDP/500 and UDP/4500 in the clear, and the ESP that carries BGP and the ping probes encapsulated in UDP/4500, encrypted.
Optional: scrape it with Prometheus and look at the dashboard
Everything above reads the metrics straight from the exporters, so the tunnel
can be verified without any monitoring stack. To collect them continuously and
to see them in Grafana, install the cgw-support chart on top. It needs more
of the cluster than the two CGW releases do:
- The Prometheus Operator CRDs, for the
ServiceMonitor, plus a Prometheus instance whose ServiceMonitor selector picks this one up. - The Grafana Operator and a Grafana instance, for the
CGW dashboard. The dashboard is a
GrafanaDashboardcustom resource, and it is disabled invalues-support.yaml— setdashboard.enabled: trueand matchdashboard.instanceSelectorto the Grafana it should land in.
The ServiceMonitor covers all five exporter ports and is scoped to this namespace:
Once Prometheus scrapes the two pods, this deployment feeds every row of the
dashboard: the two dum0 addresses and the second, unused dummy interface on
site A give the CGW_INTERFACES variable something to select and the
Network Throughput row something to repeat over, the certificates populate
the IPsec X509 Certificates row, and the asymmetric BGP session fills the
Imported / exported prefixes panel.
Note
Where the cluster already runs a ServiceMonitor that selects
app: cgw, both will scrape these pods and every shared port is reported
twice. The samples differ in their job label, so they do not overwrite each
other, but they do double the series. Narrow the selector — by release,
for instance — to keep the two monitors apart.
Teardown
Troubleshooting
site-anever establishes. Check that site B resolves the peer:kubectl exec -n "$NS" deploy/cgw-b -c debug -- nslookup cgw-a-ipsec. The name is fixed invalues-site-b.yaml, so it breaks if site A is installed under another release name or into another namespace.- IKE completes, but the ping fails. Usually the route from the init
container is missing, for example because the pod has no default route on
eth0. Compareip route get 198.18.1.1inside the pod with the XFRM policy fromip xfrm policy. - The conntrack metrics stay empty. The
iptablescontainer has to be enabled; without a rule that asks for connection tracking, the namespace is not tracked at all. - NetworkPolicies in the namespace have to allow UDP 500 and 4500 between the two pods, in both directions.
Where to go next
Each side of this deployment is one of the earlier tutorials, combined:
- Set up a VPN connection with IPsec explains the
policy-based
ipsec.confthis tutorial mirrors on both sides. - Set up a certificate-based VPN explains the
Secrets that
mkcerts.shgenerates here. - Secure CGW using a firewall covers the
iptablesvalues that this deployment uses to engage conntrack. - Monitoring configuration documents the ping-exporter configuration, and Metrics lists what the other exporters publish.