diff --git a/apps/admission-webhook-k8s/admission-webhook.yaml b/apps/admission-webhook-k8s/admission-webhook.yaml new file mode 100644 index 000000000000..36dcf255ed23 --- /dev/null +++ b/apps/admission-webhook-k8s/admission-webhook.yaml @@ -0,0 +1,40 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: admission-webhook-k8s + labels: + app: admission-webhook-k8s +spec: + selector: + matchLabels: + app: admission-webhook-k8s + template: + metadata: + labels: + app: admission-webhook-k8s + spec: + serviceAccount: admission-webhook-sa + containers: + - name: admission-webhook-k8s + image: networkservicemeshci/cmd-admission-webhook-k8s:master + imagePullPolicy: IfNotPresent + env: + - name: SPIFFE_ENDPOINT_SOCKET + value: unix:///run/spire/sockets/agent.sock + - name: NSM_SERVICE_NAME + value: admission-webhook-svc + - name: NSM_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: NSM_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: NSM_ANNOTATION + value: networkservicemesh.io + - name: NSM_CONTAINER_IMAGES + value: networkservicemeshci/cmd-nsc:281975be + - name: NSM_INIT_CONTAINER_IMAGES + value: networkservicemeshci/cmd-nsc-init:master diff --git a/apps/admission-webhook-k8s/binding.yaml b/apps/admission-webhook-k8s/binding.yaml new file mode 100644 index 000000000000..ff2dcdcc910b --- /dev/null +++ b/apps/admission-webhook-k8s/binding.yaml @@ -0,0 +1,12 @@ +--- +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: admission-webhook-binding +subjects: + - kind: ServiceAccount + name: admission-webhook-sa +roleRef: + kind: ClusterRole + name: admission-webhook-role + apiGroup: rbac.authorization.k8s.io diff --git a/apps/admission-webhook-k8s/kustomization.yaml b/apps/admission-webhook-k8s/kustomization.yaml new file mode 100644 index 000000000000..cc2c0c563bb6 --- /dev/null +++ b/apps/admission-webhook-k8s/kustomization.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: +- service.yaml +- sa.yaml +- admission-webhook.yaml +- binding.yaml +- role.yaml + +namespace: default diff --git a/apps/admission-webhook-k8s/role.yaml b/apps/admission-webhook-k8s/role.yaml new file mode 100644 index 000000000000..6224924e32b7 --- /dev/null +++ b/apps/admission-webhook-k8s/role.yaml @@ -0,0 +1,13 @@ +--- +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: admission-webhook-role + labels: + rbac.authorization.k8s.io/aggregate-to-admin: "true" + rbac.authorization.k8s.io/aggregate-to-edit: "true" +rules: + - apiGroups: ["admissionregistration.k8s.io"] + resources: + - "mutatingwebhookconfigurations" + verbs: ["*"] diff --git a/apps/admission-webhook-k8s/sa.yaml b/apps/admission-webhook-k8s/sa.yaml new file mode 100644 index 000000000000..f0ac21d3c376 --- /dev/null +++ b/apps/admission-webhook-k8s/sa.yaml @@ -0,0 +1,5 @@ +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: admission-webhook-sa diff --git a/apps/admission-webhook-k8s/service.yaml b/apps/admission-webhook-k8s/service.yaml new file mode 100644 index 000000000000..e4626644215f --- /dev/null +++ b/apps/admission-webhook-k8s/service.yaml @@ -0,0 +1,13 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: admission-webhook-svc + labels: + app: admission-webhook-k8s +spec: + ports: + - port: 443 + targetPort: 443 + selector: + app: admission-webhook-k8s diff --git a/examples/basic/README.md b/examples/basic/README.md index ed36b9a0947c..74b60efe972b 100644 --- a/examples/basic/README.md +++ b/examples/basic/README.md @@ -57,5 +57,6 @@ kubectl apply -k . To free resouces follow the next command: ```bash +kubectl delete mutatingwebhookconfiguration --all kubectl delete ns nsm-system ``` \ No newline at end of file diff --git a/examples/basic/kustomization.yaml b/examples/basic/kustomization.yaml index 65a11e939088..38a144ce36ef 100644 --- a/examples/basic/kustomization.yaml +++ b/examples/basic/kustomization.yaml @@ -8,3 +8,4 @@ bases: - ../../apps/nsmgr - ../../apps/forwarder-vpp - ../../apps/registry-k8s +- ../../apps/admission-webhook-k8s diff --git a/examples/features/README.md b/examples/features/README.md index 32e727e72303..878adc882478 100644 --- a/examples/features/README.md +++ b/examples/features/README.md @@ -14,5 +14,5 @@ To run any feature example follow steps for [Basic NSM setup](../basic) - Heal - Refresh - Timeout -- Admission webhook +- [Admission webhook](./webhook) - DNS diff --git a/examples/features/webhook/README.md b/examples/features/webhook/README.md new file mode 100644 index 000000000000..4c4fdbb5e192 --- /dev/null +++ b/examples/features/webhook/README.md @@ -0,0 +1,150 @@ +# Alpine requests for postgresql service + +This example demonstrates how alpine can get connectivity to Postgres deployment via NSM. +Alpine pod and Postgres deployment located on different nodes. + + +## Requires + +Make sure that you have completed steps from [features](../) + +## Run + +1. Create test namespace: +```bash +NAMESPACE=($(kubectl create -f ../../use-cases/namespace.yaml)[0]) +NAMESPACE=${NAMESPACE:10} +``` + +2. Register namespace in `spire` server: +```bash +kubectl exec -n spire spire-server-0 -- \ +/opt/spire/bin/spire-server entry create \ +-spiffeID spiffe://example.org/ns/${NAMESPACE}/sa/default \ +-parentID spiffe://example.org/ns/spire/sa/spire-agent \ +-selector k8s:ns:${NAMESPACE} \ +-selector k8s:sa:default +``` + +3. Get all available nodes to deploy: +```bash +NODES=($(kubectl get nodes -o go-template='{{range .items}}{{ if not .spec.taints }}{{index .metadata.labels "kubernetes.io/hostname"}} {{end}}{{end}}')) +``` + +4. Create alpine deployment and set `nodeSelector` to the first node: +```bash +cat > alpine.yaml < patch-nse.yaml < kustomization.yaml <