github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/edge/test/README.md (about) 1 # Guide on testing 2 3 - [Test with `TestManager` Module](#test-with-testmanager-module) 4 - [TestManager Overview](#Overview-About-testManager-Module) 5 - [Compile](#compile) 6 - [Configure](#Configure) 7 - [Run](#run) 8 - [Verify](#verify) 9 10 ## Overview About testManager Module 11 12 * testManager is a utility module to mimic the cloud and push messages for different kinds of actions that could happen from the cloud. Typical device , node and application lifecycle management functions are expected to be performed in the cloud and pushed to the edge node. These functions commonly encompass configurations related to 13 14 - Kubernetes Secrets and Configuration Maps. 15 - Application deployment/sync 16 - Binding devices to edge nodes via memberships. 17 - Syncing of different resources between cloud and edge ( like app status, device status etc) 18 - Node sync, etc.. 19 20 Below info can help user how to use the testManager for testing the kubeedge. 21 22 * testManager module starts http server on port 12345 to let users interact with kubeedge and perform operations which would be typically performed from cloud. 23 It exposes its API's to do the following 24 25 - /pods : Deploying a pod on to kubeedge node. 26 - /devices : Bind a Device to kubeedge node. 27 - /secrets : Configure secrets on kubeedge node. 28 - /configmaps : Configure configmaps on kubeedge node. 29 30 Using above API's user can perform the resource operations against running edge node. 31 32 testManager facilitates validating the capabilities of the edge platform by performing **curl** operations against a running edge node. 33 34 Following sections will explain the procedure to test the kubeedge with testManager. 35 36 ## Test with `TestManager` Module 37 38 ### Compile 39 40 ```shell 41 # generate the `edgecore` binary 42 make 43 # or 44 make edgecore 45 ``` 46 ### Configure 47 48 ##### Modify the configuration files accordingly 49 50 ##### in `modules.yaml` (add the `testManager`) 51 52 Kubeedge uses [beehive](https://github.com/kubeedge/kubeedge/blob/master/docs/modules/beehive.md) framework as the inter-module communication, all modules in the kubeedge need to register with beehive. 53 `testManager` is a module like other KubeEdge modules. So, it has to be configured as shown below. 54 55 ```yaml 56 modules: 57 enabled: [eventbus, websocket, metaManager, edged, twin, testManager] 58 ``` 59 #### Test kubeedge with Internal MQTT Server 60 61 ##### `edge.yaml` (`mode: 0 (default mode)` modify `certfile`, `keyfile`, etc.) 62 63 ```yaml 64 mqtt: 65 server: tcp://127.0.0.1:1883 # external mqtt broker url. 66 internal-server: tcp://127.0.0.1:1884 # internal mqtt broker url. 67 mode: 0 # 0: internal mqtt broker enable only. 1: internal and external mqtt broker enable. 2: external mqtt broker enable only. 68 qos: 0 # 0: QOSAtMostOnce, 1: QOSAtLeastOnce, 2: QOSExactlyOnce. 69 retain: false # if the flag set true, server will store the message and can be delivered to future subscribers. 70 session-queue-size: 100 # A size of how many sessions will be handled. default to 100. 71 72 edgehub: 73 websocket: 74 url: ws://127.0.0.1:20000/fake_group_id/events 75 certfile: /tmp/edge.crt 76 keyfile: /tmp/edge.key 77 handshake-timeout: 30 #second 78 write-deadline: 15 # second 79 read-deadline: 15 # second 80 controller: 81 heartbeat: 15 # second 82 refresh-ak-sk-interval: 10 # minute 83 auth-info-files-path: /var/IEF/secret 84 placement-url: https://10.154.193.32:7444/v1/placement_external/message_queue 85 project-id: e632aba927ea4ac2b575ec1603d56f10 86 node-id: edge-node 87 88 edged: 89 register-node-namespace: default 90 hostname-override: 93e05fa9-b782-4a59-9d02-9f6e639b4205 91 interface-name: eth0 92 node-status-update-frequency: 10 # second 93 device-plugin-enabled: false 94 gpu-plugin-enabled: false 95 image-gc-high-threshold: 80 # percent 96 image-gc-low-threshold: 40 # percent 97 maximum-dead-containers-per-container: 1 98 docker-address: unix:///var/run/docker.sock 99 version: 2.0.0 100 ``` 101 102 ```bash 103 # run edgecore 104 ./edgecore 105 # or 106 nohup ./edgecore > edgecore.log 2>&1 & 107 ``` 108 109 ### Test kubeedge with External MQTT Server 110 111 **Install dependency:** 112 113 You need install **mosquitto** to support mqtt. 114 115 xref: https://mosquitto.org/download/ 116 117 ```shell 118 # For ubuntu 119 apt install -y mosquitto 120 ``` 121 122 ##### `edge.yaml` (modify `mode: 2`, `certfile`, `keyfile`, etc.) 123 124 ### Run 125 126 ```bash 127 # run mosquitto 128 mosquitto -d -p 1883 129 # run edgecore 130 ./edgecore 131 # or 132 nohup ./edgecore > edgecore.log 2>&1 & 133 ``` 134 135 ### Verify 136 137 **Add Device** 138 ```bash 139 curl -X PUT \ 140 http://127.0.0.1:12345/devices \ 141 -H 'content-type: application/json' \ 142 -d '{ 143 "added_devices": [{ 144 "id": "kubeedge-device-1", 145 "name": "edgedevice", 146 "description": "integrationtest", 147 "state": "online" 148 }] 149 }' 150 ``` 151 152 #### Verify the DB 153 ```bash 154 # Enter the database 155 sqlite3 edge.db 156 157 # Query the database and you shall see the posted Device info 158 select * from device; 159 ``` 160 161 **Remove Device** 162 ```bash 163 curl -X DELETE \ 164 http://127.0.0.1:12345/devices \ 165 -H 'content-type: application/json' \ 166 -d '{ 167 "removed_devices": [{ 168 "id": "kubeedge-device-1", 169 "name": "edgedevice", 170 "description": "integrationtest", 171 "state": "online" 172 }] 173 }' 174 ``` 175 176 #### Add Pod 177 ```bash 178 curl -i -v -X POST http://127.0.0.1:12345/pod -d '{ 179 "apiVersion": "v1", 180 "kind": "Pod", 181 "metadata": { 182 "name": "nginx", 183 "labels": { 184 "name": "nginx" 185 } 186 }, 187 "spec": { 188 "containers": [ 189 { 190 "name": "nginx", 191 "image": "nginx", 192 "imagePullPolicy": "IfNotPresent" 193 } 194 ] 195 } 196 }' 197 ``` 198 #### Query Pods 199 ```bash 200 curl -i -v -X GET http://127.0.0.1:12345/pod 201 202 #or (To display response in json format) 203 204 curl -i -v -X GET http://127.0.0.1:12345/pod | python -m json.tool 205 ``` 206 207 #### Check the database 208 209 ```bash 210 # Enter the database 211 sqlite3 edge.db 212 213 # Query the database and you shall see the posted application deployment info 214 select * from meta; 215 216 # or you can check the pod container using `docker ps` 217 ``` 218 ### Remove Pod 219 ```bash 220 curl -i -v -X DELETE http://127.0.0.1:12345/pod -d '{ 221 "apiVersion": "v1", 222 "kind": "Pod", 223 "metadata": { 224 "name": "nginx", 225 "labels": { 226 "name": "nginx" 227 } 228 }, 229 "spec": { 230 "containers": [ 231 { 232 "name": "nginx", 233 "image": "nginx", 234 "imagePullPolicy": "IfNotPresent" 235 } 236 ] 237 } 238 }' 239 ```