-
Notifications
You must be signed in to change notification settings - Fork 35
Add Consul interdomain example #6517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
anastasia-malysheva
wants to merge
12
commits into
networkservicemesh:main
from
anastasia-malysheva:add-consul-example
Closed
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
78efaa5
Add nsm example with consul-k8s
anastasia-malysheva dc881c6
move basic interdomain installation from nsm_consul and nsm_istio exa…
anastasia-malysheva 6ed2b84
fixes
anastasia-malysheva 45b2a7f
Merge branch 'main' of github.com:anastasia-malysheva/deployments-k8s…
anastasia-malysheva bc2ba4e
add readme for basic interdomain
anastasia-malysheva c90a49e
fix references
anastasia-malysheva 2586ed2
replace references with export version
anastasia-malysheva c5350a8
add missed files
anastasia-malysheva 0eb379d
add fixes
anastasia-malysheva 16de6c7
add fixes, to run all example
anastasia-malysheva 2a3be6c
add fix to install consul and update cmd-nse-l7-image
anastasia-malysheva 489368d
Add commands to get more info about pods condition
anastasia-malysheva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # NSM interdomain setup | ||
|
|
||
|
|
||
| This example simply show how can be deployed and configured two NSM on different clusters | ||
|
|
||
| ## Run | ||
|
|
||
| Install NSM | ||
| ```bash | ||
| kubectl --kubeconfig=$KUBECONFIG1 apply -k https://github.com/networkservicemesh/deployments-k8s/examples/basic_interdomain/nsm/cluster1?ref=9b2e8e76fbc7505da8e87ea24bf90ac39f4b6c1a | ||
| kubectl --kubeconfig=$KUBECONFIG2 apply -k https://github.com/networkservicemesh/deployments-k8s/examples/basic_interdomain/nsm/cluster2?ref=9b2e8e76fbc7505da8e87ea24bf90ac39f4b6c1a | ||
| ``` | ||
|
|
||
| ## Cleanup | ||
|
|
||
| Cleanup NSM | ||
| ```bash | ||
| WH=$(kubectl --kubeconfig=$KUBECONFIG1 get pods -l app=admission-webhook-k8s -n nsm-system --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}') | ||
| kubectl --kubeconfig=$KUBECONFIG1 delete mutatingwebhookconfiguration ${WH} | ||
|
|
||
| WH=$(kubectl --kubeconfig=$KUBECONFIG2 get pods -l app=admission-webhook-k8s -n nsm-system --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}') | ||
| kubectl --kubeconfig=$KUBECONFIG2 delete mutatingwebhookconfiguration ${WH} | ||
|
|
||
| kubectl --kubeconfig=$KUBECONFIG1 delete -k https://github.com/networkservicemesh/deployments-k8s/examples/basic_interdomain/nsm/cluster1?ref=9b2e8e76fbc7505da8e87ea24bf90ac39f4b6c1a | ||
| kubectl --kubeconfig=$KUBECONFIG2 delete -k https://github.com/networkservicemesh/deployments-k8s/examples/basic_interdomain/nsm/cluster2?ref=9b2e8e76fbc7505da8e87ea24bf90ac39f4b6c1a | ||
| ``` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| !**/kustomization.yaml | ||
| !**/patch-*.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # NSM + Consul interdomain example over kind clusters | ||
|
|
||
| This example show how Consul can be used over nsm | ||
|
|
||
|
|
||
| ## Requires | ||
|
|
||
| - [Load balancer](../basic_interdomain/loadbalancer) | ||
| - [Interdomain DNS](../basic_interdomain/dns) | ||
| - [Interdomain spire](../basic_interdomain/spire) | ||
| - [Interdomain nsm](../basic_interdomain/nsm) | ||
|
|
||
|
|
||
| ## Run | ||
|
|
||
| Install Consul | ||
| ```bash | ||
| brew tap hashicorp/tap | ||
| brew install hashicorp/tap/consul-k8s | ||
| ``` | ||
|
|
||
| Install Consul for the second cluster: | ||
| ```bash | ||
| consul-k8s install -config-file=https://github.com/networkservicemesh/deployments-k8s/examples/nsm_consul/helm-consul-values.yaml?ref=9b2e8e76fbc7505da8e87ea24bf90ac39f4b6c1a -set global.image=hashicorp/consul:1.12.0 --kubeconfig=$KUBECONFIG2 | ||
| ``` | ||
|
|
||
| ### Verify NSM+CONSUL | ||
|
|
||
| Install networkservice for the second cluster:: | ||
| ```bash | ||
| kubectl --kubeconfig=$KUBECONFIG2 apply -f https://github.com/networkservicemesh/deployments-k8s/examples/nsm_consul/networkservice.yaml?ref=9b2e8e76fbc7505da8e87ea24bf90ac39f4b6c1a | ||
| ``` | ||
|
|
||
| Start `alpine` networkservicemesh client for the first cluster: | ||
|
|
||
| ```bash | ||
| kubectl --kubeconfig=$KUBECONFIG1 apply -f https://github.com/networkservicemesh/deployments-k8s/examples/nsm_consul/client/client.yaml?ref=9b2e8e76fbc7505da8e87ea24bf90ac39f4b6c1a | ||
| ``` | ||
|
|
||
| Create kubernetes service for the networkservicemesh endpoint: | ||
| ```bash | ||
| kubectl --kubeconfig=$KUBECONFIG2 apply -f https://github.com/networkservicemesh/deployments-k8s/examples/nsm_consul/service.yaml?ref=9b2e8e76fbc7505da8e87ea24bf90ac39f4b6c1a | ||
| ``` | ||
|
|
||
| Start `auto-scale` networkservicemesh endpoint: | ||
| ```bash | ||
|
|
||
| kubectl --kubeconfig=$KUBECONFIG2 apply -k https://github.com/networkservicemesh/deployments-k8s/examples/nsm_consul/nse-auto-scale?ref=9b2e8e76fbc7505da8e87ea24bf90ac39f4b6c1a | ||
| ``` | ||
|
|
||
| Install `static-server` Consul workload on the second cluster: | ||
| ```bash | ||
| kubectl --kubeconfig=$KUBECONFIG2 apply -f https://github.com/networkservicemesh/deployments-k8s/examples/nsm_consul/server/static-server.yaml?ref=9b2e8e76fbc7505da8e87ea24bf90ac39f4b6c1a | ||
| ``` | ||
|
|
||
| Verify connection from networkservicemesh client to consul server: | ||
| ```bash | ||
| kubectl --kubeconfig=$KUBECONFIG1 exec -it alpine-nsc -- apk add curl | ||
| kubectl --kubeconfig=$KUBECONFIG1 exec -it alpine-nsc -- curl 172.16.1.2:8080 | ||
| ``` | ||
|
|
||
| You should see "hello world" answer. | ||
|
|
||
| ## Cleanup | ||
|
|
||
|
|
||
| ```bash | ||
| kubectl --kubeconfig=$KUBECONFIG2 delete deployment static-server | ||
| kubectl --kubeconfig=$KUBECONFIG2 delete -k https://github.com/networkservicemesh/deployments-k8s/examples/nsm_consul/nse-auto-scale?ref=9b2e8e76fbc7505da8e87ea24bf90ac39f4b6c1a | ||
| kubectl --kubeconfig=$KUBECONFIG1 delete -f https://github.com/networkservicemesh/deployments-k8s/examples/nsm_consul/client/client.yaml?ref=9b2e8e76fbc7505da8e87ea24bf90ac39f4b6c1a | ||
| kubectl --kubeconfig=$KUBECONFIG2 delete -f https://github.com/networkservicemesh/deployments-k8s/examples/nsm_consul/networkservice.yaml?ref=9b2e8e76fbc7505da8e87ea24bf90ac39f4b6c1a | ||
| consul-k8s uninstall --kubeconfig=$KUBECONFIG2 -auto-approve=true -wipe-data=true | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: alpine-nsc | ||
| labels: | ||
| app: alpine-nsc | ||
| annotations: | ||
| networkservicemesh.io: kernel://autoscale-consul-proxy@my.cluster2/nsm-1?app=alpine-nsc | ||
| spec: | ||
| containers: | ||
| - name: alpine-nsc | ||
| image: alpine:3.15.0 | ||
| imagePullPolicy: IfNotPresent | ||
| stdin: true | ||
| tty: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| global: | ||
| name: consul | ||
| datacenter: dc1 | ||
| server: | ||
| replicas: 1 | ||
| connectInject: | ||
| enabled: true | ||
| transparentProxy: | ||
| defaultEnabled: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| kind: Cluster | ||
| apiVersion: kind.x-k8s.io/v1alpha4 | ||
| nodes: | ||
| - role: control-plane | ||
| - role: worker |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --- | ||
| apiVersion: networkservicemesh.io/v1 | ||
| kind: NetworkService | ||
| metadata: | ||
| name: autoscale-consul-proxy | ||
| namespace: nsm-system | ||
| spec: | ||
| payload: IP | ||
| matches: | ||
| - source_selector: | ||
| fallthrough: true | ||
| routes: | ||
| - destination_selector: | ||
| podName: "{{ .podName }}" | ||
| - source_selector: | ||
| routes: | ||
| - destination_selector: | ||
| any: "true" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| - -I PREROUTING 1 -p tcp -i {{ .NsmInterfaceName }} -j DNAT --to-destination 127.0.0.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| --- | ||
| apiVersion: kustomize.config.k8s.io/v1beta1 | ||
| kind: Kustomization | ||
|
|
||
| bases: | ||
| - https://github.com/networkservicemesh/deployments-k8s/apps/nse-supplier-k8s?ref=b4bddacfa45fafb7c15a769a1fc0f319e63d6a8d | ||
|
|
||
| patchesStrategicMerge: | ||
| - patch-supplier.yaml | ||
|
|
||
| configMapGenerator: | ||
| - name: supplier-pod-template-configmap | ||
| files: | ||
| - pod-template.yaml | ||
| - name: iptables-map | ||
| files: | ||
| - iptables-map.yaml | ||
|
|
||
| generatorOptions: | ||
| disableNameSuffixHash: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: nse-supplier-k8s | ||
| spec: | ||
| template: | ||
| metadata: | ||
| annotations: | ||
| 'consul.hashicorp.com/connect-inject': 'false' | ||
| spec: | ||
| containers: | ||
| - name: nse-supplier | ||
| env: | ||
| - name: NSM_SERVICE_NAME | ||
| value: autoscale-consul-proxy | ||
| - name: NSM_LABELS | ||
| value: any:true | ||
| - name: NSM_NAMESPACE | ||
| valueFrom: | ||
| fieldRef: | ||
| fieldPath: metadata.namespace | ||
| - name: NSM_POD_DESCRIPTION_FILE | ||
| value: /run/supplier/pod-template.yaml | ||
| volumeMounts: | ||
| - name: pod-file | ||
| mountPath: /run/supplier | ||
| readOnly: true | ||
| volumes: | ||
| - name: pod-file | ||
| configMap: | ||
| name: supplier-pod-template-configmap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: proxy-{{ index .Labels "podName" }} | ||
| labels: | ||
| app: proxy-{{ index .Labels "podName" }} | ||
| "spiffe.io/spiffe-id": "true" | ||
| annotations: | ||
| 'consul.hashicorp.com/connect-inject': 'true' | ||
| 'consul.hashicorp.com/connect-service-upstreams': 'static-server:8080' | ||
| spec: | ||
| restartPolicy: Never | ||
| containers: | ||
| - name: nse | ||
| image: ghcr.io/networkservicemesh/ci/cmd-nse-l7-proxy:32fbf26 | ||
| imagePullPolicy: IfNotPresent | ||
| securityContext: | ||
| privileged: true | ||
| env: | ||
| - name: SPIFFE_ENDPOINT_SOCKET | ||
| value: unix:///run/spire/sockets/agent.sock | ||
| - name: NSM_NAME | ||
| valueFrom: | ||
| fieldRef: | ||
| fieldPath: metadata.name | ||
| - name: POD_NAME | ||
| value: {{ index .Labels "podName" }} | ||
| - name: NSM_CONNECT_TO | ||
| value: unix:///var/lib/networkservicemesh/nsm.io.sock | ||
| - name: NSM_CIDR_PREFIX | ||
| value: 172.16.1.2/31 | ||
| - name: NSM_SERVICE_NAMES | ||
| value: autoscale-consul-proxy | ||
| - name: NSM_LABELS | ||
| value: app:{{ index .Labels "app" }} | ||
| - name: NSM_IDLE_TIMEOUT | ||
| value: 240s | ||
| - name: NSM_LOG_LEVEL | ||
| value: TRACE | ||
| - name: NSM_RULES_CONFIG_PATH | ||
| value: iptables-map.yaml | ||
| volumeMounts: | ||
| - name: spire-agent-socket | ||
| mountPath: /run/spire/sockets | ||
| readOnly: true | ||
| - name: nsm-socket | ||
| mountPath: /var/lib/networkservicemesh | ||
| readOnly: true | ||
| - name: iptables-config-map | ||
| mountPath: /iptables-map | ||
| resources: | ||
| limits: | ||
| memory: 40Mi | ||
| cpu: 150m | ||
| - name: proxy-alpine-nsc | ||
| image: hashicorp/http-echo:latest | ||
| args: | ||
| - -text="hello world from nse" | ||
| - -listen=:9090 | ||
| ports: | ||
| - containerPort: 9090 | ||
| name: http | ||
| serviceAccountName: proxy-alpine-nsc | ||
| volumes: | ||
| - name: spire-agent-socket | ||
| hostPath: | ||
| path: /run/spire/sockets | ||
| type: Directory | ||
| - name: nsm-socket | ||
| hostPath: | ||
| path: /var/lib/networkservicemesh | ||
| type: DirectoryOrCreate | ||
| - name: iptables-config-map | ||
| configMap: | ||
| name: iptables-map |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| # This name will be the service name in Consul. | ||
| name: static-server | ||
| spec: | ||
| selector: | ||
| app: static-server | ||
| ports: | ||
| - protocol: TCP | ||
| port: 8080 | ||
| targetPort: 8080 | ||
| --- | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| metadata: | ||
| name: static-server | ||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: static-server | ||
| namespace: nsm-consul | ||
| spec: | ||
| replicas: 1 | ||
| selector: | ||
| matchLabels: | ||
| app: static-server | ||
| template: | ||
| metadata: | ||
| name: static-server | ||
| labels: | ||
| app: static-server | ||
| annotations: | ||
| 'consul.hashicorp.com/connect-inject': 'true' | ||
| 'consul.hashicorp.com/connect-service-upstreams': 'proxy-alpine-nsc:9090' | ||
| spec: | ||
| containers: | ||
| - name: static-server | ||
| image: hashicorp/http-echo:latest | ||
| args: | ||
| - -text="hello world" | ||
| - -listen=:8080 | ||
| ports: | ||
| - containerPort: 8080 | ||
| name: http | ||
| # If ACLs are enabled, the serviceAccountName must match the Consul service name. | ||
| serviceAccountName: static-server |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| --- | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| metadata: | ||
| name: proxy-alpine-nsc | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: proxy-alpine-nsc | ||
| spec: | ||
| selector: | ||
| app: proxy-alpine-nsc | ||
| ports: | ||
| - protocol: TCP | ||
| port: 9090 | ||
| targetPort: 9090 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| - -N NSM_PREROUTE | ||
| - -A NSM_PREROUTE -j ISTIO_REDIRECT | ||
| - -I PREROUTING 1 -p tcp -i {{ .NsmInterfaceName }} -j NSM_PREROUTE | ||
| - -N NSM_OUTPUT | ||
| - -A NSM_OUTPUT -j DNAT --to-destination {{ index .NsmSrcIPs 0 }} | ||
| - -A OUTPUT -p tcp -s 127.0.0.6 -j NSM_OUTPUT | ||
| - -N NSM_POSTROUTING | ||
| - -A NSM_POSTROUTING -j SNAT --to-source {{ index .NsmDstIPs 0 }} | ||
| - -A POSTROUTING -p tcp -o {{ .NsmInterfaceName }} -j NSM_POSTROUTING |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably we need to add a
bashcommand to verify the connection, like here:https://github.com/networkservicemesh/deployments-k8s/blob/main/examples/nsm_istio/README.md?plain=1#L56-L58
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added, @glazychev-art, please check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to use something with UI than just 'hello world' for demo.