Wireguard
Run a Pod with WireGuard Interface
This guide explains how to securely attach a WireGuard interface to a Pod using a Kubernetes Secret for key management.
Why Use WireGuard?
WireGuard creates encrypted tunnels between the Pod and a node outside the Kubernetes cluster, enabling secure communication across networks (e.g., cross-cluster connectivity, bypassing NAT, or encrypting traffic).
Step 1: Create a Secret for WireGuard Private Key
Create the file config.json
with the following content:
Replace all three IP adresses and both keys with real content.
Current limitations
- Even if the endpoint supports multiple client addresses, current implementation in Kubernetes supports only a single address.
- The name of the file must be strictly
config.json
. - The
address
andallowedIPs
must not be from the same network. E.g.,"address": "10.1.2.3/32"
and"allowedIPs": ["10.1.2.0/24"]
will not work.
Create the secret:
Step 2: Create a Pod with WireGuard Interface
Deploy a Pod with the WireGuard interface, it will be net1
(attached via the k8s.v1.cni.cncf.io/networks
annotation).
Verification
-
Check if
net1
interface exists (requiresip
command in the Pod):Expect output showing the WireGuard interface with an IP.
-
Test connectivity (requires
ping
command in the Pod):Replace
<PEER_IP>
with the peer’s WireGuard IP from theconfig.json
.
Last updated on