Skip to content

Commit 6d9367a

Browse files
authored
Add Deploy routing peers to a Kubernetes cluster guide (#151)
* Add Deploy routing peers to a Kubernetes cluster guide * adjust images width
1 parent c0a5819 commit 6d9367a

File tree

8 files changed

+131
-0
lines changed

8 files changed

+131
-0
lines changed
Loading
Loading
Loading
Loading
Loading
Loading

src/components/NavigationDocs.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const docsNavigation = [
6060
{ title: 'Running NetBird on FaaS', href: '/how-to/netbird-on-faas' },
6161
{ title: 'Delete your NetBird account', href: '/how-to/delete-account' },
6262
{ title: 'Manage access with posture checks', href: '/how-to/manage-posture-checks' },
63+
{ title: 'Deploy routing peers to Kubernetes', href: '/how-to/routing-peers-and-kubernetes' },
6364
{ title: 'Report bugs and issues', href: '/how-to/report-bug-issues' },
6465
{ title: 'Troubleshooting client issues', href: '/how-to/troubleshooting-client' },
6566
{ title: 'Examples', href: '/how-to/examples' },
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import {Note} from "@/components/mdx";
2+
3+
# Deploy routing peers to a Kubernetes cluster
4+
This guide provides instructions on how to use NetBird agent within a Kubernetes cluster to establish secure, peer-to-peer
5+
networking between your Kubernetes pods and external services or other clusters.
6+
7+
## Prerequisites
8+
- Access to a Kubernetes cluster
9+
- Kubernetes CLI (kubectl) installed and configured
10+
- Access to the NetBird management dashboard
11+
12+
## Use Case Scenario
13+
Imagine you're running a multi-cloud Kubernetes environment where your application components are distributed across
14+
different cloud providers, including on-premise Kubernetes clusters. Your goal is to securely access your kubernetes services
15+
from hosts running on a Hetzner without exposing them to the public internet.
16+
17+
## Step-by-Step guide
18+
### Step 1: Create a setup key
19+
Navigate to Setup Keys in the NetBird management dashboard and click on "Create setup key".
20+
21+
Choose a name, e.g. `Kubernetes routing peers`, mark the key as `reusable` and enable `Ephemeral peers`. This option is
22+
ideal for stateless workloads like containers, where peers that are offline for over 10 minutes are automatically removed.
23+
24+
Create or add group called `kubernetes-routers` to the `Auto-assigned groups` list. This designation can be adjusted to
25+
suit your needs.
26+
27+
See the screenshot below for reference:
28+
<p>
29+
<img src="/docs-static/img/how-to-guides/k8s-create-setup-key.png" alt="k8s-create-setup-key" width="400" className="imagewrapper"/>
30+
</p>
31+
32+
With your setup key created, note it down for the next steps.
33+
34+
### Step 2: Add a network route
35+
Navigate to Network Routes in the NetBird management dashboard and click on `Add Route`.
36+
37+
Set your kubernetes pod range as the destination network, and select the `Peer group` option, choosing the
38+
"kubernetes-routers" group. This configuration allows for scaling pods as necessary within your Kubernetes cluster.
39+
40+
Set the distribution group to `hetzner-servers`. This group is used to distribute the route to all servers in the group.
41+
42+
See the screenshot below for reference:
43+
<p>
44+
<img src="/docs-static/img/how-to-guides/k8s-add-network-route.png" alt="k8s-add-network-route" width="400" className="imagewrapper"/>
45+
</p>
46+
47+
Click on Name & Description to give your route a name and description. Then click on `Add Route` to save your changes.
48+
<p>
49+
<img src="/docs-static/img/how-to-guides/k8s-name-network-route.png" alt="k8s-name-network-route" width="400" className="imagewrapper"/>
50+
</p>
51+
52+
### Step 3: Create an access control policy
53+
Navigate to Access Control Policies in the NetBird management dashboard and click on `Add Policy`.
54+
55+
Set the source group to `hetzner-servers` and the destination group to `kubernetes-routers`. This configuration allows
56+
the Hetzner servers to access the kubernetes pods.
57+
<p>
58+
<img src="/docs-static/img/how-to-guides/k8s-add-access-control-policy.png" alt="k8s-add-access-control-policy" width="400" className="imagewrapper"/>
59+
</p>
60+
61+
Click on Name & Description to give your policy a name and description. Then click on `Add Policy` to save your changes.
62+
<p>
63+
<img src="/docs-static/img/how-to-guides/k8s-name-access-control-policy.png" alt="k8s-name-access-control-policy" width="400" className="imagewrapper"/>
64+
</p>
65+
66+
### Step 4: Deploy the NetBird agent
67+
You can deploy the NetBird agent using a daemon set or a deployment. Below is an example of a deployment configuration with 3 replicas.
68+
69+
```yaml
70+
---
71+
apiVersion: apps/v1
72+
kind: Deployment
73+
metadata:
74+
name: netbird
75+
namespace: default
76+
spec:
77+
replicas: 3
78+
selector:
79+
matchLabels:
80+
app: netbird
81+
template:
82+
metadata:
83+
labels:
84+
app: netbird
85+
spec:
86+
containers:
87+
- name: netbird
88+
image: netbirdio/netbird:latest
89+
env:
90+
- name: NB_SETUP_KEY
91+
value: "0000000000-0000-0000-0000-0000000000" # replace with your setup key
92+
- name: NB_HOSTNAME
93+
value: "netbird-k8s-router" # name that will appear in the management UI
94+
- name: NB_LOG_LEVEL
95+
value: "info"
96+
securityContext:
97+
capabilities:
98+
add:
99+
- NET_ADMIN
100+
- SYS_RESOURCE
101+
- SYS_ADMIN
102+
```
103+
104+
Edit your deployment.yml file, incorporating the setup key into the relevant sections.
105+
106+
Apply the updated deployment file to your Kubernetes cluster using the following command:
107+
```shell
108+
kubectl apply -f deployment.yml
109+
```
110+
111+
<Note>
112+
In this example the setup key is passed as an environment variable. You should use a secret to pass the setup key.
113+
</Note>
114+
115+
### Step 5: Verify the deployment
116+
After deploying the NetBird agent, you can verify that the agent is running by checking the logs of the pods.
117+
118+
```shell
119+
kubectl logs -l app=netbird
120+
```
121+
122+
You can also verify that the agent is connected to the NetBird management dashboard by checking the dashboard.
123+
<p>
124+
<img src="/docs-static/img/how-to-guides/k8s-netbird-agent-connected.png" alt="k8s-netbird-agent-connected" width="800" className="imagewrapper"/>
125+
</p>
126+
127+
## Conclusion
128+
By following these steps, you've successfully integrated Netbird within your Kubernetes cluster, enabling secure,
129+
peer-to-peer networking between your Kubernetes pods and external services. This setup is particularly beneficial for
130+
hybrid, multi-cloud environments and remote access, ensuring seamless connectivity and security across your infrastructure.

0 commit comments

Comments
 (0)