diff --git a/.gitignore b/.gitignore index 45297fe5..68434da5 100644 --- a/.gitignore +++ b/.gitignore @@ -29,5 +29,9 @@ go.work *.swp *.swo *~ -.drawio.dtmp +*.drawio.dtmp +*drawio.svg.bkp .DS_Store + +# Temporary files +tmp diff --git a/README.md b/README.md index 4ae46011..da7136b7 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,14 @@ Example of assigning a Prefix using PrefixClaim: Key information can be found in the yaml formatted output of these resources, as well as in the events and Operator logs. +To test at scale, you can use yq to patch the Kubernetes manifests. The following is an example to create 100 IpAddressClaims based on the sample yaml file: + +```bash +for i in {001..100}; do + name="ipc-${i}" yq e '.metadata.name=strenv(name)' config/samples/netbox_v1_ipaddressclaim.yaml | kubectl apply -f - +done +``` + # Mixed usage of Prefixes Note that NetBox does handle the Address management of Prefixes separately from IP Ranges and IP Addresses. This is important to know when you plan to use the same NetBox Prefix as a parentPrefix for your IpAddressClaims, IpRangeClaims and PrefixClaims. diff --git a/docs/examples/README.md b/docs/examples/README.md new file mode 100644 index 00000000..f16d2c99 --- /dev/null +++ b/docs/examples/README.md @@ -0,0 +1,13 @@ +# NetBox Operator Examples + +This folder shows some examples how the NetBox Operator can be used. + +Each example folder contains a README.md which explains how you can set up your local enviroment to step through the examples. + +Prerequisites: +- go version v1.24.0+ +- docker image netbox-operatore:build-local +- kustomize version v5.5.0+ +- kubectl version v1.32.2+ +- kind v0.27.0 +- docker cli diff --git a/docs/examples/example1-getting-started/README.md b/docs/examples/example1-getting-started/README.md new file mode 100644 index 00000000..944200b8 --- /dev/null +++ b/docs/examples/example1-getting-started/README.md @@ -0,0 +1,64 @@ +# Example 1: Getting Started + +# 0.1 Create a local cluster with nebox-installed + +1. use the 'create-kind' and 'deploy-kind' targets from the Makefile to create a kind cluster and deploy NetBox and NetBox Operator on it +```bash +make create-kind +make deploy-kind +``` + +# 0.2 Manually Create a Prefix in NetBox + +Before prefixes and ip addresses can be claimed with the NetBox operator, a prefix has to be created in NetBox. + +1. Port-forward NetBox: +```bash +kubectl port-forward deploy/netbox 8080:8080 +``` +2. Open in your favorite browser and log in with the username `admin` and password `admin` +3. Create a new prefix '3.0.0.64/26' with custom field 'environment: prod' + +# 0.3 Navigate to the example folder + +Navigate to 'docs/examples/example1-getting-started' to run the examples below + +# 1.1 Claim a Prefix + +In this example, we use a `.spec.parentPrefix` that we know in advance. This is useful if you already know exactly from which prefix you want to claim from. + +1. Inspect the spec of the sample prefix claim CR +```bash +cat prefixclaim-simple.yaml +``` +2. Apply the manifest defining the prefix claim +```bash +kubectl apply -f prefixclaim-simple.yaml +``` +3. Check that the prefix claim CR got a prefix assigned +```bash +kubectl get pxc,px +``` + +![Example 1.1](prefixclaim-simple.drawio.svg) + +# 1.2 Dynamically Claim a Prefix with a Parent Prefix Selector + +In this example, we use a `.spec.parentPrefixSelector`, which is a list of selectors that tell NetBox Operator from which parent prefixes to claim our Prefix from. + +Navigate to 'docs/examples/example1-getting-started' to run the following commands. + +1. Inspect the spec of the sample prefix claim CR +```bash +cat prefixclaim-dynamic.yaml +``` +2. Apply the manifest defining the prefix claim +```bash +kubectl apply -f prefixclaim-dynamic.yaml +``` +3. Check that the prefix claim CR got a prefix addigned +```bash +kubectl get pxc,px +``` + +![Example 1.2](prefixclaim-dynamic.drawio.svg) diff --git a/docs/examples/example1-getting-started/dynamic_prefixclaim-large-font.drawio.svg b/docs/examples/example1-getting-started/dynamic_prefixclaim-large-font.drawio.svg new file mode 100644 index 00000000..56e2c3d2 --- /dev/null +++ b/docs/examples/example1-getting-started/dynamic_prefixclaim-large-font.drawio.svg @@ -0,0 +1,532 @@ + + + + + + + + + + + + + +
+
+
+ + k8s cluster + +
+
+
+
+ + k8s cluster + +
+
+
+ + + + + + + + + + +
+
+
+ + user namespace + +
+
+
+
+ + user namespace + +
+
+
+ + + + + + + + + + + +
+
+
+ + NetBox REST API + +
+
+
+
+ + NetBox REST API + +
+
+
+ + + + + + + +
+
+
+ + namespace netbox-operator + +
+
+
+
+ + namespace netbox-operator + +
+
+
+ + + + + + + + +
+
+
+ + create + +
+
+
+
+ + create + +
+
+
+ + + + + + + + +
+
+
+ + reconcile + +
+
+
+
+ + reconcile + +
+
+
+ + + + + + + + +
+
+
+ + create/update/delete + +
+
+
+
+ + create/update/delete + +
+
+
+ + + + + + + + +
+
+
+ + get available prefixes + +
+
+
+
+ + get available prefixes + +
+
+
+ + + + + + + + + + + +
+
+
+ + NetBox Operator + +
+
+
+
+ + NetBox Operator + +
+
+
+ + + + + + + +
+
+
+
+ + PrefixClaim CR + +
+
+
+
+
+ + PrefixClaim CR + +
+
+
+ + + + + + + +
+
+
+ + Parent +
+ Prefix +
+
+
+
+
+ + Parent... + +
+
+
+ + + + + + + + +
+
+
+ + reconcile + +
+
+
+
+ + reconcile + +
+
+
+ + + + + + + + +
+
+
+ + ownerReference + +
+
+
+
+ + ownerReference + +
+
+
+ + + + + + + +
+
+
+
+ + Prefix CR + +
+
+
+
+
+ + Prefix CR + +
+
+
+ + + + + + + +
+
+
+ + Claimed Prefix + +
+
+
+
+ + Claimed Prefix + +
+
+
+ + + + + + + + + + + + + + +
+
+
+ + consumer + +
+
+
+
+ + consumer + +
+
+
+ + + + + + + + +
+
+
+ + User +
+ w/ kubectl +
+
+
+
+
+ + User... + +
+
+
+ + + + + + + + +
+
+
+ + GitOps +
+ w/ Argo or Flux +
+
+
+
+
+ + GitOps... + +
+
+
+ + + + + + + +
+
+
+ + and/or + +
+
+
+
+ + and/or + +
+
+
+ + + + + + + +
+
+
+ + Matching Prefixes + +
+
+
+
+ + Matching Prefixes + +
+
+
+ + + + +
+
+
+ + get matching prefixes + +
+
+
+
+ + get matching prefixes + +
+
+
+
+ + + + + Text is not SVG - cannot display + + + +
\ No newline at end of file diff --git a/docs/examples/example1-getting-started/prefixclaim-dynamic.drawio.svg b/docs/examples/example1-getting-started/prefixclaim-dynamic.drawio.svg new file mode 100644 index 00000000..00f401cd --- /dev/null +++ b/docs/examples/example1-getting-started/prefixclaim-dynamic.drawio.svg @@ -0,0 +1,469 @@ + + + + + + + + + + + + + +
+
+
+ k8s cluster +
+
+
+
+ + k8s cluster + +
+
+
+ + + + + + + + + + +
+
+
+ user namespace +
+
+
+
+ + user namespace + +
+
+
+ + + + + + + + + + + +
+
+
+ consumer +
+
+
+
+ + consumer + +
+
+
+ + + + + + + +
+
+
+ NetBox REST API +
+
+
+
+ + NetBox REST API + +
+
+
+ + + + + + + +
+
+
+ namespace netbox-operator +
+
+
+
+ + namespace netbox-operator + +
+
+
+ + + + + + + + +
+
+
+ create +
+
+
+
+ + create + +
+
+
+ + + + + + + + +
+
+
+ reconcile +
+
+
+
+ + reconcile + +
+
+
+ + + + + + + + +
+
+
+ create/update/delete +
+
+
+
+ + create/update/delete + +
+
+
+ + + + + + + + +
+
+
+ select matching parnet prefix +
+ and get available prefixes +
+
+
+
+
+ + select matching parnet prefix... + +
+
+
+ + + + + + + +
+
+
+ netbox-operator +
+
+
+
+ + netbox-operator + +
+
+
+ + + + + + + +
+
+
+
+ kind: PrefixClaim +
+
+ spec: +
+
+ parentPrefixSelector: +
+
+ environment: prod +
+
+ prefixLength: /28 +
+
+
+
+
+
+ + kind: PrefixClaim... + +
+
+
+ + + + + + + +
+
+
+ Prefix 2.0.0.0/16 +
+
+
+
+ + Prefix 2.0.0.0/16 + +
+
+
+ + + + + + + + +
+
+
+ User +
+ w/ kubectl +
+
+
+
+ + User... + +
+
+
+ + + + + + + + +
+
+
+ GitOps +
+ w/ Argo or Flux +
+
+
+
+ + GitOps... + +
+
+
+ + + + + + + +
+
+
+ and/or +
+
+
+
+ + and/or + +
+
+
+ + + + + + + + +
+
+
+ reconcile +
+
+
+
+ + reconcile + +
+
+
+ + + + + + + + +
+
+
+ ownerReference +
+
+
+
+ + ownerReference + +
+
+
+ + + + + + + +
+
+
+
+ kind: Prefix +
+
+ spec: +
+
+ prefix: 2.0.0.0/28 +
+
+
+
+
+
+
+
+ + kind: Prefix... + +
+
+
+ + + + + + + +
+
+
+ Prefix 2.0.0.0/28 +
+
+
+
+ + Prefix 2.0.0.0/28 + +
+
+
+ + + + + + +
+ + + + + Text is not SVG - cannot display + + + +
\ No newline at end of file diff --git a/docs/examples/example1-getting-started/prefixclaim-dynamic.yaml b/docs/examples/example1-getting-started/prefixclaim-dynamic.yaml new file mode 100644 index 00000000..4a6c0d13 --- /dev/null +++ b/docs/examples/example1-getting-started/prefixclaim-dynamic.yaml @@ -0,0 +1,13 @@ +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + labels: + app.kubernetes.io/name: netbox-operator + app.kubernetes.io/managed-by: kustomize + name: dynamic-prefix-claim +spec: + tenant: "MY_TENANT" + parentPrefixSelector: + environment: prod + family: IPv4 + prefixLength: "/30" diff --git a/docs/examples/example1-getting-started/prefixclaim-simple.drawio.svg b/docs/examples/example1-getting-started/prefixclaim-simple.drawio.svg new file mode 100644 index 00000000..9e28233a --- /dev/null +++ b/docs/examples/example1-getting-started/prefixclaim-simple.drawio.svg @@ -0,0 +1,463 @@ + + + + + + + + + + + + + +
+
+
+ k8s cluster +
+
+
+
+ + k8s cluster + +
+
+
+ + + + + + + + + + +
+
+
+ user namespace +
+
+
+
+ + user namespace + +
+
+
+ + + + + + + + + + + +
+
+
+ consumer +
+
+
+
+ + consumer + +
+
+
+ + + + + + + +
+
+
+ NetBox REST API +
+
+
+
+ + NetBox REST API + +
+
+
+ + + + + + + +
+
+
+ namespace netbox-operator +
+
+
+
+ + namespace netbox-operator + +
+
+
+ + + + + + + + +
+
+
+ create +
+
+
+
+ + create + +
+
+
+ + + + + + + + +
+
+
+ reconcile +
+
+
+
+ + reconcile + +
+
+
+ + + + + + + + +
+
+
+ create/update/delete +
+
+
+
+ + create/update/delete + +
+
+
+ + + + + + + + +
+
+
+ get available prefixes +
+
+
+
+ + get available prefixes + +
+
+
+ + + + + + + +
+
+
+ netbox-operator +
+
+
+
+ + netbox-operator + +
+
+
+ + + + + + + +
+
+
+
+ kind: PrefixClaim +
+
+ spec: +
+
+ parentPrefix: 2.0.0.0/16 +
+
+ prefixLength: /28 +
+
+
+
+
+
+ + kind: PrefixClaim... + +
+
+
+ + + + + + + +
+
+
+ Prefix 2.0.0.0/16 +
+
+
+
+ + Prefix 2.0.0.0/16 + +
+
+
+ + + + + + + + +
+
+
+ User +
+ w/ kubectl +
+
+
+
+ + User... + +
+
+
+ + + + + + + + +
+
+
+ GitOps +
+ w/ Argo or Flux +
+
+
+
+ + GitOps... + +
+
+
+ + + + + + + +
+
+
+ and/or +
+
+
+
+ + and/or + +
+
+
+ + + + + + + + +
+
+
+ reconcile +
+
+
+
+ + reconcile + +
+
+
+ + + + + + + + +
+
+
+ ownerReference +
+
+
+
+ + ownerReference + +
+
+
+ + + + + + + +
+
+
+
+ kind: Prefix +
+
+ spec: +
+
+ prefix: 2.0.0.0/28 +
+
+
+
+
+
+
+
+ + kind: Prefix... + +
+
+
+ + + + + + + +
+
+
+ Prefix 2.0.0.0/28 +
+
+
+
+ + Prefix 2.0.0.0/28 + +
+
+
+ + + + + + +
+ + + + + Text is not SVG - cannot display + + + +
\ No newline at end of file diff --git a/docs/examples/example1-getting-started/prefixclaim-simple.yaml b/docs/examples/example1-getting-started/prefixclaim-simple.yaml new file mode 100644 index 00000000..483a0c3d --- /dev/null +++ b/docs/examples/example1-getting-started/prefixclaim-simple.yaml @@ -0,0 +1,11 @@ +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + labels: + app.kubernetes.io/name: netbox-operator + app.kubernetes.io/managed-by: kustomize + name: simple-prefixclaim +spec: + tenant: "MY_TENANT" + parentPrefix: 3.0.0.64/26 + prefixLength: "/30" diff --git a/docs/examples/example1-getting-started/simple_prefixclaim-large-font.drawio.svg b/docs/examples/example1-getting-started/simple_prefixclaim-large-font.drawio.svg new file mode 100644 index 00000000..d89c2dbe --- /dev/null +++ b/docs/examples/example1-getting-started/simple_prefixclaim-large-font.drawio.svg @@ -0,0 +1,485 @@ + + + + + + + + + + + + + +
+
+
+ + k8s cluster + +
+
+
+
+ + k8s cluster + +
+
+
+ + + + + + + + + + +
+
+
+ + user namespace + +
+
+
+
+ + user namespace + +
+
+
+ + + + + + + + + + + +
+
+
+ + NetBox REST API + +
+
+
+
+ + NetBox REST API + +
+
+
+ + + + + + + +
+
+
+ + namespace netbox-operator + +
+
+
+
+ + namespace netbox-operator + +
+
+
+ + + + + + + + +
+
+
+ + create + +
+
+
+
+ + create + +
+
+
+ + + + + + + + +
+
+
+ + reconcile + +
+
+
+
+ + reconcile + +
+
+
+ + + + + + + + +
+
+
+ + create/update/delete + +
+
+
+
+ + create/update/delete + +
+
+
+ + + + + + + + +
+
+
+ + get available prefixes + +
+
+
+
+ + get available prefixes + +
+
+
+ + + + + + + +
+
+
+ + NetBox Operator + +
+
+
+
+ + NetBox Operator + +
+
+
+ + + + + + + +
+
+
+
+ + PrefixClaim CR + +
+
+
+
+
+ + PrefixClaim CR + +
+
+
+ + + + + + + +
+
+
+ + Parent +
+ Prefix +
+
+
+
+
+ + Parent... + +
+
+
+ + + + + + + + +
+
+
+ + reconcile + +
+
+
+
+ + reconcile + +
+
+
+ + + + + + + + +
+
+
+ + ownerReference + +
+
+
+
+ + ownerReference + +
+
+
+ + + + + + + +
+
+
+
+ + Prefix CR + +
+
+
+
+
+ + Prefix CR + +
+
+
+ + + + + + + +
+
+
+ + Claimed Prefix + +
+
+
+
+ + Claimed Prefix + +
+
+
+ + + + + + + + + + + + + + +
+
+
+ + consumer + +
+
+
+
+ + consumer + +
+
+
+ + + + + + + + +
+
+
+ + User +
+ w/ kubectl +
+
+
+
+
+ + User... + +
+
+
+ + + + + + + + +
+
+
+ + GitOps +
+ w/ Argo or Flux +
+
+
+
+
+ + GitOps... + +
+
+
+ + + + + + + +
+
+
+ + and/or + +
+
+
+
+ + and/or + +
+
+
+
+ + + + + Text is not SVG - cannot display + + + +
\ No newline at end of file diff --git a/docs/examples/example2-load-balancer-ip/README.md b/docs/examples/example2-load-balancer-ip/README.md new file mode 100644 index 00000000..c365b518 --- /dev/null +++ b/docs/examples/example2-load-balancer-ip/README.md @@ -0,0 +1,68 @@ +# Example 2: Glue NetBox CRs to MetalLB CRs + +## Introduction + +So we have Prefixes represented as Kubernetes Resources. Now what can we do with this? + +We use kro.run to glue this to MetalLB IPAddressPools + +### 0.1 Create a local cluster with nebox-installed + +1. use the 'create-kind' and 'deploy-kind' targets from the Makefile to create a kind cluster and deploy NetBox and NetBox Operator on it +```bash +make create-kind +make deploy-kind +``` + +### 0.2 Manually Create a Prefix in NetBox + +Before prefixes and ip addresses can be claimed with the NetBox operator, a prefix has to be created in NetBox. + +1. Port-forward NetBox: +```bash +kubectl port-forward deploy/netbox 8080:8080 +``` +2. Open in your favorite browser and log in with the username `admin` and password `admin` +3. Create a new prefix '3.0.0.64/26' with custom field 'environment: prod' + +### 0.3 Navigate to the example folder + +Navigate to 'docs/examples/example2-load-balancer-ip/' to run the examples below + +## Example Steps + +0. Install kro and metallb with the installation script `docs/examples/example2-load-balancer-ip/prepare-demo-env.sh` +Then navigate to 'docs/examples/example2-load-balancer-ip' to follow the steps below. + +1. Inspect the spec of the sample prefix claim CR +```bash +cat zurich-pool.yaml +``` +2. Apply the manifests to create a deployment with a service and a metallb-ip-address-pool-netbox to create a metalLB IPAddressPool from the prefix claimed from NetBox +```bash +kubectl apply -f zurich-pool.yaml +``` +3. Check if the prefixclaim CR and the metalLB ipaddresspool CR got created +```bash +kubectl get pxc,ipaddresspool -A +``` +4. Inspect the spec of the sample prefix claim CR +```bash +cat sample-deployment.yaml +``` +5. Apply the manifests to createa deployment with a service that gets a ip assigned from the metalLB pool created in the prevoius step +```bash +kubectl apply -f sample-deployment.yaml +``` +6. check if the service got an external ip address assigned and that the nginx deployment is ready +```bash +kubectl get deploy,svc -n nginx +``` +7. try to connect to your service with the external ip +```bash +k exec curl -it -- sh +curl +``` + + +![Example 2](metallb-ipaddresspool-netbox.drawio.svg) diff --git a/docs/examples/example2-load-balancer-ip/load-balancer-ip-pool-netbox-large-font.drawio.svg b/docs/examples/example2-load-balancer-ip/load-balancer-ip-pool-netbox-large-font.drawio.svg new file mode 100644 index 00000000..ad17f4dc --- /dev/null +++ b/docs/examples/example2-load-balancer-ip/load-balancer-ip-pool-netbox-large-font.drawio.svg @@ -0,0 +1,4 @@ + + + +
k8s cluster
k8s cluster
user namespace
user namespace
kro namespace
kro namespace
kro
kro
PrefixClaim CR
status:
  prefix: 2.0.0.0/28
PrefixClaim CR...
MetalLBIPAddress-
PoolNetBox CR
MetalLBIPAddress-...
namespace metallb-system
namespace metallb-system
IPAddressPool CR
spec: 
 ipaddresspools:
  - 2.0.0.0/28
IPAddressPool CR...
consumer
consumer
User
w/ kubectl
User...
GitOps
w/ Argo or Flux
GitOps...
and/or
and/or
create
create
NetBox REST API
NetBox REST API
namespace netbox-operator
namespace netbox-operator
create/update/delete
create/update/delete
get available prefixes
get available prefixes
NetBox Operator
NetBox Operator
Parent
Prefix
Parent...
Claimed Prefix
Claimed Prefix
Matching Prefixes
Matching Prefixes
get matching prefixes
get matching prefixes
Prefix CR
Prefix CR
create
create
reconcile
reconcile
reconcile
reconcile
create
create
read status
read status
create
create
reconcile
reconcile
Text is not SVG - cannot display
\ No newline at end of file diff --git a/docs/examples/example2-load-balancer-ip/load-balancer-ip-pool-netbox.yaml b/docs/examples/example2-load-balancer-ip/load-balancer-ip-pool-netbox.yaml new file mode 100644 index 00000000..bc84c6ac --- /dev/null +++ b/docs/examples/example2-load-balancer-ip/load-balancer-ip-pool-netbox.yaml @@ -0,0 +1,39 @@ +apiVersion: kro.run/v1alpha1 +kind: ResourceGraphDefinition +metadata: + name: load-balancer-ip-pool-netbox +spec: + schema: + apiVersion: v1alpha1 + kind: LoadBalancerIPPoolNetBox + spec: + name: string + tenant: string + prefixLength: string + parentPrefixSelector: + environment: string + family: string + status: + + # Define the resources this API will manage. + resources: + - id: prefixclaim + template: + apiVersion: netbox.dev/v1 + kind: PrefixClaim + metadata: + name: ${schema.spec.name} + spec: + prefixLength: ${schema.spec.prefixLength} + parentPrefixSelector: ${schema.spec.parentPrefixSelector} + + - id: ipaddresspool + template: + apiVersion: metallb.io/v1beta1 + kind: IPAddressPool + metadata: + name: ${schema.spec.name} + namespace: metallb-system + spec: + addresses: + - ${prefixclaim.status.prefix} diff --git a/docs/examples/example2-load-balancer-ip/metallb-ipaddresspool-netbox.drawio.svg b/docs/examples/example2-load-balancer-ip/metallb-ipaddresspool-netbox.drawio.svg new file mode 100644 index 00000000..5d8997e1 --- /dev/null +++ b/docs/examples/example2-load-balancer-ip/metallb-ipaddresspool-netbox.drawio.svg @@ -0,0 +1,653 @@ + + + + + + + + + + + + + +
+
+
+ k8s cluster +
+
+
+
+ + k8s cluster + +
+
+
+ + + + + + + + + + +
+
+
+ user namespace +
+
+
+
+ + user namespace + +
+
+
+ + + + + + + + + + + +
+
+
+ consumer +
+
+
+
+ + consumer + +
+
+
+ + + + + + + +
+
+
+ NetBox REST API +
+
+
+
+ + NetBox REST API + +
+
+
+ + + + + + + +
+
+
+ namespace netbox-operator +
+
+
+
+ + namespace netbox-operator + +
+
+
+ + + + + + + + +
+
+
+ create +
+
+
+
+ + create + +
+
+
+ + + + + + + + +
+
+
+ reconcile +
+
+
+
+ + reconcile + +
+
+
+ + + + + + + + +
+
+
+ create/update/delete +
+
+
+
+ + create/update/delete + +
+
+
+ + + + + + + + +
+
+
+ get available prefixes +
+
+
+
+ + get available prefixes + +
+
+
+ + + + + + + +
+
+
+ netbox-operator +
+
+
+
+ + netbox-operator + +
+
+
+ + + + + + + + + + + +
+
+
+
+ kind: PrefixClaim +
+
+ spec: +
+
+ parentPrefix: 2.0.0.0/26 +
+
+ prefixLength: /28 +
+
+
+ status: +
+
+ prefix: 2.0.0.0/28 +
+
+
+
+
+ + kind: PrefixClaim... + +
+
+
+ + + + + + + +
+
+
+ Prefix 2.0.0.0/16 +
+
+
+
+ + Prefix 2.0.0.0/16 + +
+
+
+ + + + + + + + +
+
+
+ User +
+ w/ kubectl +
+
+
+
+ + User... + +
+
+
+ + + + + + + + +
+
+
+ GitOps +
+ w/ Argo or Flux +
+
+
+
+ + GitOps... + +
+
+
+ + + + + + + +
+
+
+ and/or +
+
+
+
+ + and/or + +
+
+
+ + + + + + + + +
+
+
+ + reconcile + +
+
+
+
+ + reconcile + +
+
+
+ + + + + + + + +
+
+
+ ownerReference +
+
+
+
+ + ownerReference + +
+
+
+ + + + + + + +
+
+
+
+ kind: Prefix +
+
+ spec: +
+
+ prefix: 2.0.0.0/28 +
+
+
+
+
+
+
+
+ + kind: Prefix... + +
+
+
+ + + + + + + +
+
+
+ Prefix 2.0.0.0/28 +
+
+
+
+ + Prefix 2.0.0.0/28 + +
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ kind: MetallbIPAddressPoolNetBox +
+
+ spec: +
+
+ name: my-pool +
+
+ parentPrefixSelector: +
+
+ environment: prod +
+
+ prefixLength: /28 +
+
+
+
+
+
+
+
+
+ + kind: MetallbIPAddressPoolNetBox... + +
+
+
+ + + + +
+
+
+ + owner reference + +
+
+
+
+ + owner reference + +
+
+
+ + + + + + + +
+
+
+
+ kind: IPAddressPool +
+
+ spec: +
+
+ addresses: 2.0.0.0/28 +
+
+
+
+
+
+ + kind: IPAddressPool... + +
+
+
+ + + + +
+
+
+ + read status and update spec + +
+
+
+
+ + read status and update spec + +
+
+
+ + + + +
+
+
+ + create + +
+
+
+
+ + create + +
+
+
+ + + + +
+
+
+ + create + +
+
+
+
+ + create + +
+
+
+ + + + +
+
+
+ create +
+
+
+
+ + create + +
+
+
+
+ + + + + Text is not SVG - cannot display + + + +
\ No newline at end of file diff --git a/docs/examples/example2-load-balancer-ip/prepare-demo-env.sh b/docs/examples/example2-load-balancer-ip/prepare-demo-env.sh new file mode 100755 index 00000000..db5049e3 --- /dev/null +++ b/docs/examples/example2-load-balancer-ip/prepare-demo-env.sh @@ -0,0 +1,42 @@ +#!/bin/bash +set -e + +# install netbox in the london cluster and load demo data +make deploy-kind + +# install curl pod to demo access to created service +kind load docker-image curlimages/curl +kind load docker-image curlimages/curl +kubectl run curl --image curlimages/curl --image-pull-policy=Never -- sleep infinity + +# load the nginx image into the kind cluster +kind load docker-image nginx +kind load docker-image nginx + +DEPLOYMENT_NAME=netbox-operator-controller-manager +NAMESPACE=netbox-operator-system +CONTEXT=kind-kind + +# install MetalLB +kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.14.8/config/manifests/metallb-native.yaml + +# install kro +helm install kro oci://ghcr.io/kro-run/kro/kro \ + --namespace kro \ + --create-namespace \ + --version=0.2.1 + +while true; do + # Check if the deployment is ready + READY_REPLICAS=$(kubectl --context $CONTEXT get deployment $DEPLOYMENT_NAME -n $NAMESPACE -o jsonpath='{.status.readyReplicas}') + DESIRED_REPLICAS=$(kubectl --context $CONTEXT get deployment $DEPLOYMENT_NAME -n $NAMESPACE -o jsonpath='{.status.replicas}') + + if [[ "$READY_REPLICAS" == "$DESIRED_REPLICAS" ]] && [[ "$READY_REPLICAS" -gt 0 ]]; then + echo "Deployment $DEPLOYMENT_NAME in cluster $CONTEXT is ready." + break + else + echo "Waiting... Ready replicas in cluster $CONTEXT: $READY_REPLICAS / $DESIRED_REPLICAS" + sleep 5 + fi +done +kubectl apply --context $CONTEXT -f docs/examples/example2-load-balancer-ip/load-balancer-ip-pool-netbox.yaml diff --git a/docs/examples/example2-load-balancer-ip/sample-deployment.yaml b/docs/examples/example2-load-balancer-ip/sample-deployment.yaml new file mode 100644 index 00000000..51ea0e2e --- /dev/null +++ b/docs/examples/example2-load-balancer-ip/sample-deployment.yaml @@ -0,0 +1,44 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: nginx +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-nginx + namespace: nginx +spec: + selector: + matchLabels: + run: my-nginx + replicas: 2 + template: + metadata: + labels: + run: my-nginx + spec: + containers: + - name: my-nginx + image: nginx + imagePullPolicy: Never + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: my-nginx + namespace: nginx + labels: + run: my-nginx + annotations: + metallb.universe.tf/address-pool: zurich-pool +spec: + type: LoadBalancer + ports: + - port: 80 + protocol: TCP + selector: + run: my-nginx diff --git a/docs/examples/example2-load-balancer-ip/zurich-pool.yaml b/docs/examples/example2-load-balancer-ip/zurich-pool.yaml new file mode 100644 index 00000000..0178ee87 --- /dev/null +++ b/docs/examples/example2-load-balancer-ip/zurich-pool.yaml @@ -0,0 +1,11 @@ +apiVersion: kro.run/v1alpha1 +kind: LoadBalancerIPPoolNetBox +metadata: + name: zurich-pool +spec: + name: zurich-pool + tenant: "MY_TENANT" # Use the `name` value instead of the `slug` value + prefixLength: "/30" + parentPrefixSelector: + environment: prod + family: IPv4 diff --git a/docs/examples/example3-restoration/README.md b/docs/examples/example3-restoration/README.md new file mode 100644 index 00000000..5ad6883c --- /dev/null +++ b/docs/examples/example3-restoration/README.md @@ -0,0 +1,67 @@ +# Example 3: restoration Feature Restoration + +## Introduction + +NetBox Operator offers a few restoration features. In this example we showcase how NetBox Operator can restoration prefixes. This is especially useful when e.g. you need sticky IPs or Prefixes when redeploying an entire cluster. + +## Instructions + +First, let's create some resources we want to restoration later. + +```bash +kubectl create ns restoration + +kubectl -n restoration apply -f prefixclaim-restore1.yaml +kubectl -n restoration wait --for=condition=Ready prefixclaims --all +kubectl -n restoration get prefixclaims + +kubectl -n restoration apply -f prefixclaim-restore2.yaml +kubectl -n restoration wait --for=condition=Ready prefixclaims --all +kubectl -n restoration get prefixclaims + +kubectl -n restoration apply -f prefixclaim-restore3.yaml +kubectl -n restoration wait --for=condition=Ready prefixclaims --all +kubectl -n restoration get prefixclaims +``` + +![Figure 4: Restoration](restoration.drawio.svg) + +Since we set `.spec.preserveInNetbox` to `true`, we can delete and restoration the resources. To delete all reasources, delete the entire namespace: + +```bash +kubectl delete ns restoration +``` + +Make sure the resources are gone in Kubernetes: + +```bash +kubectl -n restoration get prefixclaims +``` + +Verify in the NetBox UI that the Prefixes still exist. + +Now apply the manifests again and verify they become ready. We apply the manifests in the reverse order to make sure the order does not matter + +```bash +kubectl create ns restoration + +kubectl -n restoration apply -f prefixclaim-restore3.yaml +kubectl -n restoration wait --for=condition=Ready prefixclaims --all +kubectl -n restoration get prefixclaims + +kubectl -n restoration apply -f prefixclaim-restore2.yaml +kubectl -n restoration wait --for=condition=Ready prefixclaims --all +kubectl -n restoration get prefixclaims + +kubectl -n restoration apply -f prefixclaim-restore1.yaml +kubectl -n restoration wait --for=condition=Ready prefixclaims --all +kubectl -n restoration get prefixclaims +``` + +Delete Leases to speed up: + +```bash +kubectl -n netbox-operator-system get lease -oname | grep -v netbox | xargs -n1 kubectl -n netbox-operator-system delete +``` + +Note that the assigned Prefixes are the same as before. You can also play around with this by just restoring single prefixes. If you're curious about how this is done, make sure to read [the "Restoration from NetBox" section in the main README.md](https://github.com/netbox-community/netbox-operator/tree/main?tab=readme-ov-file#restoration-from-netbox) and to check out the code. Also have a look at the "Netbox Restoration Hash" custom field in NetBox. diff --git a/docs/examples/example3-restoration/prefixclaim-restore1.yaml b/docs/examples/example3-restoration/prefixclaim-restore1.yaml new file mode 100644 index 00000000..4f6dcf5b --- /dev/null +++ b/docs/examples/example3-restoration/prefixclaim-restore1.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: prefixclaim-restoration-sample-1 +spec: + tenant: "Dunder-Mifflin, Inc." + preserveInNetbox: true + parentPrefixSelector: + tenant: "Dunder-Mifflin, Inc." + family: IPv4 + prefixLength: "/32" diff --git a/docs/examples/example3-restoration/prefixclaim-restore2.yaml b/docs/examples/example3-restoration/prefixclaim-restore2.yaml new file mode 100644 index 00000000..1c0c9b12 --- /dev/null +++ b/docs/examples/example3-restoration/prefixclaim-restore2.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: prefixclaim-restoration-sample-2 +spec: + tenant: "Dunder-Mifflin, Inc." + preserveInNetbox: true + parentPrefixSelector: + tenant: "Dunder-Mifflin, Inc." + family: IPv4 + prefixLength: "/32" diff --git a/docs/examples/example3-restoration/prefixclaim-restore3.yaml b/docs/examples/example3-restoration/prefixclaim-restore3.yaml new file mode 100644 index 00000000..9c384150 --- /dev/null +++ b/docs/examples/example3-restoration/prefixclaim-restore3.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: prefixclaim-restoration-sample-3 +spec: + tenant: "Dunder-Mifflin, Inc." + preserveInNetbox: true + parentPrefixSelector: + tenant: "Dunder-Mifflin, Inc." + family: IPv4 + prefixLength: "/32" diff --git a/docs/examples/example3-restoration/restoration-large-font.drawio.png b/docs/examples/example3-restoration/restoration-large-font.drawio.png new file mode 100644 index 00000000..857818cb Binary files /dev/null and b/docs/examples/example3-restoration/restoration-large-font.drawio.png differ diff --git a/docs/examples/example3-restoration/restoration-large-font.drawio.svg b/docs/examples/example3-restoration/restoration-large-font.drawio.svg new file mode 100644 index 00000000..2e5face7 --- /dev/null +++ b/docs/examples/example3-restoration/restoration-large-font.drawio.svg @@ -0,0 +1,4 @@ + + + +
k8s cluster kind-london
k8s cluster kind-london
namespace default
namespace default
namespace "advanced"
namespace "advanced"
namespace "netbox-operator"
namespace "netbox-oper...
reconcile
reconcile
create & reconcile
create & reconcile
NetBox Operator
NetBox Operator
create
create
User
w/ kubectl
User...
NetBox REST API
NetBox REST API
2.0.0.0/32
2.0.0.0/32
2.0.0.1/32
2.0.0.1/32
2.0.0.2/32
2.0.0.2/32
restore by looking up
restoration hash
restore by looking up...
PrefixClaim
PrefixClaim
ownerReference
ownerReference
Prefix
Prefix
PrefixClaim
PrefixClaim
ownerReference
ownerReference
Prefix
Prefix
PrefixClaim
PrefixClaim
ownerReference
ownerReference
Prefix
Prefix
Text is not SVG - cannot display
\ No newline at end of file diff --git a/docs/examples/example3-restoration/restoration.drawio.svg b/docs/examples/example3-restoration/restoration.drawio.svg new file mode 100644 index 00000000..4bcdca6c --- /dev/null +++ b/docs/examples/example3-restoration/restoration.drawio.svg @@ -0,0 +1,4 @@ + + + +
k8s cluster kind-london
k8s cluster kind-london
namespace default
namespace default
namespace "advanced"
namespace "advanced"
namespace "netbox-operator"
namespace "netbox-operator"
reconcile
reconcile
create & reconcile
create & reconcile
netbox-operator
netbox-operator
create
create
User
w/ kubectl
User...
NetBox REST API
NetBox REST API
Prefix 2.0.0.0/32
Prefix 2.0.0.0/32
Prefix 2.0.0.1/32
Prefix 2.0.0.1/32
Prefix 2.0.0.2/32
Prefix 2.0.0.2/32
restore by looking up
restoration hash
restore by looking up...
kind: PrefixClaim
spec:
  parentPrefixSelector: 
     tenant: "Dunder-Mifflin"
  prefixLength: /32
kind: PrefixClaim...
ownerReference
ownerReference
kind: Prefix
spec:
  prefix: 2.0.0.0/32
kind: Prefix...
kind: PrefixClaim
spec:
  parentPrefixSelector: 
     tenant: "Dunder-Mifflin"
  prefixLength: /32
kind: PrefixClaim...
ownerReference
ownerReference
kind: Prefix
spec:
  prefix: 2.0.0.0/32
kind: Prefix...
kind: PrefixClaim
spec:
  parentPrefixSelector: 
     tenant: "Dunder-Mifflin"
  prefixLength: /32
kind: PrefixClaim...
ownerReference
ownerReference
kind: Prefix
spec:
  prefix: 2.0.0.0/32
kind: Prefix...
Text is not SVG - cannot display
\ No newline at end of file diff --git a/docs/examples/example4-exhaustion/README.md b/docs/examples/example4-exhaustion/README.md new file mode 100644 index 00000000..d4843fb5 --- /dev/null +++ b/docs/examples/example4-exhaustion/README.md @@ -0,0 +1,67 @@ +# Example 3: Advanced Feature Prefix Exhaustion + +## Introduction + +NetBox Operator offers a few advanced features. In this example we showcase how NetBox Operator can recover from prefix exhaustion. + +When a Prefix is exhausted and this is fixed in the NetBox backend (e.g. by the Infrastructure team), NetBox Operator will automatically reconcile this. + +## Instructions + +![Figure 1: Starting Point](exhaustion-1-starting-point.drawio.svg) + +Create a /24 Prefix (e.g. 1.122.0.0/24) with Custom Field Environment set to "prod" in NetBox UI. + +Apply Resource and show PrefixClaims: + +```bash +kubectl create ns advanced +kubectl apply -f prefixclaim-exhaustion.yaml +kubectl -n advanced get prefixclaims,prefixes +``` + +Note that only 2 out of the 3 PrefixClaims will become Ready. This is because the /24 Prefix is exhausted already after two Prefixes. This will look similar to this (note the order is non-deterministic): + +```bash +NAME PREFIX PREFIXASSIGNED READY AGE +prefixclaim.netbox.dev/prefixclaim-exhaustion-sample-1 1.122.0.0/25 True True 2m2s +prefixclaim.netbox.dev/prefixclaim-exhaustion-sample-2 1.122.0.128/25 True True 2m2s +prefixclaim.netbox.dev/prefixclaim-exhaustion-sample-3 False 2m2s + +NAME PREFIX READY ID URL AGE +prefix.netbox.dev/prefixclaim-exhaustion-sample-1 1.122.0.0/25 True 148 http://172.18.1.2/ipam/prefixes/148 2m2s +prefix.netbox.dev/prefixclaim-exhaustion-sample-2 1.122.0.128/25 True 149 http://172.18.1.2/ipam/prefixes/149 2m2s +``` + +![Figure 2: Parent Prefix Exhausted](exhaustion-2-prefix-exhausted.drawio.svg) + + +Create another /24 Prefix (e.g. 1.100.0.0/24) with Custom Field Environment set to "prod" in NetBox UI. + +Wait for the PrefixClaim to be reconciled again or trigger reconciliation by e.g. adding an annotation: + +```bash +kubectl -n advanced annotate prefixclaim prefixclaim-exhaustion-sample-3 reconcile="$(date)" --overwrite +``` + +Confirm that the third Prefix is now also assigned: + +```bash +kubectl -n advanced get prefixclaims,prefixes +``` + +Which should look as follows: + +```bash +NAME PREFIX PREFIXASSIGNED READY AGE +prefixclaim.netbox.dev/prefixclaim-exhaustion-sample-1 1.122.0.0/25 True True 4s +prefixclaim.netbox.dev/prefixclaim-exhaustion-sample-2 1.122.0.128/25 True True 4s +prefixclaim.netbox.dev/prefixclaim-exhaustion-sample-3 1.100.0.0/25 True True 4s + +NAME PREFIX READY ID URL AGE +prefix.netbox.dev/prefixclaim-exhaustion-sample-1 1.122.0.0/25 True 148 http://172.18.1.2/ipam/prefixes/148 4s +prefix.netbox.dev/prefixclaim-exhaustion-sample-2 1.122.0.128/25 True 149 http://172.18.1.2/ipam/prefixes/149 4s +prefix.netbox.dev/prefixclaim-exhaustion-sample-3 1.100.0.0/25 True 151 http://172.18.1.2/ipam/prefixes/151 3s``` +``` + +![Figure 3: Parent Prefix Exhaustion fixed](exhaustion-3-after-fix.drawio.svg) diff --git a/docs/examples/example4-exhaustion/exhaustion-1-starting-point.drawio.svg b/docs/examples/example4-exhaustion/exhaustion-1-starting-point.drawio.svg new file mode 100644 index 00000000..94e9ea20 --- /dev/null +++ b/docs/examples/example4-exhaustion/exhaustion-1-starting-point.drawio.svg @@ -0,0 +1,4 @@ + + + +
k8s cluster kind-london
k8s cluster kind-london
namespace default
namespace default
namespace "advanced"
namespace "advanced"
namespace "netbox-operator"
namespace "netbox-operator"
netbox-operator
netbox-operator
kind: PrefixClaim
spec:
  parentPrefixSelector:
    environment: prod  prefixLength: /25
kind: PrefixClaim...
create
create
User
w/ kubectl
User...
NetBox REST API
NetBox REST API
Prefix 1.122.0.0/24
environment: prod
Usage: 0%
Prefix 1.122.0.0/24...
kind: PrefixClaim
spec:
  parentPrefixSelector:
    environment: prod  prefixLength: /25
kind: PrefixClaim...
kind: PrefixClaim
spec:
  parentPrefixSelector:
    environment: prod  prefixLength: /25
kind: PrefixClaim...
Text is not SVG - cannot display
\ No newline at end of file diff --git a/docs/examples/example4-exhaustion/exhaustion-2-prefix-exhausted.drawio.svg b/docs/examples/example4-exhaustion/exhaustion-2-prefix-exhausted.drawio.svg new file mode 100644 index 00000000..a2377d28 --- /dev/null +++ b/docs/examples/example4-exhaustion/exhaustion-2-prefix-exhausted.drawio.svg @@ -0,0 +1,4 @@ + + + +
k8s cluster kind-london
k8s cluster kind-london
namespace default
namespace default
namespace "advanced"
namespace "advanced"
namespace "netbox-operator"
namespace "netbox-operator"
create & reconcile
create & reconcile
netbox-operator
netbox-operator
kind: PrefixClaim
spec:
  parentPrefixSelector:
    environment: prod  prefixLength: /25
kind: PrefixClaim...
create
create
User
w/ kubectl
User...
reconcile
reconcile
ownerReference
ownerReference
kind: Prefix
spec:
  prefix: 1.122.0.0/25
kind: Prefix...
NetBox REST API
NetBox REST API
get available prefixes
get available prefixes
Prefix 1.122.0.0/24
environment: prod
Usage: 100%
Prefix 1.122.0.0/24...
Prefix 1.122.0.0/25
Prefix 1.122.0.0/25
Prefix 1.122.0.128/25
Prefix 1.122.0.128/25
create/update/delete
create/update/delete
kind: PrefixClaim
spec:
  parentPrefixSelector:
    environment: prod  prefixLength: /25
kind: PrefixClaim...
reconcile
reconcile
ownerReference
ownerReference
kind: Prefix
spec:
  prefix: 1.122.0.128/25
kind: Prefix...
kind: PrefixClaim
spec:
  parentPrefixSelector:
    environment: prod  prefixLength: /25
kind: PrefixClaim...
reconcile
reconcile
Text is not SVG - cannot display
\ No newline at end of file diff --git a/docs/examples/example4-exhaustion/exhaustion-3-after-fix.drawio.svg b/docs/examples/example4-exhaustion/exhaustion-3-after-fix.drawio.svg new file mode 100644 index 00000000..13dd249e --- /dev/null +++ b/docs/examples/example4-exhaustion/exhaustion-3-after-fix.drawio.svg @@ -0,0 +1,4 @@ + + + +
k8s cluster kind-london
k8s cluster kind-london
namespace default
namespace default
namespace "advanced"
namespace "advanced"
namespace "netbox-operator"
namespace "netbox-operator"
create & reconcile
create & reconcile
netbox-operator
netbox-operator
kind: PrefixClaim
spec:
  parentPrefixSelector:
    environment: prod  prefixLength: /25
kind: PrefixClaim...
create
create
User
w/ kubectl
User...
reconcile
reconcile
ownerReference
ownerReference
kind: Prefix
spec:
  prefix: 1.122.0.0/25
kind: Prefix...
NetBox REST API
NetBox REST API
Prefix 1.122.0.0/24
environment: prod
Usage: 100%
Prefix 1.122.0.0/24...
Prefix 1.122.0.0/25
Prefix 1.122.0.0/25
Prefix 1.122.0.128/25
Prefix 1.122.0.128/25
kind: PrefixClaim
spec:
  parentPrefixSelector:
    environment: prod  prefixLength: /25
kind: PrefixClaim...
reconcile
reconcile
ownerReference
ownerReference
kind: Prefix
spec:
  prefix: 1.122.0.128/25
kind: Prefix...
create & reconcile
create & reconcile
kind: PrefixClaim
spec:
  parentPrefixSelector:
    environment: prod  prefixLength: /25
kind: PrefixClaim...
reconcile
reconcile
ownerReference
ownerReference
kind: Prefix
spec:
  prefix: 1.100.0.0/25
kind: Prefix...
Prefix 1.100.0.0/24
environment: prod
Usage: 50%
Prefix 1.100.0.0/24...
Prefix 1.100.0.0/25
Prefix 1.100.0.0/25
create/update/delete
create/update/delete
get available prefixes
get available prefixes
Text is not SVG - cannot display
\ No newline at end of file diff --git a/docs/examples/example4-exhaustion/prefixclaim-exhaustion.yaml b/docs/examples/example4-exhaustion/prefixclaim-exhaustion.yaml new file mode 100644 index 00000000..6885a1a0 --- /dev/null +++ b/docs/examples/example4-exhaustion/prefixclaim-exhaustion.yaml @@ -0,0 +1,36 @@ +--- +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: prefixclaim-exhaustion-sample-1 +spec: + tenant: "MY_TENANT" + preserveInNetbox: true + parentPrefixSelector: + environment: prod + family: IPv4 + prefixLength: "/25" +--- +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: prefixclaim-exhaustion-sample-2 +spec: + tenant: "MY_TENANT" + preserveInNetbox: true + parentPrefixSelector: + environment: prod + family: IPv4 + prefixLength: "/25" +--- +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: prefixclaim-exhaustion-sample-3 +spec: + tenant: "MY_TENANT" + preserveInNetbox: true + parentPrefixSelector: + environment: prod + family: IPv4 + prefixLength: "/25" diff --git a/docs/examples/example5-multicluster/README.md b/docs/examples/example5-multicluster/README.md new file mode 100644 index 00000000..7ea53c64 --- /dev/null +++ b/docs/examples/example5-multicluster/README.md @@ -0,0 +1,47 @@ +# Example 5: Advanced Feature Multi Cluster Support + +## Introduction + +NetBox Operator uses NetBox to avoid IP overlaps. This means that we can use NetBox Operator on multiple clusters. You can try this out using the example in this directory. + +This example shows how to claim multiple prefixes from different clusters and make them available as metalLB ip address pools. + +### 0.1 Create a local cluster with nebox-installed + +1. set up your local environment to run the following examples with the set up script 'docs/examples/example5-multicluster/prepare-demo-env.sh' + +### 0.2 Manually Create a Prefix in NetBox + +Before prefixes and ip addresses can be claimed with the NetBox operator, a prefix has to be created in NetBox. + +1. Port-forward NetBox: +```bash +kubectl port-forward deploy/netbox 8080:8080 +``` +2. Open in your favorite browser and log in with the username `admin` and password `admin` +3. Create a new prefix '3.0.0.64/26' with custom field 'environment: prod' + +### 0.3 Navigate to the example folder + +Navigate to 'docs/examples/example5-multicluster/' to run the examples below + +## Example Steps + +1. Create ip address pools on the london cluster +```bash +kubectl apply --context kind-london -f docs/examples/example5-multicluster/london-pools.yaml +``` +2. Create ip address pool on the zurich cluster +```bash +kubectl create --context kind-zurich -f docs/examples/example5-multicluster/zurich-pools.yaml +``` +3. Look up the created prefix claims +```bash +kubectl get --context kind-london pxc -A +``` +and +```bash +kubectl get --context kind-zurich pxc -A +``` + +![Example 2](multicluster.drawio.svg) \ No newline at end of file diff --git a/docs/examples/example5-multicluster/cluster-cfg.yaml b/docs/examples/example5-multicluster/cluster-cfg.yaml new file mode 100644 index 00000000..0dafb9be --- /dev/null +++ b/docs/examples/example5-multicluster/cluster-cfg.yaml @@ -0,0 +1,14 @@ +apiVersion: kind.x-k8s.io/v1alpha4 +kind: Cluster +networking: + serviceSubnet: "10.96.0.0/20" # until 10.96.15.255 + apiServerAddress: "127.0.0.1" + apiServerPort: 6443 +nodes: +- role: control-plane + kubeadmConfigPatches: + - | + kind: InitConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "ingress-ready=true" diff --git a/docs/examples/example5-multicluster/create-kind-clusters.sh b/docs/examples/example5-multicluster/create-kind-clusters.sh new file mode 100755 index 00000000..5ff58bdd --- /dev/null +++ b/docs/examples/example5-multicluster/create-kind-clusters.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# This script creates the specified number of kind clusters with MetalLB +set -e +# Define colors +RED='\033[0;31m' +NC='\033[0m' # No Color + +# Check if cluster names are provided +if [ $# -eq 0 ]; then + echo -e "${RED}Error: No cluster names provided${NC}" + echo "Usage: $0 ... " + exit 1 +fi + +number_of_clusters=$1 +clustername=${2:-dns} # Set default cluster name to 'dns' if not provided +mkdir -p tmp +i=0 + +# Loop to create the specified number of clusters +for clustername in "$@"; do + config_file="docs/examples/example5-multicluster/cluster-cfg.yaml" + temp_config="tmp/cluster-$clustername-cfg.yaml" + i=$((i + 1)) + + if [ -f "$config_file" ]; then + # Make a temporary copy of the configuration file + cp "$config_file" "$temp_config" + + # Modify apiServerPort in the copied config file + sed -i'' -e "s/apiServerPort: 6443/apiServerPort: $((6443 + i))/g" "$temp_config" + rm "$temp_config"-e + + # check if cluster exists + if kind get clusters | grep -q "^${clustername}$"; then + echo "Cluster ${clustername} already exists. Skipping creation." + continue + fi + kind create cluster --name $clustername --config $temp_config || { echo -e "${RED}Error: Failed to create cluster ${clustername}${NC}"; rm -f "$temp_config"; exit 1; } + + # Install MetalLB + kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.14.8/config/manifests/metallb-native.yaml + + else + echo -e "${RED}Error: Configuration file $config_file not found${NC}" + exit 1 + fi +done diff --git a/docs/examples/example5-multicluster/demo-setup.drawio.svg b/docs/examples/example5-multicluster/demo-setup.drawio.svg new file mode 100644 index 00000000..0c4fe028 --- /dev/null +++ b/docs/examples/example5-multicluster/demo-setup.drawio.svg @@ -0,0 +1,226 @@ + + + + + + + + + + + + + +
+
+
+ Zurich Cluster +
+
+
+
+ + Zurich Cluster + +
+
+
+ + + + + + + +
+
+
+ NetBox REST API +
+
+
+
+ + NetBox REST API + +
+
+
+ + + + + + + + + + + + + + +
+
+
+ London Cluster +
+
+
+
+ + London Cluster + +
+
+
+ + + + + + + +
+
+
+ NetBox Operator +
+
+
+
+ + NetBox Operator + +
+
+
+ + + + + + + +
+
+
+ NetBox Operator +
+
+
+
+ + NetBox Operator + +
+
+
+ + + + + + + +
+
+
+ + MetalLB + +
+ Load Balancer +
+
+
+
+
+ + MetalLB... + +
+
+
+ + + + + + + +
+
+
+ + Kubernetes Resource Orchestrator | kro + +
+
+
+
+ + Kubernetes Resource... + +
+
+
+ + + + + + + +
+
+
+ MetalLB +
+ Load Balancer +
+
+
+
+
+ + MetalLB... + +
+
+
+ + + + + + + +
+
+
+ Kubernetes Resource Orchestrator | kro +
+
+
+
+ + Kubernetes Resource... + +
+
+
+ + + + +
+ + + + + Text is not SVG - cannot display + + + +
\ No newline at end of file diff --git a/docs/examples/example5-multicluster/kustomization.yaml b/docs/examples/example5-multicluster/kustomization.yaml new file mode 100644 index 00000000..fe91fc3c --- /dev/null +++ b/docs/examples/example5-multicluster/kustomization.yaml @@ -0,0 +1,18 @@ +resources: + - ../../../kind + +patches: + - patch: |- + apiVersion: apps/v1 + kind: Deployment + metadata: + name: controller-manager + namespace: system + spec: + template: + spec: + containers: + - name: manager + env: + - name: NETBOX_HOST + value: "172.18.1.2" diff --git a/docs/examples/example5-multicluster/london-pools.yaml b/docs/examples/example5-multicluster/london-pools.yaml new file mode 100644 index 00000000..36c9f0db --- /dev/null +++ b/docs/examples/example5-multicluster/london-pools.yaml @@ -0,0 +1,54 @@ +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: london-prefix-1 +spec: + tenant: "MY_TENANT" + prefixLength: "/30" + parentPrefixSelector: + environment: prod + familily: IPv4 +--- +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: london-prefix-2 +spec: + tenant: "MY_TENANT" + prefixLength: "/30" + parentPrefixSelector: + environment: prod + familily: IPv4 +--- +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: london-prefix-3 +spec: + tenant: "MY_TENANT" + prefixLength: "/30" + parentPrefixSelector: + environment: prod + familily: IPv4 +--- +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: london-prefix-4 +spec: + tenant: "MY_TENANT" + prefixLength: "/30" + parentPrefixSelector: + environment: prod + familily: IPv4 +--- +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: london-prefix-5 +spec: + tenant: "MY_TENANT" + prefixLength: "/30" + parentPrefixSelector: + environment: prod + familily: IPv4 diff --git a/docs/examples/example5-multicluster/multicluster.drawio.svg b/docs/examples/example5-multicluster/multicluster.drawio.svg new file mode 100644 index 00000000..a32f6afc --- /dev/null +++ b/docs/examples/example5-multicluster/multicluster.drawio.svg @@ -0,0 +1,778 @@ + + + + + + + + + + + + + +
+
+
+ k8s cluster +
+
+
+
+ + k8s cluster + +
+
+
+ + + + + + + + + + +
+
+
+ user namespace +
+
+
+
+ + user namespace + +
+
+
+ + + + + + + + + + + + + + + +
+
+
+ consumer +
+
+
+
+ + consumer + +
+
+
+ + + + + + + +
+
+
+ NetBox REST API +
+
+
+
+ + NetBox REST API + +
+
+
+ + + + + + + +
+
+
+ namespace netbox-operator +
+
+
+
+ + namespace netbox-operator + +
+
+
+ + + + + + + + +
+
+
+ create +
+
+
+
+ + create + +
+
+
+ + + + + + + + +
+
+
+ reconcile +
+
+
+
+ + reconcile + +
+
+
+ + + + + + + + + + + + +
+
+
+ get available prefixes +
+
+
+
+ + get available prefixes + +
+
+
+ + + + + + + +
+
+
+ netbox-operator +
+
+
+
+ + netbox-operator + +
+
+
+ + + + + + + +
+
+
+
+ kind: PrefixClaim +
+
+ spec: +
+
+ parentPrefix: 2.0.0.0/16 +
+
+ prefixLength: /28 +
+
+
+
+
+
+ + kind: PrefixClaim... + +
+
+
+ + + + + + + +
+
+
+ Prefix 2.0.0.0/16 +
+
+
+
+ + Prefix 2.0.0.0/16 + +
+
+
+ + + + + + + + +
+
+
+ User +
+ w/ kubectl +
+
+
+
+ + User... + +
+
+
+ + + + + + + + +
+
+
+ GitOps +
+ w/ Argo or Flux +
+
+
+
+ + GitOps... + +
+
+
+ + + + + + + +
+
+
+ and/or +
+
+
+
+ + and/or + +
+
+
+ + + + + + + + +
+
+
+ reconcile +
+
+
+
+ + reconcile + +
+
+
+ + + + + + + + +
+
+
+ ownerReference +
+
+
+
+ + ownerReference + +
+
+
+ + + + + + + +
+
+
+
+ kind: Prefix +
+
+ spec: +
+
+ prefix: 2.0.0.0/28 +
+
+
+
+
+
+
+
+ + kind: Prefix... + +
+
+
+ + + + + + + +
+
+
+ Prefix 2.0.0.0/28 +
+
+
+
+ + Prefix 2.0.0.0/28 + +
+
+
+ + + + + + + + + + + + + +
+
+
+ k8s cluster +
+
+
+
+ + k8s cluster + +
+
+
+ + + + + + + + + + +
+
+
+ user namespace +
+
+
+
+ + user namespace + +
+
+
+ + + + + + + +
+
+
+ namespace netbox-operator +
+
+
+
+ + namespace netbox-operator + +
+
+
+ + + + + + + + +
+
+
+ create +
+
+
+
+ + create + +
+
+
+ + + + + + + + +
+
+
+ reconcile +
+
+
+
+ + reconcile + +
+
+
+ + + + +
+
+
+ create/update/delete +
+
+
+
+ + create/update/delete + +
+
+
+ + + + + + + + + + + + + + + +
+
+
+ netbox-operator +
+
+
+
+ + netbox-operator + +
+
+
+ + + + + + + +
+
+
+
+ kind: PrefixClaim +
+
+ spec: +
+
+ parentPrefix: 2.0.0.0/16 +
+
+ prefixLength: /28 +
+
+
+
+
+
+ + kind: PrefixClaim... + +
+
+
+ + + + + + + + +
+
+
+ reconcile +
+
+
+
+ + reconcile + +
+
+
+ + + + + + + + +
+
+
+ ownerReference +
+
+
+
+ + ownerReference + +
+
+
+ + + + + + + +
+
+
+
+ kind: Prefix +
+
+ spec: +
+
+ prefix: 2.0.0.0/28 +
+
+
+
+
+
+
+
+ + kind: Prefix... + +
+
+
+ + + + + + + +
+
+
+ Prefix 2.0.0.16/28 +
+
+
+
+ + Prefix 2.0.0.16/28 + +
+
+
+ + + + +
+
+
+ get available prefixes +
+
+
+
+ + get available prefixes + +
+
+
+ + + + +
+
+
+ create/update/delete +
+
+
+
+ + create/update/delete + +
+
+
+ + + + + + +
+ + + + + Text is not SVG - cannot display + + + +
\ No newline at end of file diff --git a/docs/examples/example5-multicluster/netbox-l2advertisement.yaml b/docs/examples/example5-multicluster/netbox-l2advertisement.yaml new file mode 100644 index 00000000..d04339de --- /dev/null +++ b/docs/examples/example5-multicluster/netbox-l2advertisement.yaml @@ -0,0 +1,25 @@ +--- +apiVersion: metallb.io/v1beta1 +kind: L2Advertisement +metadata: + namespace: metallb-system + name: output-l2-advertisement +spec: +--- +apiVersion: metallb.io/v1beta1 +kind: IPAddressPool +metadata: + name: db-ipaddresspool + namespace: metallb-system +spec: + addresses: + - 172.18.1.1/32 +--- +apiVersion: metallb.io/v1beta1 +kind: IPAddressPool +metadata: + name: netbox-ipaddresspool + namespace: metallb-system +spec: + addresses: + - 172.18.1.2/32 diff --git a/docs/examples/example5-multicluster/netbox-svc.yaml b/docs/examples/example5-multicluster/netbox-svc.yaml new file mode 100644 index 00000000..ddba7fc5 --- /dev/null +++ b/docs/examples/example5-multicluster/netbox-svc.yaml @@ -0,0 +1,26 @@ + +apiVersion: v1 +kind: Service +metadata: + name: netbox + namespace: default + annotations: + metallb.universe.tf/address-pool: netbox-ipaddresspool +spec: + allocateLoadBalancerNodePorts: true + externalTrafficPolicy: Cluster + type: LoadBalancer + internalTrafficPolicy: Cluster + ipFamilies: + - IPv4 + ipFamilyPolicy: SingleStack + ports: + - name: http + port: 80 + protocol: TCP + targetPort: http + selector: + app.kubernetes.io/component: netbox + app.kubernetes.io/instance: netbox + app.kubernetes.io/name: netbox + sessionAffinity: None \ No newline at end of file diff --git a/docs/examples/example5-multicluster/prepare-demo-env.sh b/docs/examples/example5-multicluster/prepare-demo-env.sh new file mode 100755 index 00000000..67db95f6 --- /dev/null +++ b/docs/examples/example5-multicluster/prepare-demo-env.sh @@ -0,0 +1,27 @@ +#!/bin/bash +set -e +#create the kind clusters zurich and london +./docs/examples/example5-multicluster/create-kind-clusters.sh zurich london + +# install netbox in the london cluster and load demo data +kubectl config use-context kind-london +./kind/deploy-netbox.sh london "4.1.8" default + +# install NetBox Operator +kubectl config use-context kind-london +kind load docker-image netbox-operator:build-local --name london +kind load docker-image netbox-operator:build-local --name london # fixes an issue with podman where the image is not correctly tagged after the first kind load docker-image +kustomize build docs/examples/example5-multicluster/ | kubectl apply -f - + +kubectl config use-context kind-zurich +kind load docker-image netbox-operator:build-local --name zurich +kind load docker-image netbox-operator:build-local --name zurich # fixes an issue with podman where the image is not correctly tagged after the first kind load docker-image +kustomize build docs/examples/example5-multicluster/ | kubectl apply -f - +kind load docker-image curlimages/curl --name zurich +kind load docker-image curlimages/curl --name zurich +kubectl run curl --image curlimages/curl --image-pull-policy=Never -- sleep infinity + +# expose netbox service +kubectl config use-context kind-london +kubectl apply -f docs/examples/example5-multicluster/netbox-svc.yaml +kubectl apply -f docs/examples/example5-multicluster/netbox-l2advertisement.yaml diff --git a/docs/examples/example5-multicluster/zurich-pools.yaml b/docs/examples/example5-multicluster/zurich-pools.yaml new file mode 100644 index 00000000..27ebd7be --- /dev/null +++ b/docs/examples/example5-multicluster/zurich-pools.yaml @@ -0,0 +1,50 @@ +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: zurich-prefix-1 +spec: + tenant: "MY_TENANT" + prefixLength: "/30" + parentPrefixSelector: + environment: prod + familiy: IPv4 +--- +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: zurich-prefix-2 +spec: + tenant: "MY_TENANT" + prefixLength: "/30" + parentPrefixSelector: + environment: prod +--- +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: zurich-prefix-3 +spec: + tenant: "MY_TENANT" + prefixLength: "/30" + parentPrefixSelector: + environment: prod +--- +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: zurich-prefix-4 +spec: + tenant: "MY_TENANT" + prefixLength: "/30" + parentPrefixSelector: + environment: prod +--- +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + name: zurich-prefix-5 +spec: + tenant: "MY_TENANT" + prefixLength: "/30" + parentPrefixSelector: + environment: prod diff --git a/docs/prefixclaim-sample-with-netbox-running-in-cluster.drawio.svg b/docs/prefixclaim-sample-with-netbox-running-in-cluster.drawio.svg index 3ccdd280..99cd828a 100644 --- a/docs/prefixclaim-sample-with-netbox-running-in-cluster.drawio.svg +++ b/docs/prefixclaim-sample-with-netbox-running-in-cluster.drawio.svg @@ -1,391 +1,4 @@ - - - - - - - - -
-
-
- k8s cluster -
-
-
-
- - k8s cluster - -
-
- - - - -
-
-
- namespace default -
-
-
-
- - namespace default - -
-
- - - - - -
-
-
- user namespace -
-
-
-
- - user namespace - -
-
- - - - - - -
-
-
- consumer -
-
-
-
- - consumer - -
-
- - - - -
-
-
- namespace netbox-operator -
-
-
-
- - namespace netbox-operator - -
-
- - - - - -
-
-
- create -
-
-
-
- - create - -
-
- - - - - -
-
-
- reconcile -
-
-
-
- - reconcile - -
-
- - - - -
-
-
- netbox-operator -
-
-
-
- - netbox-operator - -
-
- - - - -
-
-
-
- kind: PrefixClaim -
-
- spec: -
-
- parentPrefix: 2.0.0.0/16 -
-
- prefixLength: /28 -
-
-
-
-
-
- - kind: PrefixClaim... - -
-
- - - - - -
-
-
- User -
- w/ kubectl -
-
-
-
- - User... - -
-
- - - - - -
-
-
- GitOps -
- w/ Argo or Flux -
-
-
-
- - GitOps... - -
-
- - - - -
-
-
- and/or -
-
-
-
- - and/or - -
-
- - - - - -
-
-
- reconcile -
-
-
-
- - reconcile - -
-
- - - - - -
-
-
- ownerReference -
-
-
-
- - ownerReference - -
-
- - - - -
-
-
-
- kind: Prefix -
-
- spec: -
-
- prefix: 2.0.0.0/28 -
-
-
-
-
- - kind: Prefix... - -
-
- - - - - -
-
-
- NetBox REST API -
-
-
-
- - NetBox REST API - -
-
- - - - - - -
-
-
- create/update/delete -
-
-
-
- - create/update/delete - -
-
- - - - - -
-
-
- get available prefixes -
-
-
-
- - get available prefixes - -
-
- - - - -
-
-
- Prefix 2.0.0.0/16 -
-
-
-
- - Prefix 2.0.0.0/16 - -
-
- - - - -
-
-
- Prefix 2.0.0.0/28 -
-
-
-
- - Prefix 2.0.0.0/28 - -
-
-
- - - - - Text is not SVG - cannot display - - - -
+ + + +
k8s cluster
k8s cluster
namespace default
namespace default
user namespace
user namespace
namespace netbox-operator
namespace netbox-operator
create
create
reconcile
reconcile
netbox-operator
netbox-operator
reconcile
reconcile
ownerReference
ownerReference
kind: Prefix
spec:
  prefix: 2.0.0.0/28
kind: Prefix...
NetBox REST API
NetBox REST API
create/update/delete
create/update/delete
get available prefixes
get available prefixes
Prefix 2.0.0.0/16
Prefix 2.0.0.0/16
Prefix 2.0.0.0/28
Prefix 2.0.0.0/28
kind: MetalLBIPPoolNetBox (kro )
spec:
  parentPrefix: 2.0.0.0/16
  prefixLength: /28
kind: MetalLBIPPoolNetBox (kro )...
kind: PrefixClaim
spec:
  parentPrefix: 2.0.0.0/16
  prefixLength: /28
status:
  ipAddress:
kind: PrefixClaim...
kind: IPAddressPool
spec:
  parentPrefix: 2.0.0.0/16
  prefixLength: /28
kind: IPAddressPool...
Text is not SVG - cannot display
\ No newline at end of file diff --git a/kind/deploy-netbox.sh b/kind/deploy-netbox.sh new file mode 100755 index 00000000..e2ef7423 --- /dev/null +++ b/kind/deploy-netbox.sh @@ -0,0 +1,118 @@ +#!/bin/bash +set -e -u -o pipefail + +NETBOX_HELM_CHART="https://github.com/netbox-community/netbox-chart/releases/download/netbox-5.0.0-beta.169/netbox-5.0.0-beta.169.tgz" # default value + +if [[ $# -ne 3 ]]; then + echo "Usage: $0 " + exit 1 +fi + +CLUSTER=$1 +VERSION=$2 +NAMESPACE=$3 + +# load remote images +if [[ "${VERSION}" == "3.7.8" ]] ;then + echo "Using version ${VERSION}" + # need to align with netbox-chart otherwise the creation of the cluster will hang + declare -a Remote_Images=( \ + "busybox:1.36.1" \ + "docker.io/bitnami/redis:7.2.4-debian-12-r9" \ + "docker.io/netboxcommunity/netbox:v3.7.8" \ + "ghcr.io/zalando/postgres-operator:v1.12.2" \ + "ghcr.io/zalando/spilo-16:3.2-p3" \ + ) + NETBOX_HELM_CHART="https://github.com/netbox-community/netbox-chart/releases/download/netbox-5.0.0-beta5/netbox-5.0.0-beta5.tgz" + + # patch load-data.sh + sed 's/netbox-demo-v4.1.sql/netbox-demo-v3.7.sql/g' $(dirname "$0")/load-data-job/load-data.orig.sh > $(dirname "$0")/load-data-job/load-data.sh && chmod +x $(dirname "$0")/load-data-job/load-data.sh + + # patch dockerfile (See README at https://github.com/netbox-community/pynetbox for the supported version matrix) + sed 's/RUN pip install -Iv pynetbox==7.4.1/RUN pip install -Iv pynetbox==7.3.4/g' $(dirname "$0")/load-data-job/dockerfile.orig > $(dirname "$0")/load-data-job/dockerfile +elif [[ "${VERSION}" == "4.0.11" ]] ;then + echo "Using version ${VERSION}" + # need to align with netbox-chart otherwise the creation of the cluster will hang + declare -a Remote_Images=( \ + "busybox:1.36.1" \ + "docker.io/bitnami/redis:7.4.0-debian-12-r2" \ + "ghcr.io/netbox-community/netbox:v4.0.11" \ + "ghcr.io/zalando/postgres-operator:v1.12.2" \ + "ghcr.io/zalando/spilo-16:3.2-p3" \ + ) + NETBOX_HELM_CHART="https://github.com/netbox-community/netbox-chart/releases/download/netbox-5.0.0-beta.84/netbox-5.0.0-beta.84.tgz" + + # patch load-data.sh + sed 's/netbox-demo-v4.1.sql/netbox-demo-v4.0.sql/g' $(dirname "$0")/load-data-job/load-data.orig.sh > $(dirname "$0")/load-data-job/load-data.sh && chmod +x $(dirname "$0")/load-data-job/load-data.sh + + cp $(dirname "$0")/load-data-job/dockerfile.orig $(dirname "$0")/load-data-job/dockerfile +elif [[ "${VERSION}" == "4.1.8" ]] ;then + echo "Using version ${VERSION}" + # need to align with netbox-chart otherwise the creation of the cluster will hang + declare -a Remote_Images=( \ + "busybox:1.37.0" \ + "docker.io/bitnami/redis:7.4.1-debian-12-r2" \ + "ghcr.io/netbox-community/netbox:v4.1.8" \ + "ghcr.io/zalando/postgres-operator:v1.12.2" \ + "ghcr.io/zalando/spilo-16:3.2-p3" \ + ) + + # create load-data.sh + cp $(dirname "$0")/load-data-job/load-data.orig.sh $(dirname "$0")/load-data-job/load-data.sh + + cp $(dirname "$0")/load-data-job/dockerfile.orig $(dirname "$0")/load-data-job/dockerfile +else + echo "Unknown version ${VERSION}" + exit 1 +fi + +for img in "${Remote_Images[@]}"; do + docker pull "$img" + kind load docker-image "$img" --name "${CLUSTER}" +done + +# build image for loading local data via NetBox API +cd ./kind/load-data-job && docker build -t netbox-load-local-data:1.0 --load --no-cache --progress=plain -f ./dockerfile . && cd - + +# load local images +declare -a Local_Images=( \ +"netbox-load-local-data:1.0" \ +) +for img in "${Local_Images[@]}"; do + kind load docker-image "$img" --name "${CLUSTER}" +done + +# install helm charts +helm upgrade --install --namespace="${NAMESPACE}" postgres-operator \ +https://opensource.zalando.com/postgres-operator/charts/postgres-operator/postgres-operator-1.12.2.tgz + +kubectl apply --namespace="${NAMESPACE}" -f "$(dirname "$0")/netbox-db.yaml" +kubectl wait --namespace="${NAMESPACE}" --timeout=600s --for=jsonpath='{.status.PostgresClusterStatus}'=Running postgresql/netbox-db + +kubectl create configmap --namespace="${NAMESPACE}" netbox-demo-data-load-job-scripts --from-file="$(dirname "$0")/load-data-job" -o yaml --dry-run=client | kubectl apply -f - +kubectl apply --namespace="${NAMESPACE}" -f "$(dirname "$0")/load-data-job.yaml" +kubectl wait --namespace="${NAMESPACE}" --timeout=600s --for=condition=complete job/netbox-demo-data-load-job +kubectl delete configmap --namespace="${NAMESPACE}" netbox-demo-data-load-job-scripts + +helm upgrade --install --namespace="${NAMESPACE}" netbox \ + --set postgresql.enabled="false" \ + --set externalDatabase.host="netbox-db.${NAMESPACE}.svc.cluster.local" \ + --set externalDatabase.existingSecretName="netbox.netbox-db.credentials.postgresql.acid.zalan.do" \ + --set externalDatabase.existingSecretKey="password" \ + --set redis.auth.password="password" \ + --set resources.requests.cpu="500m" \ + --set resources.requests.memory="512Mi" \ + --set resources.limits.cpu="2000m" \ + --set resources.limits.memory="2Gi" \ + ${NETBOX_HELM_CHART} + +kubectl rollout status --namespace="${NAMESPACE}" deployment netbox + +# load local data +kubectl create job netbox-load-local-data --image=netbox-load-local-data:1.0 +kubectl wait --namespace="${NAMESPACE}" --timeout=600s --for=condition=complete job/netbox-load-local-data +docker rmi netbox-load-local-data:1.0 + +# clean up +rm $(dirname "$0")/load-data-job/load-data.sh +rm $(dirname "$0")/load-data-job/dockerfile diff --git a/kind/local-env.sh b/kind/local-env.sh index c3c2f932..3eb01e6d 100755 --- a/kind/local-env.sh +++ b/kind/local-env.sh @@ -3,7 +3,6 @@ set -e -u -o pipefail NAMESPACE="" VERSION="4.1.8" # default value -NETBOX_HELM_CHART="https://github.com/netbox-community/netbox-chart/releases/download/netbox-5.0.0-beta.169/netbox-5.0.0-beta.169.tgz" # default value while [[ $# -gt 0 ]]; do case $1 in -n|--namespace) @@ -40,107 +39,4 @@ fi kind create cluster || echo "cluster already exists, continuing..." kubectl wait --for=jsonpath='{.status.phase}'=Active --timeout=1s namespace/${NAMESPACE} -# load remote images -if [[ "${VERSION}" == "3.7.8" ]] ;then - echo "Using version ${VERSION}" - # need to align with netbox-chart otherwise the creation of the cluster will hang - declare -a Remote_Images=( \ - "busybox:1.36.1" \ - "docker.io/bitnami/redis:7.2.4-debian-12-r9" \ - "docker.io/netboxcommunity/netbox:v3.7.8" \ - "ghcr.io/zalando/postgres-operator:v1.12.2" \ - "ghcr.io/zalando/spilo-16:3.2-p3" \ - ) - NETBOX_HELM_CHART="https://github.com/netbox-community/netbox-chart/releases/download/netbox-5.0.0-beta5/netbox-5.0.0-beta5.tgz" - - # patch load-data.sh - sed 's/netbox-demo-v4.1.sql/netbox-demo-v3.7.sql/g' $(dirname "$0")/load-data-job/load-data.orig.sh > $(dirname "$0")/load-data-job/load-data.sh && chmod +x $(dirname "$0")/load-data-job/load-data.sh - - # patch dockerfile (See README at https://github.com/netbox-community/pynetbox for the supported version matrix) - sed 's/RUN pip install -Iv pynetbox==7.4.1/RUN pip install -Iv pynetbox==7.3.4/g' $(dirname "$0")/load-data-job/dockerfile.orig > $(dirname "$0")/load-data-job/dockerfile -elif [[ "${VERSION}" == "4.0.11" ]] ;then - echo "Using version ${VERSION}" - # need to align with netbox-chart otherwise the creation of the cluster will hang - declare -a Remote_Images=( \ - "busybox:1.36.1" \ - "docker.io/bitnami/redis:7.4.0-debian-12-r2" \ - "ghcr.io/netbox-community/netbox:v4.0.11" \ - "ghcr.io/zalando/postgres-operator:v1.12.2" \ - "ghcr.io/zalando/spilo-16:3.2-p3" \ - ) - NETBOX_HELM_CHART="https://github.com/netbox-community/netbox-chart/releases/download/netbox-5.0.0-beta.84/netbox-5.0.0-beta.84.tgz" - - # patch load-data.sh - sed 's/netbox-demo-v4.1.sql/netbox-demo-v4.0.sql/g' $(dirname "$0")/load-data-job/load-data.orig.sh > $(dirname "$0")/load-data-job/load-data.sh && chmod +x $(dirname "$0")/load-data-job/load-data.sh - - cp $(dirname "$0")/load-data-job/dockerfile.orig $(dirname "$0")/load-data-job/dockerfile -elif [[ "${VERSION}" == "4.1.8" ]] ;then - echo "Using version ${VERSION}" - # need to align with netbox-chart otherwise the creation of the cluster will hang - declare -a Remote_Images=( \ - "busybox:1.37.0" \ - "docker.io/bitnami/redis:7.4.1-debian-12-r2" \ - "ghcr.io/netbox-community/netbox:v4.1.8" \ - "ghcr.io/zalando/postgres-operator:v1.12.2" \ - "ghcr.io/zalando/spilo-16:3.2-p3" \ - ) - - # create load-data.sh - cp $(dirname "$0")/load-data-job/load-data.orig.sh $(dirname "$0")/load-data-job/load-data.sh - - cp $(dirname "$0")/load-data-job/dockerfile.orig $(dirname "$0")/load-data-job/dockerfile -else - echo "Unknown version ${VERSION}" - exit 1 -fi - -for img in "${Remote_Images[@]}"; do - docker pull "$img" - kind load docker-image "$img" -done - -# build image for loading local data via NetBox API -cd ./kind/load-data-job && docker build -t netbox-load-local-data:1.0 --load --no-cache --progress=plain -f ./dockerfile . && cd - - -# load local images -declare -a Local_Images=( \ -"netbox-load-local-data:1.0" \ -) -for img in "${Local_Images[@]}"; do - kind load docker-image "$img" -done - -# install helm charts -helm upgrade --install --namespace="${NAMESPACE}" postgres-operator \ -https://opensource.zalando.com/postgres-operator/charts/postgres-operator/postgres-operator-1.12.2.tgz - -kubectl apply --namespace="${NAMESPACE}" -f "$(dirname "$0")/netbox-db.yaml" -kubectl wait --namespace="${NAMESPACE}" --timeout=600s --for=jsonpath='{.status.PostgresClusterStatus}'=Running postgresql/netbox-db - -kubectl create configmap --namespace="${NAMESPACE}" netbox-demo-data-load-job-scripts --from-file="$(dirname "$0")/load-data-job" -o yaml --dry-run=client | kubectl apply -f - -kubectl apply --namespace="${NAMESPACE}" -f "$(dirname "$0")/load-data-job.yaml" -kubectl wait --namespace="${NAMESPACE}" --timeout=600s --for=condition=complete job/netbox-demo-data-load-job -kubectl delete configmap --namespace="${NAMESPACE}" netbox-demo-data-load-job-scripts - -helm upgrade --install --namespace="${NAMESPACE}" netbox \ - --set postgresql.enabled="false" \ - --set externalDatabase.host="netbox-db.${NAMESPACE}.svc.cluster.local" \ - --set externalDatabase.existingSecretName="netbox.netbox-db.credentials.postgresql.acid.zalan.do" \ - --set externalDatabase.existingSecretKey="password" \ - --set redis.auth.password="password" \ - --set resources.requests.cpu="500m" \ - --set resources.requests.memory="512Mi" \ - --set resources.limits.cpu="2000m" \ - --set resources.limits.memory="2Gi" \ - ${NETBOX_HELM_CHART} - -kubectl rollout status --namespace="${NAMESPACE}" deployment netbox - -# load local data -kubectl create job netbox-load-local-data --image=netbox-load-local-data:1.0 -kubectl wait --namespace="${NAMESPACE}" --timeout=600s --for=condition=complete job/netbox-load-local-data -docker rmi netbox-load-local-data:1.0 - -# clean up -rm $(dirname "$0")/load-data-job/load-data.sh -rm $(dirname "$0")/load-data-job/dockerfile +./kind/deploy-netbox.sh kind $VERSION $NAMESPACE