├── .gitignore ├── README.md ├── cmd ├── istio-cmd.txt ├── k8s-cmd.txt └── service-cmd.txt ├── images └── book.jpg ├── istio ├── fault │ ├── virtual-service-go-abort.yaml │ ├── virtual-service-go-delay-abort.yaml │ ├── virtual-service-go-delay-retry.yaml │ └── virtual-service-go-delay.yaml ├── miscellaneous │ ├── cert-manager-certificate.yaml │ ├── cert-manager-cluster-issuer.yaml │ ├── envoy-filter.yaml │ ├── gateway-httpbin-use-host.yaml │ ├── https-default.conf │ ├── istio-ingressgateway-proxy.yaml │ ├── virtual-service-go-cors.yaml │ ├── virtual-service-go-redirect.yaml │ ├── virtual-service-go-rewrite.yaml │ ├── virtual-service-httpbin-append-headers.yaml │ ├── virtual-service-tcp-route.yaml │ └── virtual-service-tls-route.yaml ├── resilience │ ├── destination-rule-go-cb.yaml │ ├── destination-rule-go-lb-hash.yaml │ ├── destination-rule-go-lb-simple.yaml │ ├── destination-rule-go-old.yaml │ ├── destination-rule-go-pool-http.yaml │ ├── destination-rule-go-pool-tcp.yaml │ ├── quota-mem-ratelimit.yaml │ ├── quota-redis-ratelimit.yaml │ ├── virtual-service-httpbin-retry.yaml │ ├── virtual-service-node-retry.yaml │ └── virtual-service-node-timeout.yaml ├── route │ ├── gateway-egress.yaml │ ├── gateway-httpbin-http.yaml │ ├── gateway-httpbin-https-letsencrypt.yaml │ ├── gateway-httpbin-https.yaml │ ├── gateway-httpbin-service-go-https.yaml │ ├── gateway-js-react-v1-v2.yaml │ ├── gateway-js-user-agent-v1-v2.yaml │ ├── gateway-js-v1-mtls.yaml │ ├── gateway-js-v1.yaml │ ├── gateway-js-v2.yaml │ ├── service-entry-baidu.yaml │ ├── service-entry-egress-baidu.yaml │ ├── service-entry-egress-httpbin.yaml │ ├── service-entry-httpbin.yaml │ ├── virtual-service-go-canary-50.yaml │ ├── virtual-service-go-canary-70.yaml │ ├── virtual-service-go-canary.yaml │ ├── virtual-service-go-v1-mirror-v2.yaml │ ├── virtual-service-go-v1.yaml │ ├── virtual-service-go-v2.yaml │ ├── virtual-service-go.yaml │ ├── virtual-service-httpbin.yaml │ ├── virtual-service-lua-v1.yaml │ ├── virtual-service-node-v1-v2.yaml │ └── virtual-service-python-ab-canary.yaml ├── security │ ├── jwt-httpbin-custom-header-query.yaml │ ├── jwt-httpbin-custom-header.yaml │ ├── jwt-httpbin-custom-query.yaml │ ├── jwt-httpbin.yaml │ ├── jwt-mtls-httpbin.yaml │ ├── mtls-apiserver-off.yaml │ ├── mtls-config-default-on.yaml │ ├── mtls-config-mesh-on.yaml │ ├── mtls-httpbin-both.yaml │ ├── mtls-httpbin-legacy-off.yaml │ ├── mtls-httpbin-strict.yaml │ ├── mtls-my-nginx-disable.yaml │ ├── mtls-my-nginx-enable.yaml │ ├── mtls-namespace-default-on.yaml │ ├── mtls-namespace-foo-on.yaml │ ├── mtls-service-go-bad-rule.yaml │ ├── mtls-service-go-off.yaml │ ├── mtls-service-go-on.yaml │ ├── mtls-service-httpbin-on.yaml │ ├── mtls-service-httpbin-port-on.yaml │ ├── policy-rule-blacklist.yaml │ ├── policy-rule-deny-simple.yaml │ ├── policy-rule-whitelist.yaml │ ├── rbac-config-on.yaml │ ├── rbac-namespace-policy.yaml │ ├── rbac-service-go-user-agent-policy.yaml │ └── rbac-service-policy.yaml ├── telemetry │ ├── log-fluentd.yaml │ ├── log-http-access-log.yaml │ ├── metric-http-request-count.yaml │ └── metric-tcp-data-size.yaml └── upgrade │ └── virtual-service-go-rbac-mtls-retry.yaml ├── kubernetes ├── dns-test.yaml ├── fortio.yaml ├── httpbin.yaml ├── istio-grafana-service.yaml ├── istio-prometheus-service.yaml ├── istio-servicegraph-service.yaml ├── istio-tracing-service.yaml ├── loging-fluentd-stdout.yaml ├── loging-stack.yaml ├── my-nginx.yaml ├── redis-cli.yaml ├── redis-proxy-service.yaml ├── redis-ratelimit.yaml ├── redis-server.yaml ├── service-go-liveness-command.yaml ├── service-go-liveness-http.yaml ├── service-go-liveness-tcp.yaml └── sleep.yaml ├── service ├── envoy │ ├── Dockerfile │ └── envoy.yaml ├── go │ ├── service-go-v2.yaml │ ├── service-go.yaml │ ├── v1 │ │ ├── Dockerfile │ │ └── main.go │ └── v2 │ │ ├── Dockerfile │ │ └── main.go ├── js │ ├── service-js-v2.yaml │ ├── service-js.yaml │ ├── v1 │ │ ├── .gitignore │ │ ├── Dockerfile │ │ ├── README.md │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── public │ │ │ ├── favicon.ico │ │ │ ├── index.html │ │ │ └── manifest.json │ │ └── src │ │ │ ├── App.css │ │ │ ├── App.js │ │ │ ├── App.test.js │ │ │ ├── index.css │ │ │ ├── index.js │ │ │ ├── logo.svg │ │ │ └── registerServiceWorker.js │ └── v2 │ │ ├── .babelrc │ │ ├── .editorconfig │ │ ├── .eslintignore │ │ ├── .eslintrc.js │ │ ├── .gitignore │ │ ├── .postcssrc.js │ │ ├── Dockerfile │ │ ├── README.md │ │ ├── build │ │ ├── build.js │ │ ├── check-versions.js │ │ ├── logo.png │ │ ├── utils.js │ │ ├── vue-loader.conf.js │ │ ├── webpack.base.conf.js │ │ ├── webpack.dev.conf.js │ │ └── webpack.prod.conf.js │ │ ├── config │ │ ├── dev.env.js │ │ ├── index.js │ │ └── prod.env.js │ │ ├── index.html │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── src │ │ ├── App.vue │ │ ├── assets │ │ │ └── logo.png │ │ ├── components │ │ │ └── HelloWorld.vue │ │ └── main.js │ │ └── static │ │ └── .gitkeep ├── lua │ ├── service-lua-v2.yaml │ ├── service-lua.yaml │ ├── v1 │ │ ├── Dockerfile │ │ └── nginx.conf │ └── v2 │ │ ├── Dockerfile │ │ └── nginx.conf ├── node │ ├── service-node-v2.yaml │ ├── service-node-with-serviceaccount.yaml │ ├── service-node.yaml │ ├── v1 │ │ ├── .gitignore │ │ ├── Dockerfile │ │ ├── main.js │ │ ├── package-lock.json │ │ └── package.json │ └── v2 │ │ ├── .gitignore │ │ ├── Dockerfile │ │ ├── main.js │ │ ├── package-lock.json │ │ └── package.json ├── python │ ├── service-python-v2.yaml │ ├── service-python-with-serviceaccount.yaml │ ├── service-python.yaml │ ├── v1 │ │ ├── .gitignore │ │ ├── Dockerfile │ │ ├── main.py │ │ └── requirements.txt │ └── v2 │ │ ├── .gitignore │ │ ├── Dockerfile │ │ ├── main.py │ │ └── requirements.txt └── redis │ ├── Dockerfile │ ├── main.go │ └── service-redis.yaml └── vagrant └── Vagrantfile /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/visualstudiocode 3 | # Edit at https://www.gitignore.io/?templates=visualstudiocode 4 | 5 | ### VisualStudioCode ### 6 | .vscode/* 7 | 8 | ### VisualStudioCode Patch ### 9 | # Ignore all local history of files 10 | .history 11 | 12 | # End of https://www.gitignore.io/api/visualstudiocode 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # istio-lab 2 | 3 | 4 | 5 | 6 | 《Istio 入门与实战》官方配套实验代码库 [购买入口](https://item.jd.com/12601120.html) 7 | 8 | 学习交流 QQ 群:747894051 9 | 10 | ![](images/book.jpg) 11 | -------------------------------------------------------------------------------- /cmd/istio-cmd.txt: -------------------------------------------------------------------------------- 1 | ### install istio 2 | sudo yum install -y wget 3 | wget https://github.com/istio/istio/releases/download/1.0.3/istio-1.0.3-linux.tar.gz 4 | tar xf istio-1.0.3-linux.tar.gz 5 | sudo mv istio-1.0.3 /usr/local 6 | sudo ln -sv /usr/local/istio-1.0.3/ /usr/local/istio 7 | echo 'export PATH=/usr/local/istio/bin:$PATH' | sudo tee /etc/profile.d/istio.sh 8 | source /etc/profile.d/istio.sh 9 | istioctl version 10 | 11 | 12 | ### official deploy istio 13 | cp /usr/local/istio/install/kubernetes/istio-demo.yaml /usr/local/istio/install/kubernetes/istio-demo.yaml.ori 14 | sed -i 's@2048Mi@500Mi@g' /usr/local/istio/install/kubernetes/istio-demo.yaml 15 | sed -i 's@quay.io/coreos/hyperkube:v1.7.6_coreos.0@registry.cn-shanghai.aliyuncs.com/gcr-k8s/hyperkube:v1.7.6_coreos.0@g' /usr/local/istio/install/kubernetes/istio-demo.yaml 16 | kubectl apply -f /usr/local/istio/install/kubernetes/helm/istio/templates/crds.yaml 17 | kubectl get crd 18 | kubectl apply -f /usr/local/istio/install/kubernetes/istio-demo.yaml 19 | kubectl get svc -n istio-system 20 | kubectl get pods -n istio-system 21 | 22 | 23 | ### vagrant save istio-1.0.3-full 24 | vagrant snapshot save istio-1.0.3-full 25 | 26 | 27 | ### istio official bookinfo test 28 | kubectl label namespace default istio-injection=enabled 29 | kubectl apply -f /usr/local/istio/samples/bookinfo/platform/kube/bookinfo.yaml 30 | kubectl get services 31 | kubectl get pods 32 | kubectl apply -f /usr/local/istio/samples/bookinfo/networking/bookinfo-gateway.yaml 33 | kubectl get gateway 34 | 35 | export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}') 36 | export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}') 37 | export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o 'jsonpath={.items[0].status.hostIP}') 38 | export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT 39 | echo http://$GATEWAY_URL/productpage 40 | curl -I http://$GATEWAY_URL/productpage 41 | 42 | 43 | ### helm install 44 | wget https://storage.googleapis.com/kubernetes-helm/helm-v2.12.2-linux-amd64.tar.gz 45 | tar xf helm-v2.12.2-linux-amd64.tar.gz 46 | sudo mv linux-amd64/ /usr/local/helm-2.12.2 47 | sudo ln -sv /usr/local/helm-2.12.2 /usr/local/helm 48 | echo 'export PATH=/usr/local/helm:$PATH' | sudo tee /etc/profile.d/helm.sh 49 | source /etc/profile.d/helm.sh 50 | helm version 51 | 52 | 53 | ### custom mini istio deploy 54 | helm template /usr/local/istio/install/kubernetes/helm/istio \ 55 | --name istio --namespace istio-system \ 56 | --set global.hyperkube.hub=registry.cn-shanghai.aliyuncs.com/gcr-k8s \ 57 | --set pilot.resources.requests.memory=500Mi \ 58 | --set gateways.istio-ingressgateway.enabled=true \ 59 | --set gateways.istio-egressgateway.enabled=true \ 60 | --set galley.enabled=true \ 61 | --set sidecarInjectorWebhook.enabled=true \ 62 | --set global.mtls.enabled=false \ 63 | --set prometheus.enabled=false \ 64 | --set grafana.enabled=false \ 65 | --set tracing.enabled=false \ 66 | --set global.proxy.envoyStatsd.enabled=false \ 67 | --set servicegraph.enabled=false > istio-mini.yaml 68 | 69 | kubectl apply -f /usr/local/istio/install/kubernetes/helm/istio/templates/crds.yaml 70 | kubectl get crd 71 | kubectl create ns istio-system 72 | kubectl apply -f istio-mini.yaml 73 | kubectl get svc -n istio-system 74 | kubectl get pod -n istio-system 75 | 76 | 77 | ### vagrant save istio-1.0.3-mini 78 | vagrant snapshot save istio-1.0.3-mini -------------------------------------------------------------------------------- /cmd/k8s-cmd.txt: -------------------------------------------------------------------------------- 1 | ### install docker 2 | sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 3 | sudo yum makecache fast 4 | sudo yum install -y yum-utils device-mapper-persistent-data lvm2 5 | sudo yum install -y docker-ce-18.06.1.ce 6 | sudo mkdir -p /etc/docker 7 | sudo tee /etc/docker/daemon.json <<-'EOF' 8 | { 9 | "registry-mirrors": ["https://registry.docker-cn.com"] 10 | } 11 | EOF 12 | sudo systemctl daemon-reload 13 | sudo systemctl restart docker 14 | 15 | 16 | ### install kubeadm 17 | sudo tee /etc/yum.repos.d/kubernetes.repo <<-'EOF' 18 | [kubernetes] 19 | name=Kubernetes 20 | baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 21 | enabled=1 22 | gpgcheck=1 23 | repo_gpgcheck=1 24 | gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg 25 | EOF 26 | sudo yum install -y kubelet-1.12.4 kubeadm-1.12.4 kubectl-1.12.4 ipvsadm kubernetes-cni-0.6.0-0 27 | 28 | 29 | ### config basic env 30 | sudo systemctl stop firewalld 31 | sudo systemctl disable firewalld 32 | sudo sed -i 's/SELINUX=permissive/SELINUX=disabled/' /etc/sysconfig/selinux 33 | sudo setenforce 0 34 | 35 | sudo swapoff -a 36 | sudo sed -ri 's@(^/.*swap.*)@#\1@g' /etc/fstab 37 | free -m 38 | 39 | sudo modprobe ip_vs 40 | sudo modprobe ip_vs_rr 41 | sudo modprobe ip_vs_wrr 42 | sudo modprobe ip_vs_sh 43 | sudo modprobe nf_conntrack_ipv4 44 | sudo lsmod | grep ip_vs 45 | sudo tee /etc/modules-load.d/k8s-ipvs.conf <<-'EOF' 46 | ip_vs 47 | ip_vs_rr 48 | ip_vs_wrr 49 | ip_vs_sh 50 | nf_conntrack_ipv4 51 | EOF 52 | 53 | sudo tee /etc/sysctl.d/k8s.conf <<-'EOF' 54 | net.bridge.bridge-nf-call-ip6tables = 1 55 | net.bridge.bridge-nf-call-iptables = 1 56 | vm.swappiness=0 57 | EOF 58 | sudo sysctl --system 59 | 60 | sudo tee /etc/hosts <<-'EOF' 61 | 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 62 | ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 63 | 11.11.11.111 lab1 64 | 11.11.11.112 lab2 65 | 11.11.11.113 lab3 66 | EOF 67 | ping -c2 lab1 68 | ping -c2 lab2 69 | ping -c2 lab3 70 | 71 | 72 | ### config kubelet 73 | DOCKER_CGROUPS=$(sudo docker info | grep 'Cgroup' | cut -d' ' -f3) 74 | echo $DOCKER_CGROUPS 75 | sudo tee /etc/sysconfig/kubelet <<-EOF 76 | KUBELET_EXTRA_ARGS="--cgroup-driver=$DOCKER_CGROUPS --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.1" 77 | EOF 78 | sudo cat /etc/sysconfig/kubelet 79 | sudo systemctl daemon-reload 80 | sudo systemctl enable docker.service 81 | sudo systemctl enable kubelet.service 82 | 83 | 84 | ### init master 85 | cat >kubeadm-master.config<dns-test.yaml< 71 | type forward 72 | 73 | output.conf: |- 74 | 75 | type stdout 76 | output_type json 77 | 78 | metadata: 79 | name: fluentd-es-config 80 | namespace: logging -------------------------------------------------------------------------------- /kubernetes/loging-stack.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: logging 5 | --- 6 | apiVersion: v1 7 | kind: Service 8 | metadata: 9 | name: elasticsearch 10 | namespace: logging 11 | labels: 12 | app: elasticsearch 13 | spec: 14 | ports: 15 | - port: 9200 16 | protocol: TCP 17 | targetPort: db 18 | selector: 19 | app: elasticsearch 20 | --- 21 | apiVersion: apps/v1 22 | kind: Deployment 23 | metadata: 24 | name: elasticsearch 25 | namespace: logging 26 | labels: 27 | app: elasticsearch 28 | annotations: 29 | sidecar.istio.io/inject: "false" 30 | spec: 31 | selector: 32 | matchLabels: 33 | app: elasticsearch 34 | template: 35 | metadata: 36 | labels: 37 | app: elasticsearch 38 | spec: 39 | containers: 40 | - image: elastic/elasticsearch:6.1.1 41 | name: elasticsearch 42 | resources: 43 | limits: 44 | cpu: 1000m 45 | requests: 46 | cpu: 100m 47 | env: 48 | - name: discovery.type 49 | value: single-node 50 | ports: 51 | - containerPort: 9200 52 | name: db 53 | protocol: TCP 54 | - containerPort: 9300 55 | name: transport 56 | protocol: TCP 57 | volumeMounts: 58 | - name: elasticsearch 59 | mountPath: /data 60 | volumes: 61 | - name: elasticsearch 62 | emptyDir: {} 63 | --- 64 | apiVersion: v1 65 | kind: Service 66 | metadata: 67 | name: fluentd-es 68 | namespace: logging 69 | labels: 70 | app: fluentd-es 71 | spec: 72 | ports: 73 | - name: fluentd-tcp 74 | port: 24224 75 | protocol: TCP 76 | targetPort: 24224 77 | - name: fluentd-udp 78 | port: 24224 79 | protocol: UDP 80 | targetPort: 24224 81 | selector: 82 | app: fluentd-es 83 | --- 84 | apiVersion: apps/v1 85 | kind: Deployment 86 | metadata: 87 | name: fluentd-es 88 | namespace: logging 89 | labels: 90 | app: fluentd-es 91 | annotations: 92 | sidecar.istio.io/inject: "false" 93 | spec: 94 | selector: 95 | matchLabels: 96 | app: fluentd-es 97 | template: 98 | metadata: 99 | labels: 100 | app: fluentd-es 101 | spec: 102 | containers: 103 | - name: fluentd-es 104 | image: mirrorgooglecontainers/fluentd-elasticsearch:v2.0.1 105 | env: 106 | - name: FLUENTD_ARGS 107 | value: --no-supervisor -q 108 | resources: 109 | limits: 110 | memory: 500Mi 111 | requests: 112 | cpu: 100m 113 | memory: 200Mi 114 | volumeMounts: 115 | - name: config-volume 116 | mountPath: /etc/fluent/config.d 117 | terminationGracePeriodSeconds: 30 118 | volumes: 119 | - name: config-volume 120 | configMap: 121 | name: fluentd-es-config 122 | --- 123 | kind: ConfigMap 124 | apiVersion: v1 125 | data: 126 | forward.input.conf: |- 127 | # Takes the messages sent over TCP 128 | 129 | type forward 130 | 131 | output.conf: |- 132 | 133 | type elasticsearch 134 | log_level info 135 | include_tag_key true 136 | host elasticsearch 137 | port 9200 138 | logstash_format true 139 | # Set the chunk limits. 140 | buffer_chunk_limit 2M 141 | buffer_queue_limit 8 142 | flush_interval 5s 143 | # Never wait longer than 5 minutes between retries. 144 | max_retry_wait 30 145 | # Disable the limit on the number of retries (retry forever). 146 | disable_retry_limit 147 | # Use multiple threads for processing. 148 | num_threads 2 149 | 150 | metadata: 151 | name: fluentd-es-config 152 | namespace: logging 153 | --- 154 | apiVersion: v1 155 | kind: Service 156 | metadata: 157 | name: kibana 158 | namespace: logging 159 | labels: 160 | app: kibana 161 | spec: 162 | type: NodePort 163 | ports: 164 | - port: 5601 165 | protocol: TCP 166 | targetPort: ui 167 | nodePort: 32142 168 | selector: 169 | app: kibana 170 | --- 171 | apiVersion: apps/v1 172 | kind: Deployment 173 | metadata: 174 | name: kibana 175 | namespace: logging 176 | labels: 177 | app: kibana 178 | annotations: 179 | sidecar.istio.io/inject: "false" 180 | spec: 181 | selector: 182 | matchLabels: 183 | app: kibana 184 | template: 185 | metadata: 186 | labels: 187 | app: kibana 188 | spec: 189 | containers: 190 | - name: kibana 191 | image: elastic/kibana:6.1.1 192 | resources: 193 | limits: 194 | cpu: 1000m 195 | requests: 196 | cpu: 100m 197 | env: 198 | - name: ELASTICSEARCH_URL 199 | value: http://elasticsearch:9200 200 | ports: 201 | - containerPort: 5601 202 | name: ui 203 | protocol: TCP -------------------------------------------------------------------------------- /kubernetes/my-nginx.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: my-nginx 5 | labels: 6 | app: nginx 7 | spec: 8 | ports: 9 | - name: https 10 | port: 443 11 | selector: 12 | app: nginx 13 | --- 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: my-nginx 18 | spec: 19 | selector: 20 | matchLabels: 21 | app: nginx 22 | replicas: 1 23 | template: 24 | metadata: 25 | labels: 26 | app: nginx 27 | spec: 28 | containers: 29 | - name: nginxhttps 30 | image: ymqytw/nginxhttps:1.5 31 | command: ["/home/auto-reload-nginx.sh"] 32 | ports: 33 | - containerPort: 443 34 | env: 35 | - name: MY_POD_NAMESPACE 36 | valueFrom: 37 | fieldRef: 38 | fieldPath: metadata.namespace 39 | lifecycle: 40 | postStart: 41 | exec: 42 | command: ["/bin/sh", "-c", "echo Hello from nginx in $MY_POD_NAMESPACE > /usr/share/nginx/html/index.html"] 43 | resources: 44 | requests: 45 | cpu: 50m 46 | memory: 50Mi 47 | limits: 48 | cpu: 100m 49 | memory: 100Mi 50 | volumeMounts: 51 | - mountPath: /etc/nginx/ssl 52 | name: secret-volume 53 | - mountPath: /etc/nginx/conf.d 54 | name: configmap-volume 55 | volumes: 56 | - name: secret-volume 57 | secret: 58 | secretName: nginxsecret 59 | - name: configmap-volume 60 | configMap: 61 | name: nginxconfigmap -------------------------------------------------------------------------------- /kubernetes/redis-cli.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: redis-cli 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: redis-cli 9 | replicas: 1 10 | template: 11 | metadata: 12 | labels: 13 | app: redis-cli 14 | spec: 15 | restartPolicy: Always 16 | containers: 17 | - name: redis-cli 18 | image: redis:5-alpine 19 | stdin: true 20 | tty: true 21 | resources: 22 | requests: 23 | cpu: 50m 24 | memory: 50Mi 25 | limits: 26 | cpu: 100m 27 | memory: 100Mi -------------------------------------------------------------------------------- /kubernetes/redis-proxy-service.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: redis-proxy 5 | labels: 6 | app: redis-proxy 7 | spec: 8 | ports: 9 | - name: redis-proxy 10 | protocol: TCP 11 | port: 16379 -------------------------------------------------------------------------------- /kubernetes/redis-ratelimit.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: redis-ratelimit 5 | namespace: istio-system 6 | labels: 7 | app: redis-ratelimit 8 | spec: 9 | selector: 10 | app: redis-ratelimit 11 | ports: 12 | - name: redis 13 | protocol: TCP 14 | port: 6379 15 | --- 16 | apiVersion: apps/v1 17 | kind: Deployment 18 | metadata: 19 | name: redis-ratelimit 20 | namespace: istio-system 21 | spec: 22 | selector: 23 | matchLabels: 24 | app: redis-ratelimit 25 | replicas: 1 26 | template: 27 | metadata: 28 | labels: 29 | app: redis-ratelimit 30 | spec: 31 | restartPolicy: Always 32 | containers: 33 | - name: redis-ratelimit 34 | image: redis:4-alpine 35 | ports: 36 | - containerPort: 6379 37 | resources: 38 | requests: 39 | cpu: 50m 40 | memory: 50Mi 41 | limits: 42 | cpu: 500m 43 | memory: 500Mi -------------------------------------------------------------------------------- /kubernetes/redis-server.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: redis 5 | labels: 6 | app: redis 7 | spec: 8 | selector: 9 | app: redis 10 | ports: 11 | - name: redis 12 | protocol: TCP 13 | port: 6379 14 | --- 15 | apiVersion: apps/v1 16 | kind: Deployment 17 | metadata: 18 | name: redis-v1 19 | spec: 20 | selector: 21 | matchLabels: 22 | app: redis 23 | version: v1 24 | replicas: 1 25 | template: 26 | metadata: 27 | labels: 28 | app: redis 29 | version: v1 30 | spec: 31 | restartPolicy: Always 32 | containers: 33 | - name: redis 34 | image: redis:5-alpine 35 | ports: 36 | - containerPort: 6379 37 | resources: 38 | requests: 39 | cpu: 50m 40 | memory: 50Mi 41 | limits: 42 | cpu: 100m 43 | memory: 100Mi -------------------------------------------------------------------------------- /kubernetes/service-go-liveness-command.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: service-go 5 | labels: 6 | app: service-go 7 | spec: 8 | selector: 9 | app: service-go 10 | ports: 11 | - name: http 12 | port: 80 13 | --- 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: service-go-v1 18 | spec: 19 | selector: 20 | matchLabels: 21 | app: service-go 22 | version: v1 23 | replicas: 1 24 | template: 25 | metadata: 26 | labels: 27 | app: service-go 28 | version: v1 29 | spec: 30 | restartPolicy: Always 31 | containers: 32 | - name: service-go 33 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-go:v1 34 | ports: 35 | - containerPort: 80 36 | resources: 37 | requests: 38 | cpu: 50m 39 | memory: 50Mi 40 | limits: 41 | cpu: 100m 42 | memory: 100Mi 43 | livenessProbe: 44 | exec: 45 | command: 46 | - /bin/sh 47 | - -c 48 | - ps -ef | grep app | grep -v grep 49 | initialDelaySeconds: 5 50 | periodSeconds: 5 51 | 52 | -------------------------------------------------------------------------------- /kubernetes/service-go-liveness-http.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: service-go 5 | labels: 6 | app: service-go 7 | spec: 8 | selector: 9 | app: service-go 10 | ports: 11 | - name: http 12 | port: 80 13 | --- 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: service-go-v1 18 | spec: 19 | selector: 20 | matchLabels: 21 | app: service-go 22 | version: v1 23 | replicas: 1 24 | template: 25 | metadata: 26 | labels: 27 | app: service-go 28 | version: v1 29 | spec: 30 | restartPolicy: Always 31 | containers: 32 | - name: service-go 33 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-go:v1 34 | ports: 35 | - containerPort: 80 36 | resources: 37 | requests: 38 | cpu: 50m 39 | memory: 50Mi 40 | limits: 41 | cpu: 100m 42 | memory: 100Mi 43 | livenessProbe: 44 | httpGet: 45 | path: /status 46 | port: 80 47 | initialDelaySeconds: 5 48 | periodSeconds: 5 -------------------------------------------------------------------------------- /kubernetes/service-go-liveness-tcp.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: service-go 5 | labels: 6 | app: service-go 7 | spec: 8 | selector: 9 | app: service-go 10 | ports: 11 | - name: http 12 | port: 80 13 | --- 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: service-go-v1 18 | spec: 19 | selector: 20 | matchLabels: 21 | app: service-go 22 | version: v1 23 | replicas: 1 24 | template: 25 | metadata: 26 | labels: 27 | app: service-go 28 | version: v1 29 | spec: 30 | restartPolicy: Always 31 | containers: 32 | - name: service-go 33 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-go:v1 34 | ports: 35 | - containerPort: 80 36 | resources: 37 | requests: 38 | cpu: 50m 39 | memory: 50Mi 40 | limits: 41 | cpu: 100m 42 | memory: 100Mi 43 | livenessProbe: 44 | tcpSocket: 45 | port: 80 46 | initialDelaySeconds: 5 47 | periodSeconds: 5 -------------------------------------------------------------------------------- /kubernetes/sleep.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: sleep 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: sleep 9 | replicas: 1 10 | template: 11 | metadata: 12 | labels: 13 | app: sleep 14 | spec: 15 | containers: 16 | - name: sleep 17 | image: pstauffer/curl 18 | command: ["/bin/sleep", "3650d"] 19 | imagePullPolicy: IfNotPresent 20 | resources: 21 | requests: 22 | cpu: 50m 23 | memory: 50Mi 24 | limits: 25 | cpu: 100m 26 | memory: 100Mi 27 | -------------------------------------------------------------------------------- /service/envoy/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM envoyproxy/envoy:latest 2 | 3 | RUN apt-get update \ 4 | && apt-get -q install -y curl \ 5 | && apt-get clean 6 | EXPOSE 80 443 7 | CMD /usr/local/bin/envoy -c /etc/front-envoy.yaml --service-cluster front-proxy -------------------------------------------------------------------------------- /service/envoy/envoy.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: front-envoy 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: front-envoy 9 | version: v1 10 | replicas: 1 11 | template: 12 | metadata: 13 | labels: 14 | app: front-envoy 15 | version: v1 16 | spec: 17 | affinity: 18 | nodeAffinity: 19 | requiredDuringSchedulingIgnoredDuringExecution: 20 | nodeSelectorTerms: 21 | - matchExpressions: 22 | - key: edgenode 23 | operator: In 24 | values: 25 | - "true" 26 | hostNetwork: true 27 | tolerations: 28 | - operator: Exists 29 | effect: NoSchedule 30 | dnsPolicy: ClusterFirstWithHostNet 31 | restartPolicy: Always 32 | containers: 33 | - name: front-envoy 34 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/envoy:v1 35 | ports: 36 | - containerPort: 80 37 | - containerPort: 443 38 | volumeMounts: 39 | - name: front-envoy 40 | mountPath: /etc/front-envoy.yaml 41 | subPath: front-envoy.yaml 42 | resources: 43 | requests: 44 | cpu: 100m 45 | memory: 100Mi 46 | limits: 47 | cpu: 200m 48 | memory: 200Mi 49 | volumes: 50 | - name: front-envoy 51 | configMap: 52 | name: front-envoy 53 | -------------------------------------------------------------------------------- /service/go/service-go-v2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: service-go-v2 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: service-go 9 | version: v2 10 | replicas: 1 11 | template: 12 | metadata: 13 | labels: 14 | app: service-go 15 | version: v2 16 | spec: 17 | restartPolicy: Always 18 | containers: 19 | - name: service-go 20 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-go:v2 21 | ports: 22 | - containerPort: 80 23 | resources: 24 | requests: 25 | cpu: 50m 26 | memory: 50Mi 27 | limits: 28 | cpu: 100m 29 | memory: 100Mi 30 | -------------------------------------------------------------------------------- /service/go/service-go.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: service-go 5 | labels: 6 | app: service-go 7 | spec: 8 | selector: 9 | app: service-go 10 | ports: 11 | - name: http 12 | port: 80 13 | --- 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: service-go-v1 18 | spec: 19 | selector: 20 | matchLabels: 21 | app: service-go 22 | version: v1 23 | replicas: 1 24 | template: 25 | metadata: 26 | labels: 27 | app: service-go 28 | version: v1 29 | spec: 30 | restartPolicy: Always 31 | containers: 32 | - name: service-go 33 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-go:v1 34 | ports: 35 | - containerPort: 80 36 | resources: 37 | requests: 38 | cpu: 50m 39 | memory: 50Mi 40 | limits: 41 | cpu: 100m 42 | memory: 100Mi 43 | --- 44 | apiVersion: apps/v1 45 | kind: Deployment 46 | metadata: 47 | name: service-go-v2 48 | spec: 49 | selector: 50 | matchLabels: 51 | app: service-go 52 | version: v2 53 | replicas: 1 54 | template: 55 | metadata: 56 | labels: 57 | app: service-go 58 | version: v2 59 | spec: 60 | restartPolicy: Always 61 | containers: 62 | - name: service-go 63 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-go:v2 64 | ports: 65 | - containerPort: 80 66 | resources: 67 | requests: 68 | cpu: 50m 69 | memory: 50Mi 70 | limits: 71 | cpu: 100m 72 | memory: 100Mi 73 | -------------------------------------------------------------------------------- /service/go/v1/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.10-alpine as builder 2 | LABEL maintainer="will835559313@163.com" 3 | COPY . /app 4 | WORKDIR /app 5 | RUN apk update && apk add git \ 6 | && go get github.com/gin-gonic/gin \ 7 | && go build 8 | 9 | FROM alpine:latest 10 | WORKDIR /app 11 | COPY --from=builder /app/app . 12 | EXPOSE 80 13 | CMD ["./app"] -------------------------------------------------------------------------------- /service/go/v1/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/gin-gonic/gin" 5 | ) 6 | 7 | func main() { 8 | r := gin.Default() 9 | 10 | r.GET("/env", func(c *gin.Context) { 11 | c.JSON(200, gin.H{ 12 | "message": "go v1", 13 | }) 14 | }) 15 | 16 | r.GET("/status", func(c *gin.Context) { 17 | c.String(200, "ok") 18 | }) 19 | 20 | r.Run(":80") 21 | } 22 | -------------------------------------------------------------------------------- /service/go/v2/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.11-alpine as builder 2 | LABEL maintainer="will835559313@163.com" 3 | COPY . /app 4 | WORKDIR /app 5 | RUN apk update && apk add git \ 6 | && go get github.com/gin-gonic/gin \ 7 | && go build 8 | 9 | FROM alpine:latest 10 | WORKDIR /app 11 | COPY --from=builder /app/app . 12 | EXPOSE 80 13 | CMD ["./app"] -------------------------------------------------------------------------------- /service/go/v2/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/gin-gonic/gin" 5 | ) 6 | 7 | func main() { 8 | r := gin.Default() 9 | 10 | r.GET("/env", func(c *gin.Context) { 11 | c.JSON(200, gin.H{ 12 | "message": "go v2", 13 | }) 14 | }) 15 | 16 | r.GET("/status", func(c *gin.Context) { 17 | c.String(200, "ok") 18 | }) 19 | 20 | r.Run(":80") 21 | } 22 | -------------------------------------------------------------------------------- /service/js/service-js-v2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: service-js-v2 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: service-js 9 | version: v2 10 | replicas: 1 11 | template: 12 | metadata: 13 | labels: 14 | app: service-js 15 | version: v2 16 | spec: 17 | restartPolicy: Always 18 | containers: 19 | - name: service-js 20 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-js:v2 21 | ports: 22 | - containerPort: 80 23 | resources: 24 | requests: 25 | cpu: 50m 26 | memory: 50Mi 27 | limits: 28 | cpu: 100m 29 | memory: 100Mi 30 | -------------------------------------------------------------------------------- /service/js/service-js.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: service-js 5 | labels: 6 | app: service-js 7 | spec: 8 | selector: 9 | app: service-js 10 | ports: 11 | - name: http 12 | port: 80 13 | --- 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: service-js-v1 18 | spec: 19 | selector: 20 | matchLabels: 21 | app: service-js 22 | version: v1 23 | replicas: 1 24 | template: 25 | metadata: 26 | labels: 27 | app: service-js 28 | version: v1 29 | spec: 30 | restartPolicy: Always 31 | containers: 32 | - name: service-js 33 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-js:v1 34 | ports: 35 | - containerPort: 80 36 | resources: 37 | requests: 38 | cpu: 50m 39 | memory: 50Mi 40 | limits: 41 | cpu: 100m 42 | memory: 100Mi 43 | --- 44 | apiVersion: apps/v1 45 | kind: Deployment 46 | metadata: 47 | name: service-js-v2 48 | spec: 49 | selector: 50 | matchLabels: 51 | app: service-js 52 | version: v2 53 | replicas: 1 54 | template: 55 | metadata: 56 | labels: 57 | app: service-js 58 | version: v2 59 | spec: 60 | restartPolicy: Always 61 | containers: 62 | - name: service-js 63 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-js:v2 64 | ports: 65 | - containerPort: 80 66 | resources: 67 | requests: 68 | cpu: 50m 69 | memory: 50Mi 70 | limits: 71 | cpu: 100m 72 | memory: 100Mi 73 | -------------------------------------------------------------------------------- /service/js/v1/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /service/js/v1/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:8-alpine 2 | LABEL maintainer="will835559313@163.com" 3 | COPY . /app 4 | WORKDIR /app 5 | RUN npm i && npm run build \ 6 | && rm -rf ./node_modules \ 7 | && npm install -g serve 8 | EXPOSE 80 9 | CMD ["serve", "-s", "build", "-p", "80"] -------------------------------------------------------------------------------- /service/js/v1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "v1", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "axios": "^0.18.0", 7 | "echarts": "^4.2.0-rc.2", 8 | "echarts-for-react": "^2.0.15-beta.0", 9 | "react": "^16.3.2", 10 | "react-dom": "^16.3.2", 11 | "react-scripts": "1.1.4" 12 | }, 13 | "scripts": { 14 | "start": "react-scripts start", 15 | "build": "react-scripts build", 16 | "test": "react-scripts test --env=jsdom", 17 | "eject": "react-scripts eject" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /service/js/v1/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mgxian/istio-lab/a01eb7e03b8a31b3b3b5b6f5726f29b1b48a192c/service/js/v1/public/favicon.ico -------------------------------------------------------------------------------- /service/js/v1/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 22 | React App 23 | 24 | 25 | 28 |
29 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /service/js/v1/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /service/js/v1/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | animation: App-logo-spin infinite 20s linear; 7 | height: 80px; 8 | } 9 | 10 | .App-header { 11 | background-color: white; 12 | height: 150px; 13 | padding: 20px; 14 | } 15 | 16 | .App-title { 17 | font-size: 1.5em; 18 | } 19 | 20 | .App-intro { 21 | font-size: large; 22 | } 23 | 24 | @keyframes App-logo-spin { 25 | from { transform: rotate(0deg); } 26 | to { transform: rotate(360deg); } 27 | } 28 | -------------------------------------------------------------------------------- /service/js/v1/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import axios from 'axios'; 3 | import logo from './logo.svg'; 4 | import './App.css'; 5 | import ReactEcharts from 'echarts-for-react'; 6 | 7 | class App extends Component { 8 | constructor(props) { 9 | super(props); 10 | this.state = { 11 | message: '', 12 | response_time: 0, 13 | graphOptions: {}, 14 | serviceCall: {}, 15 | serviceCallMockData: { 16 | message: 'python v2', 17 | upstream: [ 18 | { 19 | message: 'lua v1', 20 | response_time: 0.1 21 | }, 22 | { 23 | message: 'node v2', 24 | upstream: [ 25 | { 26 | message: 'go v1', 27 | response_time: '0.01' 28 | } 29 | ], 30 | response_time: 0.1 31 | } 32 | ] 33 | } 34 | }; 35 | this.handleClick = this.handleClick.bind(this); 36 | this.parseServiceCall = this.parseServiceCall.bind(this); 37 | this.getServiceNodesAndLinks = this.getServiceNodesAndLinks.bind(this); 38 | this.setChar = this.setChar.bind(this); 39 | } 40 | 41 | handleClick() { 42 | let url = "/env" 43 | axios.defaults.headers.common['App-Client'] = "react" 44 | let start = Date.now() 45 | axios.get(url, { timeout: 20000 }).then(res => { 46 | let response_time = ((Date.now() - start) / 1000).toFixed(2) 47 | this.setState({ 48 | message: 'react -----> ' + res.data.message, 49 | serviceCall: res.data, 50 | response_time: response_time 51 | }, () => { 52 | this.setChar(); 53 | }); 54 | }).catch(error => { 55 | console.log(error) 56 | // this.setState({ 57 | // serviceCall: this.state.serviceCallMockData 58 | // },() => { 59 | // this.setChar(); 60 | // }); 61 | }); 62 | } 63 | 64 | parseServiceCall(data, result) { 65 | if (data.upstream) { 66 | data.upstream.forEach(upstream => { 67 | let link = { 68 | source: data.message, 69 | target: upstream.message, 70 | value: upstream.response_time, 71 | label: { show: true, formatter: '{c}s' } 72 | } 73 | // console.log(link) 74 | result.links = [link, ...result.links] 75 | this.parseServiceCall(upstream, result) 76 | }) 77 | } 78 | 79 | let node = { name: data.message } 80 | // console.log(node) 81 | result.nodes = [...result.nodes, node] 82 | 83 | return result 84 | } 85 | 86 | getServiceNodesAndLinks() { 87 | let result = { nodes: [], links: [] } 88 | let ret = this.parseServiceCall(this.state.serviceCall, result) 89 | let node = { name: 'react' } 90 | let link = { 91 | source: 'react', 92 | target: ret.nodes[ret.nodes.length-1].name, 93 | value: this.state.response_time, 94 | // value: Math.ceil(Math.random()*10), 95 | label: { show: true, formatter: '{c}s' } 96 | } 97 | ret.nodes = [...ret.nodes, node]; 98 | ret.links.push(link); 99 | 100 | console.log(ret) 101 | return ret 102 | } 103 | 104 | setChar() { 105 | let ret = this.getServiceNodesAndLinks() 106 | let graphOptions = { 107 | series: [ 108 | { 109 | type: 'graph', 110 | layout: 'circular', 111 | focusNodeAdjacency: true, 112 | symbol: 'circle', 113 | symbolSize: 90, 114 | roam: false, 115 | label: { 116 | show: true, 117 | textStyle: { 118 | fontSize: 16, 119 | fontWeight: 'bolder', 120 | color: '#2c3e50' 121 | } 122 | }, 123 | color: '#61dafb', 124 | edgeSymbol: ['circle', 'arrow'], 125 | edgeSymbolSize: [4, 15], 126 | edgeLabel: { 127 | textStyle: { 128 | fontSize: 15 129 | } 130 | }, 131 | data: ret.nodes, 132 | links: ret.links, 133 | lineStyle: { 134 | opacity: 0.9, 135 | width: 3, 136 | curveness: 0 137 | 138 | } 139 | } 140 | ] 141 | } 142 | this.setState({ graphOptions: graphOptions }, () => { 143 | // console.log(this.state.graphOptions) 144 | }); 145 | } 146 | render() { 147 | return ( 148 |
149 |
150 | logo 151 |

Welcome to Istio

152 |
153 |

154 | 155 |

156 | {/*

{this.state.message}

*/} 157 | 158 |
159 | ); 160 | } 161 | } 162 | 163 | export default App; 164 | -------------------------------------------------------------------------------- /service/js/v1/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /service/js/v1/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: sans-serif; 5 | } 6 | -------------------------------------------------------------------------------- /service/js/v1/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import registerServiceWorker from './registerServiceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | registerServiceWorker(); 9 | -------------------------------------------------------------------------------- /service/js/v1/src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /service/js/v1/src/registerServiceWorker.js: -------------------------------------------------------------------------------- 1 | // In production, we register a service worker to serve assets from local cache. 2 | 3 | // This lets the app load faster on subsequent visits in production, and gives 4 | // it offline capabilities. However, it also means that developers (and users) 5 | // will only see deployed updates on the "N+1" visit to a page, since previously 6 | // cached resources are updated in the background. 7 | 8 | // To learn more about the benefits of this model, read https://goo.gl/KwvDNy. 9 | // This link also includes instructions on opting out of this behavior. 10 | 11 | const isLocalhost = Boolean( 12 | window.location.hostname === 'localhost' || 13 | // [::1] is the IPv6 localhost address. 14 | window.location.hostname === '[::1]' || 15 | // 127.0.0.1/8 is considered localhost for IPv4. 16 | window.location.hostname.match( 17 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 18 | ) 19 | ); 20 | 21 | export default function register() { 22 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 23 | // The URL constructor is available in all browsers that support SW. 24 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location); 25 | if (publicUrl.origin !== window.location.origin) { 26 | // Our service worker won't work if PUBLIC_URL is on a different origin 27 | // from what our page is served on. This might happen if a CDN is used to 28 | // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374 29 | return; 30 | } 31 | 32 | window.addEventListener('load', () => { 33 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 34 | 35 | if (isLocalhost) { 36 | // This is running on localhost. Lets check if a service worker still exists or not. 37 | checkValidServiceWorker(swUrl); 38 | 39 | // Add some additional logging to localhost, pointing developers to the 40 | // service worker/PWA documentation. 41 | navigator.serviceWorker.ready.then(() => { 42 | console.log( 43 | 'This web app is being served cache-first by a service ' + 44 | 'worker. To learn more, visit https://goo.gl/SC7cgQ' 45 | ); 46 | }); 47 | } else { 48 | // Is not local host. Just register service worker 49 | registerValidSW(swUrl); 50 | } 51 | }); 52 | } 53 | } 54 | 55 | function registerValidSW(swUrl) { 56 | navigator.serviceWorker 57 | .register(swUrl) 58 | .then(registration => { 59 | registration.onupdatefound = () => { 60 | const installingWorker = registration.installing; 61 | installingWorker.onstatechange = () => { 62 | if (installingWorker.state === 'installed') { 63 | if (navigator.serviceWorker.controller) { 64 | // At this point, the old content will have been purged and 65 | // the fresh content will have been added to the cache. 66 | // It's the perfect time to display a "New content is 67 | // available; please refresh." message in your web app. 68 | console.log('New content is available; please refresh.'); 69 | } else { 70 | // At this point, everything has been precached. 71 | // It's the perfect time to display a 72 | // "Content is cached for offline use." message. 73 | console.log('Content is cached for offline use.'); 74 | } 75 | } 76 | }; 77 | }; 78 | }) 79 | .catch(error => { 80 | console.error('Error during service worker registration:', error); 81 | }); 82 | } 83 | 84 | function checkValidServiceWorker(swUrl) { 85 | // Check if the service worker can be found. If it can't reload the page. 86 | fetch(swUrl) 87 | .then(response => { 88 | // Ensure service worker exists, and that we really are getting a JS file. 89 | if ( 90 | response.status === 404 || 91 | response.headers.get('content-type').indexOf('javascript') === -1 92 | ) { 93 | // No service worker found. Probably a different app. Reload the page. 94 | navigator.serviceWorker.ready.then(registration => { 95 | registration.unregister().then(() => { 96 | window.location.reload(); 97 | }); 98 | }); 99 | } else { 100 | // Service worker found. Proceed as normal. 101 | registerValidSW(swUrl); 102 | } 103 | }) 104 | .catch(() => { 105 | console.log( 106 | 'No internet connection found. App is running in offline mode.' 107 | ); 108 | }); 109 | } 110 | 111 | export function unregister() { 112 | if ('serviceWorker' in navigator) { 113 | navigator.serviceWorker.ready.then(registration => { 114 | registration.unregister(); 115 | }); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /service/js/v2/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "modules": false, 5 | "targets": { 6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] 7 | } 8 | }], 9 | "stage-2" 10 | ], 11 | "plugins": ["transform-vue-jsx", "transform-runtime"] 12 | } 13 | -------------------------------------------------------------------------------- /service/js/v2/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /service/js/v2/.eslintignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /config/ 3 | /dist/ 4 | /*.js 5 | -------------------------------------------------------------------------------- /service/js/v2/.eslintrc.js: -------------------------------------------------------------------------------- 1 | // https://eslint.org/docs/user-guide/configuring 2 | 3 | module.exports = { 4 | root: true, 5 | parserOptions: { 6 | parser: 'babel-eslint' 7 | }, 8 | env: { 9 | browser: true, 10 | }, 11 | extends: [ 12 | // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention 13 | // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules. 14 | 'plugin:vue/essential', 15 | // https://github.com/standard/standard/blob/master/docs/RULES-en.md 16 | 'standard' 17 | ], 18 | // required to lint *.vue files 19 | plugins: [ 20 | 'vue' 21 | ], 22 | // add your custom rules here 23 | rules: { 24 | // allow async-await 25 | 'generator-star-spacing': 'off', 26 | // allow debugger during development 27 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', 28 | 'space-before-function-paren': 'off' 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /service/js/v2/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | /dist/ 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Editor directories and files 9 | .idea 10 | .vscode 11 | *.suo 12 | *.ntvs* 13 | *.njsproj 14 | *.sln 15 | -------------------------------------------------------------------------------- /service/js/v2/.postcssrc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": { 5 | "postcss-import": {}, 6 | "postcss-url": {}, 7 | // to edit target browsers: use "browserslist" field in package.json 8 | "autoprefixer": {} 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /service/js/v2/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:8-alpine 2 | LABEL maintainer="will835559313@163.com" 3 | COPY . /app 4 | WORKDIR /app 5 | RUN npm i && npm run build \ 6 | && rm -rf ./node_modules \ 7 | && npm install -g serve 8 | EXPOSE 80 9 | CMD ["serve", "-s", "dist", "-p", "80"] 10 | -------------------------------------------------------------------------------- /service/js/v2/README.md: -------------------------------------------------------------------------------- 1 | # y 2 | 3 | > y 4 | 5 | ## Build Setup 6 | 7 | ``` bash 8 | # install dependencies 9 | npm install 10 | 11 | # serve with hot reload at localhost:8080 12 | npm run dev 13 | 14 | # build for production with minification 15 | npm run build 16 | 17 | # build for production and view the bundle analyzer report 18 | npm run build --report 19 | ``` 20 | 21 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader). 22 | -------------------------------------------------------------------------------- /service/js/v2/build/build.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | require('./check-versions')() 3 | 4 | process.env.NODE_ENV = 'production' 5 | 6 | const ora = require('ora') 7 | const rm = require('rimraf') 8 | const path = require('path') 9 | const chalk = require('chalk') 10 | const webpack = require('webpack') 11 | const config = require('../config') 12 | const webpackConfig = require('./webpack.prod.conf') 13 | 14 | const spinner = ora('building for production...') 15 | spinner.start() 16 | 17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 18 | if (err) throw err 19 | webpack(webpackConfig, (err, stats) => { 20 | spinner.stop() 21 | if (err) throw err 22 | process.stdout.write(stats.toString({ 23 | colors: true, 24 | modules: false, 25 | children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build. 26 | chunks: false, 27 | chunkModules: false 28 | }) + '\n\n') 29 | 30 | if (stats.hasErrors()) { 31 | console.log(chalk.red(' Build failed with errors.\n')) 32 | process.exit(1) 33 | } 34 | 35 | console.log(chalk.cyan(' Build complete.\n')) 36 | console.log(chalk.yellow( 37 | ' Tip: built files are meant to be served over an HTTP server.\n' + 38 | ' Opening index.html over file:// won\'t work.\n' 39 | )) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /service/js/v2/build/check-versions.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const chalk = require('chalk') 3 | const semver = require('semver') 4 | const packageConfig = require('../package.json') 5 | const shell = require('shelljs') 6 | 7 | function exec (cmd) { 8 | return require('child_process').execSync(cmd).toString().trim() 9 | } 10 | 11 | const versionRequirements = [ 12 | { 13 | name: 'node', 14 | currentVersion: semver.clean(process.version), 15 | versionRequirement: packageConfig.engines.node 16 | } 17 | ] 18 | 19 | if (shell.which('npm')) { 20 | versionRequirements.push({ 21 | name: 'npm', 22 | currentVersion: exec('npm --version'), 23 | versionRequirement: packageConfig.engines.npm 24 | }) 25 | } 26 | 27 | module.exports = function () { 28 | const warnings = [] 29 | 30 | for (let i = 0; i < versionRequirements.length; i++) { 31 | const mod = versionRequirements[i] 32 | 33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 34 | warnings.push(mod.name + ': ' + 35 | chalk.red(mod.currentVersion) + ' should be ' + 36 | chalk.green(mod.versionRequirement) 37 | ) 38 | } 39 | } 40 | 41 | if (warnings.length) { 42 | console.log('') 43 | console.log(chalk.yellow('To use this template, you must update following to modules:')) 44 | console.log() 45 | 46 | for (let i = 0; i < warnings.length; i++) { 47 | const warning = warnings[i] 48 | console.log(' ' + warning) 49 | } 50 | 51 | console.log() 52 | process.exit(1) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /service/js/v2/build/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mgxian/istio-lab/a01eb7e03b8a31b3b3b5b6f5726f29b1b48a192c/service/js/v2/build/logo.png -------------------------------------------------------------------------------- /service/js/v2/build/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const config = require('../config') 4 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 5 | const packageConfig = require('../package.json') 6 | 7 | exports.assetsPath = function (_path) { 8 | const assetsSubDirectory = process.env.NODE_ENV === 'production' 9 | ? config.build.assetsSubDirectory 10 | : config.dev.assetsSubDirectory 11 | 12 | return path.posix.join(assetsSubDirectory, _path) 13 | } 14 | 15 | exports.cssLoaders = function (options) { 16 | options = options || {} 17 | 18 | const cssLoader = { 19 | loader: 'css-loader', 20 | options: { 21 | sourceMap: options.sourceMap 22 | } 23 | } 24 | 25 | const postcssLoader = { 26 | loader: 'postcss-loader', 27 | options: { 28 | sourceMap: options.sourceMap 29 | } 30 | } 31 | 32 | // generate loader string to be used with extract text plugin 33 | function generateLoaders (loader, loaderOptions) { 34 | const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader] 35 | 36 | if (loader) { 37 | loaders.push({ 38 | loader: loader + '-loader', 39 | options: Object.assign({}, loaderOptions, { 40 | sourceMap: options.sourceMap 41 | }) 42 | }) 43 | } 44 | 45 | // Extract CSS when that option is specified 46 | // (which is the case during production build) 47 | if (options.extract) { 48 | return ExtractTextPlugin.extract({ 49 | use: loaders, 50 | fallback: 'vue-style-loader' 51 | }) 52 | } else { 53 | return ['vue-style-loader'].concat(loaders) 54 | } 55 | } 56 | 57 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html 58 | return { 59 | css: generateLoaders(), 60 | postcss: generateLoaders(), 61 | less: generateLoaders('less'), 62 | sass: generateLoaders('sass', { indentedSyntax: true }), 63 | scss: generateLoaders('sass'), 64 | stylus: generateLoaders('stylus'), 65 | styl: generateLoaders('stylus') 66 | } 67 | } 68 | 69 | // Generate loaders for standalone style files (outside of .vue) 70 | exports.styleLoaders = function (options) { 71 | const output = [] 72 | const loaders = exports.cssLoaders(options) 73 | 74 | for (const extension in loaders) { 75 | const loader = loaders[extension] 76 | output.push({ 77 | test: new RegExp('\\.' + extension + '$'), 78 | use: loader 79 | }) 80 | } 81 | 82 | return output 83 | } 84 | 85 | exports.createNotifierCallback = () => { 86 | const notifier = require('node-notifier') 87 | 88 | return (severity, errors) => { 89 | if (severity !== 'error') return 90 | 91 | const error = errors[0] 92 | const filename = error.file && error.file.split('!').pop() 93 | 94 | notifier.notify({ 95 | title: packageConfig.name, 96 | message: severity + ': ' + error.name, 97 | subtitle: filename || '', 98 | icon: path.join(__dirname, 'logo.png') 99 | }) 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /service/js/v2/build/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const utils = require('./utils') 3 | const config = require('../config') 4 | const isProduction = process.env.NODE_ENV === 'production' 5 | const sourceMapEnabled = isProduction 6 | ? config.build.productionSourceMap 7 | : config.dev.cssSourceMap 8 | 9 | module.exports = { 10 | loaders: utils.cssLoaders({ 11 | sourceMap: sourceMapEnabled, 12 | extract: isProduction 13 | }), 14 | cssSourceMap: sourceMapEnabled, 15 | cacheBusting: config.dev.cacheBusting, 16 | transformToRequire: { 17 | video: ['src', 'poster'], 18 | source: 'src', 19 | img: 'src', 20 | image: 'xlink:href' 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /service/js/v2/build/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const utils = require('./utils') 4 | const config = require('../config') 5 | const vueLoaderConfig = require('./vue-loader.conf') 6 | 7 | function resolve (dir) { 8 | return path.join(__dirname, '..', dir) 9 | } 10 | 11 | const createLintingRule = () => ({ 12 | test: /\.(js|vue)$/, 13 | loader: 'eslint-loader', 14 | enforce: 'pre', 15 | include: [resolve('src'), resolve('test')], 16 | options: { 17 | formatter: require('eslint-friendly-formatter'), 18 | emitWarning: !config.dev.showEslintErrorsInOverlay 19 | } 20 | }) 21 | 22 | module.exports = { 23 | context: path.resolve(__dirname, '../'), 24 | entry: { 25 | app: './src/main.js' 26 | }, 27 | output: { 28 | path: config.build.assetsRoot, 29 | filename: '[name].js', 30 | publicPath: process.env.NODE_ENV === 'production' 31 | ? config.build.assetsPublicPath 32 | : config.dev.assetsPublicPath 33 | }, 34 | resolve: { 35 | extensions: ['.js', '.vue', '.json'], 36 | alias: { 37 | 'vue$': 'vue/dist/vue.esm.js', 38 | '@': resolve('src'), 39 | } 40 | }, 41 | module: { 42 | rules: [ 43 | ...(config.dev.useEslint ? [createLintingRule()] : []), 44 | { 45 | test: /\.vue$/, 46 | loader: 'vue-loader', 47 | options: vueLoaderConfig 48 | }, 49 | { 50 | test: /\.js$/, 51 | loader: 'babel-loader', 52 | include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')] 53 | }, 54 | { 55 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 56 | loader: 'url-loader', 57 | options: { 58 | limit: 10000, 59 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 60 | } 61 | }, 62 | { 63 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, 64 | loader: 'url-loader', 65 | options: { 66 | limit: 10000, 67 | name: utils.assetsPath('media/[name].[hash:7].[ext]') 68 | } 69 | }, 70 | { 71 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 72 | loader: 'url-loader', 73 | options: { 74 | limit: 10000, 75 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 76 | } 77 | } 78 | ] 79 | }, 80 | node: { 81 | // prevent webpack from injecting useless setImmediate polyfill because Vue 82 | // source contains it (although only uses it if it's native). 83 | setImmediate: false, 84 | // prevent webpack from injecting mocks to Node native modules 85 | // that does not make sense for the client 86 | dgram: 'empty', 87 | fs: 'empty', 88 | net: 'empty', 89 | tls: 'empty', 90 | child_process: 'empty' 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /service/js/v2/build/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const utils = require('./utils') 3 | const webpack = require('webpack') 4 | const config = require('../config') 5 | const merge = require('webpack-merge') 6 | const path = require('path') 7 | const baseWebpackConfig = require('./webpack.base.conf') 8 | const CopyWebpackPlugin = require('copy-webpack-plugin') 9 | const HtmlWebpackPlugin = require('html-webpack-plugin') 10 | const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 11 | const portfinder = require('portfinder') 12 | 13 | const HOST = process.env.HOST 14 | const PORT = process.env.PORT && Number(process.env.PORT) 15 | 16 | const devWebpackConfig = merge(baseWebpackConfig, { 17 | module: { 18 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true }) 19 | }, 20 | // cheap-module-eval-source-map is faster for development 21 | devtool: config.dev.devtool, 22 | 23 | // these devServer options should be customized in /config/index.js 24 | devServer: { 25 | clientLogLevel: 'warning', 26 | historyApiFallback: { 27 | rewrites: [ 28 | { from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') }, 29 | ], 30 | }, 31 | hot: true, 32 | contentBase: false, // since we use CopyWebpackPlugin. 33 | compress: true, 34 | host: HOST || config.dev.host, 35 | port: PORT || config.dev.port, 36 | open: config.dev.autoOpenBrowser, 37 | overlay: config.dev.errorOverlay 38 | ? { warnings: false, errors: true } 39 | : false, 40 | publicPath: config.dev.assetsPublicPath, 41 | proxy: config.dev.proxyTable, 42 | quiet: true, // necessary for FriendlyErrorsPlugin 43 | watchOptions: { 44 | poll: config.dev.poll, 45 | } 46 | }, 47 | plugins: [ 48 | new webpack.DefinePlugin({ 49 | 'process.env': require('../config/dev.env') 50 | }), 51 | new webpack.HotModuleReplacementPlugin(), 52 | new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update. 53 | new webpack.NoEmitOnErrorsPlugin(), 54 | // https://github.com/ampedandwired/html-webpack-plugin 55 | new HtmlWebpackPlugin({ 56 | filename: 'index.html', 57 | template: 'index.html', 58 | inject: true 59 | }), 60 | // copy custom static assets 61 | new CopyWebpackPlugin([ 62 | { 63 | from: path.resolve(__dirname, '../static'), 64 | to: config.dev.assetsSubDirectory, 65 | ignore: ['.*'] 66 | } 67 | ]) 68 | ] 69 | }) 70 | 71 | module.exports = new Promise((resolve, reject) => { 72 | portfinder.basePort = process.env.PORT || config.dev.port 73 | portfinder.getPort((err, port) => { 74 | if (err) { 75 | reject(err) 76 | } else { 77 | // publish the new Port, necessary for e2e tests 78 | process.env.PORT = port 79 | // add port to devServer config 80 | devWebpackConfig.devServer.port = port 81 | 82 | // Add FriendlyErrorsPlugin 83 | devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({ 84 | compilationSuccessInfo: { 85 | messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`], 86 | }, 87 | onErrors: config.dev.notifyOnErrors 88 | ? utils.createNotifierCallback() 89 | : undefined 90 | })) 91 | 92 | resolve(devWebpackConfig) 93 | } 94 | }) 95 | }) 96 | -------------------------------------------------------------------------------- /service/js/v2/build/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const utils = require('./utils') 4 | const webpack = require('webpack') 5 | const config = require('../config') 6 | const merge = require('webpack-merge') 7 | const baseWebpackConfig = require('./webpack.base.conf') 8 | const CopyWebpackPlugin = require('copy-webpack-plugin') 9 | const HtmlWebpackPlugin = require('html-webpack-plugin') 10 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 11 | const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 12 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin') 13 | 14 | const env = require('../config/prod.env') 15 | 16 | const webpackConfig = merge(baseWebpackConfig, { 17 | module: { 18 | rules: utils.styleLoaders({ 19 | sourceMap: config.build.productionSourceMap, 20 | extract: true, 21 | usePostCSS: true 22 | }) 23 | }, 24 | devtool: config.build.productionSourceMap ? config.build.devtool : false, 25 | output: { 26 | path: config.build.assetsRoot, 27 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 28 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 29 | }, 30 | plugins: [ 31 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 32 | new webpack.DefinePlugin({ 33 | 'process.env': env 34 | }), 35 | new UglifyJsPlugin({ 36 | uglifyOptions: { 37 | compress: { 38 | warnings: false 39 | } 40 | }, 41 | sourceMap: config.build.productionSourceMap, 42 | parallel: true 43 | }), 44 | // extract css into its own file 45 | new ExtractTextPlugin({ 46 | filename: utils.assetsPath('css/[name].[contenthash].css'), 47 | // Setting the following option to `false` will not extract CSS from codesplit chunks. 48 | // Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack. 49 | // It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`, 50 | // increasing file size: https://github.com/vuejs-templates/webpack/issues/1110 51 | allChunks: true, 52 | }), 53 | // Compress extracted CSS. We are using this plugin so that possible 54 | // duplicated CSS from different components can be deduped. 55 | new OptimizeCSSPlugin({ 56 | cssProcessorOptions: config.build.productionSourceMap 57 | ? { safe: true, map: { inline: false } } 58 | : { safe: true } 59 | }), 60 | // generate dist index.html with correct asset hash for caching. 61 | // you can customize output by editing /index.html 62 | // see https://github.com/ampedandwired/html-webpack-plugin 63 | new HtmlWebpackPlugin({ 64 | filename: config.build.index, 65 | template: 'index.html', 66 | inject: true, 67 | minify: { 68 | removeComments: true, 69 | collapseWhitespace: true, 70 | removeAttributeQuotes: true 71 | // more options: 72 | // https://github.com/kangax/html-minifier#options-quick-reference 73 | }, 74 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 75 | chunksSortMode: 'dependency' 76 | }), 77 | // keep module.id stable when vendor modules does not change 78 | new webpack.HashedModuleIdsPlugin(), 79 | // enable scope hoisting 80 | new webpack.optimize.ModuleConcatenationPlugin(), 81 | // split vendor js into its own file 82 | new webpack.optimize.CommonsChunkPlugin({ 83 | name: 'vendor', 84 | minChunks (module) { 85 | // any required modules inside node_modules are extracted to vendor 86 | return ( 87 | module.resource && 88 | /\.js$/.test(module.resource) && 89 | module.resource.indexOf( 90 | path.join(__dirname, '../node_modules') 91 | ) === 0 92 | ) 93 | } 94 | }), 95 | // extract webpack runtime and module manifest to its own file in order to 96 | // prevent vendor hash from being updated whenever app bundle is updated 97 | new webpack.optimize.CommonsChunkPlugin({ 98 | name: 'manifest', 99 | minChunks: Infinity 100 | }), 101 | // This instance extracts shared chunks from code splitted chunks and bundles them 102 | // in a separate chunk, similar to the vendor chunk 103 | // see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk 104 | new webpack.optimize.CommonsChunkPlugin({ 105 | name: 'app', 106 | async: 'vendor-async', 107 | children: true, 108 | minChunks: 3 109 | }), 110 | 111 | // copy custom static assets 112 | new CopyWebpackPlugin([ 113 | { 114 | from: path.resolve(__dirname, '../static'), 115 | to: config.build.assetsSubDirectory, 116 | ignore: ['.*'] 117 | } 118 | ]) 119 | ] 120 | }) 121 | 122 | if (config.build.productionGzip) { 123 | const CompressionWebpackPlugin = require('compression-webpack-plugin') 124 | 125 | webpackConfig.plugins.push( 126 | new CompressionWebpackPlugin({ 127 | asset: '[path].gz[query]', 128 | algorithm: 'gzip', 129 | test: new RegExp( 130 | '\\.(' + 131 | config.build.productionGzipExtensions.join('|') + 132 | ')$' 133 | ), 134 | threshold: 10240, 135 | minRatio: 0.8 136 | }) 137 | ) 138 | } 139 | 140 | if (config.build.bundleAnalyzerReport) { 141 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 142 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 143 | } 144 | 145 | module.exports = webpackConfig 146 | -------------------------------------------------------------------------------- /service/js/v2/config/dev.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const merge = require('webpack-merge') 3 | const prodEnv = require('./prod.env') 4 | 5 | module.exports = merge(prodEnv, { 6 | NODE_ENV: '"development"' 7 | }) 8 | -------------------------------------------------------------------------------- /service/js/v2/config/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | // Template version: 1.3.1 3 | // see http://vuejs-templates.github.io/webpack for documentation. 4 | 5 | const path = require('path') 6 | 7 | module.exports = { 8 | dev: { 9 | 10 | // Paths 11 | assetsSubDirectory: 'static', 12 | assetsPublicPath: '/', 13 | proxyTable: {}, 14 | 15 | // Various Dev Server settings 16 | host: 'localhost', // can be overwritten by process.env.HOST 17 | port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined 18 | autoOpenBrowser: false, 19 | errorOverlay: true, 20 | notifyOnErrors: true, 21 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions- 22 | 23 | // Use Eslint Loader? 24 | // If true, your code will be linted during bundling and 25 | // linting errors and warnings will be shown in the console. 26 | useEslint: true, 27 | // If true, eslint errors and warnings will also be shown in the error overlay 28 | // in the browser. 29 | showEslintErrorsInOverlay: false, 30 | 31 | /** 32 | * Source Maps 33 | */ 34 | 35 | // https://webpack.js.org/configuration/devtool/#development 36 | devtool: 'cheap-module-eval-source-map', 37 | 38 | // If you have problems debugging vue-files in devtools, 39 | // set this to false - it *may* help 40 | // https://vue-loader.vuejs.org/en/options.html#cachebusting 41 | cacheBusting: true, 42 | 43 | cssSourceMap: true 44 | }, 45 | 46 | build: { 47 | // Template for index.html 48 | index: path.resolve(__dirname, '../dist/index.html'), 49 | 50 | // Paths 51 | assetsRoot: path.resolve(__dirname, '../dist'), 52 | assetsSubDirectory: 'static', 53 | assetsPublicPath: '/', 54 | 55 | /** 56 | * Source Maps 57 | */ 58 | 59 | productionSourceMap: true, 60 | // https://webpack.js.org/configuration/devtool/#production 61 | devtool: '#source-map', 62 | 63 | // Gzip off by default as many popular static hosts such as 64 | // Surge or Netlify already gzip all static assets for you. 65 | // Before setting to `true`, make sure to: 66 | // npm install --save-dev compression-webpack-plugin 67 | productionGzip: false, 68 | productionGzipExtensions: ['js', 'css'], 69 | 70 | // Run the build command with an extra argument to 71 | // View the bundle analyzer report after build finishes: 72 | // `npm run build --report` 73 | // Set to `true` or `false` to always turn it on or off 74 | bundleAnalyzerReport: process.env.npm_config_report 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /service/js/v2/config/prod.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | module.exports = { 3 | NODE_ENV: '"production"' 4 | } 5 | -------------------------------------------------------------------------------- /service/js/v2/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | vue 7 | 8 | 9 |
10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /service/js/v2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "y", 3 | "version": "1.0.0", 4 | "description": "y", 5 | "author": "y", 6 | "private": true, 7 | "scripts": { 8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js", 9 | "start": "npm run dev", 10 | "lint": "eslint --ext .js,.vue src", 11 | "build": "node build/build.js" 12 | }, 13 | "dependencies": { 14 | "axios": "^0.18.0", 15 | "echarts": "^4.2.0-rc.2", 16 | "vue": "^2.5.2", 17 | "vue-echarts": "^3.1.3" 18 | }, 19 | "devDependencies": { 20 | "autoprefixer": "^7.1.2", 21 | "babel-core": "^6.22.1", 22 | "babel-eslint": "^8.2.1", 23 | "babel-helper-vue-jsx-merge-props": "^2.0.3", 24 | "babel-loader": "^7.1.1", 25 | "babel-plugin-syntax-jsx": "^6.18.0", 26 | "babel-plugin-transform-runtime": "^6.22.0", 27 | "babel-plugin-transform-vue-jsx": "^3.5.0", 28 | "babel-preset-env": "^1.3.2", 29 | "babel-preset-stage-2": "^6.22.0", 30 | "chalk": "^2.0.1", 31 | "copy-webpack-plugin": "^4.0.1", 32 | "css-loader": "^0.28.0", 33 | "eslint": "^4.15.0", 34 | "eslint-config-standard": "^10.2.1", 35 | "eslint-friendly-formatter": "^3.0.0", 36 | "eslint-loader": "^1.7.1", 37 | "eslint-plugin-import": "^2.7.0", 38 | "eslint-plugin-node": "^5.2.0", 39 | "eslint-plugin-promise": "^3.4.0", 40 | "eslint-plugin-standard": "^3.0.1", 41 | "eslint-plugin-vue": "^4.0.0", 42 | "extract-text-webpack-plugin": "^3.0.0", 43 | "file-loader": "^1.1.4", 44 | "friendly-errors-webpack-plugin": "^1.6.1", 45 | "html-webpack-plugin": "^2.30.1", 46 | "node-notifier": "^8.0.1", 47 | "optimize-css-assets-webpack-plugin": "^3.2.0", 48 | "ora": "^1.2.0", 49 | "portfinder": "^1.0.13", 50 | "postcss-import": "^11.0.0", 51 | "postcss-loader": "^2.0.8", 52 | "postcss-url": "^7.2.1", 53 | "rimraf": "^2.6.0", 54 | "semver": "^5.3.0", 55 | "shelljs": "^0.7.6", 56 | "uglifyjs-webpack-plugin": "^1.1.1", 57 | "url-loader": "^0.5.8", 58 | "vue-loader": "^13.3.0", 59 | "vue-style-loader": "^3.0.1", 60 | "vue-template-compiler": "^2.5.2", 61 | "webpack": "^3.6.0", 62 | "webpack-bundle-analyzer": "^2.9.0", 63 | "webpack-dev-server": "^2.9.1", 64 | "webpack-merge": "^4.1.0" 65 | }, 66 | "engines": { 67 | "node": ">= 6.0.0", 68 | "npm": ">= 3.0.0" 69 | }, 70 | "browserslist": [ 71 | "> 1%", 72 | "last 2 versions", 73 | "not ie <= 8" 74 | ] 75 | } 76 | -------------------------------------------------------------------------------- /service/js/v2/src/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 17 | 18 | 28 | -------------------------------------------------------------------------------- /service/js/v2/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mgxian/istio-lab/a01eb7e03b8a31b3b3b5b6f5726f29b1b48a192c/service/js/v2/src/assets/logo.png -------------------------------------------------------------------------------- /service/js/v2/src/components/HelloWorld.vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | 155 | 156 | 157 | 184 | -------------------------------------------------------------------------------- /service/js/v2/src/main.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import Vue from 'vue' 4 | import App from './App' 5 | 6 | Vue.config.productionTip = false 7 | 8 | /* eslint-disable no-new */ 9 | new Vue({ 10 | el: '#app', 11 | components: { 12 | App 13 | }, 14 | template: '' 15 | }) 16 | -------------------------------------------------------------------------------- /service/js/v2/static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mgxian/istio-lab/a01eb7e03b8a31b3b3b5b6f5726f29b1b48a192c/service/js/v2/static/.gitkeep -------------------------------------------------------------------------------- /service/lua/service-lua-v2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: service-lua-v2 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: service-lua 9 | version: v2 10 | replicas: 1 11 | template: 12 | metadata: 13 | labels: 14 | app: service-lua 15 | version: v2 16 | spec: 17 | restartPolicy: Always 18 | containers: 19 | - name: service-lua 20 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-lua:v2 21 | ports: 22 | - containerPort: 80 23 | resources: 24 | requests: 25 | cpu: 50m 26 | memory: 50Mi 27 | limits: 28 | cpu: 100m 29 | memory: 100Mi 30 | -------------------------------------------------------------------------------- /service/lua/service-lua.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: service-lua 5 | labels: 6 | app: service-lua 7 | spec: 8 | selector: 9 | app: service-lua 10 | ports: 11 | - name: http 12 | port: 80 13 | --- 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: service-lua-v1 18 | spec: 19 | selector: 20 | matchLabels: 21 | app: service-lua 22 | version: v1 23 | replicas: 1 24 | template: 25 | metadata: 26 | labels: 27 | app: service-lua 28 | version: v1 29 | spec: 30 | restartPolicy: Always 31 | containers: 32 | - name: service-lua 33 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-lua:v1 34 | ports: 35 | - containerPort: 80 36 | resources: 37 | requests: 38 | cpu: 50m 39 | memory: 50Mi 40 | limits: 41 | cpu: 100m 42 | memory: 100Mi 43 | --- 44 | apiVersion: apps/v1 45 | kind: Deployment 46 | metadata: 47 | name: service-lua-v2 48 | spec: 49 | selector: 50 | matchLabels: 51 | app: service-lua 52 | version: v2 53 | replicas: 1 54 | template: 55 | metadata: 56 | labels: 57 | app: service-lua 58 | version: v2 59 | spec: 60 | restartPolicy: Always 61 | containers: 62 | - name: service-lua 63 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-lua:v2 64 | ports: 65 | - containerPort: 80 66 | resources: 67 | requests: 68 | cpu: 50m 69 | memory: 50Mi 70 | limits: 71 | cpu: 100m 72 | memory: 100Mi 73 | -------------------------------------------------------------------------------- /service/lua/v1/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openresty/openresty:1.11.2.5-alpine 2 | LABEL maintainer="will835559313@163.com" 3 | COPY . /app 4 | WORKDIR /app 5 | EXPOSE 80 6 | ENTRYPOINT ["/usr/local/openresty/bin/openresty", "-c", "/app/nginx.conf", "-g", "daemon off;"] -------------------------------------------------------------------------------- /service/lua/v1/nginx.conf: -------------------------------------------------------------------------------- 1 | worker_processes 4; 2 | error_log logs/error.log; 3 | events { 4 | worker_connections 10240; 5 | } 6 | http { 7 | server { 8 | listen 80; 9 | location / { 10 | default_type text/html; 11 | content_by_lua ' 12 | ngx.say("hello, world") 13 | '; 14 | } 15 | 16 | location = /status { 17 | default_type text/html; 18 | content_by_lua ' 19 | ngx.say("ok") 20 | '; 21 | } 22 | 23 | location = /env { 24 | charset utf-8; 25 | charset_types application/json; 26 | default_type application/json; 27 | content_by_lua ' 28 | json = require "cjson" 29 | ngx.status = ngx.HTTP_OK 30 | version = "lua v1" 31 | data = { 32 | message = version 33 | } 34 | ngx.say(json.encode(data)) 35 | return ngx.exit(ngx.HTTP_OK) 36 | '; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /service/lua/v2/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openresty/openresty:1.13.6.1-2-alpine 2 | LABEL maintainer="will835559313@163.com" 3 | COPY . /app 4 | WORKDIR /app 5 | EXPOSE 80 6 | ENTRYPOINT ["/usr/local/openresty/bin/openresty", "-c", "/app/nginx.conf", "-g", "daemon off;"] -------------------------------------------------------------------------------- /service/lua/v2/nginx.conf: -------------------------------------------------------------------------------- 1 | worker_processes 4; 2 | error_log logs/error.log; 3 | events { 4 | worker_connections 10240; 5 | } 6 | http { 7 | server { 8 | listen 80; 9 | location / { 10 | default_type text/html; 11 | content_by_lua ' 12 | ngx.say("hello, world") 13 | '; 14 | } 15 | 16 | location = /status { 17 | default_type text/html; 18 | content_by_lua ' 19 | ngx.say("ok") 20 | '; 21 | } 22 | 23 | location = /env { 24 | charset utf-8; 25 | charset_types application/json; 26 | default_type application/json; 27 | content_by_lua ' 28 | json = require "cjson" 29 | ngx.status = ngx.HTTP_OK 30 | version = "lua v2" 31 | data = { 32 | message = version 33 | } 34 | ngx.say(json.encode(data)) 35 | return ngx.exit(ngx.HTTP_OK) 36 | '; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /service/node/service-node-v2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: service-node-v2 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: service-node 9 | version: v2 10 | replicas: 1 11 | template: 12 | metadata: 13 | labels: 14 | app: service-node 15 | version: v2 16 | spec: 17 | restartPolicy: Always 18 | containers: 19 | - name: service-node 20 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-node:v2 21 | ports: 22 | - containerPort: 80 23 | resources: 24 | requests: 25 | cpu: 50m 26 | memory: 50Mi 27 | limits: 28 | cpu: 100m 29 | memory: 100Mi 30 | -------------------------------------------------------------------------------- /service/node/service-node-with-serviceaccount.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: service-node 5 | labels: 6 | app: service-node 7 | spec: 8 | selector: 9 | app: service-node 10 | ports: 11 | - name: http 12 | port: 80 13 | --- 14 | apiVersion: v1 15 | kind: ServiceAccount 16 | metadata: 17 | name: service-node 18 | --- 19 | apiVersion: apps/v1 20 | kind: Deployment 21 | metadata: 22 | name: service-node-v1 23 | spec: 24 | selector: 25 | matchLabels: 26 | app: service-node 27 | version: v1 28 | replicas: 1 29 | template: 30 | metadata: 31 | labels: 32 | app: service-node 33 | version: v1 34 | spec: 35 | restartPolicy: Always 36 | serviceAccountName: service-node 37 | containers: 38 | - name: service-node 39 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-node:v1 40 | ports: 41 | - containerPort: 80 42 | resources: 43 | requests: 44 | cpu: 50m 45 | memory: 50Mi 46 | limits: 47 | cpu: 100m 48 | memory: 100Mi 49 | --- 50 | apiVersion: apps/v1 51 | kind: Deployment 52 | metadata: 53 | name: service-node-v2 54 | spec: 55 | selector: 56 | matchLabels: 57 | app: service-node 58 | version: v2 59 | replicas: 1 60 | template: 61 | metadata: 62 | labels: 63 | app: service-node 64 | version: v2 65 | spec: 66 | restartPolicy: Always 67 | serviceAccountName: service-node 68 | containers: 69 | - name: service-node 70 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-node:v2 71 | ports: 72 | - containerPort: 80 73 | resources: 74 | requests: 75 | cpu: 50m 76 | memory: 50Mi 77 | limits: 78 | cpu: 100m 79 | memory: 100Mi 80 | -------------------------------------------------------------------------------- /service/node/service-node.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: service-node 5 | labels: 6 | app: service-node 7 | spec: 8 | selector: 9 | app: service-node 10 | ports: 11 | - name: http 12 | port: 80 13 | --- 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: service-node-v1 18 | spec: 19 | selector: 20 | matchLabels: 21 | app: service-node 22 | version: v1 23 | replicas: 1 24 | template: 25 | metadata: 26 | labels: 27 | app: service-node 28 | version: v1 29 | spec: 30 | restartPolicy: Always 31 | containers: 32 | - name: service-node 33 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-node:v1 34 | ports: 35 | - containerPort: 80 36 | resources: 37 | requests: 38 | cpu: 50m 39 | memory: 50Mi 40 | limits: 41 | cpu: 100m 42 | memory: 100Mi 43 | --- 44 | apiVersion: apps/v1 45 | kind: Deployment 46 | metadata: 47 | name: service-node-v2 48 | spec: 49 | selector: 50 | matchLabels: 51 | app: service-node 52 | version: v2 53 | replicas: 1 54 | template: 55 | metadata: 56 | labels: 57 | app: service-node 58 | version: v2 59 | spec: 60 | restartPolicy: Always 61 | containers: 62 | - name: service-node 63 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-node:v2 64 | ports: 65 | - containerPort: 80 66 | resources: 67 | requests: 68 | cpu: 50m 69 | memory: 50Mi 70 | limits: 71 | cpu: 100m 72 | memory: 100Mi 73 | -------------------------------------------------------------------------------- /service/node/v1/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/node 3 | # Edit at https://www.gitignore.io/?templates=node 4 | 5 | ### Node ### 6 | # Logs 7 | logs 8 | *.log 9 | npm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # Optional npm cache directory 48 | .npm 49 | 50 | # Optional eslint cache 51 | .eslintcache 52 | 53 | # Optional REPL history 54 | .node_repl_history 55 | 56 | # Output of 'npm pack' 57 | *.tgz 58 | 59 | # Yarn Integrity file 60 | .yarn-integrity 61 | 62 | # dotenv environment variables file 63 | .env 64 | 65 | # parcel-bundler cache (https://parceljs.org/) 66 | .cache 67 | 68 | # next.js build output 69 | .next 70 | 71 | # nuxt.js build output 72 | .nuxt 73 | 74 | # vuepress build output 75 | .vuepress/dist 76 | 77 | # Serverless directories 78 | .serverless 79 | 80 | # FuseBox cache 81 | .fusebox/ 82 | 83 | # End of https://www.gitignore.io/api/node 84 | -------------------------------------------------------------------------------- /service/node/v1/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:8-alpine 2 | LABEL maintainer="will835559313@163.com" 3 | COPY . /app 4 | WORKDIR /app 5 | RUN npm i 6 | EXPOSE 80 7 | CMD ["node", "main.js"] -------------------------------------------------------------------------------- /service/node/v1/main.js: -------------------------------------------------------------------------------- 1 | const Koa = require('koa'); 2 | const Router = require('koa-router'); 3 | const axios = require('axios') 4 | const app = new Koa(); 5 | const router = new Router(); 6 | 7 | 8 | function getForwardHeaders(request) { 9 | headers = {} 10 | incoming_headers = [ 11 | 'x-request-id', 12 | 'x-b3-traceid', 13 | 'x-b3-spanid', 14 | 'x-b3-parentspanid', 15 | 'x-b3-sampled', 16 | 'x-b3-flags', 17 | 'x-ot-span-context' 18 | ] 19 | 20 | for (idx in incoming_headers) { 21 | ihdr = incoming_headers[idx] 22 | val = request.headers[ihdr] 23 | if (val !== undefined && val !== '') { 24 | headers[ihdr] = val 25 | console.log("incoming: " + ihdr + ":" + val) 26 | } 27 | } 28 | return headers 29 | } 30 | 31 | 32 | 33 | router.get('/status', async (ctx, next) => { 34 | ctx.body = 'ok'; 35 | }) 36 | 37 | router.get('/env', async (ctx, next) => { 38 | forwardHeaders = getForwardHeaders(ctx.request) 39 | // service_go_url = 'http://httpbin.org/delay/3' 40 | service_go_url = 'http://' + 'service-go' + '/env' 41 | upstream_ret = null 42 | try { 43 | // console.log(forwardHeaders) 44 | // upstream_ret = JSON.parse('{"message": "go v1"}') 45 | let start = Date.now() 46 | const response = await axios.get(service_go_url, { 47 | headers: forwardHeaders, 48 | timeout: 20000 49 | }); 50 | response_time = ((Date.now() - start) / 1000).toFixed(2) 51 | upstream_ret = response.data 52 | upstream_ret.response_time = response_time 53 | } catch (error) { 54 | console.error('error'); 55 | } 56 | if (upstream_ret) { 57 | // console.log(upstream_ret); 58 | ctx.body = { 59 | 'message': 'node v1', 60 | 'upstream': [upstream_ret] 61 | }; 62 | } else { 63 | ctx.body = { 64 | 'message': 'node v1', 65 | 'upstream': [] 66 | } 67 | } 68 | }) 69 | 70 | app.use(router.routes()).use(router.allowedMethods()); 71 | app.listen(80); -------------------------------------------------------------------------------- /service/node/v1/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "v1", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "accepts": { 8 | "version": "1.3.5", 9 | "resolved": "http://registry.npm.taobao.org/accepts/download/accepts-1.3.5.tgz", 10 | "integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=", 11 | "requires": { 12 | "mime-types": "2.1.21", 13 | "negotiator": "0.6.1" 14 | } 15 | }, 16 | "any-promise": { 17 | "version": "1.3.0", 18 | "resolved": "http://registry.npm.taobao.org/any-promise/download/any-promise-1.3.0.tgz", 19 | "integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8=" 20 | }, 21 | "axios": { 22 | "version": "0.18.0", 23 | "resolved": "http://registry.npm.taobao.org/axios/download/axios-0.18.0.tgz", 24 | "integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=", 25 | "requires": { 26 | "follow-redirects": "1.5.10", 27 | "is-buffer": "1.1.6" 28 | } 29 | }, 30 | "cache-content-type": { 31 | "version": "1.0.1", 32 | "resolved": "http://registry.npm.taobao.org/cache-content-type/download/cache-content-type-1.0.1.tgz", 33 | "integrity": "sha1-A1zeKwjuISn0qDFeqPAKANuhRTw=", 34 | "requires": { 35 | "mime-types": "2.1.21", 36 | "ylru": "1.2.1" 37 | } 38 | }, 39 | "co": { 40 | "version": "4.6.0", 41 | "resolved": "http://registry.npm.taobao.org/co/download/co-4.6.0.tgz", 42 | "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=" 43 | }, 44 | "content-disposition": { 45 | "version": "0.5.2", 46 | "resolved": "http://registry.npm.taobao.org/content-disposition/download/content-disposition-0.5.2.tgz", 47 | "integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ=" 48 | }, 49 | "content-type": { 50 | "version": "1.0.4", 51 | "resolved": "http://registry.npm.taobao.org/content-type/download/content-type-1.0.4.tgz", 52 | "integrity": "sha1-4TjMdeBAxyexlm/l5fjJruJW/js=" 53 | }, 54 | "cookies": { 55 | "version": "0.7.3", 56 | "resolved": "http://registry.npm.taobao.org/cookies/download/cookies-0.7.3.tgz", 57 | "integrity": "sha1-eRLOIfvy6MLacM8cPzUa7PWdrfo=", 58 | "requires": { 59 | "depd": "1.1.2", 60 | "keygrip": "1.0.3" 61 | } 62 | }, 63 | "debug": { 64 | "version": "3.1.0", 65 | "resolved": "http://registry.npm.taobao.org/debug/download/debug-3.1.0.tgz", 66 | "integrity": "sha1-W7WgZyYotkFJVmuhaBnmFRjGcmE=", 67 | "requires": { 68 | "ms": "2.0.0" 69 | } 70 | }, 71 | "deep-equal": { 72 | "version": "1.0.1", 73 | "resolved": "http://registry.npm.taobao.org/deep-equal/download/deep-equal-1.0.1.tgz", 74 | "integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU=" 75 | }, 76 | "delegates": { 77 | "version": "1.0.0", 78 | "resolved": "http://registry.npm.taobao.org/delegates/download/delegates-1.0.0.tgz", 79 | "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=" 80 | }, 81 | "depd": { 82 | "version": "1.1.2", 83 | "resolved": "http://registry.npm.taobao.org/depd/download/depd-1.1.2.tgz", 84 | "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" 85 | }, 86 | "destroy": { 87 | "version": "1.0.4", 88 | "resolved": "http://registry.npm.taobao.org/destroy/download/destroy-1.0.4.tgz", 89 | "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" 90 | }, 91 | "ee-first": { 92 | "version": "1.1.1", 93 | "resolved": "http://registry.npm.taobao.org/ee-first/download/ee-first-1.1.1.tgz", 94 | "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" 95 | }, 96 | "error-inject": { 97 | "version": "1.0.0", 98 | "resolved": "http://registry.npm.taobao.org/error-inject/download/error-inject-1.0.0.tgz", 99 | "integrity": "sha1-4rPZG1Su1nLzCdlQ0VSFD6EdTzc=" 100 | }, 101 | "escape-html": { 102 | "version": "1.0.3", 103 | "resolved": "http://registry.npm.taobao.org/escape-html/download/escape-html-1.0.3.tgz", 104 | "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" 105 | }, 106 | "follow-redirects": { 107 | "version": "1.5.10", 108 | "resolved": "http://registry.npm.taobao.org/follow-redirects/download/follow-redirects-1.5.10.tgz", 109 | "integrity": "sha1-e3qfmuov3/NnhqlP9kPtB/T/Xio=", 110 | "requires": { 111 | "debug": "3.1.0" 112 | } 113 | }, 114 | "fresh": { 115 | "version": "0.5.2", 116 | "resolved": "http://registry.npm.taobao.org/fresh/download/fresh-0.5.2.tgz", 117 | "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" 118 | }, 119 | "http-assert": { 120 | "version": "1.4.0", 121 | "resolved": "http://registry.npm.taobao.org/http-assert/download/http-assert-1.4.0.tgz", 122 | "integrity": "sha1-DlULT8pq3xIbvu2DJIwX5i9ZOpo=", 123 | "requires": { 124 | "deep-equal": "1.0.1", 125 | "http-errors": "1.7.1" 126 | } 127 | }, 128 | "http-errors": { 129 | "version": "1.7.1", 130 | "resolved": "http://registry.npm.taobao.org/http-errors/download/http-errors-1.7.1.tgz", 131 | "integrity": "sha1-ak/+XTUYjhw5+HJTRpBYWFLh8Cc=", 132 | "requires": { 133 | "depd": "1.1.2", 134 | "inherits": "2.0.3", 135 | "setprototypeof": "1.1.0", 136 | "statuses": "1.5.0", 137 | "toidentifier": "1.0.0" 138 | } 139 | }, 140 | "inherits": { 141 | "version": "2.0.3", 142 | "resolved": "http://registry.npm.taobao.org/inherits/download/inherits-2.0.3.tgz", 143 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" 144 | }, 145 | "is-buffer": { 146 | "version": "1.1.6", 147 | "resolved": "http://registry.npm.taobao.org/is-buffer/download/is-buffer-1.1.6.tgz", 148 | "integrity": "sha1-76ouqdqg16suoTqXsritUf776L4=" 149 | }, 150 | "is-generator-function": { 151 | "version": "1.0.7", 152 | "resolved": "http://registry.npm.taobao.org/is-generator-function/download/is-generator-function-1.0.7.tgz", 153 | "integrity": "sha1-0hMuUpuwAAp/gHlNS99c1eWBNSI=" 154 | }, 155 | "isarray": { 156 | "version": "0.0.1", 157 | "resolved": "http://registry.npm.taobao.org/isarray/download/isarray-0.0.1.tgz", 158 | "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" 159 | }, 160 | "keygrip": { 161 | "version": "1.0.3", 162 | "resolved": "http://registry.npm.taobao.org/keygrip/download/keygrip-1.0.3.tgz", 163 | "integrity": "sha1-OZ1wnwrtK6sKBZ4M3TpQI6BT4dw=" 164 | }, 165 | "koa": { 166 | "version": "2.6.2", 167 | "resolved": "http://registry.npm.taobao.org/koa/download/koa-2.6.2.tgz", 168 | "integrity": "sha1-V7pNBJsKmcrg1ZTmFE4pMZSafOE=", 169 | "requires": { 170 | "accepts": "1.3.5", 171 | "cache-content-type": "1.0.1", 172 | "content-disposition": "0.5.2", 173 | "content-type": "1.0.4", 174 | "cookies": "0.7.3", 175 | "debug": "3.1.0", 176 | "delegates": "1.0.0", 177 | "depd": "1.1.2", 178 | "destroy": "1.0.4", 179 | "error-inject": "1.0.0", 180 | "escape-html": "1.0.3", 181 | "fresh": "0.5.2", 182 | "http-assert": "1.4.0", 183 | "http-errors": "1.7.1", 184 | "is-generator-function": "1.0.7", 185 | "koa-compose": "4.1.0", 186 | "koa-convert": "1.2.0", 187 | "koa-is-json": "1.0.0", 188 | "on-finished": "2.3.0", 189 | "only": "0.0.2", 190 | "parseurl": "1.3.2", 191 | "statuses": "1.5.0", 192 | "type-is": "1.6.16", 193 | "vary": "1.1.2" 194 | } 195 | }, 196 | "koa-compose": { 197 | "version": "4.1.0", 198 | "resolved": "http://registry.npm.taobao.org/koa-compose/download/koa-compose-4.1.0.tgz", 199 | "integrity": "sha1-UHMGuTcZAdtBEhyBLpI9DWfT6Hc=" 200 | }, 201 | "koa-convert": { 202 | "version": "1.2.0", 203 | "resolved": "http://registry.npm.taobao.org/koa-convert/download/koa-convert-1.2.0.tgz", 204 | "integrity": "sha1-2kCHXfSd4FOQmNFwC1CCDOvNIdA=", 205 | "requires": { 206 | "co": "4.6.0", 207 | "koa-compose": "3.2.1" 208 | }, 209 | "dependencies": { 210 | "koa-compose": { 211 | "version": "3.2.1", 212 | "resolved": "http://registry.npm.taobao.org/koa-compose/download/koa-compose-3.2.1.tgz", 213 | "integrity": "sha1-qFzLQLfZhtjlo0Wzoazo6rz1Tec=", 214 | "requires": { 215 | "any-promise": "1.3.0" 216 | } 217 | } 218 | } 219 | }, 220 | "koa-is-json": { 221 | "version": "1.0.0", 222 | "resolved": "http://registry.npm.taobao.org/koa-is-json/download/koa-is-json-1.0.0.tgz", 223 | "integrity": "sha1-JzwH7c3Ljfaiwat9We52SRRR7BQ=" 224 | }, 225 | "koa-router": { 226 | "version": "7.4.0", 227 | "resolved": "http://registry.npm.taobao.org/koa-router/download/koa-router-7.4.0.tgz", 228 | "integrity": "sha1-ruH3rcAtXLMdfWdGXJ6syCXoxeA=", 229 | "requires": { 230 | "debug": "3.1.0", 231 | "http-errors": "1.7.1", 232 | "koa-compose": "3.2.1", 233 | "methods": "1.1.2", 234 | "path-to-regexp": "1.7.0", 235 | "urijs": "1.19.1" 236 | }, 237 | "dependencies": { 238 | "koa-compose": { 239 | "version": "3.2.1", 240 | "resolved": "http://registry.npm.taobao.org/koa-compose/download/koa-compose-3.2.1.tgz", 241 | "integrity": "sha1-qFzLQLfZhtjlo0Wzoazo6rz1Tec=", 242 | "requires": { 243 | "any-promise": "1.3.0" 244 | } 245 | } 246 | } 247 | }, 248 | "media-typer": { 249 | "version": "0.3.0", 250 | "resolved": "http://registry.npm.taobao.org/media-typer/download/media-typer-0.3.0.tgz", 251 | "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" 252 | }, 253 | "methods": { 254 | "version": "1.1.2", 255 | "resolved": "http://registry.npm.taobao.org/methods/download/methods-1.1.2.tgz", 256 | "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" 257 | }, 258 | "mime-db": { 259 | "version": "1.37.0", 260 | "resolved": "http://registry.npm.taobao.org/mime-db/download/mime-db-1.37.0.tgz", 261 | "integrity": "sha1-C2oM5v2+lXbiXx8tL96IMNwK0Ng=" 262 | }, 263 | "mime-types": { 264 | "version": "2.1.21", 265 | "resolved": "http://registry.npm.taobao.org/mime-types/download/mime-types-2.1.21.tgz", 266 | "integrity": "sha1-KJlaoey3cHQv5q5+WPkYHHRLP5Y=", 267 | "requires": { 268 | "mime-db": "1.37.0" 269 | } 270 | }, 271 | "ms": { 272 | "version": "2.0.0", 273 | "resolved": "http://registry.npm.taobao.org/ms/download/ms-2.0.0.tgz", 274 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" 275 | }, 276 | "negotiator": { 277 | "version": "0.6.1", 278 | "resolved": "http://registry.npm.taobao.org/negotiator/download/negotiator-0.6.1.tgz", 279 | "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" 280 | }, 281 | "on-finished": { 282 | "version": "2.3.0", 283 | "resolved": "http://registry.npm.taobao.org/on-finished/download/on-finished-2.3.0.tgz", 284 | "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", 285 | "requires": { 286 | "ee-first": "1.1.1" 287 | } 288 | }, 289 | "only": { 290 | "version": "0.0.2", 291 | "resolved": "http://registry.npm.taobao.org/only/download/only-0.0.2.tgz", 292 | "integrity": "sha1-Kv3oTQPlC5qO3EROMGEKcCle37Q=" 293 | }, 294 | "parseurl": { 295 | "version": "1.3.2", 296 | "resolved": "http://registry.npm.taobao.org/parseurl/download/parseurl-1.3.2.tgz", 297 | "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" 298 | }, 299 | "path-to-regexp": { 300 | "version": "1.7.0", 301 | "resolved": "http://registry.npm.taobao.org/path-to-regexp/download/path-to-regexp-1.7.0.tgz", 302 | "integrity": "sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=", 303 | "requires": { 304 | "isarray": "0.0.1" 305 | } 306 | }, 307 | "setprototypeof": { 308 | "version": "1.1.0", 309 | "resolved": "http://registry.npm.taobao.org/setprototypeof/download/setprototypeof-1.1.0.tgz", 310 | "integrity": "sha1-0L2FU2iHtv58DYGMuWLZ2RxU5lY=" 311 | }, 312 | "statuses": { 313 | "version": "1.5.0", 314 | "resolved": "http://registry.npm.taobao.org/statuses/download/statuses-1.5.0.tgz", 315 | "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" 316 | }, 317 | "toidentifier": { 318 | "version": "1.0.0", 319 | "resolved": "http://registry.npm.taobao.org/toidentifier/download/toidentifier-1.0.0.tgz", 320 | "integrity": "sha1-fhvjRw8ed5SLxD2Uo8j013UrpVM=" 321 | }, 322 | "type-is": { 323 | "version": "1.6.16", 324 | "resolved": "http://registry.npm.taobao.org/type-is/download/type-is-1.6.16.tgz", 325 | "integrity": "sha1-+JzjQVQcZysl7nrjxz3uOyvlAZQ=", 326 | "requires": { 327 | "media-typer": "0.3.0", 328 | "mime-types": "2.1.21" 329 | } 330 | }, 331 | "urijs": { 332 | "version": "1.19.1", 333 | "resolved": "http://registry.npm.taobao.org/urijs/download/urijs-1.19.1.tgz", 334 | "integrity": "sha1-Ww/1MMDL3oOG9jQiNbpcpumV0lo=" 335 | }, 336 | "vary": { 337 | "version": "1.1.2", 338 | "resolved": "http://registry.npm.taobao.org/vary/download/vary-1.1.2.tgz", 339 | "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" 340 | }, 341 | "ylru": { 342 | "version": "1.2.1", 343 | "resolved": "http://registry.npm.taobao.org/ylru/download/ylru-1.2.1.tgz", 344 | "integrity": "sha1-9Xa2M0FUeYnB3nuiiHYJI7J/6E8=" 345 | } 346 | } 347 | } 348 | -------------------------------------------------------------------------------- /service/node/v1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "v1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "main.js", 6 | "dependencies": { 7 | "axios": "^0.18.0", 8 | "koa": "^2.5.1", 9 | "koa-router": "^7.4.0" 10 | }, 11 | "devDependencies": {}, 12 | "scripts": { 13 | "test": "echo \"Error: no test specified\" && exit 1" 14 | }, 15 | "author": "", 16 | "license": "ISC" 17 | } 18 | -------------------------------------------------------------------------------- /service/node/v2/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/node 3 | # Edit at https://www.gitignore.io/?templates=node 4 | 5 | ### Node ### 6 | # Logs 7 | logs 8 | *.log 9 | npm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # Optional npm cache directory 48 | .npm 49 | 50 | # Optional eslint cache 51 | .eslintcache 52 | 53 | # Optional REPL history 54 | .node_repl_history 55 | 56 | # Output of 'npm pack' 57 | *.tgz 58 | 59 | # Yarn Integrity file 60 | .yarn-integrity 61 | 62 | # dotenv environment variables file 63 | .env 64 | 65 | # parcel-bundler cache (https://parceljs.org/) 66 | .cache 67 | 68 | # next.js build output 69 | .next 70 | 71 | # nuxt.js build output 72 | .nuxt 73 | 74 | # vuepress build output 75 | .vuepress/dist 76 | 77 | # Serverless directories 78 | .serverless 79 | 80 | # FuseBox cache 81 | .fusebox/ 82 | 83 | # End of https://www.gitignore.io/api/node 84 | -------------------------------------------------------------------------------- /service/node/v2/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:10-alpine 2 | LABEL maintainer="will835559313@163.com" 3 | COPY . /app 4 | WORKDIR /app 5 | RUN npm i 6 | EXPOSE 80 7 | CMD ["node", "main.js"] -------------------------------------------------------------------------------- /service/node/v2/main.js: -------------------------------------------------------------------------------- 1 | const Koa = require('koa'); 2 | const Router = require('koa-router'); 3 | const axios = require('axios') 4 | const app = new Koa(); 5 | const router = new Router(); 6 | 7 | 8 | function getForwardHeaders(request) { 9 | headers = {} 10 | incoming_headers = [ 11 | 'x-request-id', 12 | 'x-b3-traceid', 13 | 'x-b3-spanid', 14 | 'x-b3-parentspanid', 15 | 'x-b3-sampled', 16 | 'x-b3-flags', 17 | 'x-ot-span-context' 18 | ] 19 | 20 | for (idx in incoming_headers) { 21 | ihdr = incoming_headers[idx] 22 | val = request.headers[ihdr] 23 | if (val !== undefined && val !== '') { 24 | headers[ihdr] = val 25 | console.log("incoming: " + ihdr + ":" + val) 26 | } 27 | } 28 | return headers 29 | } 30 | 31 | 32 | 33 | router.get('/status', async (ctx, next) => { 34 | ctx.body = 'ok'; 35 | }) 36 | 37 | router.get('/env', async (ctx, next) => { 38 | forwardHeaders = getForwardHeaders(ctx.request) 39 | // service_go_url = 'http://httpbin.org/delay/10' 40 | service_go_url = 'http://' + 'service-go' + '/env' 41 | upstream_ret = null 42 | try { 43 | // console.log(forwardHeaders) 44 | // upstream_ret = JSON.parse('{"message": "go v1"}') 45 | let start = Date.now() 46 | const response = await axios.get(service_go_url, { 47 | headers: forwardHeaders, 48 | timeout: 20000 49 | }); 50 | response_time = ((Date.now() - start) / 1000).toFixed(2) 51 | upstream_ret = response.data 52 | upstream_ret.response_time = response_time 53 | } catch (error) { 54 | console.error('error'); 55 | } 56 | if (upstream_ret) { 57 | // console.log(upstream_ret); 58 | ctx.body = { 59 | 'message': 'node v2', 60 | 'upstream': [upstream_ret] 61 | }; 62 | } else { 63 | ctx.body = { 64 | 'message': 'node v2', 65 | 'upstream': [] 66 | } 67 | } 68 | }) 69 | 70 | app.use(router.routes()).use(router.allowedMethods()); 71 | app.listen(80); -------------------------------------------------------------------------------- /service/node/v2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "v1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "main.js", 6 | "dependencies": { 7 | "axios": "^0.18.0", 8 | "koa": "^2.5.1", 9 | "koa-router": "^7.4.0" 10 | }, 11 | "devDependencies": {}, 12 | "scripts": { 13 | "test": "echo \"Error: no test specified\" && exit 1" 14 | }, 15 | "author": "", 16 | "license": "ISC" 17 | } 18 | -------------------------------------------------------------------------------- /service/python/service-python-v2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: service-python-v2 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: service-python 9 | version: v2 10 | replicas: 1 11 | template: 12 | metadata: 13 | labels: 14 | app: service-python 15 | version: v2 16 | spec: 17 | restartPolicy: Always 18 | containers: 19 | - name: service-python 20 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-python:v2 21 | ports: 22 | - containerPort: 80 23 | resources: 24 | requests: 25 | cpu: 50m 26 | memory: 50Mi 27 | limits: 28 | cpu: 100m 29 | memory: 100Mi 30 | -------------------------------------------------------------------------------- /service/python/service-python-with-serviceaccount.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: service-python 5 | labels: 6 | app: service-python 7 | spec: 8 | selector: 9 | app: service-python 10 | ports: 11 | - name: http 12 | port: 80 13 | --- 14 | apiVersion: v1 15 | kind: ServiceAccount 16 | metadata: 17 | name: service-python 18 | --- 19 | apiVersion: apps/v1 20 | kind: Deployment 21 | metadata: 22 | name: service-python-v1 23 | spec: 24 | selector: 25 | matchLabels: 26 | app: service-python 27 | version: v1 28 | replicas: 1 29 | template: 30 | metadata: 31 | labels: 32 | app: service-python 33 | version: v1 34 | spec: 35 | restartPolicy: Always 36 | serviceAccountName: service-python 37 | containers: 38 | - name: service-python 39 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-python:v1 40 | ports: 41 | - containerPort: 80 42 | resources: 43 | requests: 44 | cpu: 50m 45 | memory: 50Mi 46 | limits: 47 | cpu: 100m 48 | memory: 100Mi 49 | --- 50 | apiVersion: apps/v1 51 | kind: Deployment 52 | metadata: 53 | name: service-python-v2 54 | spec: 55 | selector: 56 | matchLabels: 57 | app: service-python 58 | version: v2 59 | replicas: 1 60 | template: 61 | metadata: 62 | labels: 63 | app: service-python 64 | version: v2 65 | spec: 66 | restartPolicy: Always 67 | serviceAccountName: service-python 68 | containers: 69 | - name: service-python 70 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-python:v2 71 | ports: 72 | - containerPort: 80 73 | resources: 74 | requests: 75 | cpu: 50m 76 | memory: 50Mi 77 | limits: 78 | cpu: 100m 79 | memory: 100Mi 80 | -------------------------------------------------------------------------------- /service/python/service-python.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: service-python 5 | labels: 6 | app: service-python 7 | spec: 8 | selector: 9 | app: service-python 10 | ports: 11 | - name: http 12 | port: 80 13 | --- 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: service-python-v1 18 | spec: 19 | selector: 20 | matchLabels: 21 | app: service-python 22 | version: v1 23 | replicas: 1 24 | template: 25 | metadata: 26 | labels: 27 | app: service-python 28 | version: v1 29 | spec: 30 | restartPolicy: Always 31 | containers: 32 | - name: service-python 33 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-python:v1 34 | ports: 35 | - containerPort: 80 36 | resources: 37 | requests: 38 | cpu: 50m 39 | memory: 50Mi 40 | limits: 41 | cpu: 100m 42 | memory: 100Mi 43 | --- 44 | apiVersion: apps/v1 45 | kind: Deployment 46 | metadata: 47 | name: service-python-v2 48 | spec: 49 | selector: 50 | matchLabels: 51 | app: service-python 52 | version: v2 53 | replicas: 1 54 | template: 55 | metadata: 56 | labels: 57 | app: service-python 58 | version: v2 59 | spec: 60 | restartPolicy: Always 61 | containers: 62 | - name: service-python 63 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-python:v2 64 | ports: 65 | - containerPort: 80 66 | resources: 67 | requests: 68 | cpu: 50m 69 | memory: 50Mi 70 | limits: 71 | cpu: 100m 72 | memory: 100Mi 73 | -------------------------------------------------------------------------------- /service/python/v1/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/python 2 | # Edit at https://www.gitignore.io/?templates=python 3 | 4 | ### Python ### 5 | # Byte-compiled / optimized / DLL files 6 | __pycache__/ 7 | *.py[cod] 8 | *$py.class 9 | 10 | # C extensions 11 | *.so 12 | 13 | # Distribution / packaging 14 | .Python 15 | build/ 16 | develop-eggs/ 17 | dist/ 18 | downloads/ 19 | eggs/ 20 | .eggs/ 21 | lib/ 22 | lib64/ 23 | parts/ 24 | sdist/ 25 | var/ 26 | wheels/ 27 | *.egg-info/ 28 | .installed.cfg 29 | *.egg 30 | MANIFEST 31 | 32 | # PyInstaller 33 | # Usually these files are written by a python script from a template 34 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 35 | *.manifest 36 | *.spec 37 | 38 | # Installer logs 39 | pip-log.txt 40 | pip-delete-this-directory.txt 41 | 42 | # Unit test / coverage reports 43 | htmlcov/ 44 | .tox/ 45 | .nox/ 46 | .coverage 47 | .coverage.* 48 | .cache 49 | nosetests.xml 50 | coverage.xml 51 | *.cover 52 | .hypothesis/ 53 | .pytest_cache/ 54 | 55 | # Translations 56 | *.mo 57 | *.pot 58 | 59 | # Django stuff: 60 | *.log 61 | local_settings.py 62 | db.sqlite3 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # celery beat schedule file 88 | celerybeat-schedule 89 | 90 | # SageMath parsed files 91 | *.sage.py 92 | 93 | # Environments 94 | .env 95 | .venv 96 | env/ 97 | venv/ 98 | ENV/ 99 | env.bak/ 100 | venv.bak/ 101 | 102 | # Spyder project settings 103 | .spyderproject 104 | .spyproject 105 | 106 | # Rope project settings 107 | .ropeproject 108 | 109 | # mkdocs documentation 110 | /site 111 | 112 | # mypy 113 | .mypy_cache/ 114 | .dmypy.json 115 | dmypy.json 116 | 117 | # Pyre type checker 118 | .pyre/ 119 | 120 | ### Python Patch ### 121 | .venv/ 122 | 123 | ### Python.VirtualEnv Stack ### 124 | # Virtualenv 125 | # http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ 126 | [Bb]in 127 | [Ii]nclude 128 | [Ll]ib 129 | [Ll]ib64 130 | [Ll]ocal 131 | [Ss]cripts 132 | pyvenv.cfg 133 | pip-selfcheck.json 134 | 135 | # End of https://www.gitignore.io/api/python 136 | -------------------------------------------------------------------------------- /service/python/v1/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:2-alpine 2 | LABEL maintainer="will835559313@163.com" 3 | COPY . /app 4 | WORKDIR /app 5 | RUN pip install -r requirements.txt 6 | CMD [ "python", "main.py" ] -------------------------------------------------------------------------------- /service/python/v1/main.py: -------------------------------------------------------------------------------- 1 | import time 2 | import requests 3 | from functools import partial 4 | from flask import Flask, jsonify, g, request 5 | from multiprocessing.dummy import Pool as ThreadPool 6 | 7 | 8 | app = Flask(__name__) 9 | 10 | 11 | def getForwardHeaders(request): 12 | headers = {} 13 | incoming_headers = [ 14 | 'x-request-id', 15 | 'x-b3-traceid', 16 | 'x-b3-spanid', 17 | 'x-b3-parentspanid', 18 | 'x-b3-sampled', 19 | 'x-b3-flags', 20 | 'x-ot-span-context' 21 | ] 22 | 23 | for ihdr in incoming_headers: 24 | val = request.headers.get(ihdr) 25 | if val is not None: 26 | headers[ihdr] = val 27 | # print("incoming: "+ihdr+":"+val) 28 | 29 | return headers 30 | 31 | 32 | @app.before_request 33 | def before_request(): 34 | g.forwardHeaders = getForwardHeaders(request) 35 | 36 | 37 | def get_url_response(url, headers={}): 38 | try: 39 | start = time.time() 40 | resp = requests.get(url, headers=headers, timeout=20) 41 | response_time = round(time.time() - start, 2) 42 | data = resp.json() 43 | data['response_time'] = response_time 44 | except Exception as e: 45 | print(e) 46 | data = None 47 | return data 48 | 49 | 50 | @app.route("/env") 51 | def env(): 52 | # service_lua_url = 'http://httpbin.org/delay/3' 53 | # service_node_url = 'http://httpbin.org/delay/4' 54 | 55 | service_lua_url = 'http://' + 'service-lua' + '/env' 56 | service_node_url = 'http://' + 'service-node' + '/env' 57 | 58 | services_url = [service_lua_url, service_node_url] 59 | pool = ThreadPool(2) 60 | wrap_get_url_response = partial(get_url_response, headers=g.forwardHeaders) 61 | results = pool.map(wrap_get_url_response, services_url) 62 | upstream = [r for r in results if r] 63 | 64 | return jsonify({ 65 | "message": 'python v1', 66 | "upstream": upstream 67 | }) 68 | 69 | 70 | @app.route("/status") 71 | def status(): 72 | return "ok" 73 | 74 | 75 | if __name__ == '__main__': 76 | app.run(host='0.0.0.0', port=80) 77 | -------------------------------------------------------------------------------- /service/python/v1/requirements.txt: -------------------------------------------------------------------------------- 1 | flask 2 | requests -------------------------------------------------------------------------------- /service/python/v2/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/python 2 | # Edit at https://www.gitignore.io/?templates=python 3 | 4 | ### Python ### 5 | # Byte-compiled / optimized / DLL files 6 | __pycache__/ 7 | *.py[cod] 8 | *$py.class 9 | 10 | # C extensions 11 | *.so 12 | 13 | # Distribution / packaging 14 | .Python 15 | build/ 16 | develop-eggs/ 17 | dist/ 18 | downloads/ 19 | eggs/ 20 | .eggs/ 21 | lib/ 22 | lib64/ 23 | parts/ 24 | sdist/ 25 | var/ 26 | wheels/ 27 | *.egg-info/ 28 | .installed.cfg 29 | *.egg 30 | MANIFEST 31 | 32 | # PyInstaller 33 | # Usually these files are written by a python script from a template 34 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 35 | *.manifest 36 | *.spec 37 | 38 | # Installer logs 39 | pip-log.txt 40 | pip-delete-this-directory.txt 41 | 42 | # Unit test / coverage reports 43 | htmlcov/ 44 | .tox/ 45 | .nox/ 46 | .coverage 47 | .coverage.* 48 | .cache 49 | nosetests.xml 50 | coverage.xml 51 | *.cover 52 | .hypothesis/ 53 | .pytest_cache/ 54 | 55 | # Translations 56 | *.mo 57 | *.pot 58 | 59 | # Django stuff: 60 | *.log 61 | local_settings.py 62 | db.sqlite3 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # celery beat schedule file 88 | celerybeat-schedule 89 | 90 | # SageMath parsed files 91 | *.sage.py 92 | 93 | # Environments 94 | .env 95 | .venv 96 | env/ 97 | venv/ 98 | ENV/ 99 | env.bak/ 100 | venv.bak/ 101 | 102 | # Spyder project settings 103 | .spyderproject 104 | .spyproject 105 | 106 | # Rope project settings 107 | .ropeproject 108 | 109 | # mkdocs documentation 110 | /site 111 | 112 | # mypy 113 | .mypy_cache/ 114 | .dmypy.json 115 | dmypy.json 116 | 117 | # Pyre type checker 118 | .pyre/ 119 | 120 | ### Python Patch ### 121 | .venv/ 122 | 123 | ### Python.VirtualEnv Stack ### 124 | # Virtualenv 125 | # http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ 126 | [Bb]in 127 | [Ii]nclude 128 | [Ll]ib 129 | [Ll]ib64 130 | [Ll]ocal 131 | [Ss]cripts 132 | pyvenv.cfg 133 | pip-selfcheck.json 134 | 135 | # End of https://www.gitignore.io/api/python 136 | -------------------------------------------------------------------------------- /service/python/v2/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3-alpine 2 | LABEL maintainer="will835559313@163.com" 3 | COPY . /app 4 | WORKDIR /app 5 | RUN pip install -r requirements.txt 6 | CMD [ "python", "main.py" ] -------------------------------------------------------------------------------- /service/python/v2/main.py: -------------------------------------------------------------------------------- 1 | import time 2 | import requests 3 | from functools import partial 4 | from flask import Flask, jsonify, g, request 5 | from multiprocessing.dummy import Pool as ThreadPool 6 | 7 | 8 | app = Flask(__name__) 9 | 10 | 11 | def getForwardHeaders(request): 12 | headers = {} 13 | incoming_headers = [ 14 | 'x-request-id', 15 | 'x-b3-traceid', 16 | 'x-b3-spanid', 17 | 'x-b3-parentspanid', 18 | 'x-b3-sampled', 19 | 'x-b3-flags', 20 | 'x-ot-span-context' 21 | ] 22 | 23 | for ihdr in incoming_headers: 24 | val = request.headers.get(ihdr) 25 | if val is not None: 26 | headers[ihdr] = val 27 | # print("incoming: "+ihdr+":"+val) 28 | 29 | return headers 30 | 31 | 32 | @app.before_request 33 | def before_request(): 34 | g.forwardHeaders = getForwardHeaders(request) 35 | 36 | 37 | def get_url_response(url, headers={}): 38 | try: 39 | start = time.time() 40 | resp = requests.get(url, headers=headers, timeout=20) 41 | response_time = round(time.time() - start, 2) 42 | data = resp.json() 43 | data['response_time'] = response_time 44 | except Exception as e: 45 | print(e) 46 | data = None 47 | return data 48 | 49 | 50 | @app.route("/env") 51 | def env(): 52 | # service_lua_url = 'http://httpbin.org/delay/3' 53 | # service_node_url = 'http://httpbin.org/delay/4' 54 | 55 | service_lua_url = 'http://' + 'service-lua' + '/env' 56 | service_node_url = 'http://' + 'service-node' + '/env' 57 | 58 | services_url = [service_lua_url, service_node_url] 59 | pool = ThreadPool(2) 60 | wrap_get_url_response = partial(get_url_response, headers=g.forwardHeaders) 61 | results = pool.map(wrap_get_url_response, services_url) 62 | upstream = [r for r in results if r] 63 | 64 | return jsonify({ 65 | "message": 'python v2', 66 | "upstream": upstream 67 | }) 68 | 69 | 70 | @app.route("/status") 71 | def status(): 72 | return "ok" 73 | 74 | 75 | if __name__ == '__main__': 76 | app.run(host='0.0.0.0', port=80) 77 | -------------------------------------------------------------------------------- /service/python/v2/requirements.txt: -------------------------------------------------------------------------------- 1 | flask 2 | requests -------------------------------------------------------------------------------- /service/redis/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.11-alpine as builder 2 | LABEL maintainer="will835559313@163.com" 3 | COPY . /app 4 | WORKDIR /app 5 | RUN apk update && apk add git \ 6 | && go get github.com/gin-gonic/gin \ 7 | && go get github.com/go-redis/redis \ 8 | && go build 9 | 10 | FROM alpine:latest 11 | WORKDIR /app 12 | COPY --from=builder /app/app . 13 | EXPOSE 80 14 | CMD ["./app"] -------------------------------------------------------------------------------- /service/redis/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/gin-gonic/gin" 7 | "github.com/go-redis/redis" 8 | ) 9 | 10 | // NewClient new redis client 11 | func NewClient() *redis.Client { 12 | client := redis.NewClient(&redis.Options{ 13 | Addr: "redis:6379", 14 | Password: "", 15 | DB: 0, 16 | }) 17 | return client 18 | } 19 | 20 | func main() { 21 | r := gin.Default() 22 | client := NewClient() 23 | r.GET("/env", func(c *gin.Context) { 24 | val, err := client.Info().Result() 25 | if err != nil { 26 | log.Print(err) 27 | } 28 | c.String(200, val) 29 | }) 30 | r.GET("/status", func(c *gin.Context) { 31 | c.String(200, "ok") 32 | }) 33 | r.Run(":80") 34 | } 35 | -------------------------------------------------------------------------------- /service/redis/service-redis.yaml: -------------------------------------------------------------------------------- 1 | kind: Service 2 | apiVersion: v1 3 | metadata: 4 | name: service-redis 5 | labels: 6 | app: service-redis 7 | spec: 8 | selector: 9 | app: service-redis 10 | ports: 11 | - name: http 12 | port: 80 13 | --- 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: service-redis-v1 18 | spec: 19 | selector: 20 | matchLabels: 21 | app: service-redis 22 | version: v1 23 | replicas: 1 24 | template: 25 | metadata: 26 | labels: 27 | app: service-redis 28 | version: v1 29 | spec: 30 | restartPolicy: Always 31 | containers: 32 | - name: service-redis 33 | image: registry.cn-shanghai.aliyuncs.com/istio-lab/service-redis:v1 34 | ports: 35 | - containerPort: 80 36 | resources: 37 | requests: 38 | cpu: 50m 39 | memory: 50Mi 40 | limits: 41 | cpu: 100m 42 | memory: 100Mi -------------------------------------------------------------------------------- /vagrant/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant.configure("2") do |config| 5 | (1..3).each do |i| 6 | config.vm.define "lab#{i}" do |node| 7 | node.vm.box = "centos-7.4-base" 8 | 9 | node.ssh.insert_key = false 10 | node.vm.hostname = "lab#{i}" 11 | 12 | node.vm.network "private_network", ip: "11.11.11.11#{i}" 13 | 14 | node.vm.provision "shell", run: "always", 15 | inline: "ntpdate ntp.api.bz" 16 | 17 | node.vm.provision "shell", run: "always", 18 | inline: "echo hello from lab#{i}" 19 | 20 | node.vm.provider "virtualbox" do |v| 21 | v.cpus = 2 22 | v.customize ["modifyvm", :id, "--name", "lab#{i}", "--memory", "2048"] 23 | end 24 | end 25 | end 26 | end --------------------------------------------------------------------------------