This example demonstrates how Postgres-client can get connectivity to Postgres-server deployment via NSM. Client pod and server deployment located on different nodes.
Make sure that you have completed steps from features
- Create test namespace:
NAMESPACE=($(kubectl create -f https://raw.githubusercontent.com/networkservicemesh/deployments-k8s/91e80e8e4531562720d50ea9e84a82299813db65/examples/features/namespace.yaml)[0])
NAMESPACE=${NAMESPACE:10}
- Get all available nodes to deploy:
NODES=($(kubectl get nodes -o go-template='{{range .items}}{{ if not .spec.taints }}{{index .metadata.labels "kubernetes.io/hostname"}} {{end}}{{end}}'))
- Create client deployment and set
nodeName
to the first node:
cat > client.yaml <<EOF
---
apiVersion: v1
kind: Pod
metadata:
name: nettools
labels:
app: nettools
annotations:
networkservicemesh.io: kernel://my-nginx-service/nsm-1
spec:
containers:
- name: nettools
image: travelping/nettools:1.10.1
imagePullPolicy: IfNotPresent
stdin: true
tty: true
nodeName: ${NODE}
EOF
- Add to nse-kernel the nginx container and set
nodeName
it to the second node:
cat > patch-nse.yaml <<EOF
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nse-kernel
spec:
template:
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
- name: nse
env:
- name: NSM_SERVICE_NAMES
value: my-nginx-service
- name: NSM_CIDR_PREFIX
value: 172.16.1.100/31
nodeName: ${NODES[1]}
EOF
- Create kustomization file:
cat > kustomization.yaml <<EOF
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: ${NAMESPACE}
bases:
- https://github.com/networkservicemesh/deployments-k8s/apps/nse-kernel?ref=91e80e8e4531562720d50ea9e84a82299813db65
resources:
- client.yaml
patchesStrategicMerge:
- patch-nse.yaml
EOF
- Deploy client and nginx-nse
kubectl apply -k .
- Wait for applications ready:
kubectl wait --for=condition=ready --timeout=5m pod -l app=nse-kernel -n ${NAMESPACE}
kubectl wait --for=condition=ready --timeout=1m pod -l app=nettools -n ${NAMESPACE}
- Find NSC and NSE pods by labels:
NSC=$(kubectl get pods -l app=nettools -n ${NAMESPACE} --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
NSE=$(kubectl get pods -l app=nse-kernel -n ${NAMESPACE} --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
- Try to connect from client to nginx service:
kubectl exec ${NSC} -n ${NAMESPACE} -- curl 172.16.1.100:80 | grep -o "<title>Welcome to nginx!</title>"
Delete ns:
kubectl delete ns ${NAMESPACE}