├── jdk-example
├── .java-version
├── meeting-server
│ ├── .dockerignore
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ ├── module-info.java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── jdk
│ │ │ └── MeetingServer.java
│ ├── Dockerfile
│ └── pom.xml
├── work-server
│ ├── .dockerignore
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ ├── module-info.java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── jdk
│ │ │ └── WorkServer.java
│ ├── Dockerfile
│ └── pom.xml
├── kubernetes-latest
│ ├── work-sa.yaml
│ ├── meeting-sa.yaml
│ ├── work-svc.yaml
│ ├── meeting-svc.yaml
│ ├── meeting-deployment-latest.yaml
│ └── work-deployment-latest.yaml
├── istio-auth
│ ├── istio-auth-rbac.yaml
│ ├── istio-rbac-work-server.yaml
│ └── istio-rbac-meeting-server.yaml
├── istio-rules
│ ├── meeting-dest.yaml
│ ├── serviceentry.xml
│ ├── gateway.yaml
│ ├── work-v1v2-dest.yaml
│ ├── meeting-vs-retry.yaml
│ ├── work-vs.yaml
│ ├── meeting-vs-503.yaml
│ ├── work-vs-v1.yaml
│ ├── work-vs-v2.yaml
│ └── meeting-dest-cb.yaml
├── kubernetes-v1
│ ├── meeting-deployment-v1.yaml
│ └── work-deployment-v1.yaml
├── kubernetes-v2
│ └── work-deployment-v2.yaml
├── README.md
└── pom.xml
├── spring-boot-example
├── meeting-server
│ ├── src
│ │ ├── main
│ │ │ ├── resources
│ │ │ │ └── application.properties
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── meetingserver
│ │ │ │ └── MeetingServerApplication.java
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── meetingserver
│ │ │ └── MeetingServerApplicationTests.java
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.properties
│ │ │ └── maven-wrapper.jar
│ ├── Dockerfile
│ ├── .gitignore
│ ├── pom.xml
│ ├── mvnw.cmd
│ └── mvnw
├── work-server
│ ├── src
│ │ ├── main
│ │ │ ├── resources
│ │ │ │ └── application.properties
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── workserver
│ │ │ │ └── WorkServerApplication.java
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── workserver
│ │ │ └── WorkServerApplicationTests.java
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.properties
│ │ │ └── maven-wrapper.jar
│ ├── Dockerfile
│ ├── .gitignore
│ ├── pom.xml
│ ├── mvnw.cmd
│ └── mvnw
├── guestbook-ui
│ ├── Dockerfile
│ ├── src
│ │ ├── main
│ │ │ ├── resources
│ │ │ │ ├── application.properties
│ │ │ │ └── templates
│ │ │ │ │ └── index.html
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── guestbook
│ │ │ │ ├── HelloworldUiApplication.java
│ │ │ │ ├── ApplicationConfig.java
│ │ │ │ ├── HelloworldUiController.java
│ │ │ │ ├── HelloworldService.java
│ │ │ │ └── GuestbookService.java
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── guestbook
│ │ │ └── HelloworldUiApplicationTests.java
│ └── pom.xml
├── guestbook-service
│ ├── Dockerfile
│ ├── src
│ │ ├── test
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── guestbook
│ │ │ │ └── GuestbookServiceApplicationTests.java
│ │ └── main
│ │ │ ├── resources
│ │ │ └── application.yaml
│ │ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── guestbook
│ │ │ ├── MessageService.java
│ │ │ ├── GuestbookServiceApplication.java
│ │ │ └── Message.java
│ └── pom.xml
├── helloworld-service
│ ├── Dockerfile
│ ├── src
│ │ ├── main
│ │ │ ├── resources
│ │ │ │ └── application.properties
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── guestbook
│ │ │ │ └── HelloworldApplication.java
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── guestbook
│ │ │ └── HelloworldApplicationTests.java
│ └── pom.xml
├── istio-rules
│ ├── istio-auth-rbac.yaml
│ ├── guestbook-ui-dest.yaml
│ ├── gateway.yaml
│ ├── guestbook-ui-vs.yaml
│ ├── guestbook-service-retry.yaml
│ ├── guestbook-service-503.yaml
│ ├── guestbook-ui-vs-v1.yaml
│ ├── guestbook-ui-vs-delay.yaml
│ ├── guestbook-ui-vs-20p-v2.yaml
│ ├── guestbook-service-dest.yaml
│ ├── istio-role-webuser.yaml
│ ├── guestbook-ui-vs-chrome.yaml
│ ├── istio-role-guestbook-service-rw.yaml
│ ├── istio-role-viewer.yaml
│ └── guestbook-service-deny.yaml
├── kubernetes-mtls
│ ├── service-accounts.yaml
│ ├── redis-service.yaml
│ ├── mysql-pvc.yaml
│ ├── ui-service.yaml
│ ├── guestbook-service.yaml
│ ├── helloworld-service.yaml
│ ├── mysql-service.yaml
│ ├── redis-deployment.yaml
│ ├── guestbook-deployment-v1.yaml
│ ├── mysql-deployment.yaml
│ ├── helloworld-deployment-v1.yaml
│ ├── ui-deployment-v1.yaml
│ └── ui-deployment-v2.yaml
├── kubernetes
│ ├── mysql-pvc.yaml
│ ├── redis-service.yaml
│ ├── ui-service.yaml
│ ├── guestbook-service.yaml
│ ├── helloworld-service.yaml
│ ├── mysql-service.yaml
│ ├── redis-deployment.yaml
│ ├── guestbook-deployment-v1.yaml
│ ├── helloworld-deployment-v1.yaml
│ ├── mysql-deployment.yaml
│ └── ui-deployment-v1.yaml
├── README.md
├── kubernetes-v2
│ ├── ui-deployment-v2.yaml
│ └── helloworld-deployment-v2.yaml
└── pom.xml
├── README.md
├── .gitignore
├── pom.xml
├── CONTRIBUTING.md
├── visualizer
├── style.css
├── index.html
├── script.js
└── LICENSE
└── LICENSE
/jdk-example/.java-version:
--------------------------------------------------------------------------------
1 | 9
2 |
--------------------------------------------------------------------------------
/jdk-example/meeting-server/.dockerignore:
--------------------------------------------------------------------------------
1 | **/*
2 | !target/*.jar
3 |
--------------------------------------------------------------------------------
/jdk-example/work-server/.dockerignore:
--------------------------------------------------------------------------------
1 | **/*
2 | !target/*.jar
3 |
--------------------------------------------------------------------------------
/spring-boot-example/meeting-server/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=8081
2 |
--------------------------------------------------------------------------------
/jdk-example/meeting-server/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 | module com.example.jdk {
2 | requires jdk.httpserver;
3 | }
4 |
--------------------------------------------------------------------------------
/jdk-example/kubernetes-latest/work-sa.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: ServiceAccount
3 | metadata:
4 | name: work-server
5 |
--------------------------------------------------------------------------------
/jdk-example/kubernetes-latest/meeting-sa.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: ServiceAccount
3 | metadata:
4 | name: meeting-server
5 |
--------------------------------------------------------------------------------
/spring-boot-example/work-server/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.sleuth.propagation-keys=x-request-id,x-ot-span-context
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | This is the source code material for the Istio Codelab.
2 |
3 | See [Istio Code Lab](http://bit.ly/istio-lab) for setup instructions.
4 |
--------------------------------------------------------------------------------
/jdk-example/work-server/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 | module com.example.jdk {
2 | requires jdk.httpserver;
3 | requires jdk.incubator.httpclient;
4 | }
5 |
--------------------------------------------------------------------------------
/jdk-example/meeting-server/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:9-jre-slim
2 | COPY target/meeting-server-1.0-SNAPSHOT.jar /app.jar
3 |
4 | ENTRYPOINT ["java", "-jar", "/app.jar"]
5 |
--------------------------------------------------------------------------------
/spring-boot-example/work-server/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-example/meeting-server/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-example/work-server/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saturnism/istio-by-example-java/HEAD/spring-boot-example/work-server/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-example/meeting-server/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saturnism/istio-by-example-java/HEAD/spring-boot-example/meeting-server/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-example/work-server/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8u131-jre-alpine
2 |
3 | COPY target/work-server-0.0.1-SNAPSHOT.jar /app/app.jar
4 |
5 | ENTRYPOINT ["java", "-jar", "/app/app.jar"]
6 |
--------------------------------------------------------------------------------
/spring-boot-example/meeting-server/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8u131-jre-alpine
2 |
3 | COPY target/meeting-server-0.0.1-SNAPSHOT.jar /app/app.jar
4 |
5 | ENTRYPOINT ["java", "-jar", "/app/app.jar"]
6 |
--------------------------------------------------------------------------------
/jdk-example/work-server/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:9-jre-slim
2 | COPY target/work-server-1.0-SNAPSHOT.jar /app.jar
3 |
4 | ENTRYPOINT ["java", "--add-modules", "jdk.incubator.httpclient", "-jar", "/app.jar"]
5 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-ui/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8u131-jre-alpine
2 |
3 | COPY target/lib/* /app/lib/
4 | COPY target/guestbook-ui-0.0.1-SNAPSHOT.jar /app/app.jar
5 |
6 | ENTRYPOINT ["java", "-jar", "/app/app.jar"]
7 |
--------------------------------------------------------------------------------
/jdk-example/istio-auth/istio-auth-rbac.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: "rbac.istio.io/v1alpha1"
2 | kind: RbacConfig
3 | metadata:
4 | name: default
5 | spec:
6 | mode: 'ON_WITH_INCLUSION'
7 | inclusion:
8 | namespaces: ["default"]
9 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-service/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8u131-jre-alpine
2 |
3 | COPY target/lib/* /app/lib/
4 | COPY target/guestbook-service-0.0.1-SNAPSHOT.jar /app/app.jar
5 |
6 | ENTRYPOINT ["java", "-jar", "/app/app.jar"]
7 |
--------------------------------------------------------------------------------
/spring-boot-example/helloworld-service/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8u131-jre-alpine
2 |
3 | COPY target/lib/* /app/lib/
4 | COPY target/helloworld-service-0.0.1-SNAPSHOT.jar /app/app.jar
5 |
6 | ENTRYPOINT ["java", "-jar", "/app/app.jar"]
7 |
--------------------------------------------------------------------------------
/spring-boot-example/istio-rules/istio-auth-rbac.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: "rbac.istio.io/v1alpha1"
2 | kind: RbacConfig
3 | metadata:
4 | name: default
5 | spec:
6 | mode: 'ON_WITH_INCLUSION'
7 | inclusion:
8 | namespaces: ["default"]
9 |
--------------------------------------------------------------------------------
/spring-boot-example/helloworld-service/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | version=1.0
2 | greeting=Hello $name from $hostname with $version
3 | spring.application.name=helloworld-service
4 | spring.sleuth.propagation-keys=x-request-id,x-ot-span-context
5 |
--------------------------------------------------------------------------------
/jdk-example/istio-rules/meeting-dest.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: DestinationRule
3 | metadata:
4 | name: meeting-server
5 | spec:
6 | host: meeting-server
7 | trafficPolicy:
8 | loadBalancer:
9 | simple: ROUND_ROBIN
10 |
--------------------------------------------------------------------------------
/jdk-example/istio-rules/serviceentry.xml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: ServiceEntry
3 | metadata:
4 | name: debian
5 | spec:
6 | hosts:
7 | - "*.debian.org"
8 | location: MESH_EXTERNAL
9 | ports:
10 | - number: 80
11 | name: http
12 | protocol: HTTP
13 |
--------------------------------------------------------------------------------
/jdk-example/istio-rules/gateway.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: Gateway
3 | metadata:
4 | name: work-gateway
5 | spec:
6 | selector:
7 | istio: ingressgateway
8 | servers:
9 | - hosts:
10 | - "*"
11 | port:
12 | number: 80
13 | name: http
14 | protocol: HTTP
15 |
--------------------------------------------------------------------------------
/jdk-example/istio-rules/work-v1v2-dest.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: DestinationRule
3 | metadata:
4 | name: work-server
5 | spec:
6 | host: work-server
7 | subsets:
8 | - name: v1
9 | labels:
10 | version: "latest"
11 | - name: v2
12 | labels:
13 | version: "2.0"
14 |
--------------------------------------------------------------------------------
/spring-boot-example/istio-rules/guestbook-ui-dest.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: DestinationRule
3 | metadata:
4 | name: guestbook-ui
5 | spec:
6 | host: guestbook-ui
7 | subsets:
8 | - name: v1
9 | labels:
10 | version: "1.0"
11 | - name: v2
12 | labels:
13 | version: "2.0"
14 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes-mtls/service-accounts.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: ServiceAccount
3 | metadata:
4 | name: guestbook-ui
5 | ---
6 | apiVersion: v1
7 | kind: ServiceAccount
8 | metadata:
9 | name: guestbook-service
10 | ---
11 | apiVersion: v1
12 | kind: ServiceAccount
13 | metadata:
14 | name: helloworld-service
15 |
--------------------------------------------------------------------------------
/spring-boot-example/istio-rules/gateway.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: Gateway
3 | metadata:
4 | name: guestbook-gateway
5 | spec:
6 | selector:
7 | istio: ingressgateway
8 | servers:
9 | - hosts:
10 | - "*"
11 | port:
12 | number: 80
13 | name: http
14 | protocol: HTTP
15 |
16 |
--------------------------------------------------------------------------------
/jdk-example/istio-rules/meeting-vs-retry.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: VirtualService
3 | metadata:
4 | name: meeting-server
5 | spec:
6 | hosts:
7 | - meeting-server
8 | http:
9 | - route:
10 | - destination:
11 | host: meeting-server
12 | retries:
13 | attempts: 3
14 | perTryTimeout: 2s
15 |
--------------------------------------------------------------------------------
/jdk-example/istio-rules/work-vs.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: VirtualService
3 | metadata:
4 | name: work-server
5 | spec:
6 | hosts:
7 | - "*"
8 | gateways:
9 | - work-gateway
10 | http:
11 | - match:
12 | - uri:
13 | prefix: /work
14 | route:
15 | - destination:
16 | host: work-server
17 |
--------------------------------------------------------------------------------
/spring-boot-example/istio-rules/guestbook-ui-vs.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: VirtualService
3 | metadata:
4 | name: guestbook-ui
5 | spec:
6 | hosts:
7 | - "*"
8 | gateways:
9 | - guestbook-gateway
10 | http:
11 | - match:
12 | - uri:
13 | prefix: /
14 | route:
15 | - destination:
16 | host: guestbook-ui
17 |
--------------------------------------------------------------------------------
/jdk-example/istio-rules/meeting-vs-503.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: VirtualService
3 | metadata:
4 | name: meeting-server
5 | spec:
6 | hosts:
7 | - meeting-server
8 | http:
9 | - route:
10 | - destination:
11 | host: meeting-server
12 | fault:
13 | abort:
14 | percent: 100
15 | httpStatus: 503
16 |
17 |
--------------------------------------------------------------------------------
/spring-boot-example/istio-rules/guestbook-service-retry.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: VirtualService
3 | metadata:
4 | name: guestbook-service
5 | spec:
6 | hosts:
7 | - guestbook-service
8 | http:
9 | - route:
10 | - destination:
11 | host: guestbook-service
12 | retries:
13 | attempts: 3
14 | perTryTimeout: 2s
15 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-ui/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=ui
2 | backend.guestbook-service.url=http://guestbook-service:8080/messages
3 | backend.helloworld-service.url=http://helloworld-service:8080/hello
4 | spring.redis.host=redis
5 | spring.redis.port=6379
6 | spring.session.store-type=redis
7 | spring.sleuth.propagation-keys=x-request-id,x-ot-span-context
8 |
--------------------------------------------------------------------------------
/spring-boot-example/istio-rules/guestbook-service-503.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: VirtualService
3 | metadata:
4 | name: guestbook-service
5 | spec:
6 | hosts:
7 | - guestbook-service
8 | http:
9 | - route:
10 | - destination:
11 | host: guestbook-service
12 | fault:
13 | abort:
14 | percent: 100
15 | httpStatus: 503
16 |
17 |
--------------------------------------------------------------------------------
/spring-boot-example/istio-rules/guestbook-ui-vs-v1.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: VirtualService
3 | metadata:
4 | name: guestbook-ui
5 | spec:
6 | hosts:
7 | - "*"
8 | gateways:
9 | - guestbook-gateway
10 | http:
11 | - match:
12 | - uri:
13 | prefix: /
14 | route:
15 | - destination:
16 | host: guestbook-ui
17 | subset: v1
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
25 |
26 | ### Mac OSX ###
27 | .DS_Store
28 |
--------------------------------------------------------------------------------
/spring-boot-example/work-server/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-example/meeting-server/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-example/istio-rules/guestbook-ui-vs-delay.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: VirtualService
3 | metadata:
4 | name: guestbook-ui
5 | spec:
6 | hosts:
7 | - "*"
8 | gateways:
9 | - guestbook-gateway
10 | http:
11 | - match:
12 | - uri:
13 | prefix: /
14 | route:
15 | - destination:
16 | host: guestbook-ui
17 | subset: v1
18 | fault:
19 | delay:
20 | percent: 100
21 | fixedDelay: 5s
22 |
--------------------------------------------------------------------------------
/jdk-example/istio-rules/work-vs-v1.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: VirtualService
3 | metadata:
4 | name: work-server
5 | spec:
6 | hosts:
7 | - "*"
8 | gateways:
9 | - work-gateway
10 | http:
11 | - match:
12 | - uri:
13 | prefix: /work
14 | route:
15 | - destination:
16 | host: work-server
17 | subset: v1
18 | weight: 100
19 | - destination:
20 | host: work-server
21 | subset: v2
22 | weight: 0
23 |
--------------------------------------------------------------------------------
/jdk-example/istio-rules/work-vs-v2.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: VirtualService
3 | metadata:
4 | name: work-server
5 | spec:
6 | hosts:
7 | - "*"
8 | gateways:
9 | - work-gateway
10 | http:
11 | - match:
12 | - uri:
13 | prefix: /work
14 | route:
15 | - destination:
16 | host: work-server
17 | subset: v1
18 | weight: 0
19 | - destination:
20 | host: work-server
21 | subset: v2
22 | weight: 100
23 |
--------------------------------------------------------------------------------
/spring-boot-example/work-server/src/test/java/com/example/workserver/WorkServerApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example.workserver;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class WorkServerApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-example/istio-rules/guestbook-ui-vs-20p-v2.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: VirtualService
3 | metadata:
4 | name: guestbook-ui
5 | spec:
6 | hosts:
7 | - "*"
8 | gateways:
9 | - guestbook-gateway
10 | http:
11 | - match:
12 | - uri:
13 | prefix: /
14 | route:
15 | - destination:
16 | host: guestbook-ui
17 | subset: v1
18 | weight: 80
19 | - destination:
20 | host: guestbook-ui
21 | subset: v2
22 | weight: 20
23 |
--------------------------------------------------------------------------------
/spring-boot-example/meeting-server/src/test/java/com/example/meetingserver/MeetingServerApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example.meetingserver;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class MeetingServerApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-example/istio-rules/guestbook-service-dest.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: DestinationRule
3 | metadata:
4 | name: guestbook-service
5 | spec:
6 | host: guestbook-service
7 | trafficPolicy:
8 | connectionPool:
9 | tcp:
10 | maxConnections: 100
11 | http:
12 | maxRequestsPerConnection: 10
13 | http1MaxPendingRequests: 1024
14 | outlierDetection:
15 | http:
16 | consecutiveErrors: 7
17 | interval: 5m
18 | baseEjectionTime: 15m
19 |
--------------------------------------------------------------------------------
/jdk-example/istio-rules/meeting-dest-cb.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: DestinationRule
3 | metadata:
4 | name: meeting-server
5 | spec:
6 | host: meeting-server
7 | trafficPolicy:
8 | loadBalancer:
9 | simple: ROUND_ROBIN
10 | connectionPool:
11 | tcp:
12 | maxConnections: 100
13 | http:
14 | maxRequestsPerConnection: 10
15 | http1MaxPendingRequests: 1024
16 | outlierDetection:
17 | http:
18 | consecutiveErrors: 7
19 | interval: 5m
20 | baseEjectionTime: 15m
21 |
--------------------------------------------------------------------------------
/spring-boot-example/istio-rules/istio-role-webuser.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: "rbac.istio.io/v1alpha1"
2 | kind: ServiceRole
3 | metadata:
4 | name: webuser
5 | namespace: default
6 | spec:
7 | rules:
8 | - services: ["guestbook-ui.default.svc.cluster.local"]
9 | methods: ["*"]
10 | ---
11 | apiVersion: rbac.istio.io/v1alpha1
12 | kind: ServiceRoleBinding
13 | metadata:
14 | name: bind-webuser
15 | namespace: default
16 | spec:
17 | subjects:
18 | - properties:
19 | source.namespace: istio-system
20 | roleRef:
21 | kind: ServiceRole
22 | name: webuser
23 |
--------------------------------------------------------------------------------
/jdk-example/istio-auth/istio-rbac-work-server.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: "rbac.istio.io/v1alpha1"
2 | kind: ServiceRole
3 | metadata:
4 | name: work-server-webuser
5 | namespace: default
6 | spec:
7 | rules:
8 | - services: ["work-server.default.svc.cluster.local"]
9 | methods: ["*"]
10 | ---
11 | apiVersion: rbac.istio.io/v1alpha1
12 | kind: ServiceRoleBinding
13 | metadata:
14 | name: bind-work-server-webuser
15 | namespace: default
16 | spec:
17 | subjects:
18 | - properties:
19 | source.namespace: istio-system
20 | roleRef:
21 | kind: ServiceRole
22 | name: work-server-webuser
23 |
--------------------------------------------------------------------------------
/jdk-example/istio-auth/istio-rbac-meeting-server.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: "rbac.istio.io/v1alpha1"
2 | kind: ServiceRole
3 | metadata:
4 | name: meeting-server-viewer
5 | namespace: default
6 | spec:
7 | rules:
8 | - services: ["meeting-server.default.svc.cluster.local"]
9 | methods: ["GET"]
10 | ---
11 | apiVersion: "rbac.istio.io/v1alpha1"
12 | kind: ServiceRoleBinding
13 | metadata:
14 | name: meeting-server-viewer-binding
15 | namespace: default
16 | spec:
17 | subjects:
18 | - user: "cluster.local/ns/default/sa/work-server"
19 | roleRef:
20 | kind: ServiceRole
21 | name: meeting-server-viewer
22 |
--------------------------------------------------------------------------------
/spring-boot-example/istio-rules/guestbook-ui-vs-chrome.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.istio.io/v1alpha3
2 | kind: VirtualService
3 | metadata:
4 | name: guestbook-ui
5 | spec:
6 | hosts:
7 | - "*"
8 | gateways:
9 | - guestbook-gateway
10 | http:
11 | - match:
12 | - uri:
13 | prefix: /
14 | headers:
15 | user-agent:
16 | regex: ".*Chrome.*"
17 | route:
18 | - destination:
19 | host: guestbook-ui
20 | subset: v2
21 | - match:
22 | - uri:
23 | prefix: /
24 | route:
25 | - destination:
26 | host: guestbook-ui
27 | subset: v1
28 |
29 |
--------------------------------------------------------------------------------
/spring-boot-example/istio-rules/istio-role-guestbook-service-rw.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: "rbac.istio.io/v1alpha1"
2 | kind: ServiceRole
3 | metadata:
4 | name: guestbook-service-rw
5 | namespace: default
6 | spec:
7 | rules:
8 | - services: ["guestbook-service.default.svc.cluster.local"]
9 | methods: ["*"]
10 | ---
11 | apiVersion: rbac.istio.io/v1alpha1
12 | kind: ServiceRoleBinding
13 | metadata:
14 | name: bind-guestbook-service-rw
15 | namespace: default
16 | spec:
17 | subjects:
18 | - properties:
19 | source.principal: cluster.local/ns/default/sa/guestbook-ui
20 | roleRef:
21 | kind: ServiceRole
22 | name: guestbook-service-rw
23 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.example.istio
8 | istio-by-example
9 | pom
10 | 1.0-SNAPSHOT
11 | Examples of how to use Istio in Java
12 |
13 | spring-boot-example
14 | jdk-example
15 |
16 |
17 |
--------------------------------------------------------------------------------
/spring-boot-example/istio-rules/istio-role-viewer.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: "rbac.istio.io/v1alpha1"
2 | kind: ServiceRole
3 | metadata:
4 | name: viewer
5 | namespace: default
6 | spec:
7 | rules:
8 | - services: ["guestbook-service.default.svc.cluster.local", "helloworld-service.default.svc.cluster.local", "guestbook-ui.default.svc.cluster.local"]
9 | methods: ["GET", "HEAD"]
10 | ---
11 | apiVersion: rbac.istio.io/v1alpha1
12 | kind: ServiceRoleBinding
13 | metadata:
14 | name: bind-viewer
15 | namespace: default
16 | spec:
17 | subjects:
18 | - properties:
19 | source.namespace: istio-system
20 | - properties:
21 | source.namespace: default
22 | roleRef:
23 | kind: ServiceRole
24 | name: viewer
25 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes/mysql-pvc.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | kind: PersistentVolumeClaim
16 | apiVersion: v1
17 | metadata:
18 | name: mysql-pvc
19 | spec:
20 | accessModes:
21 | - ReadWriteOnce
22 | resources:
23 | requests:
24 | storage: 5Gi
25 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes/redis-service.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | kind: Service
16 | apiVersion: v1
17 | metadata:
18 | name: redis
19 | labels:
20 | app: redis
21 | visualize: "true"
22 | spec:
23 | ports:
24 | - port: 6379
25 | targetPort: 6379
26 | name: redis
27 | selector:
28 | app: redis
29 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes-mtls/redis-service.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | kind: Service
16 | apiVersion: v1
17 | metadata:
18 | name: redis
19 | labels:
20 | app: redis
21 | visualize: "true"
22 | spec:
23 | ports:
24 | - port: 6379
25 | targetPort: 6379
26 | name: redis
27 | selector:
28 | app: redis
29 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes-mtls/mysql-pvc.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | kind: PersistentVolumeClaim
16 | apiVersion: v1
17 | metadata:
18 | name: mysql-pvc
19 | annotations:
20 | volume.beta.kubernetes.io/storage-class: standard
21 | spec:
22 | accessModes:
23 | - ReadWriteOnce
24 | resources:
25 | requests:
26 | storage: 5Gi
27 |
--------------------------------------------------------------------------------
/spring-boot-example/istio-rules/guestbook-service-deny.yaml:
--------------------------------------------------------------------------------
1 | # Create a denier that returns a google.rpc.Code 7 (PERMISSION_DENIED)
2 | apiVersion: config.istio.io/v1alpha2
3 | kind: denier
4 | metadata:
5 | name: denyall
6 | namespace: istio-system
7 | spec:
8 | status:
9 | code: 7
10 | message: Not allowed
11 | ---
12 | # The (empty) data handed to denyall at run time
13 | apiVersion: config.istio.io/v1alpha2
14 | kind: checknothing
15 | metadata:
16 | name: denyrequest
17 | namespace: istio-system
18 | spec:
19 | ---
20 | # The rule that uses denier to deny requests with source.labels["app"] == "helloworld-service"
21 | apiVersion: config.istio.io/v1alpha2
22 | kind: rule
23 | metadata:
24 | name: deny-guestbook-service
25 | namespace: istio-system
26 | spec:
27 | match: destination.service=="guestbook-service.default.svc.cluster.local"
28 | actions:
29 | - handler: denyall.denier
30 | instances:
31 | - denyrequest.checknothing
32 |
--------------------------------------------------------------------------------
/jdk-example/kubernetes-latest/work-svc.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | kind: Service
16 | apiVersion: v1
17 | metadata:
18 | name: work-server
19 | labels:
20 | app: work-server
21 | visualize: "true"
22 | spec:
23 | ports:
24 | - port: 8080
25 | targetPort: 8080
26 | name: http
27 | selector:
28 | app: work-server
29 | serving: "true"
30 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes/ui-service.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | kind: Service
16 | apiVersion: v1
17 | metadata:
18 | name: guestbook-ui
19 | labels:
20 | app: guestbook-ui
21 | visualize: "true"
22 | spec:
23 | ports:
24 | - port: 8080
25 | targetPort: 8080
26 | name: http
27 | selector:
28 | app: guestbook-ui
29 | serving: "true"
30 |
--------------------------------------------------------------------------------
/jdk-example/kubernetes-latest/meeting-svc.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | kind: Service
16 | apiVersion: v1
17 | metadata:
18 | name: meeting-server
19 | labels:
20 | app: meeting-server
21 | visualize: "true"
22 | spec:
23 | ports:
24 | - port: 8081
25 | targetPort: 8081
26 | name: http
27 | selector:
28 | app: meeting-server
29 | serving: "true"
30 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes-mtls/ui-service.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | kind: Service
16 | apiVersion: v1
17 | metadata:
18 | name: guestbook-ui
19 | labels:
20 | app: guestbook-ui
21 | visualize: "true"
22 | spec:
23 | ports:
24 | - port: 8080
25 | targetPort: 8080
26 | name: http
27 | selector:
28 | app: guestbook-ui
29 | serving: "true"
30 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes/guestbook-service.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | kind: Service
16 | apiVersion: v1
17 | metadata:
18 | name: guestbook-service
19 | labels:
20 | app: guestbook-service
21 | visualize: "true"
22 | spec:
23 | ports:
24 | - port: 80
25 | targetPort: 8080
26 | name: http
27 | selector:
28 | app: guestbook-service
29 | serving: "true"
30 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes-mtls/guestbook-service.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | kind: Service
16 | apiVersion: v1
17 | metadata:
18 | name: guestbook-service
19 | labels:
20 | app: guestbook-service
21 | visualize: "true"
22 | spec:
23 | ports:
24 | - port: 80
25 | targetPort: 8080
26 | name: http
27 | selector:
28 | app: guestbook-service
29 | serving: "true"
30 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes/helloworld-service.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | kind: Service
16 | apiVersion: v1
17 | metadata:
18 | name: helloworld-service
19 | labels:
20 | app: helloworld-service
21 | visualize: "true"
22 | spec:
23 | ports:
24 | - port: 8080
25 | targetPort: 8080
26 | name: http
27 | selector:
28 | app: helloworld-service
29 | serving: "true"
30 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes-mtls/helloworld-service.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | kind: Service
16 | apiVersion: v1
17 | metadata:
18 | name: helloworld-service
19 | labels:
20 | app: helloworld-service
21 | visualize: "true"
22 | spec:
23 | ports:
24 | - port: 8080
25 | targetPort: 8080
26 | name: http
27 | selector:
28 | app: helloworld-service
29 | serving: "true"
30 |
--------------------------------------------------------------------------------
/spring-boot-example/meeting-server/src/main/java/com/example/meetingserver/MeetingServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.meetingserver;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.web.bind.annotation.GetMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | @SpringBootApplication
11 | @RestController
12 | public class MeetingServerApplication {
13 | private static Logger logger = LoggerFactory.getLogger(MeetingServerApplication.class);
14 |
15 | @GetMapping("/meet")
16 | public void meeting() {
17 | logger.info("Meeting for work!");
18 | try {
19 | Thread.sleep(250L);
20 | }
21 | catch (InterruptedException e) {
22 | // do nothing
23 | }
24 | }
25 |
26 | public static void main(String[] args) {
27 | SpringApplication.run(MeetingServerApplication.class, args);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes/mysql-service.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: v1
16 | kind: Service
17 | metadata:
18 | name: mysql
19 | labels:
20 | app: mysql
21 | visualize: "true"
22 | spec:
23 | ports:
24 | # the port that this service should serve on
25 | - port: 3306
26 | name: mysql
27 | # label keys and values that must match in order to receive traffic for this service
28 | selector:
29 | app: mysql
30 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes-mtls/mysql-service.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: v1
16 | kind: Service
17 | metadata:
18 | name: mysql
19 | labels:
20 | app: mysql
21 | visualize: "true"
22 | spec:
23 | ports:
24 | # the port that this service should serve on
25 | - port: 3306
26 | name: mysql
27 | # label keys and values that must match in order to receive traffic for this service
28 | selector:
29 | app: mysql
30 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution,
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
--------------------------------------------------------------------------------
/visualizer/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: helvetica;
3 | }
4 |
5 | .logo {
6 | background: url('titlelogo.svg');
7 | background-repeat: no-repeat;
8 | height: 150px;
9 | width: 600px;
10 | }
11 |
12 | .navbar-logo {
13 | margin-left: 0px;
14 | margin-top: 0px;
15 | }
16 |
17 | #nav-logo-img {
18 | height: 42px;
19 | }
20 |
21 | .navbar {
22 | position: absolute;
23 | padding: 5px;
24 | left: 0;
25 | top: 0;
26 | right: 0;
27 | background-color: #447AE8;
28 | border: 0px;
29 | border-radius: 0;
30 | }
31 |
32 | .demo {
33 | position: absolute;
34 | padding: 5%;
35 | left: 0;
36 | right: 0;
37 | top: 50px;
38 | height: 100%;
39 | }
40 |
41 | span {
42 | display: block;
43 | font-size: 1.2em;
44 | clear: left;
45 | padding: 0.5em;
46 | }
47 |
48 | .pod {
49 | border-radius: 4px;
50 | width: 40px;
51 | height: 40px;
52 | margin: 2px;
53 | float: left;
54 | }
55 |
56 | .running {
57 | background-color: #297b48;
58 | }
59 |
60 | .pending {
61 | /* background-color: #7bb992; */
62 | background-color: #297b48;
63 | }
64 |
65 | .terminating {
66 | background-color: #d47d6a;
67 | }
68 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-ui/src/test/java/com/example/guestbook/HelloworldUiApplicationTests.java:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // TODO: High-level file comment.
16 |
17 | package com.example.guestbook;
18 |
19 | import org.junit.Test;
20 | import org.junit.runner.RunWith;
21 | import org.springframework.boot.test.context.SpringBootTest;
22 | import org.springframework.test.context.junit4.SpringRunner;
23 |
24 | @RunWith(SpringRunner.class)
25 | @SpringBootTest
26 | public class HelloworldUiApplicationTests {
27 |
28 | @Test
29 | public void contextLoads() {
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/spring-boot-example/helloworld-service/src/test/java/com/example/guestbook/HelloworldApplicationTests.java:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // TODO: High-level file comment.
16 |
17 | package com.example.guestbook;
18 |
19 | import org.junit.Test;
20 | import org.junit.runner.RunWith;
21 | import org.springframework.boot.test.context.SpringBootTest;
22 | import org.springframework.test.context.junit4.SpringRunner;
23 |
24 | @RunWith(SpringRunner.class)
25 | @SpringBootTest
26 | public class HelloworldApplicationTests {
27 |
28 | @Test
29 | public void contextLoads() {
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-service/src/test/java/com/example/guestbook/GuestbookServiceApplicationTests.java:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // TODO: High-level file comment.
16 |
17 | package com.example.guestbook;
18 |
19 | import org.junit.Test;
20 | import org.junit.runner.RunWith;
21 | import org.springframework.boot.test.context.SpringBootTest;
22 | import org.springframework.test.context.junit4.SpringRunner;
23 |
24 | @RunWith(SpringRunner.class)
25 | @SpringBootTest
26 | public class GuestbookServiceApplicationTests {
27 |
28 | @Test
29 | public void contextLoads() {
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/jdk-example/kubernetes-v1/meeting-deployment-v1.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: extensions/v1beta1
16 | kind: Deployment
17 | metadata:
18 | name: meeting-server-v1
19 | labels:
20 | app: meeting-server
21 | version: "1.0"
22 | visualize: "true"
23 | spec:
24 | replicas: 2
25 | template:
26 | metadata:
27 | labels:
28 | app: meeting-server
29 | serving: "true"
30 | version: "1.0"
31 | visualize: "true"
32 | spec:
33 | containers:
34 | - name: meeting-server
35 | image: saturnism/meeting-server-istio:v1
36 | ports:
37 | - containerPort: 8081
38 | name: http
39 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes/redis-deployment.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: apps/v1
16 | kind: Deployment
17 | metadata:
18 | name: redis
19 | labels:
20 | app: redis
21 | visualize: "true"
22 | spec:
23 | replicas: 1
24 | selector:
25 | matchLabels:
26 | app: redis
27 | version: "4.0.2"
28 | template:
29 | metadata:
30 | labels:
31 | app: redis
32 | version: "4.0.2"
33 | visualize: "true"
34 | spec:
35 | containers:
36 | - name: redis
37 | image: redis:4.0.2
38 | livenessProbe:
39 | tcpSocket:
40 | port: 6379
41 | ports:
42 | - name: redis-server
43 | containerPort: 6379
44 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes-mtls/redis-deployment.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: apps/v1
16 | kind: Deployment
17 | metadata:
18 | name: redis
19 | labels:
20 | app: redis
21 | visualize: "true"
22 | spec:
23 | replicas: 1
24 | selector:
25 | matchLabels:
26 | app: redis
27 | version: "4.0.2"
28 | template:
29 | metadata:
30 | labels:
31 | app: redis
32 | version: "4.0.2"
33 | visualize: "true"
34 | spec:
35 | containers:
36 | - name: redis
37 | image: redis:4.0.2
38 | livenessProbe:
39 | tcpSocket:
40 | port: 6379
41 | ports:
42 | - name: redis-server
43 | containerPort: 6379
44 |
--------------------------------------------------------------------------------
/jdk-example/kubernetes-latest/meeting-deployment-latest.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: extensions/v1beta1
16 | kind: Deployment
17 | metadata:
18 | name: meeting-server-latest
19 | labels:
20 | app: meeting-server
21 | version: latest
22 | visualize: "true"
23 | spec:
24 | replicas: 2
25 | template:
26 | metadata:
27 | labels:
28 | app: meeting-server
29 | serving: "true"
30 | version: latest
31 | visualize: "true"
32 | spec:
33 | serviceAccountName: meeting-server
34 | containers:
35 | - name: meeting-server
36 | image: saturnism/meeting-server-istio:latest
37 | ports:
38 | - containerPort: 8081
39 | name: http
40 |
--------------------------------------------------------------------------------
/jdk-example/work-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.example.istio
8 | work-server
9 | 1.0-SNAPSHOT
10 | A fun example using libraries available in the JDK.
11 |
12 | com.example.istio
13 | jdk-example
14 | 1.0-SNAPSHOT
15 | ../pom.xml
16 |
17 |
18 | com.example.jdk.WorkServer
19 |
20 |
21 |
22 |
23 | com.google.cloud.tools
24 | jib-maven-plugin
25 |
26 |
27 | com.spotify
28 | dockerfile-maven-plugin
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/jdk-example/kubernetes-v1/work-deployment-v1.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: extensions/v1beta1
16 | kind: Deployment
17 | metadata:
18 | name: work-server-v1
19 | labels:
20 | app: work-server
21 | version: "1.0"
22 | visualize: "true"
23 | spec:
24 | replicas: 2
25 | template:
26 | metadata:
27 | labels:
28 | app: work-server
29 | serving: "true"
30 | version: "1.0"
31 | visualize: "true"
32 | spec:
33 | containers:
34 | - name: work-server
35 | image: saturnism/work-server-istio:v1
36 | env:
37 | - name: ENDPOINT
38 | value: http://meeting-server:8081/meet
39 | ports:
40 | - containerPort: 8080
41 | name: http
42 |
--------------------------------------------------------------------------------
/jdk-example/meeting-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.example.istio
8 | meeting-server
9 | 1.0-SNAPSHOT
10 | A fun example using libraries available in the JDK.
11 |
12 | com.example.istio
13 | jdk-example
14 | 1.0-SNAPSHOT
15 | ../pom.xml
16 |
17 |
18 | com.example.jdk.MeetingServer
19 |
20 |
21 |
22 |
23 | com.google.cloud.tools
24 | jib-maven-plugin
25 |
26 |
27 | com.spotify
28 | dockerfile-maven-plugin
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-service/src/main/resources/application.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | # TODO: High-level file comment.
16 |
17 | spring:
18 | application:
19 | name: guestbook-service
20 | rest:
21 | base-path: /api
22 | datasource:
23 | driverClassName: com.mysql.jdbc.Driver
24 | url: jdbc:mysql://mysql:3306/app?autoReconnect=true
25 | username: root
26 | password: yourpassword
27 | test-on-borrow: true
28 | validation-query: SELECT 1
29 | jpa:
30 | database-platform: org.hibernate.dialect.MySQL5Dialect
31 | hibernate:
32 | generate-ddl: true
33 | ddl-auto: update
34 | globally_quoted_identifiers: true
35 | sleuth:
36 | propagation-keys: x-request-id,x-ot-span-context
37 |
--------------------------------------------------------------------------------
/jdk-example/kubernetes-v2/work-deployment-v2.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: extensions/v1beta1
16 | kind: Deployment
17 | metadata:
18 | name: work-server-v2
19 | labels:
20 | app: work-server
21 | version: "2.0"
22 | visualize: "true"
23 | spec:
24 | replicas: 2
25 | template:
26 | metadata:
27 | labels:
28 | app: work-server
29 | serving: "true"
30 | version: "2.0"
31 | visualize: "true"
32 | spec:
33 | serviceAccountName: work-server
34 | containers:
35 | - name: work-server
36 | image: saturnism/work-server-istio:v2
37 | env:
38 | - name: ENDPOINT
39 | value: http://meeting-server:8081/meet
40 | ports:
41 | - containerPort: 8080
42 | name: http
43 |
--------------------------------------------------------------------------------
/jdk-example/kubernetes-latest/work-deployment-latest.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: extensions/v1beta1
16 | kind: Deployment
17 | metadata:
18 | name: work-server-latest
19 | labels:
20 | app: work-server
21 | version: latest
22 | visualize: "true"
23 | spec:
24 | replicas: 2
25 | template:
26 | metadata:
27 | labels:
28 | app: work-server
29 | serving: "true"
30 | version: latest
31 | visualize: "true"
32 | spec:
33 | serviceAccountName: work-server
34 | containers:
35 | - name: work-server
36 | image: saturnism/work-server-istio:latest
37 | env:
38 | - name: ENDPOINT
39 | value: http://meeting-server:8081/meet
40 | ports:
41 | - containerPort: 8080
42 | name: http
43 |
--------------------------------------------------------------------------------
/visualizer/index.html:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
33 |

34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/spring-boot-example/README.md:
--------------------------------------------------------------------------------
1 | ## Deploy Application to Kubernetes
2 | Check out the example code:
3 | ```
4 | $ cd ~/
5 | $ git clone https://github.com/saturnism/istio-by-example-java.git
6 | $ cd istio-by-example-java/spring-boot-example
7 | ```
8 |
9 | Deploy the application:
10 | ```
11 | $ kubectl apply -f kubernetes/
12 | ```
13 |
14 | Notice that the YAML files are just regular Kubernetes deployment YAML. This is because Istio 0.2+ can use Kubernetes initializer feature.
15 | During deployment time, Kubernetes will automatically & transparently inject additional sidecars and configurations to these YAML files.
16 |
17 | ## Addons
18 | ### Grafana
19 | Establish port forward from local port 3000 to the Grafana instance:
20 | ```
21 | $ kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=grafana -o jsonpath='{.items[0].metadata.name}') 3000:3000
22 | ```
23 |
24 | Browse to http://localhost:3000 and navigate to Istio Dashboard
25 |
26 | ### Zipkin
27 | Establish port forward from local port
28 | ```
29 | $ kubectl port-forward -n istio-system $(kubectl get pod -n istio-system -l app=zipkin -o jsonpath='{.items[0].metadata.name}') 9411:9411
30 | ```
31 |
32 | Browse to http://localhost:9411
33 |
34 | ### Prometheus
35 | ```
36 | $ kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') 9090:9090
37 | ```
38 |
39 | ### Service Graph
40 | ```
41 | $ kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=servicegraph -o jsonpath='{.items[0].metadata.name}') 8088:8088
42 | ```
43 |
44 | Browse to http://localhost:8088/dotviz
45 |
--------------------------------------------------------------------------------
/jdk-example/meeting-server/src/main/java/com/example/jdk/MeetingServer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.jdk;
17 |
18 | import com.sun.net.httpserver.HttpServer;
19 |
20 | import java.io.IOException;
21 | import java.io.OutputStream;
22 | import java.net.InetAddress;
23 | import java.net.InetSocketAddress;
24 | import java.nio.charset.StandardCharsets;
25 | import java.util.concurrent.Executors;
26 | import java.util.concurrent.ThreadLocalRandom;
27 |
28 | public class MeetingServer {
29 | public static void main(String[] args) throws IOException {
30 | HttpServer server = HttpServer.create(new InetSocketAddress(8081), 0);
31 | server.setExecutor(Executors.newCachedThreadPool());
32 |
33 | server.createContext("/meet", exchange -> {
34 | try {
35 | Thread.sleep(250);
36 | } catch (InterruptedException e) {
37 | }
38 |
39 | exchange.sendResponseHeaders(200, 0);
40 | exchange.getResponseBody().close();
41 | });
42 |
43 | server.start();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes/guestbook-deployment-v1.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: apps/v1
16 | kind: Deployment
17 | metadata:
18 | name: guestbook-service-v1
19 | labels:
20 | app: guestbook-service
21 | version: "1.0"
22 | visualize: "true"
23 | spec:
24 | replicas: 2
25 | selector:
26 | matchLabels:
27 | app: guestbook-service
28 | version: "1.0"
29 | serving: "true"
30 | template:
31 | metadata:
32 | labels:
33 | app: guestbook-service
34 | serving: "true"
35 | version: "1.0"
36 | visualize: "true"
37 | spec:
38 | containers:
39 | - name: guestbook-service
40 | image: saturnism/guestbook-service-istio:1.0
41 | livenessProbe:
42 | initialDelaySeconds: 90
43 | httpGet:
44 | path: /actuator/health
45 | port: 8080
46 | readinessProbe:
47 | httpGet:
48 | path: /
49 | port: 8080
50 | ports:
51 | - containerPort: 8080
52 | name: http
53 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes/helloworld-deployment-v1.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: apps/v1
16 | kind: Deployment
17 | metadata:
18 | name: helloworld-service-v1
19 | labels:
20 | app: helloworld-service
21 | version: "1.0"
22 | visualize: "true"
23 | spec:
24 | replicas: 2
25 | selector:
26 | matchLabels:
27 | app: helloworld-service
28 | version: "1.0"
29 | serving: "true"
30 | template:
31 | metadata:
32 | labels:
33 | app: helloworld-service
34 | version: "1.0"
35 | serving: "true"
36 | visualize: "true"
37 | spec:
38 | containers:
39 | - name: helloworld-service
40 | image: saturnism/helloworld-service-istio:1.0
41 | livenessProbe:
42 | initialDelaySeconds: 60
43 | httpGet:
44 | path: /actuator/health
45 | port: 8080
46 | readinessProbe:
47 | httpGet:
48 | path: /hello/ready
49 | port: 8080
50 | ports:
51 | - name: http
52 | containerPort: 8080
53 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-service/src/main/java/com/example/guestbook/MessageService.java:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // TODO: High-level file comment.
16 |
17 | /*
18 | * Copyright 2015 Google Inc. All Rights Reserved.
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | */
32 | package com.example.guestbook;
33 |
34 | import org.springframework.data.repository.PagingAndSortingRepository;
35 | import org.springframework.data.rest.core.annotation.RepositoryRestResource;
36 |
37 | /**
38 | * Created by rayt on 5/1/17.
39 | */
40 | @RepositoryRestResource
41 | public interface MessageService extends PagingAndSortingRepository {
42 | }
43 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-ui/src/main/java/com/example/guestbook/HelloworldUiApplication.java:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // TODO: High-level file comment.
16 |
17 | /*
18 | * Copyright 2015 Google Inc. All Rights Reserved.
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | */
32 | package com.example.guestbook;
33 |
34 | import org.springframework.boot.SpringApplication;
35 | import org.springframework.boot.autoconfigure.SpringBootApplication;
36 |
37 | @SpringBootApplication
38 | public class HelloworldUiApplication {
39 |
40 | public static void main(String[] args) {
41 | SpringApplication.run(HelloworldUiApplication.class, args);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes-mtls/guestbook-deployment-v1.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: apps/v1
16 | kind: Deployment
17 | metadata:
18 | name: guestbook-service-v1
19 | labels:
20 | app: guestbook-service
21 | version: "1.0"
22 | visualize: "true"
23 | spec:
24 | replicas: 2
25 | selector:
26 | matchLabels:
27 | app: guestbook-service
28 | version: "1.0"
29 | serving: "true"
30 | template:
31 | metadata:
32 | labels:
33 | app: guestbook-service
34 | serving: "true"
35 | version: "1.0"
36 | visualize: "true"
37 | spec:
38 | serviceAccountName: guestbook-service
39 | containers:
40 | - name: guestbook-service
41 | image: saturnism/guestbook-service-istio:1.0
42 | livenessProbe:
43 | initialDelaySeconds: 90
44 | exec:
45 | command:
46 | - wget
47 | - -qO-
48 | - http://localhost:8080/actuator/health
49 | readinessProbe:
50 | exec:
51 | command:
52 | - wget
53 | - -qO-
54 | - http://localhost:8080/
55 | ports:
56 | - containerPort: 8080
57 | name: http
58 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-service/src/main/java/com/example/guestbook/GuestbookServiceApplication.java:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // TODO: High-level file comment.
16 |
17 | /*
18 | * Copyright 2015 Google Inc. All Rights Reserved.
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | */
32 | package com.example.guestbook;
33 |
34 | import org.springframework.boot.SpringApplication;
35 | import org.springframework.boot.autoconfigure.SpringBootApplication;
36 |
37 | @SpringBootApplication
38 | public class GuestbookServiceApplication {
39 |
40 | public static void main(String[] args) {
41 | SpringApplication.run(GuestbookServiceApplication.class, args);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes/mysql-deployment.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: apps/v1
16 | kind: Deployment
17 | metadata:
18 | name: mysql
19 | labels:
20 | app: mysql
21 | visualize: "true"
22 | spec:
23 | replicas: 1
24 | selector:
25 | matchLabels:
26 | app: mysql
27 | version: "5.6"
28 | template:
29 | metadata:
30 | labels:
31 | app: mysql
32 | version: "5.6"
33 | visualize: "true"
34 | spec:
35 | containers:
36 | - name: mysql
37 | image: mysql:5.6
38 | livenessProbe:
39 | tcpSocket:
40 | port: 3306
41 | env:
42 | - name: MYSQL_ROOT_PASSWORD
43 | # change this
44 | value: yourpassword
45 | - name: MYSQL_DATABASE
46 | value: app
47 | ports:
48 | - containerPort: 3306
49 | name: mysql
50 | volumeMounts:
51 | # name must match the volume name below
52 | - name: mysql-persistent-storage
53 | # mount path within the container
54 | mountPath: /var/lib/mysql
55 | volumes:
56 | - name: mysql-persistent-storage
57 | persistentVolumeClaim:
58 | claimName: mysql-pvc
59 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes-mtls/mysql-deployment.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: apps/v1
16 | kind: Deployment
17 | metadata:
18 | name: mysql
19 | labels:
20 | app: mysql
21 | visualize: "true"
22 | spec:
23 | replicas: 1
24 | selector:
25 | matchLabels:
26 | app: mysql
27 | version: "5.6"
28 | template:
29 | metadata:
30 | labels:
31 | app: mysql
32 | version: "5.6"
33 | visualize: "true"
34 | spec:
35 | containers:
36 | - name: mysql
37 | image: mysql:5.6
38 | livenessProbe:
39 | tcpSocket:
40 | port: 3306
41 | env:
42 | - name: MYSQL_ROOT_PASSWORD
43 | # change this
44 | value: yourpassword
45 | - name: MYSQL_DATABASE
46 | value: app
47 | ports:
48 | - containerPort: 3306
49 | name: mysql
50 | volumeMounts:
51 | # name must match the volume name below
52 | - name: mysql-persistent-storage
53 | # mount path within the container
54 | mountPath: /var/lib/mysql
55 | volumes:
56 | - name: mysql-persistent-storage
57 | persistentVolumeClaim:
58 | claimName: mysql-pvc
59 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes-v2/ui-deployment-v2.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: apps/v1
16 | kind: Deployment
17 | metadata:
18 | name: guestbook-ui-v2
19 | labels:
20 | app: guestbook-ui
21 | version: "2.0"
22 | visualize: "true"
23 | spec:
24 | replicas: 2
25 | selector:
26 | matchLabels:
27 | app: guestbook-ui
28 | version: "2.0"
29 | serving: "true"
30 | template:
31 | metadata:
32 | labels:
33 | app: guestbook-ui
34 | version: "2.0"
35 | serving: "true"
36 | visualize: "true"
37 | annotations:
38 | visualizer/uses: helloworld-service,guestbook-service,redis
39 | spec:
40 | containers:
41 | - name: guestbook-ui
42 | image: saturnism/guestbook-ui-istio:2.0
43 | env:
44 | - name: BACKEND_GUESTBOOK_SERVICE_URL
45 | value: http://guestbook-service/messages
46 | livenessProbe:
47 | initialDelaySeconds: 60
48 | httpGet:
49 | path: /actuator/health
50 | port: 8080
51 | readinessProbe:
52 | httpGet:
53 | path: /
54 | port: 8080
55 | ports:
56 | - name: http
57 | containerPort: 8080
58 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes/ui-deployment-v1.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: apps/v1
16 | kind: Deployment
17 | metadata:
18 | name: guestbook-ui-v1
19 | labels:
20 | app: guestbook-ui
21 | version: "1.0"
22 | visualize: "true"
23 | spec:
24 | replicas: 2
25 | selector:
26 | matchLabels:
27 | app: guestbook-ui
28 | version: "1.0"
29 | serving: "true"
30 | template:
31 | metadata:
32 | labels:
33 | app: guestbook-ui
34 | version: "1.0"
35 | serving: "true"
36 | visualize: "true"
37 | annotations:
38 | visualizer/uses: helloworld-service,guestbook-service,redis
39 | spec:
40 | containers:
41 | - name: guestbook-ui
42 | image: saturnism/guestbook-ui-istio:1.0
43 | env:
44 | - name: BACKEND_GUESTBOOK_SERVICE_URL
45 | value: http://guestbook-service/messages
46 | livenessProbe:
47 | initialDelaySeconds: 60
48 | httpGet:
49 | path: /actuator/health
50 | port: 8080
51 | readinessProbe:
52 | httpGet:
53 | path: /
54 | port: 8080
55 | ports:
56 | - name: http
57 | containerPort: 8080
58 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes-mtls/helloworld-deployment-v1.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: apps/v1
16 | kind: Deployment
17 | metadata:
18 | name: helloworld-service-v1
19 | labels:
20 | app: helloworld-service
21 | version: "1.0"
22 | visualize: "true"
23 | spec:
24 | replicas: 2
25 | selector:
26 | matchLabels:
27 | app: helloworld-service
28 | version: "1.0"
29 | serving: "true"
30 | template:
31 | metadata:
32 | labels:
33 | app: helloworld-service
34 | version: "1.0"
35 | serving: "true"
36 | visualize: "true"
37 | spec:
38 | serviceAccount: helloworld-service
39 | containers:
40 | - name: helloworld-service
41 | image: saturnism/helloworld-service-istio:1.0
42 | livenessProbe:
43 | initialDelaySeconds: 60
44 | exec:
45 | command:
46 | - wget
47 | - -qO-
48 | - http://localhost:8080/actuator/health
49 | readinessProbe:
50 | exec:
51 | command:
52 | - wget
53 | - -qO-
54 | - http://localhost:8080/hello/ready
55 | ports:
56 | - name: http
57 | containerPort: 8080
58 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes-v2/helloworld-deployment-v2.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: apps/v1
16 | kind: Deployment
17 | metadata:
18 | name: helloworld-service-v2
19 | labels:
20 | app: helloworld-service
21 | version: "2.0"
22 | visualize: "true"
23 | spec:
24 | replicas: 2
25 | selector:
26 | matchLabels:
27 | app: helloworld-service
28 | version: "2.0"
29 | serving: "true"
30 | template:
31 | metadata:
32 | labels:
33 | app: helloworld-service
34 | version: "2.0"
35 | serving: "true"
36 | visualize: "true"
37 | spec:
38 | containers:
39 | - name: helloworld-service
40 | image: saturnism/helloworld-service-istio:1.0
41 | env:
42 | - name: VERSION
43 | value: "2.0"
44 | - name: GREETING
45 | value: "Hola $name from $hostname version $version"
46 | livenessProbe:
47 | initialDelaySeconds: 60
48 | httpGet:
49 | path: /actuator/health
50 | port: 8080
51 | readinessProbe:
52 | httpGet:
53 | path: /hello/ready
54 | port: 8080
55 | ports:
56 | - name: http
57 | containerPort: 8080
58 |
--------------------------------------------------------------------------------
/spring-boot-example/work-server/src/main/java/com/example/workserver/WorkServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.workserver;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.beans.factory.annotation.Value;
7 | import org.springframework.boot.SpringApplication;
8 | import org.springframework.boot.autoconfigure.SpringBootApplication;
9 | import org.springframework.context.annotation.Bean;
10 | import org.springframework.http.HttpStatus;
11 | import org.springframework.http.ResponseEntity;
12 | import org.springframework.web.bind.annotation.GetMapping;
13 | import org.springframework.web.bind.annotation.RestController;
14 | import org.springframework.web.client.RestTemplate;
15 |
16 | import java.net.URI;
17 |
18 | @SpringBootApplication
19 | public class WorkServerApplication {
20 |
21 | @Bean
22 | public RestTemplate restTemplate() {
23 | return new RestTemplate();
24 | }
25 |
26 | public static void main(String[] args) {
27 | SpringApplication.run(WorkServerApplication.class, args);
28 | }
29 |
30 | @RestController
31 | public static class WorkController {
32 | private static Logger logger = LoggerFactory.getLogger(WorkController.class);
33 |
34 | @Value("${endpoint:http://localhost:8081/meet}")
35 | private String endpoint;
36 |
37 | @Autowired
38 | private RestTemplate restTemplate;
39 |
40 |
41 | @GetMapping("/work")
42 | public String work() {
43 | int count = 0;
44 | for (int i = 0; i < 4; i++) {
45 | logger.info("Going to meeting: {}", i);
46 | ResponseEntity entity = restTemplate
47 | .getForEntity(URI.create(endpoint), Void.class);
48 | if (entity.getStatusCode() == HttpStatus.OK) {
49 | count++;
50 | }
51 | }
52 |
53 | return "went to " + count + " meetings";
54 | }
55 |
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes-mtls/ui-deployment-v1.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: apps/v1
16 | kind: Deployment
17 | metadata:
18 | name: guestbook-ui-v1
19 | labels:
20 | app: guestbook-ui
21 | version: "1.0"
22 | visualize: "true"
23 | spec:
24 | replicas: 2
25 | selector:
26 | matchLabels:
27 | app: guestbook-ui
28 | version: "1.0"
29 | serving: "true"
30 | template:
31 | metadata:
32 | labels:
33 | app: guestbook-ui
34 | version: "1.0"
35 | serving: "true"
36 | visualize: "true"
37 | annotations:
38 | visualizer/uses: helloworld-service,guestbook-service,redis
39 | spec:
40 | serviceAccount: guestbook-ui
41 | containers:
42 | - name: guestbook-ui
43 | image: saturnism/guestbook-ui-istio:1.0
44 | env:
45 | - name: BACKEND_GUESTBOOK_SERVICE_URL
46 | value: http://guestbook-service/messages
47 | livenessProbe:
48 | initialDelaySeconds: 60
49 | exec:
50 | command:
51 | - wget
52 | - -qO-
53 | - http://localhost:8080/actuator/health
54 | readinessProbe:
55 | exec:
56 | command:
57 | - wget
58 | - -qO-
59 | - http://localhost:8080/
60 | ports:
61 | - name: http
62 | containerPort: 8080
63 |
--------------------------------------------------------------------------------
/spring-boot-example/kubernetes-mtls/ui-deployment-v2.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google Inc.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | apiVersion: apps/v1
16 | kind: Deployment
17 | metadata:
18 | name: guestbook-ui-v2
19 | labels:
20 | app: guestbook-ui
21 | version: "2.0"
22 | visualize: "true"
23 | spec:
24 | replicas: 2
25 | selector:
26 | matchLabels:
27 | app: guestbook-ui
28 | version: "2.0"
29 | serving: "true"
30 | template:
31 | metadata:
32 | labels:
33 | app: guestbook-ui
34 | version: "2.0"
35 | serving: "true"
36 | visualize: "true"
37 | annotations:
38 | visualizer/uses: helloworld-service,guestbook-service,redis
39 | spec:
40 | serviceAccount: guestbook-ui
41 | containers:
42 | - name: guestbook-ui
43 | image: saturnism/guestbook-ui-istio:2.0
44 | env:
45 | - name: BACKEND_GUESTBOOK_SERVICE_URL
46 | value: http://guestbook-service/messages
47 | livenessProbe:
48 | initialDelaySeconds: 60
49 | exec:
50 | command:
51 | - wget
52 | - -qO-
53 | - http://localhost:8080/actuator/health
54 | readinessProbe:
55 | exec:
56 | command:
57 | - wget
58 | - -qO-
59 | - http://localhost:8080/
60 | ports:
61 | - name: http
62 | containerPort: 8080
63 |
--------------------------------------------------------------------------------
/visualizer/script.js:
--------------------------------------------------------------------------------
1 | jQuery(document).ready(function($) {
2 | var graph_url = '/api/v1/namespaces/istio-system/services/servicegraph:http/proxy/graph?time_horizon=30s&filter_empty=true';
3 |
4 | var sankey_options = {
5 | animation: {
6 | startup: true,
7 | duration: 100,
8 | easing: 'out'
9 | },
10 | sankey: {
11 | link: {
12 | color: {
13 | fill: '#D4EAF6'
14 | }
15 | },
16 | node: {
17 | colors: [ '#a6cee3' ],
18 | width: 12,
19 | nodePadding: 10,
20 | label: {
21 | fontSize: 12,
22 | color: '#4C84A2'
23 | }
24 | }
25 | }
26 | };
27 |
28 | function setup() {
29 | }
30 |
31 | function refresh() {
32 | var chart = new google.visualization.Sankey(document.getElementById('sankey'));
33 | var request = $.getJSON(graph_url, function(data) {
34 | if (!data || !data.edges) return;
35 |
36 | var table = new google.visualization.DataTable();
37 |
38 | table.addColumn('string', 'Source');
39 | table.addColumn('string', 'Destination');
40 | table.addColumn('number', 'RPS');
41 |
42 | var rows = data.edges
43 | .filter(e => !e.source.startsWith('unknown'))
44 | // .filter(e => !e.source.startsWith('ingress.istio-system'))
45 | .filter(e => !isNaN(e.labels['reqs/sec']))
46 | .map(function(e) {
47 | return [e.source, e.target, Number(e.labels['reqs/sec'])];
48 | // return [e.source, e.target, 1];
49 | })
50 | .filter(e => e[2] > 0);
51 |
52 | if (rows && rows.length > 0) {
53 | table.addRows(rows);
54 | table.sort([{column: 0}, {column: 1}]);
55 | chart.draw(table, sankey_options);
56 | }
57 | console.log(rows);
58 |
59 | });
60 |
61 | $.when(request).then(function() {
62 | setTimeout(refresh, 1000);
63 | });
64 | }
65 |
66 | google.charts.load('current', {'packages':['sankey']});
67 | google.charts.setOnLoadCallback(refresh);
68 | setup();
69 | });
70 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-ui/src/main/java/com/example/guestbook/ApplicationConfig.java:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // TODO: High-level file comment.
16 |
17 | /*
18 | * Copyright 2015 Google Inc. All Rights Reserved.
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | */
32 | package com.example.guestbook;
33 |
34 | import org.springframework.beans.factory.annotation.Value;
35 | import org.springframework.context.annotation.Bean;
36 | import org.springframework.context.annotation.Configuration;
37 | import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
38 | import org.springframework.web.client.RestTemplate;
39 |
40 | /**
41 | * Created by rayt on 5/1/17.
42 | */
43 | @Configuration
44 | @EnableRedisHttpSession
45 | public class ApplicationConfig {
46 | @Bean
47 | RestTemplate restTemplate() {
48 | RestTemplate restTemplate = new RestTemplate();
49 | return restTemplate;
50 | }
51 |
52 | @Bean
53 | HelloworldService helloworldService(RestTemplate restTemplate, @Value("${backend.helloworld-service.url}") String endpoint) {
54 | return new HelloworldService(restTemplate, endpoint);
55 | }
56 |
57 | @Bean
58 | GuestbookService guestbookService(RestTemplate restTemplate, @Value("${backend.guestbook-service.url}") String endpoint) {
59 | return new GuestbookService(restTemplate, endpoint);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-service/src/main/java/com/example/guestbook/Message.java:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // TODO: High-level file comment.
16 |
17 | /*
18 | * Copyright 2015 Google Inc. All Rights Reserved.
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | */
32 | package com.example.guestbook;
33 |
34 | import javax.persistence.Entity;
35 | import javax.persistence.GeneratedValue;
36 | import javax.persistence.GenerationType;
37 | import javax.persistence.Id;
38 | import java.io.Serializable;
39 | import java.util.Date;
40 |
41 | /**
42 | * Created by rayt on 5/1/17.
43 | */
44 | @Entity
45 | public class Message implements Serializable {
46 | @Id
47 | @GeneratedValue(strategy = GenerationType.IDENTITY)
48 | private Long id;
49 |
50 | private String username;
51 | private String message;
52 | private Date timestamp;
53 |
54 | public Long getId() {
55 | return id;
56 | }
57 |
58 | public void setId(Long id) {
59 | this.id = id;
60 | }
61 |
62 | public String getUsername() {
63 | return username;
64 | }
65 |
66 | public void setUsername(String username) {
67 | this.username = username;
68 | }
69 |
70 | public String getMessage() {
71 | return message;
72 | }
73 |
74 | public void setMessage(String message) {
75 | this.message = message;
76 | }
77 |
78 | public Date getTimestamp() {
79 | return timestamp;
80 | }
81 |
82 | public void setTimestamp(Date timestamp) {
83 | this.timestamp = timestamp;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-ui/src/main/java/com/example/guestbook/HelloworldUiController.java:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // TODO: High-level file comment.
16 |
17 | /*
18 | * Copyright 2015 Google Inc. All Rights Reserved.
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | */
32 | package com.example.guestbook;
33 |
34 | import org.springframework.stereotype.Controller;
35 | import org.springframework.ui.Model;
36 | import org.springframework.web.bind.annotation.*;
37 | import org.springframework.web.context.annotation.SessionScope;
38 |
39 | import java.util.Map;
40 |
41 | /**
42 | * Created by rayt on 5/1/17.
43 | */
44 | @Controller
45 | @SessionAttributes("name")
46 | public class HelloworldUiController {
47 | private final HelloworldService helloworldService;
48 | private final GuestbookService guestbookService;
49 |
50 | public HelloworldUiController(HelloworldService helloworldService, GuestbookService guestbookService) {
51 | this.helloworldService = helloworldService;
52 | this.guestbookService = guestbookService;
53 | }
54 |
55 | @GetMapping("/")
56 | public String index(Model model) {
57 | if (model.containsAttribute("name")) {
58 | String name = (String) model.asMap().get("name");
59 | Map greeting = helloworldService.greeting(name);
60 | model.addAttribute("greeting", greeting);
61 | }
62 |
63 | model.addAttribute("messages", guestbookService.all());
64 |
65 | return "index";
66 | }
67 |
68 | @PostMapping("/greet")
69 | public String greet(@RequestParam String name, @RequestParam String message, Model model) {
70 | model.addAttribute("name", name);
71 | if (message != null && !message.trim().isEmpty()) {
72 | guestbookService.add(name, message);
73 | }
74 |
75 | return "redirect:/";
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-ui/src/main/java/com/example/guestbook/HelloworldService.java:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // TODO: High-level file comment.
16 |
17 | /*
18 | * Copyright 2015 Google Inc. All Rights Reserved.
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | */
32 | package com.example.guestbook;
33 |
34 | import io.github.resilience4j.bulkhead.Bulkhead;
35 | import org.apache.commons.logging.Log;
36 | import org.apache.commons.logging.LogFactory;
37 | import org.springframework.http.HttpStatus;
38 | import org.springframework.http.client.ClientHttpResponse;
39 | import org.springframework.web.client.HttpStatusCodeException;
40 | import org.springframework.web.client.ResponseErrorHandler;
41 | import org.springframework.web.client.RestTemplate;
42 |
43 | import java.io.IOException;
44 | import java.util.HashMap;
45 | import java.util.Map;
46 | import java.util.function.Supplier;
47 |
48 | /**
49 | * Created by rayt on 5/1/17.
50 | */
51 | public class HelloworldService {
52 | private final static Log log = LogFactory.getLog(HelloworldService.class);
53 | private final RestTemplate restTemplate;
54 | private final String endpoint;
55 |
56 | public HelloworldService(RestTemplate restTemplate, String endpoint) {
57 | this.restTemplate = restTemplate;
58 | this.endpoint = endpoint;
59 | }
60 |
61 | public Map greetingFallback() {
62 | Map response = new HashMap<>();
63 | response.put("greeting", "Unable to connect");
64 | return response;
65 | }
66 |
67 | public Map greeting(String name) {
68 | try {
69 | return restTemplate.getForObject(endpoint + "/" + name, Map.class);
70 | } catch (HttpStatusCodeException e) {
71 | log.error("Error from Helloworld Service, falling back", e);
72 | return greetingFallback();
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/spring-boot-example/helloworld-service/src/main/java/com/example/guestbook/HelloworldApplication.java:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // TODO: High-level file comment.
16 |
17 | /*
18 | * Copyright 2015 Google Inc. All Rights Reserved.
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | */
32 | package com.example.guestbook;
33 |
34 | import org.slf4j.Logger;
35 | import org.slf4j.LoggerFactory;
36 | import org.springframework.beans.factory.annotation.Value;
37 | import org.springframework.boot.SpringApplication;
38 | import org.springframework.boot.autoconfigure.SpringBootApplication;
39 | import org.springframework.web.bind.annotation.GetMapping;
40 | import org.springframework.web.bind.annotation.PathVariable;
41 | import org.springframework.web.bind.annotation.RestController;
42 |
43 | import java.net.InetAddress;
44 | import java.net.UnknownHostException;
45 | import java.util.HashMap;
46 | import java.util.Map;
47 |
48 | @SpringBootApplication
49 | public class HelloworldApplication {
50 | public static void main(String[] args) {
51 | SpringApplication.run(HelloworldApplication.class, args);
52 | }
53 | }
54 |
55 | @RestController
56 | class HelloworldController {
57 | private static final Logger log = LoggerFactory.getLogger(HelloworldController.class);
58 |
59 | @Value("${version:1.0}")
60 | public String version;
61 |
62 | @GetMapping("/hello/{name}")
63 | public Map hello(@Value("${greeting}") String greetingTemplate, @PathVariable String name) throws UnknownHostException {
64 | log.info("Recevied hello request for: " + name);
65 | Map response = new HashMap<>();
66 |
67 | String hostname = InetAddress.getLocalHost().getHostName();
68 | String greeting = greetingTemplate
69 | .replaceAll("\\$name", name)
70 | .replaceAll("\\$hostname", hostname)
71 | .replaceAll("\\$version", version);
72 |
73 | response.put("greeting", greeting);
74 | response.put("version", version);
75 | response.put("hostname", hostname);
76 |
77 | return response;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/jdk-example/work-server/src/main/java/com/example/jdk/WorkServer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.jdk;
17 |
18 | import com.sun.net.httpserver.HttpServer;
19 | import jdk.incubator.http.HttpClient;
20 | import jdk.incubator.http.HttpRequest;
21 | import jdk.incubator.http.HttpResponse;
22 |
23 | import java.io.IOException;
24 | import java.io.OutputStream;
25 | import java.net.InetAddress;
26 | import java.net.InetSocketAddress;
27 | import java.net.URI;
28 | import java.nio.charset.StandardCharsets;
29 | import java.util.Arrays;
30 | import java.util.concurrent.Executors;
31 |
32 | public class WorkServer {
33 | static final String[] TRACE_HEADERS = new String[] {"x-request-id", "x-b3-traceid", "x-b3-spanid", "x-b3-parentspanid", "x-b3-sampled", "x-b3-flags", "x-ot-span-context"};
34 |
35 | public static void main(String[] args) throws IOException {
36 | String endpoint = System.getenv().getOrDefault("ENDPOINT", "http://localhost:8081/meet");
37 | HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
38 | server.setExecutor(Executors.newCachedThreadPool());
39 | String hostName = InetAddress.getLocalHost().getHostName();
40 |
41 | server.createContext("/work", exchange -> {
42 | long start = System.currentTimeMillis();
43 |
44 | HttpClient httpClient = HttpClient.newHttpClient();
45 | HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create(endpoint)).GET()
46 | .version(HttpClient.Version.HTTP_1_1)
47 | .setHeader("User-Agent", "Java/9");
48 |
49 | Arrays.stream(TRACE_HEADERS).forEach(header -> {
50 | String value = exchange.getRequestHeaders().getFirst(header);
51 | if (value != null) {
52 | builder.header(header, value);
53 | }
54 | });
55 |
56 | HttpRequest request = builder.build();
57 |
58 | int meetings = 0;
59 | for (int i = 0; i < 8; i++) {
60 | try {
61 | HttpResponse response = httpClient.send(request, HttpResponse.BodyHandler.asString());
62 | if (response.statusCode() == 200) {
63 | meetings++;
64 | }
65 | } catch (InterruptedException e) {
66 | }
67 | }
68 |
69 | long end = System.currentTimeMillis();
70 |
71 | String response = "Working REALLY HARD for " + (end - start) + "ms, attended " + meetings + " meetings at " + hostName + "\n";
72 | byte[] bytes = response.getBytes(StandardCharsets.UTF_8);
73 | exchange.sendResponseHeaders(200, bytes.length);
74 | OutputStream os = exchange.getResponseBody();
75 |
76 | os.write(bytes);
77 | os.close();
78 | });
79 |
80 | server.start();
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/spring-boot-example/work-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.example
7 | work-server
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | work-server
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.0.2.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 | Finchley.RELEASE
26 | saturnism
27 |
28 |
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-starter-web
33 |
34 |
35 | org.springframework.cloud
36 | spring-cloud-starter-sleuth
37 |
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-starter-test
42 | test
43 |
44 |
45 |
46 |
47 |
48 |
49 | org.springframework.cloud
50 | spring-cloud-dependencies
51 | ${spring-cloud.version}
52 | pom
53 | import
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | org.springframework.boot
62 | spring-boot-maven-plugin
63 |
64 |
65 | com.spotify
66 | dockerfile-maven-plugin
67 | 1.3.6
68 |
69 | ${docker.image.prefix}/${project.artifactId}-istio
70 | latest
71 |
72 |
73 |
74 | package
75 |
76 | build
77 | push
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | spring-snapshots
88 | Spring Snapshots
89 | https://repo.spring.io/snapshot
90 |
91 | true
92 |
93 |
94 |
95 | spring-milestones
96 | Spring Milestones
97 | https://repo.spring.io/milestone
98 |
99 | false
100 |
101 |
102 |
103 |
104 |
105 |
106 |
--------------------------------------------------------------------------------
/spring-boot-example/meeting-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.example
7 | meeting-server
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | meeting-server
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.0.2.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 | Finchley.RELEASE
26 | saturnism
27 |
28 |
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-starter-web
33 |
34 |
35 | org.springframework.cloud
36 | spring-cloud-starter-sleuth
37 |
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-starter-test
42 | test
43 |
44 |
45 |
46 |
47 |
48 |
49 | org.springframework.cloud
50 | spring-cloud-dependencies
51 | ${spring-cloud.version}
52 | pom
53 | import
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | org.springframework.boot
62 | spring-boot-maven-plugin
63 |
64 |
65 | com.spotify
66 | dockerfile-maven-plugin
67 | 1.3.6
68 |
69 | ${docker.image.prefix}/${project.artifactId}-istio
70 | latest
71 |
72 |
73 |
74 | package
75 |
76 | build
77 | push
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | spring-snapshots
88 | Spring Snapshots
89 | https://repo.spring.io/snapshot
90 |
91 | true
92 |
93 |
94 |
95 | spring-milestones
96 | Spring Milestones
97 | https://repo.spring.io/milestone
98 |
99 | false
100 |
101 |
102 |
103 |
104 |
105 |
106 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-ui/src/main/resources/templates/index.html:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | Hello World Guestbook
19 |
20 |
21 |
22 |
32 |
33 |
34 |
52 |
53 |
54 |
55 |
60 |
61 |
62 |
63 | Greeting
64 |
65 |
66 |
67 |
68 | Username
69 | Message
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/spring-boot-example/helloworld-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
19 | 4.0.0
20 |
21 | com.example.guestbook
22 | helloworld-service
23 | 0.0.1-SNAPSHOT
24 | jar
25 |
26 | helloworld-service
27 | Demo project for Spring Boot
28 |
29 |
30 | com.example.guestbook
31 | spring-boot2-example
32 | 0.0.1-SNAPSHOT
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-web
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-starter-actuator
43 |
44 |
45 | org.springframework.cloud
46 | spring-cloud-starter-sleuth
47 |
48 |
49 | org.springframework.boot
50 | spring-boot-starter-test
51 | test
52 |
53 |
54 |
55 |
56 |
57 |
58 | org.springframework.cloud
59 | spring-cloud-dependencies
60 | ${spring-cloud.version}
61 | pom
62 | import
63 |
64 |
65 |
66 |
67 |
68 |
69 |
75 |
76 | maven-jar-plugin
77 |
78 |
79 |
80 | true
81 | lib/
82 | com.example.guestbook.HelloworldApplication
83 |
84 |
85 |
86 |
87 |
88 | maven-dependency-plugin
89 |
90 |
91 | com.spotify
92 | dockerfile-maven-plugin
93 |
94 |
95 | pl.project13.maven
96 | git-commit-id-plugin
97 |
98 |
99 |
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
19 | 4.0.0
20 |
21 | com.example.guestbook
22 | guestbook-service
23 | 0.0.1-SNAPSHOT
24 | jar
25 |
26 | guestbook-service
27 | Demo project for Spring Boot
28 |
29 |
30 | com.example.guestbook
31 | spring-boot2-example
32 | 0.0.1-SNAPSHOT
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-actuator
39 |
40 |
41 | org.springframework.cloud
42 | spring-cloud-starter-sleuth
43 |
44 |
45 | org.springframework.boot
46 | spring-boot-starter-data-jpa
47 |
48 |
49 | org.springframework.boot
50 | spring-boot-starter-data-rest
51 |
52 |
53 | mysql
54 | mysql-connector-java
55 |
56 |
57 | org.springframework.boot
58 | spring-boot-starter-test
59 | test
60 |
61 |
62 |
63 |
64 |
65 |
66 | org.springframework.cloud
67 | spring-cloud-dependencies
68 | ${spring-cloud.version}
69 | pom
70 | import
71 |
72 |
73 |
74 |
75 |
76 |
77 |
83 |
84 | maven-jar-plugin
85 |
86 |
87 |
88 | true
89 | lib/
90 | com.example.guestbook.GuestbookServiceApplication
91 |
92 |
93 |
94 |
95 |
96 | maven-dependency-plugin
97 |
98 |
99 | com.spotify
100 | dockerfile-maven-plugin
101 |
102 |
103 | pl.project13.maven
104 | git-commit-id-plugin
105 |
106 |
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/jdk-example/README.md:
--------------------------------------------------------------------------------
1 | ## Setup a Kubernetes cluster on Google Cloud Platform
2 |
3 | You'll need a [Google Cloud Platform account](https://cloud.google.com/), a [Project](https://cloud.google.com/resource-manager/docs/creating-managing-projects), and [gcloud SDK](https://cloud.google.com/sdk/).
4 |
5 | First, create a new Kubernetes cluster with alpha features to take advantage of Kubernetes initializer.
6 | ```
7 | $ export ISTIO_PROJECT_ID=$(gcloud config get-value core/project)
8 | $ gcloud --project=$ISTIO_PROJECT_ID alpha container clusters create istio-cluster \
9 | --zone=us-central1-c --num-nodes=4 --machine-type=n1-standard-4 \
10 | --cluster-version=1.7.8-gke.0 --enable-kubernetes-alpha
11 | ```
12 |
13 | Once the cluster was created, make sure your user account has admin role within the Kubernetes cluster:
14 | ```
15 | $ kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin \
16 | --user=$(gcloud config get-value core/account)
17 | ```
18 |
19 | ## Install Istio
20 |
21 | Install Istio CLI:
22 | ```
23 | $ cd ~/
24 | $ curl -L https://git.io/getLatestIstio | sh -
25 | $ export PATH="$PATH:$HOME/istio-0.2.7/bin"
26 | ```
27 |
28 | Install Istio Service Mesh in Kubernetes:
29 | ```
30 | $ cd ~/istio-0.2.7
31 | $ kubectl apply -f install/kubernetes/istio-auth.yaml
32 | $ kubectl apply -f install/kubernetes/istio-initializer.yaml
33 | ```
34 |
35 | Install Add-ons for Grafana, Prometheus, and Zipkin:
36 | ```
37 | $ cd ~/istio-0.2.7
38 | $ kubectl apply -f install/kubernetes/addons/zipkin.yaml
39 | $ kubectl apply -f install/kubernetes/addons/grafana.yaml
40 | $ kubectl apply -f install/kubernetes/addons/prometheus.yaml
41 | $ kubectl apply -f install/kubernetes/addons/servicegraph.yaml
42 | ```
43 |
44 | Check the status and make sure all the components are in running state before continuing:
45 | ```
46 | $ kubectl get pods -n istio-system
47 | ```
48 |
49 | Enable firewall to allow connection to the Istio ingress:
50 | ```
51 | $ gcloud --project=$ISTIO_PROJECT_ID compute firewall-rules create allow-istio-ingress \
52 | --allow tcp:$(kubectl get svc istio-ingress -n istio-system -o jsonpath='{.spec.ports[0].nodePort}')
53 | ```
54 |
55 | ## Deploy Application to Kubernetes
56 | Check out the example code:
57 | ```
58 | $ cd ~/
59 | $ git clone https://github.com/saturnism/istio-by-example-java.git
60 | $ cd istio-by-example-java/jdk-example
61 | ```
62 |
63 | Deploy the application:
64 | ```
65 | $ kubectl apply -f kubernetes/
66 | ```
67 |
68 | Notice that the YAML files are just regular Kubernetes deployment YAML. This is because Istio 0.2+ can use Kubernetes initializer feature.
69 | During deployment time, Kubernetes will automatically & transparently inject additional sidecars and configurations to these YAML files.
70 |
71 | ## Addons
72 | ### Grafana
73 | Establish port forward from local port 3000 to the Grafana instance:
74 | ```
75 | $ kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=grafana \
76 | -o jsonpath='{.items[0].metadata.name}') 3000:3000
77 | ```
78 |
79 | Browse to http://localhost:3000 and navigate to Istio Dashboard
80 |
81 | ### Zipkin
82 | Establish port forward from local port
83 | ```
84 | $ kubectl port-forward -n istio-system \
85 | $(kubectl get pod -n istio-system -l app=zipkin -o jsonpath='{.items[0].metadata.name}') \
86 | 9411:9411
87 | ```
88 |
89 | Browse to http://localhost:9411
90 |
91 | ### Prometheus
92 | ```
93 | $ kubectl -n istio-system port-forward \
94 | $(kubectl -n istio-system get pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') \
95 | 9090:9090
96 | ```
97 |
98 | ### Service Graph
99 | ```
100 | $ kubectl -n istio-system port-forward \
101 | $(kubectl -n istio-system get pod -l app=servicegraph -o jsonpath='{.items[0].metadata.name}') \
102 | 8088:8088
103 | ```
104 |
105 | Browse to http://localhost:8088/dotviz
106 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-ui/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
19 | 4.0.0
20 |
21 | com.example.guestbook
22 | guestbook-ui
23 | 0.0.1-SNAPSHOT
24 | jar
25 |
26 | guestbook-ui
27 | Demo project for Spring Boot
28 |
29 |
30 | com.example.guestbook
31 | spring-boot2-example
32 | 0.0.1-SNAPSHOT
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-actuator
39 |
40 |
41 | org.springframework.cloud
42 | spring-cloud-starter-sleuth
43 |
44 |
45 | io.github.resilience4j
46 | resilience4j-bulkhead
47 | 0.10.0
48 |
49 |
50 | org.springframework.boot
51 | spring-boot-starter-thymeleaf
52 |
53 |
54 | org.springframework.boot
55 | spring-boot-starter-web
56 |
57 |
58 | org.springframework.boot
59 | spring-boot-starter-data-redis
60 |
61 |
62 | org.springframework.session
63 | spring-session-data-redis
64 |
65 |
66 | org.springframework.boot
67 | spring-boot-starter-test
68 | test
69 |
70 |
71 |
72 |
73 |
74 |
75 | org.springframework.cloud
76 | spring-cloud-dependencies
77 | ${spring-cloud.version}
78 | pom
79 | import
80 |
81 |
82 |
83 |
84 |
85 |
86 |
92 |
93 | maven-jar-plugin
94 |
95 |
96 |
97 | true
98 | lib/
99 | com.example.guestbook.HelloworldUiApplication
100 |
101 |
102 |
103 |
104 |
105 | maven-dependency-plugin
106 |
107 |
108 | com.spotify
109 | dockerfile-maven-plugin
110 |
111 |
112 | pl.project13.maven
113 | git-commit-id-plugin
114 |
115 |
116 |
117 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/spring-boot-example/guestbook-ui/src/main/java/com/example/guestbook/GuestbookService.java:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // TODO: High-level file comment.
16 |
17 | /*
18 | * Copyright 2015 Google Inc. All Rights Reserved.
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | */
32 | package com.example.guestbook;
33 |
34 | import io.vavr.control.Try;
35 | import org.apache.commons.logging.Log;
36 | import org.apache.commons.logging.LogFactory;
37 | import org.slf4j.LoggerFactory;
38 | import org.springframework.http.HttpStatus;
39 | import org.springframework.web.client.HttpStatusCodeException;
40 | import org.springframework.web.client.RestTemplate;
41 |
42 | import java.text.DateFormat;
43 | import java.text.SimpleDateFormat;
44 | import java.util.*;
45 | import java.util.stream.Collectors;
46 |
47 | /**
48 | * Created by rayt on 5/1/17.
49 | */
50 | public class GuestbookService {
51 | private static final Log log = LogFactory.getLog(GuestbookService.class);
52 | private final RestTemplate restTemplate;
53 | private final String endpoint;
54 | private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
55 |
56 | public GuestbookService(RestTemplate restTemplate, String endpoint) {
57 | this.restTemplate = restTemplate;
58 | this.endpoint = endpoint;
59 | }
60 |
61 | public Map add(String username, String message) {
62 | Map payload = new HashMap<>();
63 | payload.put("username", username);
64 | payload.put("message", message);
65 | payload.put("timestamp", dateFormat.format(new Date()));
66 |
67 | // Istio can handle circuit breaking. Don't need to retry here.
68 | return restTemplate.postForObject(endpoint, payload, Map.class);
69 | }
70 |
71 | public List