Skip to content

Commit 1fa72db

Browse files
Merge pull request #7 from netbirdio/docs/ingress
Add documentation
2 parents 00cf45b + 58c2831 commit 1fa72db

File tree

14 files changed

+364
-89
lines changed

14 files changed

+364
-89
lines changed

README.md

Lines changed: 23 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,56 @@
11
# NetBird Kubernetes Operator
22
For easily provisioning access to Kubernetes resources using NetBird.
33

4+
https://github.com/user-attachments/assets/5472a499-e63d-4301-a513-ad84cfe5ca7b
5+
46
## Description
57

6-
This operator enables easily provisioning NetBird access on kubernetes clusters, allowing users to access internal resources directly.
8+
This operator easily provides NetBird access on Kubernetes clusters, allowing users to access internal resources directly.
79

810
## Getting Started
911

1012
### Prerequisites
11-
- helm version 3+
13+
- (Recommended) helm version 3+
1214
- kubectl version v1.11.3+.
1315
- Access to a Kubernetes v1.11.3+ cluster.
14-
- (Optional for Helm chart installation) Cert Manager.
15-
16-
### To Deploy on the cluster
16+
- (Recommended) Cert Manager.
1717

18-
**Using the install.yaml**
1918

20-
```sh
21-
kubectl create namespace netbird
22-
kubectl apply -n netbird -f https://github.com/netbirdio/kubernetes-operator/releases/latest/manifests/install.yaml
23-
```
19+
### Deployment
20+
> [!NOTE]
21+
> Helm Installation method is recommended due to the automation of multiple settings within the deployment.
2422
25-
**Using the Helm Chart**
23+
#### Using Helm
2624

25+
1. Add helm repository.
2726
```sh
2827
helm repo add netbirdio https://netbirdio.github.io/kubernetes-operator
29-
helm install -n netbird kubernetes-operator netbirdio/kubernetes-operator
3028
```
29+
2. (Recommended) Install [cert-manager](https://cert-manager.io/docs/installation/#default-static-install).
30+
3. (Recommended) Create a values.yaml file, check `helm show values netbirdio/kubernetes-operator` for more info.
31+
4. Install using `helm install --create-namespace -f values.yaml -n netbird netbird-operator netbirdio/kubernetes-operator`.
3132

32-
For more options, check the default values by running
33-
```sh
34-
helm show values netbirdio/kubernetes-operator
35-
```
33+
> Learn more about the values.yaml options [here](helm/kubernetes-operator/values.yaml) and [Granting controller access to NetBird Management](docs/usage.md#granting-controller-access-to-netbird-management).
34+
#### Using install.yaml
3635

37-
### To Uninstall
38-
**Using install.yaml**
36+
> [!IMPORTANT]
37+
> install.yaml only includes a very basic template for deploying a stripped-down version of Kubernetes-operator.
38+
> This excludes any and all configurations for ingress capabilities and requires the cert-manager to be installed.
3939
4040
```sh
41-
kubectl delete -n netbird -f https://github.com/netbirdio/kubernetes-operator/releases/latest/manifests/install.yaml
42-
kubectl delete namespace netbird
43-
```
44-
45-
**Using helm**
46-
47-
```sh
48-
helm uninstall -n netbird kubernetes-operator
41+
kubectl create namespace netbird
42+
kubectl apply -n netbird -f https://raw.githubusercontent.com/netbirdio/kubernetes-operator/refs/heads/main/manifests/install.yaml
4943
```
5044

51-
### Provision pods with NetBird access
52-
53-
1. Create a Setup Key in your [NetBird console](https://docs.netbird.io/how-to/register-machines-using-setup-keys#using-setup-keys).
54-
1. Create a Secret object in the namespace where you need to provision NetBird access (secret name and field can be anything).
55-
```yaml
56-
apiVersion: v1
57-
stringData:
58-
setupkey: EEEEEEEE-EEEE-EEEE-EEEE-EEEEEEEEEEEE
59-
kind: Secret
60-
metadata:
61-
name: test
62-
```
63-
1. Create an NBSetupKey object referring to your secret.
64-
```yaml
65-
apiVersion: netbird.io/v1
66-
kind: NBSetupKey
67-
metadata:
68-
name: test
69-
spec:
70-
# Optional, overrides management URL for this setupkey only
71-
# defaults to https://api.netbird.io
72-
managementURL: https://netbird.example.com
73-
secretKeyRef:
74-
name: test # Required
75-
key: setupkey # Required
76-
```
77-
1. Annotate the pods you need to inject NetBird into with `netbird.io/setup-key`.
78-
```yaml
79-
apiVersion: apps/v1
80-
kind: Deployment
81-
metadata:
82-
name: deployment
83-
spec:
84-
selector:
85-
matchLabels:
86-
app: myapp
87-
template:
88-
metadata:
89-
labels:
90-
app: myapp
91-
annotations:
92-
netbird.io/setup-key: test # Must match the name of an NBSetupKey object in the same namespace
93-
spec:
94-
containers:
95-
- image: yourimage
96-
name: container
45+
### Usage
9746

98-
```
47+
Check the usage of [usage.md](docs/usage.md) and examples.
9948

10049
## Contributing
10150

10251
### Prerequisites
10352

104-
To be able to develop on this project, you need to have the following tools installed:
53+
To be able to develop this project, you need to have the following tools installed:
10554

10655
- [Git](https://git-scm.com/).
10756
- [Make](https://www.gnu.org/software/make/).

docs/usage.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# Usage
2+
3+
## Provision pods with NetBird access
4+
5+
1. Create a Setup Key in your [NetBird console](https://docs.netbird.io/how-to/register-machines-using-setup-keys#using-setup-keys).
6+
1. Create a Secret object in the namespace where you need to provision NetBird access (secret name and field can be anything).
7+
```yaml
8+
apiVersion: v1
9+
stringData:
10+
setupkey: EEEEEEEE-EEEE-EEEE-EEEE-EEEEEEEEEEEE
11+
kind: Secret
12+
metadata:
13+
name: test
14+
```
15+
1. Create an NBSetupKey object referring to your secret.
16+
```yaml
17+
apiVersion: netbird.io/v1
18+
kind: NBSetupKey
19+
metadata:
20+
name: test
21+
spec:
22+
# Optional, overrides management URL for this setupkey only
23+
# defaults to https://api.netbird.io
24+
managementURL: https://netbird.example.com
25+
secretKeyRef:
26+
name: test # Required
27+
key: setupkey # Required
28+
```
29+
1. Annotate the pods you need to inject NetBird into with `netbird.io/setup-key`.
30+
```yaml
31+
kind: Deployment
32+
...
33+
spec:
34+
...
35+
template:
36+
metadata:
37+
annotations:
38+
netbird.io/setup-key: test # Must match the name of an NBSetupKey object in the same namespace
39+
...
40+
spec:
41+
containers:
42+
...
43+
```
44+
45+
## Provisioning Networks (Ingress Functionality)
46+
47+
### Granting controller access to NetBird Management
48+
49+
> [!IMPORTANT]
50+
> The NetBird Kubernetes operator generates configurations using NetBird API; editing or deleting these configurations in the NetBird console may cause temporary network disconnection until the operator reconciles the configuration.
51+
52+
1. Create a Service User on your NetBird dashboard (Must be Admin). [Doc](https://docs.netbird.io/how-to/access-netbird-public-api#creating-a-service-user).
53+
1. Create an access token for the Service User (Must be Admin). [Doc](https://docs.netbird.io/how-to/access-netbird-public-api#creating-a-service-user).
54+
1. Add access token to your helm values file under `netbirdAPI.key`.
55+
1. Alternatively, provision secret in the same namespace as the operator and set the key `NB_API_KEY` to the access token generated.
56+
1. Set `netbirdAPI.keyFromSecret` to the name of the secret created.
57+
1. Set `ingress.enabled` to `true`.
58+
1. Optionally, to provision the network immediately, set `ingress.router.enabled` to `true`.
59+
1. Optionally, to provision 1 network per > The NetBird Kubernetes operator generates configurations using NetBird API; editing or deleting these configurations in the NetBird console may cause temporary network disconnection until the operator reconciles the configuration. namespace, set `ingress.namespacedNetworks` to `true`.
60+
1. Run `helm install` or `helm upgrade`.
61+
62+
Minimum values.yaml example:
63+
```yaml
64+
netbirdAPI:
65+
key: "nbp_XXxxxxxxXXXXxxxxXXXXXxxx"
66+
67+
ingress:
68+
enabled: true
69+
cluster:
70+
name: kubernetes
71+
```
72+
73+
### Exposing a Service
74+
75+
> [!IMPORTANT]
76+
> Ingress DNS Resolution requires DNS Wildcard Routing to be enabled and at least one DNS Nameserver configured for clients.
77+
78+
|Annotation|Description|Default|Valid Values|
79+
|---|---|---|---|
80+
|`netbird.io/expose`| Expose service using NetBird Network Resource ||(`null`, `true`)|
81+
|`netbird.io/groups`| Comma-separated list of group names to assign to Network Resource |`{ClusterName}-{Namespace}-{Service}`|Any comma-separated list of strings.|
82+
|`netbird.io/resource-name`| Network Resource name |`{Namespace}-{Service}`|Any valid network resource name, make sure they're unique!|
83+
|`netbird.io/policy`| Name of NBPolicy to propagate service ports as destination. ||Name of any NBPolicy resource|
84+
|`netbird.io/policy-ports`| Narrow down exposed ports in a policy. Leave empty for all ports. ||Comma-separated integer list, integers must be between 0-65535|
85+
|`netbird.io/policy-protocol`| Narrow down protocol for use in a policy. Leave empty for all protocols. ||(`tcp`,`udp`)|
86+
87+
Example service:
88+
```yaml
89+
apiVersion: apps/v1
90+
kind: Deployment
91+
metadata:
92+
name: nginx-deployment
93+
spec:
94+
replicas: 0
95+
selector:
96+
matchLabels:
97+
app: nginx
98+
template:
99+
metadata:
100+
labels:
101+
app: nginx
102+
spec:
103+
containers:
104+
- name: nginx
105+
image: nginx:latest
106+
ports:
107+
- containerPort: 80
108+
109+
---
110+
apiVersion: v1
111+
kind: Service
112+
metadata:
113+
name: nginx-service
114+
annotations:
115+
netbird.io/expose: "true"
116+
netbird.io/groups: "groupA,groupB"
117+
spec:
118+
selector:
119+
app: nginx
120+
ports:
121+
- protocol: TCP
122+
port: 8080
123+
targetPort: 80
124+
type: ClusterIP
125+
```
126+
### Notes
127+
* `netbird.io/expose` will interpret any string as a `true` value; the only `false` value is `null`.
128+
* The operator does **not** handle duplicate resource names within the same network, it is up to you to ensure resource names are unique within the same network.
129+
* While the NetBird console will allow group names to contain commas, this is not allowed in `netbird.io/groups` annotation as commas are used as separators.
130+
* If a group already exists on NetBird console with the same name, NetBird Operator will use that group ID instead of creating a new group.
131+
* NetBird Operator will attempt to clean up any resources created, including groups created for resources.
132+
* If a group is used by resources that the operator cannot clean up, the operator will eventually ignore the group in NetBird.
133+
* It's recommended that unique groups be used per NetBird Operator installation to remove any possible conflicts.
134+
* The Operator does not validate service annotations on updates, as this may cause unnecessary overhead on any Service update.
135+
136+
### Managing Policies
137+
138+
Simply add policies under `ingress.policies`, for example:
139+
1. Add the following configuration in your `values.yaml` file.
140+
```yaml
141+
ingress:
142+
policies:
143+
default:
144+
name: Kubernetes Default Policy # Required, name of policy in NetBird console
145+
description: Default # Optional
146+
sourceGroups: # Required, name of groups to assign as source in Policy.
147+
- All
148+
ports: # Optional, resources annotated 'netbird.io/policy=default' will append to this.
149+
- 443
150+
protocols: # Optional, restricts protocols allowed to resources, defaults to ['tcp', 'udp'].
151+
- tcp
152+
- udp
153+
bidirectional: true # Optional, defaults to true
154+
```
155+
2. Reference policy in Services using `netbird.io/policy=default`, this will add relevant ports and destination groups to policy.
156+
3. (Optional) Limit specific ports in exposed service by adding `netbird.io/policy-ports=443`.
157+
4. (Optional) Limit specific protocol in exposed service by adding `netbird.io/policy-protocol=tcp`.
158+
159+
#### Notes
160+
* Each NBPolicy will only create policies in the NetBird console when the information provided is enough to create one. If no services act as a destination or specified services do not conform to the protocol(s) defined, the policy will not be created.
161+
* Each NBPolicy will create one policy in the NetBird console per protocol specified as long as the protocol has destinations; this ensures better-secured policies by separating ports for TCP and UDP.
162+
* Policies currently do not support ICMP protocol, as ICMP is not supported in Kubernetes services, and there are [no current plans to support it](https://discuss.kubernetes.io/t/icmp-support-for-kubernetes-service/21738).
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
app: test
6+
name: test
7+
namespace: default
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: test
13+
strategy:
14+
rollingUpdate:
15+
maxSurge: 25%
16+
maxUnavailable: 25%
17+
type: RollingUpdate
18+
template:
19+
metadata:
20+
labels:
21+
app: test
22+
spec:
23+
containers:
24+
- image: nginx
25+
imagePullPolicy: Always
26+
name: nginx
27+
---
28+
apiVersion: v1
29+
kind: Service
30+
metadata:
31+
annotations:
32+
netbird.io/expose: "true"
33+
netbird.io/policy: default
34+
netbird.io/resource-name: nginx
35+
labels:
36+
app: test
37+
name: test
38+
namespace: default
39+
spec:
40+
ports:
41+
- name: http
42+
port: 80
43+
protocol: TCP
44+
targetPort: 80
45+
selector:
46+
app: test
47+
type: ClusterIP

examples/ingress/values.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ingress:
2+
enabled: true
3+
router:
4+
enabled: true
5+
policies:
6+
default:
7+
name: Kubernetes Default Policy
8+
sourceGroups:
9+
- All
10+
11+
netbirdAPI:
12+
key: "nbp_m0LM9ZZvDUzFO0pY50iChDOTxJgKFM3DIqmZ" # Replace with valid NetBird Service Account token

0 commit comments

Comments
 (0)