Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Alpine requests for CoreDNS service

This example demonstrates how an external client configures DNS from the connected endpoint. Note: NSE provides DNS by itself. Also, NSE could provide configs for any other external DNS servers(that are not located as sidecar with NSE).

Requires

Make sure that you have completed steps from features

Run

  1. Create test namespace:
NAMESPACE=($(kubectl create -f https://raw.githubusercontent.com/networkservicemesh/deployments-k8s/3d1dcfe1de90681213c7f0006f25279bb4699966/examples/features/namespace.yaml)[0])
NAMESPACE=${NAMESPACE:10}
  1. 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}}'))
  1. Create dnsutils deployment and set nodeName to the first node:
cat > dnsutils.yaml <<EOF
---
apiVersion: v1
kind: Pod
metadata:
  name: dnsutils
  annotations:
    networkservicemesh.io: kernel://my-coredns-service/nsm-1
  labels:
    app: dnsutils
    "spiffe.io/spiffe-id": "true"
spec:
  containers:
  - name: dnsutils
    image: k8s.gcr.io/e2e-test-images/jessie-dnsutils:1.3
    imagePullPolicy: IfNotPresent
    stdin: true
    tty: true
  nodeName: ${NODES[0]}
EOF
  1. Add to nse-kernel the corends 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: nse
        env:
          - name: NSM_SERVICE_NAMES
            value: my-coredns-service
          - name: NSM_CIDR_PREFIX
            value: 172.16.1.100/31
          - name: NSM_DNS_CONFIGS
            value: "[{\"dns_server_ips\": [\"172.16.1.100\"], \"search_domains\": [\"my.coredns.service\"]}]"
      - name: coredns
        image: coredns/coredns:1.8.3
        imagePullPolicy: IfNotPresent
        resources:
          limits:
            memory: 170Mi
          requests:
            cpu: 100m
            memory: 70Mi
        args: [ "-conf", "/etc/coredns/Corefile" ]
        volumeMounts:
        - name: config-volume
          mountPath: /etc/coredns
          readOnly: true
        ports:
        - containerPort: 53
          name: dns
          protocol: UDP
        - containerPort: 53
          name: dns-tcp
          protocol: TCP
      nodeName: ${NODES[1]}
      volumes:
        - name: config-volume
          configMap:
            name: coredns
            items:
            - key: Corefile
              path: Corefile
EOF
  1. 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=3d1dcfe1de90681213c7f0006f25279bb4699966

resources:
- dnsutils.yaml
- https://raw.githubusercontent.com/networkservicemesh/deployments-k8s/3d1dcfe1de90681213c7f0006f25279bb4699966/examples/features/dns/coredns-config-map.yaml

patchesStrategicMerge:
- patch-nse.yaml
EOF
  1. Deploy alpine and nse
kubectl apply -k .
  1. Wait for applications ready:
kubectl wait --for=condition=ready --timeout=5m pod dnsutils -n ${NAMESPACE}
kubectl wait --for=condition=ready --timeout=5m pod -l app=nse-kernel -n ${NAMESPACE}
  1. Find NSC and NSE pods by labels:
NSC=$(kubectl get pods -l app=dnsutils -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}}')
  1. Ping from dnsutils to NSE by domain name:
kubectl exec ${NSC} -c dnsutils -n ${NAMESPACE} -- nslookup -norec -nodef my.coredns.service
kubectl exec ${NSC} -c dnsutils -n ${NAMESPACE} -- ping -c 4 my.coredns.service
  1. Validate that default DNS server is working:
kubectl exec ${NSC} -c dnsutils -n ${NAMESPACE} -- nslookup kubernetes.default

Cleanup

Delete ns:

kubectl delete ns ${NAMESPACE}