├── .gitignore ├── LICENSE ├── README.md ├── createMinikubeEnv.sh ├── deploy.sh ├── etcd ├── deployment.yaml └── etcd-operator-deployment.yaml ├── gateway ├── http-gateway.yaml └── virtual-service.yaml ├── icp-helm-deploy.sh ├── images ├── 1397375_910870955327_147651637_o.jpg ├── loadtest_grafana.png ├── loadtest_kiali.png ├── loadtest_prometheus.png ├── ui.png └── weavescope.png ├── istioaddons └── prometheus_telemetry.yaml ├── nodejs ├── Dockerfile ├── deployAppDocker.sh ├── deployment.yaml ├── package.json ├── server.js └── web │ └── index.html ├── security ├── kiala-cluster-role.yaml ├── permissions-weave.yaml └── permissions.yaml.tmpl ├── setupKiali.sh ├── testICPEnv.sh └── testMinikubeEnv.sh /.gitignore: -------------------------------------------------------------------------------- 1 | istio-* 2 | nodejs/node_modules 3 | security/permissions.yaml 4 | kiali/ 5 | helm 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![alt text][israel] 2 | 3 | # Istio is not just for microservices 4 | 5 | Secure Kubernetes platform services by using Istio Service Mesh. Typically seeing live running code helps users understand how to apply concepts to their own use cases. This project centers around a basic Node.js application demonstrating the power of Istio Service Mesh for persistence datastores such as etcd. 6 | 7 | ## Background on Istio 8 | Istio is an open platform to connect, manage, and secure microservices. To learn more about Istio, please visit the [Intro page]( https://istio.io/about/intro.html). 9 | 10 | ## Setup 11 | Getting started assumes an elementary understanding of Kubernetes. In this project, there are a set of scripts that assume the prior installation of Docker, the Kubernetes CLI as well as jq for manipulating JSON objects returned from the various Kubernetes commands. There is also the assumption around some level of Node.js knowledge. 12 | 13 | **Here are some quick links to the various tools.** 14 | **Docker Install:** https://docs.docker.com/install/ 15 | **Kubernetes Install:** https://kubernetes.io/docs/tasks/tools/install-kubectl/ 16 | **jq Download:** https://stedolan.github.io/jq/download/ 17 | **Node.js Download:** https://nodejs.org/en/download/ 18 | 19 | ## Kubernetes Providers 20 | The code below should run on any Kubernetes compliant provider and has been tested on both Minikube and IBM Cloud Private. Depending upon which provider chosen, the instructions will vary slightly. 21 | 22 | ### Minikube 23 | Minikube is available for download and installation instructions are located [here](https://kubernetes.io/docs/tasks/tools/install-minikube/). Minikube provides a simple and easy to use developer environment for learning about Kubernetes. 24 | 25 | ### IBM Cloud Private 26 | IBM provides a Community Edition of their Kubernetes runtime free for development purposes and includes most of the same feature functions as their production version, Enterprise Edition, with the one exception being High Availability. To install IBM Cloud Private, please refer to the [Installation Guide for 2.1.0](https://www.ibm.com/support/knowledgecenter/en/SSBS6K_2.1.0/installing/install_containers_CE.html) 27 | 28 | ## Istio Index Conference 2018 Application 29 | To get started with the code, clone the repo ```git clone git@github.com:todkap/istio-index-conf2018.git``` 30 | 31 | ### Kubernetes Setup 32 | - **Minikube:** Prior to deploying to Minikube, Minikube first needs to be started. In the root directory of this project, there is a script ```createMinikubeEnv.sh``` that tears down the previous Minikube environment and initializes a new environment with the appropriate Kubernetes context. 33 | 34 | - **IBM Cloud Private:** IBM Cloud Private has a [configure client](https://www.ibm.com/support/knowledgecenter/en/SSBS6K_2.1.0/manage_cluster/cfc_cli.html) step that will configure the Kubernetes CLI to point to a given IBM Cloud Private installation. This context will be used each time the Kubectl CLI executes commands. 35 | 36 | ### Deploy 37 | #### Kubernetes Installation 38 | This project contains a script that will deploy Istio and the application to Kubernetes called ```deploy.sh```. The script provides verbose output as it progresses through the various steps waiting for the entire system to be in ```Running``` state prior to exiting. 39 | 40 | #### Helm Installation 41 | Starting with IBM Cloud Private version 2.1.0.3, the Istio Control Plane can be installed via a Helm chart as part of the initial install or via the Catalog post installation. Included in this project is an additional script called ```icp-helm-deploy``` that leverages a combination of the IBM Cloud Private CLI, Helm CLI and Kubernetes CLI to install the Istio Index application. In an effort to simplify the deployment process and promote some of the latest features of Istio, I have enabled [automatic sidecar injection](https://istio.io/docs/setup/kubernetes/sidecar-injection.html#automatic-sidecar-injection) for this application. 42 | 43 | ### Testing 44 | This project contains two scripts for testing depending upon which Kubernetes provider that is used. The only difference in the two scripts is the setting of the ingress IP address for IBM Cloud Private. To test choose either ```testICPEnv.sh``` or ```testMinikubeEnv.sh``` based upon your provider. 45 | 46 | In addition to the scripts, there is a lightweight web interface for interacting with the REST APIs. 47 | ![alt text][ui] 48 | 49 | ### Verification 50 | To verify the success of the Istio integration, the script executes a set of tests. 51 | 52 | - The first test verifies a simple put test to the etcd service NodePort to validate connectivity to etcd. 53 | **Example output** 54 | ``` 55 | simple etcd test 56 | * Trying 192.168.64.20... 57 | * TCP_NODELAY set 58 | * Connected to 192.168.64.20 (192.168.64.20) port 32012 (#0) 59 | > PUT /v2/keys/message HTTP/1.1 60 | > Host: 192.168.64.20:32012 61 | > User-Agent: curl/7.54.0 62 | > Accept: */* 63 | > Content-Length: 17 64 | > Content-Type: application/x-www-form-urlencoded 65 | > 66 | * upload completely sent off: 17 out of 17 bytes 67 | < HTTP/1.1 201 Created 68 | < content-type: application/json 69 | < x-etcd-cluster-id: cdf818194e3a8c32 70 | < x-etcd-index: 14 71 | < x-raft-index: 15 72 | < x-raft-term: 2 73 | < date: Wed, 14 Feb 2018 19:45:24 GMT 74 | < content-length: 102 75 | < x-envoy-upstream-service-time: 1 76 | < server: envoy 77 | < x-envoy-decorator-operation: default-route 78 | < 79 | {"action":"set","node":{"key":"/message","value":"Hello world","modifiedIndex":14,"createdIndex":14}} 80 | * Connection #0 to host 192.168.64.20 left intact 81 | ``` 82 | 83 | - The second test verifies that the Node application can handle a simply ping request as well as proxy requests to etcd using the Node applications NodePort. 84 | **Example output** 85 | ``` 86 | ------------------------------- 87 | simple ping test 88 | * Trying 192.168.64.20... 89 | * TCP_NODELAY set 90 | * Connected to 192.168.64.20 (192.168.64.20) port 32380 (#0) 91 | > GET / HTTP/1.1 92 | > Host: 192.168.64.20:32380 93 | > User-Agent: curl/7.54.0 94 | > Accept: */* 95 | > 96 | < HTTP/1.1 200 OK 97 | < x-powered-by: Express 98 | < content-type: text/html; charset=utf-8 99 | < content-length: 46 100 | < etag: W/"2e-FL84XHNKKzHT+F1kbgSNIW2RslI" 101 | < date: Wed, 14 Feb 2018 19:45:24 GMT 102 | < x-envoy-upstream-service-time: 1 103 | < server: envoy 104 | < x-envoy-decorator-operation: default-route 105 | < 106 | * Connection #0 to host 192.168.64.20 left intact 107 | Simple test for liveliness of the application! 108 | ------------------------------- 109 | test etcd service API call from node app 110 | * Trying 192.168.64.20... 111 | * TCP_NODELAY set 112 | * Connected to 192.168.64.20 (192.168.64.20) port 32380 (#0) 113 | > PUT /storage HTTP/1.1 114 | > Host: 192.168.64.20:32380 115 | > User-Agent: curl/7.54.0 116 | > Accept: */* 117 | > Content-Type: application/json 118 | > Content-Length: 60 119 | > 120 | * upload completely sent off: 60 out of 60 bytes 121 | < HTTP/1.1 201 Created 122 | < x-powered-by: Express 123 | < date: Wed, 14 Feb 2018 19:45:24 GMT 124 | < x-envoy-upstream-service-time: 12 125 | < server: envoy 126 | < x-envoy-decorator-operation: default-route 127 | < transfer-encoding: chunked 128 | < 129 | * Connection #0 to host 192.168.64.20 left intact 130 | nodeAppTesting created(etcd-service) ->{"key":"istioTest","value":"Testing Istio using NodePort"}:{"action":"set","node":{"key":"/istioTest","value":"Testing Istio using NodePort","modifiedIndex":15,"createdIndex":15},"prevNode":{"key":"/istioTest","value":"Testing Istio using Ingress","modifiedIndex":13,"createdIndex":13}} 131 | * Trying 192.168.64.20... 132 | * TCP_NODELAY set 133 | * Connected to 192.168.64.20 (192.168.64.20) port 32380 (#0) 134 | > GET /storage/istioTest HTTP/1.1 135 | > Host: 192.168.64.20:32380 136 | > User-Agent: curl/7.54.0 137 | > Accept: */* 138 | > 139 | < HTTP/1.1 200 OK 140 | < x-powered-by: Express 141 | < date: Wed, 14 Feb 2018 19:45:24 GMT 142 | < x-envoy-upstream-service-time: 14 143 | < server: envoy 144 | < x-envoy-decorator-operation: default-route 145 | < transfer-encoding: chunked 146 | < 147 | * Connection #0 to host 192.168.64.20 left intact 148 | nodeAppTesting(etcd-service) ->{"action":"get","node":{"key":"/istioTest","value":"Testing Istio using NodePort","modifiedIndex":15,"createdIndex":15}} 149 | ------------------------------- 150 | ``` 151 | 152 | - The next level of tests start to test Istio where traffic is routed through the Istio Ingress then to the Node application. 153 | **Example output** 154 | ``` 155 | simple hello test 156 | * Trying 192.168.64.20... 157 | * TCP_NODELAY set 158 | * Connected to 192.168.64.20 (192.168.64.20) port 32612 (#0) 159 | > GET / HTTP/1.1 160 | > Host: 192.168.64.20:32612 161 | > User-Agent: curl/7.54.0 162 | > Accept: */* 163 | > 164 | < HTTP/1.1 200 OK 165 | < x-powered-by: Express 166 | < content-type: text/html; charset=utf-8 167 | < content-length: 46 168 | < etag: W/"2e-FL84XHNKKzHT+F1kbgSNIW2RslI" 169 | < date: Wed, 14 Feb 2018 19:45:24 GMT 170 | < x-envoy-upstream-service-time: 6 171 | < server: envoy 172 | < 173 | * Connection #0 to host 192.168.64.20 left intact 174 | Simple test for liveliness of the application! 175 | ------------------------------- 176 | test etcd service API call from node app 177 | * Trying 192.168.64.20... 178 | * TCP_NODELAY set 179 | * Connected to 192.168.64.20 (192.168.64.20) port 32612 (#0) 180 | > PUT /storage HTTP/1.1 181 | > Host: 192.168.64.20:32612 182 | > User-Agent: curl/7.54.0 183 | > Accept: */* 184 | > Content-Type: application/json 185 | > Content-Length: 59 186 | > 187 | * upload completely sent off: 59 out of 59 bytes 188 | < HTTP/1.1 201 Created 189 | < x-powered-by: Express 190 | < date: Wed, 14 Feb 2018 19:45:24 GMT 191 | < x-envoy-upstream-service-time: 15 192 | < server: envoy 193 | < transfer-encoding: chunked 194 | < 195 | * Connection #0 to host 192.168.64.20 left intact 196 | nodeAppTesting created(etcd-service) ->{"key":"istioTest","value":"Testing Istio using Ingress"}:{"action":"set","node":{"key":"/istioTest","value":"Testing Istio using Ingress","modifiedIndex":16,"createdIndex":16},"prevNode":{"key":"/istioTest","value":"Testing Istio using NodePort","modifiedIndex":15,"createdIndex":15}} 197 | * Trying 192.168.64.20... 198 | * TCP_NODELAY set 199 | * Connected to 192.168.64.20 (192.168.64.20) port 32612 (#0) 200 | > GET /storage/istioTest HTTP/1.1 201 | > Host: 192.168.64.20:32612 202 | > User-Agent: curl/7.54.0 203 | > Accept: */* 204 | > 205 | < HTTP/1.1 200 OK 206 | < x-powered-by: Express 207 | < date: Wed, 14 Feb 2018 19:45:24 GMT 208 | < x-envoy-upstream-service-time: 13 209 | < server: envoy 210 | < transfer-encoding: chunked 211 | < 212 | * Connection #0 to host 192.168.64.20 left intact 213 | nodeAppTesting(etcd-service) ->{"action":"get","node":{"key":"/istioTest","value":"Testing Istio using Ingress","modifiedIndex":16,"createdIndex":16}} 214 | ------------------------------- 215 | ``` 216 | 217 | - The final set of tests grep the istio-proxy logs searching for access logs for the client and server proxies to validate the traffic is routed through Istio. 218 | **Example output** 219 | ``` 220 | client logs from istio-proxy 221 | [2018-02-14T16:28:24.640Z] "PUT /v2/keys/istioTest HTTP/1.1" 201 - 40 119 6 5 "-" "-" "45dd6431-49cf-9bcf-b611-1d319c56eb2e" "etcd-service:2379" "172.17.0.9:2379" 222 | [2018-02-14T16:28:24.672Z] "GET /v2/keys/istioTest HTTP/1.1" 200 - 0 119 3 3 "-" "-" "8aa0f7d8-caac-9065-bb4c-d11c7af7d93f" "etcd-service:2379" "172.17.0.9:2379" 223 | server logs from istio-proxy 224 | [2018-02-14T16:28:24.640Z] "PUT /v2/keys/istioTest HTTP/1.1" 201 - 40 119 4 1 "-" "-" "45dd6431-49cf-9bcf-b611-1d319c56eb2e" "etcd-service:2379" "127.0.0.1:2379" 225 | [2018-02-14T16:28:24.673Z] "GET /v2/keys/istioTest HTTP/1.1" 200 - 0 119 3 0 "-" "-" "8aa0f7d8-caac-9065-bb4c-d11c7af7d93f" "etcd-service:2379" "127.0.0.1:2379" 226 | ``` 227 | 228 | ### Istio Metrics 229 | Istio provides native enablement for capturimg metrics for network activity. To drive some additional metrics, a simple test script can be run to populate the charts for both Grafana and Promotheus similar to the code below. 230 | 231 | **Test Script** 232 | ``` 233 | ## Simple load test using loadtest (https://www.npmjs.com/package/loadtest) 234 | if [ -x "$(command -v loadtest)" ]; then 235 | loadtest -n 400 -c 10 --rps 20 http://$ingressIP:$ingressPort/storage/istioTest 236 | loadtest -n 400 -c 10 --rps 10 http://$ingressIP:$ingressPort/storage/istioTest 237 | loadtest -n 400 -c 10 --rps 40 http://$ingressIP:$ingressPort/storage/istioTest 238 | fi 239 | ``` 240 | 241 | #### Grafana 242 | In your Kubernetes environment, execute the following command: 243 | ``` 244 | kubectl -n istio-system port-forward $(kubectl -n istio-system get \ 245 | pod -l app=grafana -o jsonpath='{.items[0].metadata.name}') 3000:3000 & 246 | ``` 247 | Visit http://localhost:3000/dashboard/db/istio-dashboard in your web browser. The Istio Dashboard will look similar to: 248 | 249 | ![alt text][grafana] 250 | 251 | #### Prometheus 252 | In your Kubernetes environment, execute the following command: 253 | ``` 254 | kubectl -n istio-system port-forward $(kubectl -n istio-system get \ 255 | pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') 9090:9090 & 256 | ``` 257 | Visit http://localhost:9090/graph in your web browser. The Istio Dashboard will look similar to: 258 | 259 | ![alt text][prometheus] 260 | 261 | #### Weave Scope 262 | During the deploy script, Weave Scope was also deployed to the environment. In the console, the port for Weave Scope is logged but is also available using the command. 263 | ``` 264 | kubectl get service weave-scope-app --namespace=weave -o 'jsonpath={.spec.ports[0].nodePort}'; echo '' 265 | ``` 266 | Weave Scope provides a Service Graph which will display the request flow for the tests executed in the test process. The Weave Scope Dashboard will look similar to: 267 | 268 | ![alt text][weavescope] 269 | 270 | #### Kiali 271 | Kiali is a relatively new project focused on Service Mesh Observability and supports Istio 0.7.1 or later. Inside of this project is a separate script ```setupKiali.s``` that will build and install Kiali as well as apply the appropriate ClusterRole required to run on IBM Cloud Private. To view the console in your environemnt, you will need the NodePort for the servivce. To retrieve the port for Kiali use the following command. 272 | ``` 273 | kubectl get service kiali --namespace=istio-system -o 'jsonpath={.spec.ports[0].nodePort}'; echo '' 274 | ``` 275 | Kiali provides a Service Graph similar to Weave Scope capable of showing historical view of the request flow as well as other interesting views of your K8 environment such as Services and Tracing. To see this capability in action, the service graph should be viewed after the load test scripts are executed. The Kiali Dashboard will look similar to: 276 | 277 | ![alt text][kiali] 278 | 279 | 280 | 281 | ### Slides 282 | **Istio is not just for microservices on Slideshare:** https://www.slideshare.net/ToddKaplinger/istio-is-not-just-for-microservices 283 | 284 | 285 | ### Notes 286 | - This project is based upon a Medium Article [Istio is not just for microservices](https://medium.com/ibm-cloud/istio-is-not-just-for-microservices-4ed199322bf4) written in 2017 and updated to support the latest version of Istio and Kubernetes. Since most of the content was embedded within the original Medium article, this project was created to encourage developers to clone this repository and modify it to learn more about Kubernetes, Istio and etcd. 287 | - The Node.js application source code is included in the nodejs subdirectory of the project and also includes the Dockerfile and build script for deploying to a Docker registry. Some modifications would be required to publish the image to your own Docker registry and to have the deployment yaml reference the new image but should be relatively easy to figure out if necessary. 288 | 289 | [grafana]: https://github.com/todkap/istio-index-conf2018/blob/master/images/loadtest_grafana.png "Load Test Grafana" 290 | [prometheus]: https://github.com/todkap/istio-index-conf2018/blob/master/images/loadtest_prometheus.png "Load Test Prometheus" 291 | [weavescope]: https://github.com/todkap/istio-index-conf2018/blob/master/images/weavescope.png "Weave Scope" 292 | [kiali]: https://github.com/todkap/istio-index-conf2018/blob/master/images/loadtest_kiali.png "Kiali Console" 293 | 294 | 295 | [israel]: https://github.com/todkap/istio-index-conf2018/blob/master/images/1397375_910870955327_147651637_o.jpg "Israel" 296 | [ui]: https://github.com/todkap/istio-index-conf2018/blob/master/images/ui.png "Simple Form" 297 | 298 | -------------------------------------------------------------------------------- /createMinikubeEnv.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function timer() 4 | { 5 | if [[ $# -eq 0 ]]; then 6 | echo $(date '+%s') 7 | else 8 | local stime=$1 9 | etime=$(date '+%s') 10 | 11 | if [[ -z "$stime" ]]; then stime=$etime; fi 12 | 13 | dt=$((etime - stime)) 14 | ds=$((dt % 60)) 15 | dm=$(((dt / 60) % 60)) 16 | dh=$((dt / 3600)) 17 | printf '%d:%02d:%02d' $dh $dm $ds 18 | fi 19 | } 20 | startTime=$(timer) 21 | 22 | minikube stop 23 | minikube delete 24 | rm -rf ~/.minikube 25 | sudo chown root:wheel $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve 26 | sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve 27 | 28 | echo "Let's start minikube" 29 | minikube start --vm-driver=xhyve 30 | 31 | 32 | endTime=$(timer startTime) 33 | printf 'createMinikubeEnv Elapsed time: %s\n' $endTime 34 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export PATH_TO_ISTIO_ADDONS=$PWD/istioaddons 4 | export PATH_TO_ETCD=$PWD/etcd 5 | export PATH_TO_NODE=$PWD/nodejs 6 | export SECURITY=$PWD/security 7 | export GATEWAY=$PWD/gateway 8 | 9 | 10 | 11 | function timer() 12 | { 13 | if [[ $# -eq 0 ]]; then 14 | echo $(date '+%s') 15 | else 16 | local stime=$1 17 | etime=$(date '+%s') 18 | 19 | if [[ -z "$stime" ]]; then stime=$etime; fi 20 | 21 | dt=$((etime - stime)) 22 | ds=$((dt % 60)) 23 | dm=$(((dt / 60) % 60)) 24 | dh=$((dt / 3600)) 25 | printf '%d:%02d:%02d' $dh $dm $ds 26 | fi 27 | } 28 | startTime=$(timer) 29 | 30 | 31 | 32 | if [ ! -d "istio-1.0.0" ]; then 33 | curl -L https://git.io/getLatestIstio | ISTIO_VERSION=1.0.0 sh - 34 | fi 35 | 36 | cd istio-1.0.0 37 | export PATH=$PWD/bin:$PATH 38 | 39 | ACTION=apply 40 | 41 | # echo "deploy the default istio platform with istio-auth" 42 | # kubectl $ACTION -f install/kubernetes/istio-auth.yaml 43 | echo "deploy the default istio platform with istio" 44 | kubectl create namespace istio-system 45 | kubectl $ACTION -f install/kubernetes/istio-demo.yaml 46 | 47 | 48 | statusCheck="NOT_STARTED" 49 | while [ "$statusCheck" != "" ] ; do 50 | sleep 20 51 | statusCheck=$(kubectl get pods -o json | jq '.items[].status.phase' | grep -v "Running") 52 | echo "Still starting pods $(date)" 53 | done 54 | 55 | kubectl $ACTION -f install/kubernetes/addons/prometheus.yaml 56 | kubectl $ACTION -f $PATH_TO_ISTIO_ADDONS/prometheus_telemetry.yaml 57 | kubectl $ACTION -f install/kubernetes/addons/grafana.yaml 58 | kubectl apply --namespace=istio-system -f https://raw.githubusercontent.com/jaegertracing/jaeger-kubernetes/master/all-in-one/jaeger-all-in-one-template.yml 59 | 60 | 61 | 62 | export kcontext=$(kubectl config current-context) 63 | export kns=$(kubectl config view $kcontext -o json | jq --raw-output '.contexts[] | select(.name=="'$kcontext'") | .context.namespace') 64 | if [ "$kns" != "default" ] ; then 65 | if [[ ! -z "$kns" ]] ; then 66 | kns="default" 67 | fi 68 | cat $SECURITY/permissions.yaml.tmpl | \ 69 | sed -e "s/{NAMESPACE}/$kns/" > $SECURITY/permissions.yaml 70 | kubectl $ACTION -f $SECURITY/permissions.yaml 71 | fi 72 | 73 | statusCheck="NOT_STARTED" 74 | while [ "$statusCheck" != "" ] ; do 75 | sleep 20 76 | statusCheck=$(kubectl get pods -o json | jq '.items[].status.phase' | grep -v "Running") 77 | echo "Still starting pods $(date)" 78 | done 79 | 80 | echo "deploy Node application" 81 | kubectl $ACTION -f <(istioctl kube-inject -f $PATH_TO_NODE/deployment.yaml) 82 | 83 | echo "deploy Istio Gateway and routing rule" 84 | istioctl delete -f $ACTION -f $GATEWAY/http-gateway.yaml 85 | istioctl delete -f $ACTION -f $GATEWAY/virtual-service.yaml 86 | 87 | istioctl create -f $ACTION -f $GATEWAY/http-gateway.yaml 88 | istioctl create -f $ACTION -f $GATEWAY/virtual-service.yaml 89 | 90 | statusCheck="NOT_STARTED" 91 | while [ "$statusCheck" != "" ] ; do 92 | sleep 20 93 | statusCheck=$(kubectl get pods -o json | jq '.items[].status.phase' | grep -v "Running") 94 | echo "Still starting pods $(date)" 95 | done 96 | 97 | echo "deploy etcd" 98 | kubectl $ACTION -f <(istioctl kube-inject -f $PATH_TO_ETCD/deployment.yaml) 99 | 100 | statusCheck="NOT_STARTED" 101 | while [ "$statusCheck" != "" ] ; do 102 | sleep 20 103 | statusCheck=$(kubectl get pods -o json | jq '.items[].status.phase' | grep -v "Running") 104 | echo "Still starting pods $(date)" 105 | done 106 | 107 | echo "deploy etcd operator" 108 | kubectl $ACTION -f $PATH_TO_ETCD/etcd-operator-deployment.yaml 109 | 110 | 111 | statusCheck="NOT_STARTED" 112 | while [ "$statusCheck" != "" ] ; do 113 | sleep 20 114 | statusCheck=$(kubectl get pods -o json | jq '.items[].status.phase' | grep -v "Running") 115 | echo "Still starting pods $(date)" 116 | done 117 | 118 | kubectl $ACTION -f "https://cloud.weave.works/k8s/scope.yaml?k8s-service-type=NodePort&k8s-version=$(kubectl version | base64 | tr -d '\n')" 119 | kubectl $ACTION -f $SECURITY/permissions-weave.yaml 120 | 121 | if [ "$ACTION" != "delete" ] ; then 122 | statusCheck="NOT_STARTED" 123 | while [ "$statusCheck" != "" ] ; do 124 | sleep 20 125 | statusCheck=$(kubectl get pods -o json | jq '.items[].status.phase' | grep -v "Running") 126 | echo "Still starting pods $(date)" 127 | done 128 | 129 | WEAVE_SCOPE_PORT=$(kubectl get service weave-scope-app --namespace=weave -o 'jsonpath={.spec.ports[0].nodePort}') 130 | echo "Weave Scope is available on port $WEAVE_SCOPE_PORT" 131 | fi 132 | 133 | endTime=$(timer startTime) 134 | printf 'deploy Elapsed time: %s\n' $endTime 135 | -------------------------------------------------------------------------------- /etcd/deployment.yaml: -------------------------------------------------------------------------------- 1 | ################################################################################################## 2 | # etcd service 3 | ################################################################################################## 4 | apiVersion: v1 5 | kind: Service 6 | metadata: 7 | name: etcd-service 8 | annotations: 9 | sidecar.istio.io/inject: "true" 10 | labels: 11 | app: etcd 12 | etcd_cluster: example-etcd-cluster 13 | spec: 14 | ports: 15 | - port: 2379 16 | name: http 17 | nodePort: 32012 18 | selector: 19 | app: etcd 20 | type: NodePort 21 | --- 22 | apiVersion: extensions/v1beta1 23 | kind: Deployment 24 | metadata: 25 | name: etcd-v1 26 | spec: 27 | replicas: 1 28 | template: 29 | metadata: 30 | labels: 31 | app: etcd 32 | version: v1 33 | spec: 34 | containers: 35 | - name: etcd 36 | image: quay.io/coreos/etcd:latest 37 | imagePullPolicy: Always 38 | ports: 39 | - containerPort: 2379 40 | 41 | --- -------------------------------------------------------------------------------- /etcd/etcd-operator-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: extensions/v1beta1 2 | kind: Deployment 3 | metadata: 4 | name: etcd-operator 5 | spec: 6 | replicas: 1 7 | template: 8 | metadata: 9 | annotations: 10 | sidecar.istio.io/inject: "false" 11 | labels: 12 | name: etcd-operator 13 | spec: 14 | containers: 15 | - name: etcd-operator 16 | image: quay.io/coreos/etcd-operator:v0.9.0 17 | command: 18 | - etcd-operator 19 | env: 20 | - name: MY_POD_NAMESPACE 21 | valueFrom: 22 | fieldRef: 23 | fieldPath: metadata.namespace 24 | - name: MY_POD_NAME 25 | valueFrom: 26 | fieldRef: 27 | fieldPath: metadata.name 28 | -------------------------------------------------------------------------------- /gateway/http-gateway.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.istio.io/v1alpha3 2 | kind: Gateway 3 | metadata: 4 | name: proxy-etcd-storage-gateway 5 | spec: 6 | selector: 7 | istio: ingressgateway # use Istio default gateway implementation 8 | servers: 9 | - port: 10 | number: 80 11 | name: http 12 | protocol: HTTP 13 | hosts: 14 | - "*" -------------------------------------------------------------------------------- /gateway/virtual-service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.istio.io/v1alpha3 2 | kind: VirtualService 3 | metadata: 4 | name: proxy-etcd-storage 5 | spec: 6 | hosts: 7 | - "*" 8 | gateways: 9 | - proxy-etcd-storage-gateway 10 | http: 11 | - match: 12 | - uri: 13 | prefix: /storage 14 | - uri: 15 | prefix: /web 16 | - uri: 17 | prefix: / 18 | route: 19 | - destination: 20 | port: 21 | number: 9080 22 | host: proxy-etcd-storage -------------------------------------------------------------------------------- /icp-helm-deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export MASTER_IP=9.37.39.42 4 | 5 | export PATH_TO_ETCD=$PWD/etcd 6 | export PATH_TO_NODE=$PWD/nodejs 7 | export SECURITY=$PWD/security 8 | export GATEWAY=$PWD/gateway 9 | 10 | function timer() 11 | { 12 | if [[ $# -eq 0 ]]; then 13 | echo $(date '+%s') 14 | else 15 | local stime=$1 16 | etime=$(date '+%s') 17 | 18 | if [[ -z "$stime" ]]; then stime=$etime; fi 19 | 20 | dt=$((etime - stime)) 21 | ds=$((dt % 60)) 22 | dm=$(((dt / 60) % 60)) 23 | dh=$((dt / 3600)) 24 | printf '%d:%02d:%02d' $dh $dm $ds 25 | fi 26 | } 27 | startTime=$(timer) 28 | 29 | if [ ! -d "istio-1.0.0" ]; then 30 | curl -L https://git.io/getLatestIstio | ISTIO_VERSION=1.0.0 sh - 31 | fi 32 | 33 | cd istio-1.0.0 34 | export PATH=$PWD/bin:$PATH 35 | 36 | ACTION=apply 37 | 38 | # install bx cli 39 | curl -sL https://ibm.biz/idt-installer | bash 40 | 41 | os=`uname` 42 | case "$os" in 43 | Linux) os="linux" ;; 44 | Darwin) os="darwin" ;; 45 | esac 46 | 47 | curl -L https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash -s -- --version v2.7.2 48 | export HELM_HOME=~/.helm 49 | 50 | echo "helm version" 51 | helm version 52 | 53 | # install bx pr plugin 54 | curl -ko icp-plugin https://$MASTER_IP:8443/api/cli/icp-$os-amd64 55 | bx plugin install -f icp-plugin 56 | rm -f icp-plugin 57 | bx pr login -u admin -p admin --skip-ssl-validation -c id-mycluster-account -a https://$MASTER_IP:8443 58 | bx pr cluster-config mycluster 59 | 60 | helm init --client-only 61 | 62 | echo "delete istio helm chart" 63 | helm delete --purge istio --tls 64 | 65 | echo "install istio CRDs" 66 | ## temporary install until helm can be updated on later release of ICP. 67 | kubectl $ACTION -f https://raw.githubusercontent.com/IBM/charts/master/stable/ibm-istio/templates/crds.yaml 68 | 69 | echo "deploy istio helm chart" 70 | helm install https://raw.githubusercontent.com/IBM/charts/master/repo/stable/ibm-istio-1.0.0.tgz --name istio \ 71 | --namespace istio-system --set sidecarInjectorWebhook.enabled=true \ 72 | --set global.mtls.enabled=false --tls 73 | 74 | statusCheck="NOT_STARTED" 75 | while [ "$statusCheck" != "" ] ; do 76 | sleep 20 77 | statusCheck=$(kubectl get pods --namespace=istio-system -o json | jq '.items[].status.phase' | grep -v "Running") 78 | echo "Still starting pods $(date)" 79 | done 80 | 81 | export kcontext=$(kubectl config current-context) 82 | export kns=$(kubectl config view $kcontext -o json | jq --raw-output '.contexts[] | select(.name=="'$kcontext'") | .context.namespace') 83 | if [ "$kns" != "default" ]; then 84 | cat $SECURITY/permissions.yaml.tmpl | \ 85 | sed -e "s/{NAMESPACE}/$kns/" > $SECURITY/permissions.yaml 86 | kubectl $ACTION -f $SECURITY/permissions.yaml 87 | fi 88 | 89 | kubectl label namespace $kns istio-injection=enabled --overwrite 90 | kubectl get namespace -L istio-injection 91 | 92 | statusCheck="NOT_STARTED" 93 | while [ "$statusCheck" != "" ] ; do 94 | sleep 20 95 | statusCheck=$(kubectl get pods -o json | jq '.items[].status.phase' | grep -v "Running") 96 | echo "Still starting pods $(date)" 97 | done 98 | 99 | echo "deploy Node application" 100 | kubectl $ACTION -f $PATH_TO_NODE/deployment.yaml 101 | 102 | 103 | echo "deploy Istio Gateway and routing rule" 104 | istioctl delete -f $ACTION -f $GATEWAY/http-gateway.yaml 105 | istioctl delete -f $ACTION -f $GATEWAY/virtual-service.yaml 106 | 107 | istioctl create -f $ACTION -f $GATEWAY/http-gateway.yaml 108 | istioctl create -f $ACTION -f $GATEWAY/virtual-service.yaml 109 | 110 | statusCheck="NOT_STARTED" 111 | while [ "$statusCheck" != "" ] ; do 112 | sleep 20 113 | statusCheck=$(kubectl get pods -o json | jq '.items[].status.phase' | grep -v "Running") 114 | echo "Still starting pods $(date)" 115 | done 116 | 117 | echo "deploy etcd" 118 | kubectl $ACTION -f $PATH_TO_ETCD/deployment.yaml 119 | 120 | statusCheck="NOT_STARTED" 121 | while [ "$statusCheck" != "" ] ; do 122 | sleep 20 123 | statusCheck=$(kubectl get pods -o json | jq '.items[].status.phase' | grep -v "Running") 124 | echo "Still starting pods $(date)" 125 | done 126 | 127 | echo "deploy etcd operator" 128 | kubectl $ACTION -f $PATH_TO_ETCD/etcd-operator-deployment.yaml 129 | 130 | statusCheck="NOT_STARTED" 131 | while [ "$statusCheck" != "" ] ; do 132 | sleep 20 133 | statusCheck=$(kubectl get pods -o json | jq '.items[].status.phase' | grep -v "Running") 134 | echo "Still starting pods $(date)" 135 | done 136 | 137 | kubectl $ACTION -f "https://cloud.weave.works/k8s/scope.yaml?k8s-service-type=NodePort&k8s-version=$(kubectl version | base64 | tr -d '\n')" 138 | kubectl $ACTION -f $SECURITY/permissions-weave.yaml 139 | 140 | if [ "$ACTION" != "delete" ] ; then 141 | statusCheck="NOT_STARTED" 142 | while [ "$statusCheck" != "" ] ; do 143 | sleep 20 144 | statusCheck=$(kubectl get pods -o json | jq '.items[].status.phase' | grep -v "Running") 145 | echo "Still starting pods $(date)" 146 | done 147 | 148 | WEAVE_SCOPE_PORT=$(kubectl get service weave-scope-app --namespace=weave -o 'jsonpath={.spec.ports[0].nodePort}') 149 | echo "Weave Scope is available on port $WEAVE_SCOPE_PORT" 150 | fi 151 | 152 | 153 | endTime=$(timer startTime) 154 | printf 'deploy Elapsed time: %s\n' $endTime 155 | -------------------------------------------------------------------------------- /images/1397375_910870955327_147651637_o.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/todkap/istio-index-conf2018/bde994cfa2bae8fb7214c9d700a099d3e78d7837/images/1397375_910870955327_147651637_o.jpg -------------------------------------------------------------------------------- /images/loadtest_grafana.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/todkap/istio-index-conf2018/bde994cfa2bae8fb7214c9d700a099d3e78d7837/images/loadtest_grafana.png -------------------------------------------------------------------------------- /images/loadtest_kiali.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/todkap/istio-index-conf2018/bde994cfa2bae8fb7214c9d700a099d3e78d7837/images/loadtest_kiali.png -------------------------------------------------------------------------------- /images/loadtest_prometheus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/todkap/istio-index-conf2018/bde994cfa2bae8fb7214c9d700a099d3e78d7837/images/loadtest_prometheus.png -------------------------------------------------------------------------------- /images/ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/todkap/istio-index-conf2018/bde994cfa2bae8fb7214c9d700a099d3e78d7837/images/ui.png -------------------------------------------------------------------------------- /images/weavescope.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/todkap/istio-index-conf2018/bde994cfa2bae8fb7214c9d700a099d3e78d7837/images/weavescope.png -------------------------------------------------------------------------------- /istioaddons/prometheus_telemetry.yaml: -------------------------------------------------------------------------------- 1 | # Configuration for metric instances 2 | apiVersion: "config.istio.io/v1alpha2" 3 | kind: metric 4 | metadata: 5 | name: doublerequestcount 6 | namespace: istio-system 7 | spec: 8 | value: "2" # count each request twice 9 | dimensions: 10 | source: source.service | "unknown" 11 | destination: destination.service | "unknown" 12 | message: '"twice the fun!"' 13 | monitored_resource_type: '"UNSPECIFIED"' 14 | --- 15 | # Configuration for a Prometheus handler 16 | apiVersion: "config.istio.io/v1alpha2" 17 | kind: prometheus 18 | metadata: 19 | name: doublehandler 20 | namespace: istio-system 21 | spec: 22 | metrics: 23 | - name: double_request_count # Prometheus metric name 24 | instance_name: doublerequestcount.metric.istio-system # Mixer instance name (fully-qualified) 25 | kind: COUNTER 26 | label_names: 27 | - source 28 | - destination 29 | - message 30 | --- 31 | # Rule to send metric instances to a Prometheus handler 32 | apiVersion: "config.istio.io/v1alpha2" 33 | kind: rule 34 | metadata: 35 | name: doubleprom 36 | namespace: istio-system 37 | spec: 38 | actions: 39 | - handler: doublehandler.prometheus 40 | instances: 41 | - doublerequestcount.metric 42 | --- 43 | # Configuration for logentry instances 44 | apiVersion: "config.istio.io/v1alpha2" 45 | kind: logentry 46 | metadata: 47 | name: newlog 48 | namespace: istio-system 49 | spec: 50 | severity: '"warning"' 51 | timestamp: request.time 52 | variables: 53 | source: source.labels["app"] | source.service | "unknown" 54 | user: source.user | "unknown" 55 | destination: destination.labels["app"] | destination.service | "unknown" 56 | responseCode: response.code | 0 57 | responseSize: response.size | 0 58 | latency: response.duration | "0ms" 59 | monitored_resource_type: '"UNSPECIFIED"' 60 | --- 61 | # Configuration for a stdio handler 62 | apiVersion: "config.istio.io/v1alpha2" 63 | kind: stdio 64 | metadata: 65 | name: newhandler 66 | namespace: istio-system 67 | spec: 68 | severity_levels: 69 | warning: 1 # Params.Level.WARNING 70 | outputAsJson: true 71 | --- 72 | # Rule to send logentry instances to a stdio handler 73 | apiVersion: "config.istio.io/v1alpha2" 74 | kind: rule 75 | metadata: 76 | name: newlogstdio 77 | namespace: istio-system 78 | spec: 79 | match: "true" # match for all requests 80 | actions: 81 | - handler: newhandler.stdio 82 | instances: 83 | - newlog.logentry 84 | --- -------------------------------------------------------------------------------- /nodejs/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:boron-alpine 2 | 3 | # Create app directory 4 | RUN mkdir -p /usr/src/app 5 | WORKDIR /usr/src/app 6 | 7 | # Install app dependencies 8 | COPY package.json /usr/src/app/ 9 | RUN npm install 10 | 11 | # Bundle app source 12 | COPY . /usr/src/app 13 | 14 | EXPOSE 9080 15 | CMD [ "npm", "start" ] -------------------------------------------------------------------------------- /nodejs/deployAppDocker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | export DOCKER_ID_USER="todkap" 5 | docker login 6 | 7 | docker build --no-cache=true -t todkap/proxy-etcd-storage:v1 . 8 | 9 | docker push todkap/proxy-etcd-storage:v1 -------------------------------------------------------------------------------- /nodejs/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: proxy-etcd-storage 5 | labels: 6 | app: proxy-etcd-storage 7 | spec: 8 | ports: 9 | - port: 9080 10 | name: http 11 | nodePort: 32380 12 | selector: 13 | app: proxy-etcd-storage 14 | type: NodePort 15 | --- 16 | apiVersion: extensions/v1beta1 17 | kind: Deployment 18 | metadata: 19 | name: proxy-etcd-storage-v1 20 | spec: 21 | replicas: 1 22 | template: 23 | metadata: 24 | labels: 25 | app: proxy-etcd-storage 26 | version: v1 27 | spec: 28 | containers: 29 | - name: proxy-etcd-storage 30 | image: todkap/proxy-etcd-storage:v1 31 | imagePullPolicy: Always 32 | ports: 33 | - containerPort: 9080 34 | --- 35 | 36 | ################################################################################################## 37 | # Ingress Routing 38 | ################################################################################################## 39 | # apiVersion: extensions/v1beta1 40 | # kind: Ingress 41 | # metadata: 42 | # name: simple-ingress 43 | # annotations: 44 | # kubernetes.io/ingress.class: "istio" 45 | # spec: 46 | # rules: 47 | # - http: 48 | # paths: 49 | # - path: /storage 50 | # backend: 51 | # serviceName: proxy-etcd-storage 52 | # servicePort: 9080 53 | # - path: /storage/.* 54 | # backend: 55 | # serviceName: proxy-etcd-storage 56 | # servicePort: 9080 57 | # - path: /web/.* 58 | # backend: 59 | # serviceName: proxy-etcd-storage 60 | # servicePort: 9080 61 | # - path: / 62 | # backend: 63 | # serviceName: proxy-etcd-storage 64 | # servicePort: 9080 65 | # --- -------------------------------------------------------------------------------- /nodejs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "istio-index-app", 3 | "version": "1.0.0", 4 | "main": "server.js", 5 | "dependencies": { 6 | "body-parser": "^1.17.2", 7 | "express": "^4.15.3", 8 | "node-etcd": "^5.0.3", 9 | "request": "^2.81.0" 10 | }, 11 | "devDependencies": {}, 12 | "scripts": { 13 | "test": "echo \"Error: no test specified\" && exit 1", 14 | "start": "node server.js" 15 | }, 16 | "author": "", 17 | "license": "ISC", 18 | "description": "istio-index-conf2018 application to demonstrate how to leverage Istio when interacting with services such as etcd" 19 | } 20 | -------------------------------------------------------------------------------- /nodejs/server.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | const Etcd = require('node-etcd'); 3 | const express = require('express') 4 | const app = express() 5 | 6 | const bodyParser = require('body-parser'); 7 | app.use(bodyParser.json()); // for parsing application/json 8 | 9 | const scheme = "http"; 10 | const ipAddress = "etcd-service"; 11 | const port = "2379"; 12 | // const ipAddress = "192.168.64.42"; 13 | // const port = "32012"; 14 | 15 | const connectionAddress = scheme +"://" + ipAddress +":" + port; 16 | const etcd = new Etcd([connectionAddress] /*, options */); 17 | 18 | app.get('/', function (request, response) { 19 | response.send('Simple test for liveliness of the application!'); 20 | }); 21 | 22 | app.get('/storage', function (request, response) { 23 | etcd.get("/", { recursive: true }, function(err, res){ 24 | if(!err){ 25 | response.writeHead(200); 26 | response.write(JSON.stringify(res) ) ; 27 | response.end(); 28 | }else{ 29 | response.writeHead(500); 30 | response.write("nodeAppTesting failed("+ ipAddress+") ->"+ JSON.stringify(err) ) ; 31 | response.end(); 32 | } 33 | }); 34 | }); 35 | 36 | 37 | app.delete('/storage/:key', function (request, response) { 38 | etcd.del(request.params.key, { recursive: true }, function(err, res){ 39 | if(!err){ 40 | response.writeHead(200); 41 | response.end(); 42 | }else{ 43 | response.writeHead(500); 44 | response.write("nodeAppTesting failed("+ ipAddress+") ->"+ JSON.stringify(err) ) ; 45 | response.end(); 46 | } 47 | }); 48 | }); 49 | 50 | 51 | app.get('/storage/:key', function (request, response) { 52 | etcd.get(request.params.key, { recursive: true }, function(err, res){ 53 | if(!err){ 54 | response.writeHead(200); 55 | response.write(JSON.stringify(res) ) ; 56 | response.end(); 57 | }else{ 58 | response.writeHead(500); 59 | response.write("nodeAppTesting failed("+ ipAddress+") ->"+ JSON.stringify(err) ) ; 60 | response.end(); 61 | } 62 | }); 63 | }); 64 | 65 | 66 | app.put('/storage', function (request, response) { 67 | var jsonData = request.body; 68 | etcd.set(jsonData.key, jsonData.value, function(err, res){ 69 | if(err){ 70 | response.writeHead(500); 71 | response.write (JSON.stringify(err) ); 72 | response.end(); 73 | }else{ 74 | response.writeHead(201); 75 | response.write("nodeAppTesting created") ; 76 | response.end(); 77 | } 78 | }); 79 | }); 80 | 81 | 82 | app.use('/web', express.static('web')) 83 | 84 | app.listen(9080, function () { 85 | console.log('Example app listening on port 9080!') 86 | }); -------------------------------------------------------------------------------- /nodejs/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 33 | 34 | 36 | 38 | 40 |
41 | 42 |Name | 48 |Value | 49 |50 | | |||
---|---|---|---|---|---|
53 | {{ x.key }} | 54 |55 | {{ x.key }} | 56 |57 | {{ x.value }} | 58 |59 | {{ x.value }} | 60 |61 | | 62 | |