|
| 1 | +//module included in the following assembly: |
| 2 | +// |
| 3 | +// * networking/multiple_networks/primary_networks/about-user-defined-networks.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="nw-cudn-cr_{context}"] |
| 7 | += Creating a ClusterUserDefinedNetwork custom resource |
| 8 | + |
| 9 | +The following procedure creates a `ClusterUserDefinedNetwork` custom resource definition (CRD). Based upon your use case, create your request using either the `cluster-layer-two-udn.yaml` example for a `Layer2` topology type or the `cluster-layer-three-udn.yaml` example for a `Layer3` topology type. |
| 10 | + |
| 11 | +[IMPORTANT] |
| 12 | +==== |
| 13 | +* The `ClusterUserDefinedNetwork` CRD is intended for use by cluster administrators and should not be used by non-administrators. If used incorrectly, it might result in security issues with your deployment, cause disruptions, or break the cluster network. |
| 14 | +* {VirtProductName} only supports the `Layer2` topology. |
| 15 | +==== |
| 16 | + |
| 17 | +.Prerequisites |
| 18 | + |
| 19 | +* You have logged in as a user with `cluster-admin` privileges. |
| 20 | +
|
| 21 | +.Procedure |
| 22 | + |
| 23 | +. Optional: For a `ClusterUserDefinedNetwork` CR that uses a primary network, create a namespace with the `k8s.ovn.org/primary-user-defined-network` label by entering the following command: |
| 24 | ++ |
| 25 | +[source,yaml] |
| 26 | +---- |
| 27 | +$ cat << EOF | oc apply -f - |
| 28 | +apiVersion: v1 |
| 29 | +kind: Namespace |
| 30 | +metadata: |
| 31 | + name: <cudn_namespace_name> |
| 32 | + labels: |
| 33 | + k8s.ovn.org/primary-user-defined-network: "" |
| 34 | +EOF |
| 35 | +---- |
| 36 | + |
| 37 | +. Create a request for either a `Layer2` or `Layer3` topology type cluster-wide user-defined network: |
| 38 | + |
| 39 | +.. Create a YAML file, such as `cluster-layer-two-udn.yaml`, to define your request for a `Layer2` topology as in the following example: |
| 40 | ++ |
| 41 | +[source, yaml] |
| 42 | +---- |
| 43 | +apiVersion: k8s.ovn.org/v1 |
| 44 | +kind: ClusterUserDefinedNetwork |
| 45 | +metadata: |
| 46 | + name: <cudn_name> # <1> |
| 47 | +spec: |
| 48 | + namespaceSelector: # <2> |
| 49 | + matchLabels: # <3> |
| 50 | + - "<example_namespace_one>":"" # <4> |
| 51 | + - "<example_namespace_two>":"" # <4> |
| 52 | + network: # <5> |
| 53 | + topology: Layer2 # <6> |
| 54 | + layer2: # <7> |
| 55 | + role: Primary # <8> |
| 56 | + subnets: |
| 57 | + - "2001:db8::/64" |
| 58 | + - "10.100.0.0/16" # <9> |
| 59 | +---- |
| 60 | +<1> Name of your `ClusterUserDefinedNetwork` custom resource. |
| 61 | +<2> A label query over the set of namespaces that the cluster UDN applies to. Uses the standard Kubernetes `MatchLabel` selector. Must not point to `default` or `openshift-*` namespaces. |
| 62 | +<3> Uses the `matchLabels` selector type, where terms are evaluated with an `AND` relationship. |
| 63 | +<4> Because the `matchLabels` selector type is used, provisions namespaces matching both `<example_namespace_one>` _and_ `<example_namespace_two>`. |
| 64 | +<5> Describes the network configuration. |
| 65 | +<6> The `topology` field describes the network configuration; accepted values are `Layer2` and `Layer3`. Specifying a `Layer2` topology type creates one logical switch that is shared by all nodes. |
| 66 | +<7> This field specifies the topology configuration. It can be `layer2` or `layer3`. |
| 67 | +<8> Specifies `Primary` or `Secondary`. `Primary` is the only `role` specification supported in {product-version}. |
| 68 | +<9> For `Layer2` topology types the following specifies config details for the `subnet` field: |
| 69 | ++ |
| 70 | +* The subnets field is optional. |
| 71 | +* The subnets field is of type `string` and accepts standard CIDR formats for both IPv4 and IPv6. |
| 72 | +* The subnets field accepts one or two items. For two items, they must be of a different family. For example, subnets values of `10.100.0.0/16` and `2001:db8::/64`. |
| 73 | +* `Layer2` subnets can be omitted. If omitted, users must configure static IP addresses for the pods. As a consequence, port security only prevents MAC spoofing. For more information, see "Configuring pods with a static IP address". |
| 74 | ++ |
| 75 | +.. Create a YAML file, such as `cluster-layer-three-udn.yaml`, to define your request for a `Layer3` topology as in the following example: |
| 76 | ++ |
| 77 | +[source, yaml] |
| 78 | +---- |
| 79 | +apiVersion: k8s.ovn.org/v1 |
| 80 | +kind: ClusterUserDefinedNetwork |
| 81 | +metadata: |
| 82 | + name: <cudn_name> # <1> |
| 83 | +spec: |
| 84 | + namespaceSelector: # <2> |
| 85 | + matchExpressions: # <3> |
| 86 | + - key: kubernetes.io/metadata.name # <4> |
| 87 | + operator: In # <5> |
| 88 | + values: ["<example_namespace_one>, <example_namespace_two>"] # <6> |
| 89 | + network: # <7> |
| 90 | + topology: Layer3 # <8> |
| 91 | + layer3: # <9> |
| 92 | + role: Primary # <10> |
| 93 | + subnets: # <11> |
| 94 | + - cidr: 10.100.0.0/16 |
| 95 | + hostSubnet: 64 |
| 96 | +---- |
| 97 | +<1> Name of your `ClusterUserDefinedNetwork` custom resource. |
| 98 | +<2> A label query over the set of namespaces that the cluster UDN applies to. Uses the standard Kubernetes `MatchLabel` selector. Must not point to `default` or `openshift-*` namespaces. |
| 99 | +<3> Uses the `matchExpressions` selector type, where terms are evaluated with an _*OR*_ relationship. |
| 100 | +<4> Specifies the label key to match. |
| 101 | +<5> Specifies the operator. Valid values include: `In`, `NotIn`, `Exists`, and `DoesNotExist`. |
| 102 | +<6> Because the `matchExpressions` type is used, provisions namespaces matching either `<example_namespace_one>` or `<example_namespace_two>`. |
| 103 | +<7> Describes the network configuration. |
| 104 | +<8> The `topology` field describes the network configuration; accepted values are `Layer2` and `Layer3`. Specifying a `Layer3` topology type creates a layer 2 segment per node, each with a different subnet. Layer 3 routing is used to interconnect node subnets. |
| 105 | +<9> This field specifies the topology configuration. Valid values are `layer2` or `layer3`. |
| 106 | +<10> Specifies a `Primary` or `Secondary` role. `Primary` is the only `role` specification supported in {product-version}. |
| 107 | +<11> For `Layer3` topology types the following specifies config details for the `subnet` field: |
| 108 | ++ |
| 109 | +* The `subnets` field is mandatory. |
| 110 | +* The type for the `subnets` field is `cidr` and `hostSubnet`: |
| 111 | +** `cidr` is the cluster subnet and accepts a string value. |
| 112 | +** `hostSubnet` specifies the nodes subnet prefix that the cluster subnet is split to. |
| 113 | +** For IPv6, only a `/64` length is supported for `hostSubnet`. |
| 114 | ++ |
| 115 | +. Apply your request by running the following command: |
| 116 | ++ |
| 117 | +[source,terminal] |
| 118 | +---- |
| 119 | +$ oc create --validate=true -f <example_cluster_udn>.yaml |
| 120 | +---- |
| 121 | ++ |
| 122 | +Where `<example_cluster_udn>.yaml` is the name of your `Layer2` or `Layer3` configuration file. |
| 123 | + |
| 124 | +. Verify that your request is successful by running the following command: |
| 125 | ++ |
| 126 | +[source,terminal] |
| 127 | +---- |
| 128 | +$ oc get clusteruserdefinednetwork <cudn_name> -o yaml |
| 129 | +---- |
| 130 | ++ |
| 131 | +Where `<cudn_name>` is the name you created of your cluster-wide user-defined network. |
| 132 | ++ |
| 133 | +.Example output |
| 134 | +[source,yaml] |
| 135 | +---- |
| 136 | +apiVersion: k8s.ovn.org/v1 |
| 137 | +kind: ClusterUserDefinedNetwork |
| 138 | +metadata: |
| 139 | + creationTimestamp: "2024-12-05T15:53:00Z" |
| 140 | + finalizers: |
| 141 | + - k8s.ovn.org/user-defined-network-protection |
| 142 | + generation: 1 |
| 143 | + name: my-cudn |
| 144 | + resourceVersion: "47985" |
| 145 | + uid: 16ee0fcf-74d1-4826-a6b7-25c737c1a634 |
| 146 | +spec: |
| 147 | + namespaceSelector: |
| 148 | + matchExpressions: |
| 149 | + - key: custom.network.selector |
| 150 | + operator: In |
| 151 | + values: |
| 152 | + - example-namespace-1 |
| 153 | + - example-namespace-2 |
| 154 | + - example-namespace-3 |
| 155 | + network: |
| 156 | + layer3: |
| 157 | + role: Primary |
| 158 | + subnets: |
| 159 | + - cidr: 10.100.0.0/16 |
| 160 | + topology: Layer3 |
| 161 | +status: |
| 162 | + conditions: |
| 163 | + - lastTransitionTime: "2024-11-19T16:46:34Z" |
| 164 | + message: 'NetworkAttachmentDefinition has been created in following namespaces: |
| 165 | + [example-namespace-1, example-namespace-2, example-namespace-3]' |
| 166 | + reason: NetworkAttachmentDefinitionReady |
| 167 | + status: "True" |
| 168 | + type: NetworkCreated |
| 169 | +---- |
0 commit comments