github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/docs/guides/edgemesh_test_env_guide.md (about)

     1  # Edgemesh test env config guide
     2  ## Docker support
     3  * Refer to [Usage](./../setup/installer_setup.md) to prepare KubeEdge environment, make sure "docker0" exists
     4  * Then follow [EdgeMesh guide](#EdgeMesh test guide) to deploy Service
     5  
     6  ## Usage of EdgeMesh
     7  ![edgemesh test env example](../images/edgemesh/edgemesh-test-env-example.png)
     8  
     9  ## EdgeMesh test guide
    10  ### Model
    11  ![model](../images/edgemesh/model.jpg)
    12  1. a headless service (a service with selector but ClusterIP is None)
    13  2. one or more pods' labels match the headless service's selector
    14  3. to request a server, use: ```<service_name>.<service_namespace>.svc.<cluster>:<port>```:
    15      1. get the service's name and namespace from domain name
    16      2. query all the backend pods from MetaManager by service's namespace and name
    17      3. LoadBalance returns the real backend containers' hostIP and hostPort
    18  
    19  ### Flow from client to server
    20  ![flow](../images/edgemesh/endtoend-test-flow.jpg)
    21  1. client requests to server by server's domain name
    22  2. DNS being hijacked to EdgeMesh by iptables rules, then a fake ip returned
    23  3. request hijacked to EdgeMesh by iptables rules
    24  4. EdgeMesh resolves request, gets domain name, protocol, request and so on
    25  5. EdgeMesh load balances:
    26      1. get the service's name and namespace from the domain name
    27      2. query backend pods of the service from MetaManager
    28      3. choose a backend based on strategy
    29  6. EdgeMesh transports request to server, wait for server's response and then sends response back to client
    30  
    31  ### How to test EdgeMesh
    32  Assume we have two edge nodes in ready state, we call them edge node "a" and "b"
    33  ```bash
    34  $ kubectl get nodes
    35  NAME          STATUS     ROLES    AGE   VERSION
    36  edge-node-a   Ready      edge     25m   v1.15.3-kubeedge-v1.1.0-beta.0.358+0b7ac7172442b5-dirty
    37  edge-node-b   Ready      edge     25m   v1.15.3-kubeedge-v1.1.0-beta.0.358+0b7ac7172442b5-dirty
    38  master        NotReady   master   8d    v1.15.0
    39  ```
    40  Deploy a sample pod from Cloud VM (you may already did it)
    41  
    42  **https://github.com/kubeedge/kubeedge/blob/master/build/deployment.yaml**
    43  
    44  Copy the deployment.yaml from the above link in cloud host, and run
    45  
    46  ```bash
    47  $ kubectl create -f deployment.yaml
    48  deployment.apps/nginx-deployment created
    49  ``` 
    50  Check the pod is up and is running state, as we could see the pod is running on edge node b
    51  
    52  ```bash
    53  $ kubectl get pods -o wide
    54  NAME                                READY   STATUS    RESTARTS   AGE   IP           NODE          NOMINATED NODE   READINESS GATES
    55  nginx-deployment-54bf9847f8-sxk94   1/1     Running   0          14m   172.17.0.2   edge-node-b   <none>           <none>
    56  ```
    57  
    58  Check the deployment is up and is running state
    59  ```bash
    60  $ kubectl get deployments
    61  NAME               READY   UP-TO-DATE   AVAILABLE   AGE
    62  nginx-deployment   1/1     1            1           63s
    63  ```
    64  
    65  Now create a service for the sample deployment
    66  ```yaml
    67  apiVersion: v1
    68  kind: Service
    69  metadata:
    70    name: nginx-svc
    71    namespace: default
    72  spec:
    73    clusterIP: None
    74    selector:
    75      app: nginx
    76    ports:
    77      - name: http-0
    78        port: 12345
    79        protocol: TCP
    80        targetPort: 80
    81  ```
    82  >* For L4/L7 proxy, specify what protocol a port would use by the port's "name". First HTTP port should be named "http-0" and the second one should be called "http-1", etc.
    83  >* Currently we only support HTTP1.x, more protocols like HTTPS and gRPC coming later
    84  
    85  Check the service and endpoints
    86  ```bash
    87  $ kubectl get service
    88  NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)     AGE
    89  nginx-svc    ClusterIP   None         <none>        12345/TCP   77m
    90  ```
    91  ```bash
    92  $ kubectl get endpoints
    93  NAME         ENDPOINTS            AGE
    94  nginx-svc    172.17.0.2:80        81m
    95  ```
    96  
    97  To request a server, use url like this: ```<service_name>.<service_namespace>.svc.<cluster>:<port>```
    98  
    99  In our case, from edge node a or b, run the command:
   100  ```bash
   101  $ curl http://nginx-svc.default.svc.cluster.local:12345
   102  <!DOCTYPE html>
   103  <html>
   104  <head>
   105  <title>Welcome to nginx!</title>
   106  <style>
   107      body {
   108          width: 35em;
   109          margin: 0 auto;
   110          font-family: Tahoma, Verdana, Arial, sans-serif;
   111      }
   112  </style>
   113  </head>
   114  <body>
   115  <h1>Welcome to nginx!</h1>
   116  <p>If you see this page, the nginx web server is successfully installed and
   117  working. Further configuration is required.</p>
   118  
   119  <p>For online documentation and support please refer to
   120  <a href="http://nginx.org/">nginx.org</a>.<br/>
   121  Commercial support is available at
   122  <a href="http://nginx.com/">nginx.com</a>.</p>
   123  
   124  <p><em>Thank you for using nginx.</em></p>
   125  </body>
   126  </html>
   127  ```
   128  >* EdgeMesh supports both Host Networking and Container Networking
   129  >* If you ever used EdgeMesh of old version, check your iptables rules. It might affect your test result.