diff --git a/examples/features/README.md b/examples/features/README.md index 5c4e80804961..817cb33fb2ed 100644 --- a/examples/features/README.md +++ b/examples/features/README.md @@ -17,6 +17,7 @@ To run any feature example follow steps for [Basic NSM setup](../basic) - [Memif2IP2Memif IPv6 example](ipv6/Memif2IP2Memif_ipv6) - [Kernel2Kernel dual stack example](dual-stack/Kernel2Kernel_dual_stack) - [Kernel2IP2Kernel dual stack example](dual-stack/Kernel2IP2Kernel_dual_stack) +- [vL3 dual stack example](dual-stack/vl3-dual-stack) - [Admission webhook](./webhook) - [DNS](./dns) - [Topology aware scale from zero](./scale-from-zero) diff --git a/examples/features/dual-stack/vl3-dual-stack/README.md b/examples/features/dual-stack/vl3-dual-stack/README.md new file mode 100644 index 000000000000..eb1e3c1e392f --- /dev/null +++ b/examples/features/dual-stack/vl3-dual-stack/README.md @@ -0,0 +1,92 @@ +# vL3 dual stack example + +This example shows how could be configured vL3 dual stack network via NSM. + +Diagram: + +![NSM vL3 dual stack Diagram](./vl3-dual-stack.png "NSM Authorize Scheme") + +**NOTE: Forwarder and NSMmgr are missed in the diagram for the simplicity** + + +## Run + +Deploy network service, nsc and vl3 nses (See at `kustomization.yaml`): +```bash +kubectl apply -k https://github.com/networkservicemesh/deployments-k8s/examples/features/dual-stack/vl3-dual-stack?ref=05a9319b78acdb91b0d4d0ef6b21736d7b17602c +kubectl apply -k https://github.com/networkservicemesh/deployments-k8s/examples/features/dual-stack/vl3-dual-stack/ipam-ipv6?ref=05a9319b78acdb91b0d4d0ef6b21736d7b17602c +``` + +Wait for clients to be ready: +```bash +kubectl wait --for=condition=ready --timeout=2m pod -l app=alpine -n ns-vl3-dual-stack +``` + +Find all nscs: +```bash +nscs=$(kubectl get pods -l app=alpine -o go-template --template="{{range .items}}{{.metadata.name}} {{end}}" -n ns-vl3-dual-stack) +[[ ! -z $nscs ]] +``` + +Ping each client by each client: +```bash +( +for nsc in $nscs +do + ipAddr=$(kubectl exec -n ns-vl3-dual-stack $nsc -- ifconfig nsm-1) || exit + ipv4Addr=$(echo $ipAddr | grep -Eo 'inet addr:[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'| cut -c 11-) + ipv6Addr=$(echo $ipAddr | grep -Eo 'inet6 addr: 2001:.*' | cut -d ' ' -f 3 | cut -d '/' -f 1) + for pinger in $nscs + do + if [ "$nsc" != "$pinger" ]; then + echo $pinger pings $ipv4Addr + kubectl exec $pinger -n ns-vl3-dual-stack -- ping -c2 -i 0.5 $ipv4Addr || exit + echo $pinger pings $ipv6Addr + kubectl exec $pinger -n ns-vl3-dual-stack -- ping6 -c2 -i 0.5 $ipv6Addr || exit + fi + done +done +) +``` + +Ping each vl3-nse by each client. +Note: By default ipam prefixes are `172.16.0.0/16` and `2001:db8::/64` and corresponding client prefix len-s are `24` and `112`. We also have two vl3 nses in this example. So we expect to have two ipv4 vl3 addresses: `172.16.0.0` and `172.16.1.0` and two ipv6 vl3 addresses: `2001:db8::` and `2001:db8::1:0` that should be accessible by each client. +```bash +( +for nsc in $nscs +do + echo $nsc pings nses + kubectl exec -n ns-vl3-dual-stack $nsc -- ping 172.16.0.0 -c2 -i 0.5 || exit + kubectl exec -n ns-vl3-dual-stack $nsc -- ping 172.16.1.0 -c2 -i 0.5 || exit + kubectl exec -n ns-vl3-dual-stack $nsc -- ping6 2001:db8:: -c2 -i 0.5 || exit + kubectl exec -n ns-vl3-dual-stack $nsc -- ping6 2001:db8::1:0 -c2 -i 0.5 || exit +done +) +``` + +Find all nses: +```bash +nses=$(kubectl get pods -l app=nse-vl3-vpp -o go-template --template="{{range .items}}{{.metadata.name}} {{end}}" -n ns-vl3-dual-stack) +[[ ! -z $nses ]] +``` + +Ping vl3-nse by each vl3-nse. +```bash +( +for nse in $nses +do + echo $nse pings nses + kubectl exec -n ns-vl3-dual-stack $nse -- ping 172.16.0.0 -c2 -i 0.5 || exit + kubectl exec -n ns-vl3-dual-stack $nse -- ping 172.16.1.0 -c2 -i 0.5 || exit + kubectl exec -n ns-vl3-dual-stack $nse -- ping6 2001:db8:: -c2 -i 0.5 || exit + kubectl exec -n ns-vl3-dual-stack $nse -- ping6 2001:db8::1:0 -c2 -i 0.5 || exit +done +) +``` + +## Cleanup + +To cleanup the example just follow the next command: +```bash +kubectl delete ns ns-vl3-dual-stack +``` diff --git a/examples/features/dual-stack/vl3-dual-stack/client.yaml b/examples/features/dual-stack/vl3-dual-stack/client.yaml new file mode 100644 index 000000000000..2d8ee6576645 --- /dev/null +++ b/examples/features/dual-stack/vl3-dual-stack/client.yaml @@ -0,0 +1,26 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: alpine + labels: + app: alpine +spec: + replicas: 2 + selector: + matchLabels: + app: alpine + template: + metadata: + labels: + app: alpine + annotations: + networkservicemesh.io: kernel://vl3-dual-stack/nsm-1 + spec: + containers: + - name: alpine + image: alpine:3.15.0 + imagePullPolicy: IfNotPresent + # simple `sleep` command would work + # but we need `trap` to be able to delete pods quckly + command: ["/bin/sh", "-c", "trap : TERM INT; sleep infinity & wait"] diff --git a/examples/features/dual-stack/vl3-dual-stack/ipam-deployment-patch.yaml b/examples/features/dual-stack/vl3-dual-stack/ipam-deployment-patch.yaml new file mode 100644 index 000000000000..772ad78565ba --- /dev/null +++ b/examples/features/dual-stack/vl3-dual-stack/ipam-deployment-patch.yaml @@ -0,0 +1,13 @@ +--- +- op: replace + path: /metadata/name + value: vl3-ipam-ds-ipv4 +- op: replace + path: /metadata/labels/app + value: vl3-ipam-ds-ipv4 +- op: replace + path: /spec/selector/matchLabels/app + value: vl3-ipam-ds-ipv4 +- op: replace + path: /spec/template/metadata/labels/app + value: vl3-ipam-ds-ipv4 diff --git a/examples/features/dual-stack/vl3-dual-stack/ipam-ipv6/ipam-deployment-patch.yaml b/examples/features/dual-stack/vl3-dual-stack/ipam-ipv6/ipam-deployment-patch.yaml new file mode 100644 index 000000000000..423682fffcba --- /dev/null +++ b/examples/features/dual-stack/vl3-dual-stack/ipam-ipv6/ipam-deployment-patch.yaml @@ -0,0 +1,13 @@ +--- +- op: replace + path: /metadata/name + value: vl3-ipam-ds-ipv6 +- op: replace + path: /metadata/labels/app + value: vl3-ipam-ds-ipv6 +- op: replace + path: /spec/selector/matchLabels/app + value: vl3-ipam-ds-ipv6 +- op: replace + path: /spec/template/metadata/labels/app + value: vl3-ipam-ds-ipv6 diff --git a/examples/features/dual-stack/vl3-dual-stack/ipam-ipv6/ipam-patch.yaml b/examples/features/dual-stack/vl3-dual-stack/ipam-ipv6/ipam-patch.yaml new file mode 100644 index 000000000000..56d24c9e090d --- /dev/null +++ b/examples/features/dual-stack/vl3-dual-stack/ipam-ipv6/ipam-patch.yaml @@ -0,0 +1,17 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: vl3-ipam + labels: + app: vl3-ipam +spec: + template: + spec: + containers: + - name: vl3-ipam + env: + - name: NSM_PREFIX + value: 2001:db8::/64 + - name: NSM_CLIENT_PREFIX_LEN + value: "112" diff --git a/examples/features/dual-stack/vl3-dual-stack/ipam-ipv6/ipam-service-patch.yaml b/examples/features/dual-stack/vl3-dual-stack/ipam-ipv6/ipam-service-patch.yaml new file mode 100644 index 000000000000..d28014527b61 --- /dev/null +++ b/examples/features/dual-stack/vl3-dual-stack/ipam-ipv6/ipam-service-patch.yaml @@ -0,0 +1,10 @@ +--- +- op: replace + path: /metadata/name + value: vl3-ipam-ds-ipv6 +- op: replace + path: /spec/selector/app + value: vl3-ipam-ds-ipv6 +- op: replace + path: /spec/ports/0/name + value: vl3-ipam-ds-ipv6 diff --git a/examples/features/dual-stack/vl3-dual-stack/ipam-ipv6/kustomization.yaml b/examples/features/dual-stack/vl3-dual-stack/ipam-ipv6/kustomization.yaml new file mode 100644 index 000000000000..9b184e9152b5 --- /dev/null +++ b/examples/features/dual-stack/vl3-dual-stack/ipam-ipv6/kustomization.yaml @@ -0,0 +1,21 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +namespace: ns-vl3-dual-stack + +resources: +- ../../../../../apps/vl3-ipam + +patches: + - path: ipam-patch.yaml + - target: + version: v1 + kind: Deployment + name: vl3-ipam + path: ipam-deployment-patch.yaml + - target: + version: v1 + kind: Service + name: vl3-ipam + path: ipam-service-patch.yaml diff --git a/examples/features/dual-stack/vl3-dual-stack/ipam-service-patch.yaml b/examples/features/dual-stack/vl3-dual-stack/ipam-service-patch.yaml new file mode 100644 index 000000000000..4a781d9e6c84 --- /dev/null +++ b/examples/features/dual-stack/vl3-dual-stack/ipam-service-patch.yaml @@ -0,0 +1,10 @@ +--- +- op: replace + path: /metadata/name + value: vl3-ipam-ds-ipv4 +- op: replace + path: /spec/selector/app + value: vl3-ipam-ds-ipv4 +- op: replace + path: /spec/ports/0/name + value: vl3-ipam-ds-ipv4 diff --git a/examples/features/dual-stack/vl3-dual-stack/kustomization.yaml b/examples/features/dual-stack/vl3-dual-stack/kustomization.yaml new file mode 100644 index 000000000000..bd327b8e6e7c --- /dev/null +++ b/examples/features/dual-stack/vl3-dual-stack/kustomization.yaml @@ -0,0 +1,25 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +namespace: ns-vl3-dual-stack + +resources: +- ns-vl3-dual-stack.yaml +- netsvc.yaml +- client.yaml +- ../../../../apps/vl3-ipam +- ../../../../apps/nse-vl3-vpp + +patches: + - path: nse-patch.yaml + - target: + version: v1 + kind: Deployment + name: vl3-ipam + path: ipam-deployment-patch.yaml + - target: + version: v1 + kind: Service + name: vl3-ipam + path: ipam-service-patch.yaml diff --git a/examples/features/dual-stack/vl3-dual-stack/netsvc.yaml b/examples/features/dual-stack/vl3-dual-stack/netsvc.yaml new file mode 100644 index 000000000000..bbb8a8aa10d8 --- /dev/null +++ b/examples/features/dual-stack/vl3-dual-stack/netsvc.yaml @@ -0,0 +1,7 @@ +--- +apiVersion: networkservicemesh.io/v1 +kind: NetworkService +metadata: + name: vl3-dual-stack +spec: + payload: IP diff --git a/examples/features/dual-stack/vl3-dual-stack/ns-vl3-dual-stack.yaml b/examples/features/dual-stack/vl3-dual-stack/ns-vl3-dual-stack.yaml new file mode 100644 index 000000000000..b20285d6cfb0 --- /dev/null +++ b/examples/features/dual-stack/vl3-dual-stack/ns-vl3-dual-stack.yaml @@ -0,0 +1,5 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: ns-vl3-dual-stack diff --git a/examples/features/dual-stack/vl3-dual-stack/nse-patch.yaml b/examples/features/dual-stack/vl3-dual-stack/nse-patch.yaml new file mode 100644 index 000000000000..d1c201c1a875 --- /dev/null +++ b/examples/features/dual-stack/vl3-dual-stack/nse-patch.yaml @@ -0,0 +1,20 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nse-vl3-vpp + labels: + app: nse-vl3-vpp +spec: + replicas: 2 + template: + spec: + containers: + - name: nse + env: + - name: NSM_PREFIX_SERVER_URL + value: "vl3-ipam-ds-ipv4:5006,vl3-ipam-ds-ipv6:5006" + - name: NSM_SERVICE_NAMES + value: "vl3-dual-stack" + - name: NSM_REGISTER_SERVICE + value: "false" diff --git a/examples/features/dual-stack/vl3-dual-stack/vl3-dual-stack.png b/examples/features/dual-stack/vl3-dual-stack/vl3-dual-stack.png new file mode 100644 index 000000000000..51b33310648d Binary files /dev/null and b/examples/features/dual-stack/vl3-dual-stack/vl3-dual-stack.png differ