|
| 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 | +> 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 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 network immediately, set `ingress.router.enabled` to `true`. |
| 59 | + 1. Optionally, to provision 1 network per kubernetes namespace, set `ingress.namespacedNetworks` to `true`. |
| 60 | +1. Run `helm install` or `helm upgrade`. |
| 61 | + |
| 62 | +### Exposing a Service |
| 63 | + |
| 64 | +> [!IMPORTANT] |
| 65 | +> Ingress DNS Resolution requires DNS Wildcard Routing to be enabled, and at least one DNS Nameserver configured for clients. |
| 66 | + |
| 67 | +|Annotation|Description|Default|Valid Values| |
| 68 | +|---|---|---|---| |
| 69 | +|`netbird.io/expose`|Expose service using NetBird Network Resource||(`null`, `true`)| |
| 70 | +|`netbird.io/groups`|Comma-separated list of group names to assign to Network Resource|`{ClusterName}-{Namespace}-{Service}`|Any comma-separated list of strings.| |
| 71 | +|`netbird.io/resource-name`|Network Resource name|`{Namespace}-{Service}`|Any valid network resource name, make sure they're unique!| |
| 72 | +|`netbird.io/policy`|Name of NBPolicy to propagate service ports as destination.||Name of any NBPolicy resource| |
| 73 | +|`netbird.io/policy-ports`|Narrow down exposed ports in policy, leave empty for all ports.||Comma-separated integer list, integers must be between 0-65535| |
| 74 | +|`netbird.io/policy-protocol`|Narrow down protocol for use in policy, leave empty for all protocols.||(`tcp`,`udp`)| |
| 75 | + |
| 76 | +### Notes |
| 77 | +* `netbird.io/expose` will interpret any string as true value, the only false value is `null`. |
| 78 | +* 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. |
| 79 | +* 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. |
| 80 | +* 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. |
| 81 | +* NetBird Operator will attempt to clean up any resources created, including groups created for resources. |
| 82 | + * In case a group is used by resources that cannot be cleaned up by the operator, the operator will eventually ignore the group in NetBird. |
| 83 | + * It's recommended to use unique groups per NetBird Operator installation to remove any possible conflicts. |
| 84 | +* NetBird Operator does not validate service annotations on update, as this may cause unnecessary overhead on any Service update. |
| 85 | + |
| 86 | +### Managing Policies |
| 87 | + |
| 88 | +Simply add policies under `ingress.policies`, for example: |
| 89 | +1. Add the following configuration in your `values.yaml` file. |
| 90 | +```yaml |
| 91 | +ingress: |
| 92 | + policies: |
| 93 | + default: |
| 94 | + name: Kubernetes Default Policy # Required, name of policy in NetBird console |
| 95 | + description: Default # Optional |
| 96 | + sourceGroups: # Required, name of groups to assign as source in Policy. |
| 97 | + - All |
| 98 | + ports: # Optional, resources annotated 'netbird.io/policy=default' will append to this. |
| 99 | + - 443 |
| 100 | + protocols: # Optional, restricts protocols allowed to resources, defaults to ['tcp', 'udp']. |
| 101 | + - tcp |
| 102 | + - udp |
| 103 | + bidirectional: true # Optional, defaults to true |
| 104 | +``` |
| 105 | +2. Reference policy in Services using `netbird.io/policy=default`, this will add relevant ports and destination groups to Policy. |
| 106 | +3. (Optional) limit specific ports in exposed service by adding `netbird.io/policy-ports=443`. |
| 107 | +4. (Optional) limit specific protocol in exposed service by adding `netbird.io/policy-protocol=tcp`. |
| 108 | + |
| 109 | +#### Notes |
| 110 | +* Each NBPolicy will only create policies in NetBird console when information provided is enough to create one. If there are no services acting as destination, or specified services do not conform to the protocol(s) defined, policy will not be created. |
| 111 | +* Each NBPolicy will create one Policy in NetBird console per protocol specified as long as protocol has destinations, this ensures better secured policies by separating ports for TCP and UDP. |
| 112 | +* 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). |
0 commit comments