From 4fa4b1123097fd935cae65094426916cc1badd9e Mon Sep 17 00:00:00 2001 From: spencergibb Date: Wed, 20 May 2020 12:35:43 -0400 Subject: [PATCH] Removes references to ribbon modules from docs and poms Fixes gh-530 --- README.adoc | 99 +------- docs/src/main/asciidoc/discovery-client.adoc | 3 +- .../asciidoc/discovery-kubernetes-native.adoc | 2 +- docs/src/main/asciidoc/getting-started.adoc | 10 - .../src/main/asciidoc/ribbon-integration.adoc | 80 ------- docs/src/main/asciidoc/sagan-index.adoc | 1 - .../asciidoc/security-service-accounts.adoc | 3 - .../asciidoc/spring-cloud-kubernetes.adoc | 2 - spring-cloud-kubernetes-dependencies/pom.xml | 12 - .../greeting-service/pom.xml | 73 ------ .../src/main/fabric8/route.yml | 10 - .../examples/GreetingController.java | 55 ----- .../examples/GreetingServiceApplication.java | 49 ---- .../kubernetes/examples/NameService.java | 50 ---- .../examples/RibbonConfiguration.java | 63 ----- .../src/main/resources/application.yml | 17 -- .../name-service/pom.xml | 57 ----- .../name-service/src/main/fabric8/route.yml | 10 - .../kubernetes/examples/NameController.java | 68 ------ .../examples/NameServiceApplication.java | 34 --- .../src/main/resources/application.yml | 6 - .../pom.xml | 174 -------------- .../readme.md | 219 ------------------ .../kubernetes-zipkin-example/README.md | 159 ------------- .../kubernetes-zipkin-example/pom.xml | 154 ------------ .../kubernetes/examples/TraceController.java | 73 ------ .../examples/ZipkinApplication.java | 46 ---- .../src/main/resources/application.yml | 12 - spring-cloud-kubernetes-examples/pom.xml | 2 - 29 files changed, 4 insertions(+), 1539 deletions(-) delete mode 100644 docs/src/main/asciidoc/ribbon-integration.adoc delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/pom.xml delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/fabric8/route.yml delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/GreetingController.java delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/GreetingServiceApplication.java delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/NameService.java delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/RibbonConfiguration.java delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/resources/application.yml delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/pom.xml delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/fabric8/route.yml delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/java/org/springframework/cloud/kubernetes/examples/NameController.java delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/java/org/springframework/cloud/kubernetes/examples/NameServiceApplication.java delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/resources/application.yml delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/pom.xml delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/readme.md delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-zipkin-example/README.md delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-zipkin-example/pom.xml delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-zipkin-example/src/main/java/org/springframework/cloud/kubernetes/examples/TraceController.java delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-zipkin-example/src/main/java/org/springframework/cloud/kubernetes/examples/ZipkinApplication.java delete mode 100644 spring-cloud-kubernetes-examples/kubernetes-zipkin-example/src/main/resources/application.yml diff --git a/README.adoc b/README.adoc index 84345252..fae8bfc2 100644 --- a/README.adoc +++ b/README.adoc @@ -61,16 +61,6 @@ resolves service names to Kubernetes Services. <> application properties when a ConfigMap or Secret changes. -| [source,xml] ----- - - org.springframework.cloud - spring-cloud-starter-kubernetes-ribbon - ----- -| <> client-side load balancer with -server list obtained from Kubernetes Endpoints. - | [source,xml] ---- @@ -88,8 +78,7 @@ This project provides an implementation of https://github.com/spring-cloud/sprin for https://kubernetes.io[Kubernetes]. This client lets you query Kubernetes endpoints (see https://kubernetes.io/docs/user-guide/services/[services]) by name. A service is typically exposed by the Kubernetes API server as a collection of endpoints that represent `http` and `https` addresses and that a client can -access from a Spring Boot application running as a pod. This discovery feature is also used by the Spring Cloud Kubernetes Ribbon project -to fetch the list of the endpoints defined for an application to be load balanced. +access from a Spring Boot application running as a pod. This is something that you get for free by adding the following dependency inside your project: @@ -158,7 +147,7 @@ Spring Cloud Kubernetes can also watch the Kubernetes service catalog for change == Kubernetes native service discovery Kubernetes itself is capable of (server side) service discovery (see: https://kubernetes.io/docs/concepts/services-networking/service/#discovering-services). -Using native kubernetes service discovery ensures compatibility with additional tooling, such as Istio (https://istio.io), a service mesh that is capable of load balancing, ribbon, circuit breaker, failover, and much more. +Using native kubernetes service discovery ensures compatibility with additional tooling, such as Istio (https://istio.io), a service mesh that is capable of load balancing, circuit breaker, failover, and much more. The caller service then need only refer to names resolvable in a particular Kubernetes cluster. A simple implementation might use a spring `RestTemplate` that refers to a fully qualified domain name (FQDN), such as `https://{service-name}.{namespace}.svc.{cluster}.local:{service-port}`. @@ -733,87 +722,6 @@ Notes: * You should not use properties under `spring.cloud.kubernetes.reload` in config maps or secrets. Changing such properties at runtime may lead to unexpected results. * Deleting a property or the whole config map does not restore the original state of the beans when you use the `refresh` level. -== Ribbon Discovery in Kubernetes - - -Spring Cloud client applications that call a microservice should be interested on relying on a client load-balancing -feature in order to automatically discover at which endpoint(s) it can reach a given service. This mechanism has been -implemented within the https://github.com/spring-cloud/spring-cloud-kubernetes/tree/master/spring-cloud-kubernetes-ribbon[spring-cloud-kubernetes-ribbon] project, where a -Kubernetes client populates a https://github.com/Netflix/ribbon[Ribbon] `ServerList` that contains information -about such endpoints. - -The implementation is part of the following starter that you can use by adding its dependency to your pom file: - -==== -[source,xml] ----- - - org.springframework.cloud - spring-cloud-starter-kubernetes-ribbon - ${latest.version} - ----- -==== - -When the list of the endpoints is populated, the Kubernetes client searches the registered endpoints that live in -the current namespace or project by matching the service name defined in the Ribbon Client annotation, as follows: - -==== -[source,java] ----- -@RibbonClient(name = "name-service") ----- -==== - -You can configure Ribbon's behavior by providing properties in your `application.properties` (through your application's -dedicated `ConfigMap`) by using the following format: `.ribbon.`, where: - -* `` corresponds to the service name you access over Ribbon, as configured by using the -`@RibbonClient` annotation (such as `name-service` in the preceding example). -* `` is one of the Ribbon configuration keys defined by -https://github.com/Netflix/ribbon/blob/master/ribbon-core/src/main/java/com/netflix/client/config/CommonClientConfigKey.java[Ribbon's `CommonClientConfigKey` class]. - -Additionally, the `spring-cloud-kubernetes-ribbon` project defines two additional configuration keys to further -control how Ribbon interacts with Kubernetes. In particular, if an endpoint defines multiple ports, the default -behavior is to use the first one found. To select more specifically which port to use in a multi-port service, you can use -the `PortName` key. If you want to specify in which Kubernetes namespace the target service should be looked up, you can use -the `KubernetesNamespace` key, remembering in both instances to prefix these keys with your service name and -`ribbon` prefix, as specified earlier. - -.Spring Cloud Kubernetes Ribbon Configuration -|=== -|Property Key |Type |Default Value - -|spring.cloud.kubernetes.ribbon.enabled -|boolean -|true - -|spring.cloud.kubernetes.ribbon.mode -|`KubernetesRibbonMode` -|POD - -|spring.cloud.kubernetes.ribbon.cluster-domain -|string -|cluster.local -|=== - -* `spring.cloud.kubernetes.ribbon.mode` supports `POD` and `SERVICE` modes. -** The POD mode is to achieve load balancing by obtaining the Pod IP address of Kubernetes and using Ribbon. - POD mode uses the load balancing of the Ribbon Does not support Kubernetes load balancing, The traffic policy of `Istio` is not supported. -** the `SERVICE` mode is directly based on the `service name` of the Ribbon. Get -The Kubernetes service is concatenated into `service-name.{namespace}.svc.{cluster.domain}:{port}` such as: `demo1.default.svc.cluster.local:8080`. -the `SERVICE` mode uses load balancing of the Kubernetes service to support Istio's traffic policy. - -* `spring.cloud.kubernetes.ribbon.cluster-domain` Set the custom Kubernetes cluster domain suffix. The default value is: 'cluster.local' - -The following examples use this module for ribbon discovery: - -* link:./spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example[Spring Cloud Circuitbreaker and Ribbon] -* https://github.com/fabric8-quickstarts/spring-boot-ribbon[fabric8-quickstarts - Spring Boot - Ribbon] -* https://github.com/fabric8io/kubeflix/tree/master/examples/loanbroker/bank[Kubeflix - LoanBroker - Bank] - -NOTE: You can disable the Ribbon discovery client by setting the `spring.cloud.kubernetes.ribbon.enabled=false` key within the application properties file. - == Kubernetes Ecosystem Awareness All of the features described earlier in this guide work equally well, regardless of whether your application is running inside @@ -893,9 +801,6 @@ Depending on the requirements, you'll need `get`, `list` and `watch` permission |spring-cloud-starter-kubernetes-config |configmaps, secrets - -|spring-cloud-starter-kubernetes-ribbon -|pods, services, endpoints |=== For development purposes, you can add `cluster-reader` permissions to your `default` service account. On a production system you'll likely want to provide more granular permissions. diff --git a/docs/src/main/asciidoc/discovery-client.adoc b/docs/src/main/asciidoc/discovery-client.adoc index c191751c..c830197b 100644 --- a/docs/src/main/asciidoc/discovery-client.adoc +++ b/docs/src/main/asciidoc/discovery-client.adoc @@ -4,8 +4,7 @@ This project provides an implementation of https://github.com/spring-cloud/sprin for https://kubernetes.io[Kubernetes]. This client lets you query Kubernetes endpoints (see https://kubernetes.io/docs/user-guide/services/[services]) by name. A service is typically exposed by the Kubernetes API server as a collection of endpoints that represent `http` and `https` addresses and that a client can -access from a Spring Boot application running as a pod. This discovery feature is also used by the Spring Cloud Kubernetes Ribbon project -to fetch the list of the endpoints defined for an application to be load balanced. +access from a Spring Boot application running as a pod. This is something that you get for free by adding the following dependency inside your project: diff --git a/docs/src/main/asciidoc/discovery-kubernetes-native.adoc b/docs/src/main/asciidoc/discovery-kubernetes-native.adoc index d828681f..aa5e2f8d 100644 --- a/docs/src/main/asciidoc/discovery-kubernetes-native.adoc +++ b/docs/src/main/asciidoc/discovery-kubernetes-native.adoc @@ -1,7 +1,7 @@ == Kubernetes native service discovery Kubernetes itself is capable of (server side) service discovery (see: https://kubernetes.io/docs/concepts/services-networking/service/#discovering-services). -Using native kubernetes service discovery ensures compatibility with additional tooling, such as Istio (https://istio.io), a service mesh that is capable of load balancing, ribbon, circuit breaker, failover, and much more. +Using native kubernetes service discovery ensures compatibility with additional tooling, such as Istio (https://istio.io), a service mesh that is capable of load balancing, circuit breaker, failover, and much more. The caller service then need only refer to names resolvable in a particular Kubernetes cluster. A simple implementation might use a spring `RestTemplate` that refers to a fully qualified domain name (FQDN), such as `https://{service-name}.{namespace}.svc.{cluster}.local:{service-port}`. diff --git a/docs/src/main/asciidoc/getting-started.adoc b/docs/src/main/asciidoc/getting-started.adoc index 87f299e1..fee5e34b 100644 --- a/docs/src/main/asciidoc/getting-started.adoc +++ b/docs/src/main/asciidoc/getting-started.adoc @@ -30,16 +30,6 @@ resolves service names to Kubernetes Services. <> application properties when a ConfigMap or Secret changes. -| [source,xml] ----- - - org.springframework.cloud - spring-cloud-starter-kubernetes-ribbon - ----- -| <> client-side load balancer with -server list obtained from Kubernetes Endpoints. - | [source,xml] ---- diff --git a/docs/src/main/asciidoc/ribbon-integration.adoc b/docs/src/main/asciidoc/ribbon-integration.adoc deleted file mode 100644 index 967ef343..00000000 --- a/docs/src/main/asciidoc/ribbon-integration.adoc +++ /dev/null @@ -1,80 +0,0 @@ -== Ribbon Discovery in Kubernetes - - -Spring Cloud client applications that call a microservice should be interested on relying on a client load-balancing -feature in order to automatically discover at which endpoint(s) it can reach a given service. This mechanism has been -implemented within the https://github.com/spring-cloud/spring-cloud-kubernetes/tree/master/spring-cloud-kubernetes-ribbon[spring-cloud-kubernetes-ribbon] project, where a -Kubernetes client populates a https://github.com/Netflix/ribbon[Ribbon] `ServerList` that contains information -about such endpoints. - -The implementation is part of the following starter that you can use by adding its dependency to your pom file: - -==== -[source,xml] ----- - - org.springframework.cloud - spring-cloud-starter-kubernetes-ribbon - ${latest.version} - ----- -==== - -When the list of the endpoints is populated, the Kubernetes client searches the registered endpoints that live in -the current namespace or project by matching the service name defined in the Ribbon Client annotation, as follows: - -==== -[source,java] ----- -@RibbonClient(name = "name-service") ----- -==== - -You can configure Ribbon's behavior by providing properties in your `application.properties` (through your application's -dedicated `ConfigMap`) by using the following format: `.ribbon.`, where: - -* `` corresponds to the service name you access over Ribbon, as configured by using the -`@RibbonClient` annotation (such as `name-service` in the preceding example). -* `` is one of the Ribbon configuration keys defined by -https://github.com/Netflix/ribbon/blob/master/ribbon-core/src/main/java/com/netflix/client/config/CommonClientConfigKey.java[Ribbon's `CommonClientConfigKey` class]. - -Additionally, the `spring-cloud-kubernetes-ribbon` project defines two additional configuration keys to further -control how Ribbon interacts with Kubernetes. In particular, if an endpoint defines multiple ports, the default -behavior is to use the first one found. To select more specifically which port to use in a multi-port service, you can use -the `PortName` key. If you want to specify in which Kubernetes namespace the target service should be looked up, you can use -the `KubernetesNamespace` key, remembering in both instances to prefix these keys with your service name and -`ribbon` prefix, as specified earlier. - -.Spring Cloud Kubernetes Ribbon Configuration -|=== -|Property Key |Type |Default Value - -|spring.cloud.kubernetes.ribbon.enabled -|boolean -|true - -|spring.cloud.kubernetes.ribbon.mode -|`KubernetesRibbonMode` -|POD - -|spring.cloud.kubernetes.ribbon.cluster-domain -|string -|cluster.local -|=== - -* `spring.cloud.kubernetes.ribbon.mode` supports `POD` and `SERVICE` modes. -** The POD mode is to achieve load balancing by obtaining the Pod IP address of Kubernetes and using Ribbon. - POD mode uses the load balancing of the Ribbon Does not support Kubernetes load balancing, The traffic policy of `Istio` is not supported. -** the `SERVICE` mode is directly based on the `service name` of the Ribbon. Get -The Kubernetes service is concatenated into `service-name.{namespace}.svc.{cluster.domain}:{port}` such as: `demo1.default.svc.cluster.local:8080`. -the `SERVICE` mode uses load balancing of the Kubernetes service to support Istio's traffic policy. - -* `spring.cloud.kubernetes.ribbon.cluster-domain` Set the custom Kubernetes cluster domain suffix. The default value is: 'cluster.local' - -The following examples use this module for ribbon discovery: - -* link:./spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example[Spring Cloud Circuitbreaker and Ribbon] -* https://github.com/fabric8-quickstarts/spring-boot-ribbon[fabric8-quickstarts - Spring Boot - Ribbon] -* https://github.com/fabric8io/kubeflix/tree/master/examples/loanbroker/bank[Kubeflix - LoanBroker - Bank] - -NOTE: You can disable the Ribbon discovery client by setting the `spring.cloud.kubernetes.ribbon.enabled=false` key within the application properties file. diff --git a/docs/src/main/asciidoc/sagan-index.adoc b/docs/src/main/asciidoc/sagan-index.adoc index dd6294ef..16f5bec6 100644 --- a/docs/src/main/asciidoc/sagan-index.adoc +++ b/docs/src/main/asciidoc/sagan-index.adoc @@ -7,7 +7,6 @@ The main objective of the projects provided in this repository is to facilitate * Kubernetes awareness * `DiscoveryClient` implementation * `PropertySource` objects configured via ConfigMaps -* Client side loadbalancing via Netflix Ribbon ## Getting Started The easiest way to get started is by including the Spring Cloud BOM and then adding `spring-cloud-starter-kubernetes-all` to your application's classpath. If you don't want to include all of the Spring Cloud Kubernetes features you can add individual starters for the features you would like. By default Spring Cloud Kubernetes will enable the `kubernetes` profile when it detects it is running inside a Kubernetes cluster. You can take advantage of this by creating a `kubernetes-application` configuration properties for anything specific to Kubernetes you might want to configure. Once the starter is on the classpath the application should behave as any other Spring Cloud application. diff --git a/docs/src/main/asciidoc/security-service-accounts.adoc b/docs/src/main/asciidoc/security-service-accounts.adoc index 3aa77034..f4d08a78 100644 --- a/docs/src/main/asciidoc/security-service-accounts.adoc +++ b/docs/src/main/asciidoc/security-service-accounts.adoc @@ -34,9 +34,6 @@ Depending on the requirements, you'll need `get`, `list` and `watch` permission |spring-cloud-starter-kubernetes-config |configmaps, secrets - -|spring-cloud-starter-kubernetes-ribbon -|pods, services, endpoints |=== For development purposes, you can add `cluster-reader` permissions to your `default` service account. On a production system you'll likely want to provide more granular permissions. diff --git a/docs/src/main/asciidoc/spring-cloud-kubernetes.adoc b/docs/src/main/asciidoc/spring-cloud-kubernetes.adoc index 3ad907fa..2b194831 100644 --- a/docs/src/main/asciidoc/spring-cloud-kubernetes.adoc +++ b/docs/src/main/asciidoc/spring-cloud-kubernetes.adoc @@ -16,8 +16,6 @@ include::discovery-kubernetes-native.adoc[] include::property-source-config.adoc[] -include::ribbon-integration.adoc[] - include::kubernetes-awareness.adoc[] include::pod-health-indicator.adoc[] diff --git a/spring-cloud-kubernetes-dependencies/pom.xml b/spring-cloud-kubernetes-dependencies/pom.xml index 701510d5..48b97e1a 100644 --- a/spring-cloud-kubernetes-dependencies/pom.xml +++ b/spring-cloud-kubernetes-dependencies/pom.xml @@ -80,12 +80,6 @@ ${project.version} - - org.springframework.cloud - spring-cloud-kubernetes-ribbon - ${project.version} - - org.springframework.cloud spring-cloud-kubernetes-leader @@ -105,12 +99,6 @@ ${project.version} - - org.springframework.cloud - spring-cloud-starter-kubernetes-ribbon - ${project.version} - - org.springframework.cloud spring-cloud-starter-kubernetes-all diff --git a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/pom.xml b/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/pom.xml deleted file mode 100644 index f9617e9e..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/pom.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - 4.0.0 - - org.springframework.cloud - kubernetes-circuitbreaker-ribbon-example - 1.1.3.BUILD-SNAPSHOT - - - greeting-service - Circuit Breaker & Load Balancer :: Greeting Service - Circuit Breaker & Load Balancer :: Greeting Service - - - - - org.apache.maven.plugins - maven-deploy-plugin - ${maven-deploy-plugin.version} - - true - - - - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.cloud - spring-cloud-starter-netflix-ribbon - - - org.springframework.cloud - spring-cloud-starter-netflix-hystrix - - - org.springframework.cloud - spring-cloud-starter-kubernetes-ribbon - - - com.squareup.okhttp3 - okhttp - - - - diff --git a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/fabric8/route.yml b/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/fabric8/route.yml deleted file mode 100644 index d6881f9f..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/fabric8/route.yml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: v1 -kind: Route -metadata: - name: greeting-service -spec: - port: - targetPort: 8080 - to: - kind: Service - name: greeting-service diff --git a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/GreetingController.java b/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/GreetingController.java deleted file mode 100644 index ea98d147..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/GreetingController.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2016 to the original authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.kubernetes.examples; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -/** - * Greeting service controller. - * - * @author Gytis Trikleris - */ -@RestController -public class GreetingController { - - private final NameService nameService; - - public GreetingController(NameService nameService) { - this.nameService = nameService; - } - - /** - * Endpoint to get a greeting. This endpoint uses a name server to get a name for the - * greeting. - * - * Request to the name service is guarded with a circuit breaker. Therefore if a name - * service is not available or is too slow to response fallback name is used. - * - * Delay parameter can me used to make name service response slower. - * @param delay Milliseconds for how long the response from name service should be - * delayed. - * @return Greeting string. - */ - @RequestMapping("/greeting") - public String getGreeting( - @RequestParam(value = "delay", defaultValue = "0") int delay) { - return String.format("Hello from %s!", this.nameService.getName(delay)); - } - -} diff --git a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/GreetingServiceApplication.java b/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/GreetingServiceApplication.java deleted file mode 100644 index 695c0e18..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/GreetingServiceApplication.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2016 to the original authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.kubernetes.examples; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.client.loadbalancer.LoadBalanced; -import org.springframework.cloud.netflix.ribbon.RibbonClient; -import org.springframework.context.annotation.Bean; -import org.springframework.web.client.RestTemplate; - -/** - * Entry point to the application. - * - * @author Gytis Trikleris - */ -@SpringBootApplication -@EnableDiscoveryClient -@EnableCircuitBreaker -@RibbonClient(name = "name-service", configuration = RibbonConfiguration.class) -public class GreetingServiceApplication { - - public static void main(String[] args) { - SpringApplication.run(GreetingServiceApplication.class, args); - } - - @LoadBalanced - @Bean - RestTemplate restTemplate() { - return new RestTemplate(); - } - -} diff --git a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/NameService.java b/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/NameService.java deleted file mode 100644 index a1de3dbe..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/NameService.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2016 to the original authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.kubernetes.examples; - -import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; -import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; - -import org.springframework.stereotype.Service; -import org.springframework.web.client.RestTemplate; - -/** - * Service invoking name-service via REST and guarded by Hystrix. - * - * @author Gytis Trikleris - */ -@Service -public class NameService { - - private final RestTemplate restTemplate; - - public NameService(RestTemplate restTemplate) { - this.restTemplate = restTemplate; - } - - @HystrixCommand(fallbackMethod = "getFallbackName", commandProperties = { - @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000") }) - public String getName(int delay) { - return this.restTemplate.getForObject( - String.format("https://name-service/name?delay=%d", delay), String.class); - } - - private String getFallbackName(int delay) { - return "Fallback"; - } - -} diff --git a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/RibbonConfiguration.java b/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/RibbonConfiguration.java deleted file mode 100644 index 053453e2..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/java/org/springframework/cloud/kubernetes/examples/RibbonConfiguration.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2016 to the original authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.kubernetes.examples; - -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.AvailabilityFilteringRule; -import com.netflix.loadbalancer.IPing; -import com.netflix.loadbalancer.IRule; -import com.netflix.loadbalancer.PingUrl; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; - -/** - * Ribbon configuration. - * - * @author Obsidian Quickstarts - */ -public class RibbonConfiguration { - - @Autowired - IClientConfig ribbonClientConfig; - - /** - * PingUrl will ping a URL to check the status of each server. Say Hello has, as - * you’ll recall, a method mapped to the /path; that means that Ribbon will get an - * HTTP 200 response when it pings a running Backend Server - * @param config Client configuration - * @return The URL to be used for the Ping - */ - @Bean - public IPing ribbonPing(IClientConfig config) { - return new PingUrl(); - } - - /** - * AvailabilityFilteringRule will use Ribbon’s built-in circuit breaker functionality - * to filter out any servers in an “open-circuit” state: if a ping fails to connect to - * a given server, or if it gets a read failure for the server, Ribbon will consider - * that server “dead” until it begins to respond normally. - * @param config Client configuration - * @return The Load Balancer rule - */ - @Bean - public IRule ribbonRule(IClientConfig config) { - return new AvailabilityFilteringRule(); - } - -} diff --git a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/resources/application.yml b/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/resources/application.yml deleted file mode 100644 index 83f34e7e..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/greeting-service/src/main/resources/application.yml +++ /dev/null @@ -1,17 +0,0 @@ -spring: - application: - name: greeting-service - -server: - port: 8080 - -backend: - ribbon: - eureka: - enabled: false - client: - enabled: true - ServerListRefreshInterval: 5000 - -hystrix.command.BackendCall.execution.isolation.thread.timeoutInMilliseconds: 5000 -hystrix.threadpool.BackendCallThread.coreSize: 5 diff --git a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/pom.xml b/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/pom.xml deleted file mode 100644 index 4d8360b2..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/pom.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - 4.0.0 - - org.springframework.cloud - kubernetes-circuitbreaker-ribbon-example - 1.1.3.BUILD-SNAPSHOT - - - name-service - - Circuit Breaker & Load Balancer :: Name Service - Circuit Breaker & Load Balancer :: Name Service - - - - - org.apache.maven.plugins - maven-deploy-plugin - ${maven-deploy-plugin.version} - - true - - - - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-actuator - - - diff --git a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/fabric8/route.yml b/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/fabric8/route.yml deleted file mode 100644 index adb5a71a..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/fabric8/route.yml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: v1 -kind: Route -metadata: - name: name-service -spec: - port: - targetPort: 8080 - to: - kind: Service - name: name-service diff --git a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/java/org/springframework/cloud/kubernetes/examples/NameController.java b/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/java/org/springframework/cloud/kubernetes/examples/NameController.java deleted file mode 100644 index e7be08b7..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/java/org/springframework/cloud/kubernetes/examples/NameController.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2016-2017 Red Hat, Inc, and individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.kubernetes.examples; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -/** - * Name service controller. - * - * @author Gytis Trikleris - */ -@RestController -public class NameController { - - private static final Logger LOG = LoggerFactory.getLogger(NameController.class); - - private final String hostName = System.getenv("HOSTNAME"); - - @RequestMapping("/") - public String ribbonPing() { - LOG.info("Ribbon ping"); - return this.hostName; - } - - /** - * Endpoint to get a name with a capability to delay a response for some number of - * milliseconds. - * @param delayValue Milliseconds for how long the response should be delayed. - * @return Host name. - */ - @RequestMapping("/name") - public String getName( - @RequestParam(value = "delay", defaultValue = "0") int delayValue) { - LOG.info(String.format("Returning a name '%s' with a delay '%d'", this.hostName, - delayValue)); - delay(delayValue); - return this.hostName; - } - - private void delay(int delayValue) { - try { - Thread.sleep(delayValue); - } - catch (InterruptedException e) { - e.printStackTrace(); - } - } - -} diff --git a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/java/org/springframework/cloud/kubernetes/examples/NameServiceApplication.java b/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/java/org/springframework/cloud/kubernetes/examples/NameServiceApplication.java deleted file mode 100644 index 8e03f365..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/java/org/springframework/cloud/kubernetes/examples/NameServiceApplication.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2016 to the original authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.kubernetes.examples; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -/** - * Entry point to the application. - * - * @author Gytis Trikleris - */ -@SpringBootApplication -public class NameServiceApplication { - - public static void main(String[] args) { - SpringApplication.run(NameServiceApplication.class, args); - } - -} diff --git a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/resources/application.yml b/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/resources/application.yml deleted file mode 100644 index b08d6019..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/name-service/src/main/resources/application.yml +++ /dev/null @@ -1,6 +0,0 @@ -spring: - application: - name: name-service - -server: - port: 8080 \ No newline at end of file diff --git a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/pom.xml b/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/pom.xml deleted file mode 100644 index 6bd44d9f..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/pom.xml +++ /dev/null @@ -1,174 +0,0 @@ - - - - - 4.0.0 - - spring-cloud-kubernetes-examples - org.springframework.cloud - 1.1.3.BUILD-SNAPSHOT - - - org.springframework.cloud - kubernetes-circuitbreaker-ribbon-example - Circuit Breaker & Load Balancer - pom - - - name-service - greeting-service - - - - - - - org.apache.maven.plugins - maven-deploy-plugin - ${maven-deploy-plugin.version} - - true - - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot.version} - - - - repackage - - - - - - - io.fabric8 - fabric8-maven-plugin - ${fabric8.maven.plugin.version} - - - fmp - - resource - - - - - - - - - - kubernetes - - - - io.fabric8 - fabric8-maven-plugin - ${fabric8.maven.plugin.version} - - - fmp - - resource - build - - - - - - - - NodePort - - - - - - - - - - release - - - - io.fabric8 - fabric8-maven-plugin - ${fabric8.maven.plugin.version} - - - fmp - - resource - helm - - - - - - - - - - integration - - - - io.fabric8 - fabric8-maven-plugin - ${fabric8.maven.plugin.version} - - - fmp - - resource - build - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - ${maven-failsafe-plugin.version} - - - run-integration-tests - integration-test - - integration-test - verify - - - - - false - false - - - - - - - diff --git a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/readme.md b/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/readme.md deleted file mode 100644 index 4e7e2002..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-circuitbreaker-ribbon-example/readme.md +++ /dev/null @@ -1,219 +0,0 @@ -## Kubernetes Circuit Breaker & Load Balancer Example - -This example demonstrates how to use [Hystrix circuit breaker](https://martinfowler.com/bliki/CircuitBreaker.html) and the [Ribbon Load Balancing](https://microservices.io/patterns/client-side-discovery.html). The circuit breaker which is backed with Ribbon will check regularly if the target service is still alive. If this is not loner the case, then a fall back process will be excuted. In our case, the REST `greeting service` which is calling the `name Service` responsible to generate the response message will reply a "fallback message" to the client if the `name service` is not longer replying. -As the Ribbon Kubernetes client is configured within this example, it will fetch from the Kubernetes API Server, the list of the endpoints available for the name service and loadbalance the request between the IP addresses available - -### Running the example - -This project example runs on ALL the Kubernetes or OpenShift environments, but for development purposes you can use [Minishift - OpenShift](https://github.com/minishift/minishift) or [Minikube - Kubernetes](https://kubernetes.io/docs/getting-started-guides/minikube/) tool -to install the platform locally within a virtual machine managed by VirtualBox, Xhyve or KVM, with no fuss. - -### Build/Deploy using Minikube - -First, create a new virtual machine provisioned with Kubernetes on your laptop using the command `minikube start`. - -Next, you can compile your project and generate the Kubernetes resources (yaml files containing the definition of the pod, deployment, build, service and route to be created) -like also to deploy the application on Kubernetes in one maven line : - -``` -mvn clean install fabric8:deploy -Dfabric8.generator.from=fabric8/java-jboss-openjdk8-jdk -Pkubernetes -``` - -### Call the Greeting service - -When maven has finished to compile the code but also to call the platform in order to deploy the yaml files generated and tell to the platform to start the process -to build/deploy the docker image and create the containers where the Spring Boot application will run 'greeting-service" and "name-service", you will be able to -check if the pods have been created using this command : - -``` -kc get pods -``` - -If the status of the Spring Boot pod application is `running` and ready state `1`, then you can -get the external address IP/Hostname to be used to call the service from your laptop - -``` -minikube service --url greeting-service -``` - -and then call the service using the curl client - -``` -curl https://IP_OR_HOSTNAME/greeting -``` - -to get a response as such - -``` -Hello from name-service-1-0dzb4!d -``` - -### Verify the load balancing - -First, scale the number of pods of the `name service` to 2 - -``` -kc scale --replicas=2 deployment name-service -``` - -Wait a few minutes before to issue the curl request to call the Greeting Service to let the platform to create the new pod. - -``` -kc get pods --selector=project=name-service -NAME READY STATUS RESTARTS AGE -name-service-1652024859-fsnfw 1/1 Running 0 33s -name-service-1652024859-wrzjs 1/1 Running 0 6m -``` - -If you issue the curl request to access the greeting service, you should see that the message response -contains a different id end of the message which corresponds to the name of the pod. - -``` -Hello from name-service-1-0ss0r! -``` - -As Ribbon will question the Kubernetes API to get, base on the `name-service` name, the list of IP Addresses assigned to the service as endpoints, -you should see that you will get a response from one of the 2 pods running - -``` -kc get endpoints/name-service -NAME ENDPOINTS AGE -name-service 172.17.0.5:8080,172.17.0.6:8080 40m -``` - -Here is an example about what you will get - -``` -curl https://IP_OR_HOSTNAME/greeting -Hello from name-service-1652024859-hf3xv! -curl https://IP_OR_HOSTNAME/greeting -Hello from name-service-1652024859-426kv! -... -``` - -### Test the fall back - -In order to test the circuit breaker and the fallback option, you will scale the `name-service` to 0 pods as such - -``` -kc scale --replicas=0 deployment name-service -``` - -and next issue a new curl request to get the response from the greeting service - -``` -Hello from Fallback! -``` - -### Build/Deploy using Minishift - -First, create a new virtual machine provisioned with OpenShift on your laptop using the command `minishift start`. - -Next, log on to the OpenShift platform and next within your terminal use the `oc` client to create a project where -we will install the circuit breaker and load balancing application - -``` -oc new-project circuit-loadbalancing -``` - -When using OpenShift, you must assign the `view` role to the *default* service account in the current project in orde to allow our Java Kubernetes Api to access -the API Server : - -``` -oc policy add-role-to-user view --serviceaccount=default -``` - -You can now compile your project and generate the OpenShift resources (yaml files containing the definition of the pod, deployment, build, service and route to be created) -like also to deploy the application on the OpenShift platform in one maven line : - -``` -mvn clean install fabric8:deploy -Pkubernetes -``` - -### Call the Greeting service - -When maven has finished to compile the code but also to call the platform in order to deploy the yaml files generated and tell to the platform to start the process -to build/deploy the docker image and create the containers where the Spring Boot application will run 'greeting-service" and "name-service", you will be able to -check if the pods have been created using this command : - -``` -oc get pods --selector=project=greeting-service -``` - -If the status of the Spring Boot pod application is `running` and ready state `1`, then you can -get the external address IP/Hostname to be used to call the service from your laptop - -``` -oc get route/greeting-service -``` - -and then call the service using the curl client - -``` -curl https://IP_OR_HOSTNAME/greeting -``` - -to get a response as such - -``` -Hello from name-service-1-0dzb4!d -``` - -### Verify the load balancing - -First, scale the number of pods of the `name service` to 2 - -``` -oc scale --replicas=2 dc name-service -``` - -Wait a few minutes before to issue the curl request to call the Greeting Service to let the platform to create the new pod. - -``` -oc get pods --selector=project=name-service -NAME READY STATUS RESTARTS AGE -name-service-1-0ss0r 1/1 Running 0 3m -name-service-1-fblp1 1/1 Running 0 36m -``` - -If you issue the curl request to access the greeting service, you should see that the message response -contains a different id end of the message which corresponds to the name of the pod. - -``` -Hello from name-service-1-0ss0r! -``` - -As Ribbon will question the Kubernetes API to get, base on the `name-service` name, the list of IP Addresses assigned to the service as endpoints, -you should see that you will get a different response from one of the 2 pods running - -``` -oc get endpoints/name-service -NAME ENDPOINTS AGE -name-service 172.17.0.2:8080,172.17.0.3:8080 40m -``` - -Here is an example about what you will get - -``` -curl https://IP_OR_HOSTNAME/greeting -Hello from name-service-1-0ss0r! -curl https://IP_OR_HOSTNAME/greeting -Hello from name-service-1-fblp1! -... -``` - -### Test the fall back - -In order to test the circuit breaker and the fallback option, you will scale the `name-service` to 0 pods as such - -``` -oc scale --replicas=0 dc name-service -``` - -and next issue a new curl request to get the response from the greeting service - -``` -Hello from Fallback! -``` - - diff --git a/spring-cloud-kubernetes-examples/kubernetes-zipkin-example/README.md b/spring-cloud-kubernetes-examples/kubernetes-zipkin-example/README.md deleted file mode 100644 index db1650c6..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-zipkin-example/README.md +++ /dev/null @@ -1,159 +0,0 @@ -## Kubernetes Zipkin Example - -This project demonstrates how a Spring Boot application generating statistics as Spring Cloud Sleuth Spans/Traces can send them to a ZipKin server deployed in Kubernetes without the need to -configure the baseUrl of the ZipKin server deployed as the server will be discovered. The spans/traces generated can be viewed within the Zipkin dashboard under the `serviceName=sleuth-zipkin` - -The Zipkin server is deployed according to the steps described within the `Minishift` or `Minikube` section. - -The project exposes under the `TraceController` 2 endpoints `/` and `/hi` that you can play with in order to generate traces. When you call the root endpoint `/`, then -it will issue a call against the second endpoint `/hi` and you will receive `/hi/hello` as response. If you look to the Zipkin dashboard, you will be able to get 2 traces recorded. - - -``` - @RequestMapping("/") - public String say() throws InterruptedException { - Thread.sleep(this.random.nextInt(1000)); - log.info("Home"); - String s = this.restTemplate.getForObject("http://localhost:" + this.port - + "/hi", String.class); - return "hi/" + s; - } - - @RequestMapping("/hi") - public String hi() throws InterruptedException { - log.info("hi"); - int millis = this.random.nextInt(1000); - Thread.sleep(millis); - this.tracer.addTag("random-sleep-millis", String.valueOf(millis)); - return "hello"; - } -``` - -### Running the example - -This project example runs on ALL the Kubernetes or OpenShift environments, but for development purposes you can use [Minishift - OpenShift](https://github.com/minishift/minishift) or [Minikube - Kubernetes](https://kubernetes.io/docs/getting-started-guides/minikube/) tool -to install the platform locally within a virtual machine managed by VirtualBox, Xhyve or KVM, with no fuss. - -### Build/Deploy using Minikube - -First, create a new virtual machine provisioned with Kubernetes on your laptop using the command `minikube start`. - -To deploy the Zipkin server and store the traces under a MySQL server, execute the following commands to create a persistent volume for the database -and next to deploy the Zipkin application - -``` -kubectl create -f https://repo1.maven.org/maven2/io/fabric8/zipkin/zipkin-starter-minimal/0.1.9/zipkin-starter-minimal-0.1.9-kubernetes.yml - -cat << EOF | kubectl create -f - -kind: PersistentVolume -apiVersion: v1 -metadata: - name: pv0001 - labels: - type: local -spec: - capacity: - storage: 10Gi - accessModes: - - ReadWriteOnce - hostPath: - path: "/tmp/data01" -EOF - -cat << EOF | kubectl create -f - -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: mysql-data - labels: - type: local -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 1Gi -EOF -``` - -Next, you can compile your project and generate the Kubernetes resources (yaml files containing the definition of the pod, deployment, build, service and route to be created) -like also to deploy the application on Kubernetes in one maven line : - -``` -mvn clean install fabric8:deploy -Dservice.type=NodePort -Dfabric8.generator.from=fabric8/java-jboss-openjdk8-jdk -Pkubernetes -``` - -You can find the address of the zipkin server to be opened within your browser using this command - -``` -minikube service zipkin --url -``` - -like also the endpoint to call to generate traces - -``` -export ENDPOINT=$(minikube service kubernetes-zipkin --url) -curl $ENDPOINT -curl $ENDPOINT/hi -``` - -### Build/Deploy using Minishift - -First, create a new virtual machine provisioned with OpenShift on your laptop using the command `minishift start`. - -Next, log on to the OpenShift platform and next within your terminal use the `oc` client to create a project where -we will install the circuit breaker and load balancing application - -``` -oc new-project zipkin -``` - -When using OpenShift, you must assign the `view` role to the *default* service account in the current project in order to allow our Java Kubernetes Api to access -the API Server : - -``` -oc policy add-role-to-user view --serviceaccount=default -``` - -To deploy the Zipkin server and store the traces under a MySQL server, execute the following commands to deploy the Zipkin application - -``` -oc create -f https://repo1.maven.org/maven2/io/fabric8/zipkin/zipkin-starter-minimal/0.1.9/zipkin-starter-minimal-0.1.9-openshift.yml -oc delete pvc/mysql-data - -cat << EOF | oc create -f - -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: mysql-data - labels: - type: local -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 1Gi -EOF -``` - -You can now compile your project and generate the OpenShift resources (yaml files containing the definition of the pod, deployment, build, service and route to be created) -like also to deploy the application on the OpenShift platform in one maven line : - -``` -mvn clean install fabric8:deploy -Pkubernetes -``` - -You can find the address of the Zipkin server to be opened within your browser using this command - -``` -oc get route/zipkin --template='{{.spec.host}}' -``` - -like also the endpoint to call to generate traces - -``` -export ENDPOINT=$(oc get route/kubernetes-zipkin --template='{{.spec.host}}') -curl $ENDPOINT -curl $ENDPOINT/hi -``` diff --git a/spring-cloud-kubernetes-examples/kubernetes-zipkin-example/pom.xml b/spring-cloud-kubernetes-examples/kubernetes-zipkin-example/pom.xml deleted file mode 100644 index 256afed5..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-zipkin-example/pom.xml +++ /dev/null @@ -1,154 +0,0 @@ - - - - - - spring-cloud-kubernetes-examples - org.springframework.cloud - 1.1.3.BUILD-SNAPSHOT - - 4.0.0 - - kubernetes-zipkin-example - Spring Cloud Kubernetes :: Examples :: Zipkin - Example that demonstrates how to send Zipkin traces from a Spring Boot - application to Zipkin server running In Kubernetes - - - - LoadBalancer - - - - - - org.springframework.boot - spring-boot-dependencies - pom - import - ${spring-boot.version} - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - repackage - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - io.fabric8 - fabric8-maven-plugin - ${fabric8.maven.plugin.version} - - - fmp - - resource - - - - - - org.apache.maven.plugins - maven-deploy-plugin - ${maven-deploy-plugin.version} - - true - - - - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-actuator - - - - - org.springframework.cloud - spring-cloud-kubernetes-zipkin - - - org.springframework.cloud - spring-cloud-sleuth-zipkin - - - org.springframework.boot - spring-boot-starter-aop - - - - - - kubernetes - - - - io.fabric8 - fabric8-maven-plugin - ${fabric8.maven.plugin.version} - - - fmp - - resource - build - - - - - - - - ${service.type} - - - - - - - - - - - diff --git a/spring-cloud-kubernetes-examples/kubernetes-zipkin-example/src/main/java/org/springframework/cloud/kubernetes/examples/TraceController.java b/spring-cloud-kubernetes-examples/kubernetes-zipkin-example/src/main/java/org/springframework/cloud/kubernetes/examples/TraceController.java deleted file mode 100644 index d7ead11d..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-zipkin-example/src/main/java/org/springframework/cloud/kubernetes/examples/TraceController.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2016 to the original authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.springframework.cloud.kubernetes.examples; - -import java.util.Random; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; -import org.springframework.cloud.sleuth.Tracer; -import org.springframework.context.ApplicationListener; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; - -@RestController -public class TraceController - implements ApplicationListener { - - private static final Log log = LogFactory.getLog(TraceController.class); - - @Autowired - private RestTemplate restTemplate; - - @Autowired - private Tracer tracer; - - @Autowired - private Random random; - - private int port; - - @RequestMapping("/") - public String say() throws InterruptedException { - Thread.sleep(this.random.nextInt(1000)); - log.info("Home"); - String s = this.restTemplate.getForObject("http://localhost:" + this.port + "/hi", - String.class); - return "hi/" + s; - } - - @RequestMapping("/hi") - public String hi() throws InterruptedException { - log.info("hi"); - int millis = this.random.nextInt(1000); - Thread.sleep(millis); - this.tracer.addTag("random-sleep-millis", String.valueOf(millis)); - return "hello"; - } - - @Override - public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) { - this.port = event.getEmbeddedServletContainer().getPort(); - } - -} diff --git a/spring-cloud-kubernetes-examples/kubernetes-zipkin-example/src/main/java/org/springframework/cloud/kubernetes/examples/ZipkinApplication.java b/spring-cloud-kubernetes-examples/kubernetes-zipkin-example/src/main/java/org/springframework/cloud/kubernetes/examples/ZipkinApplication.java deleted file mode 100644 index 11193034..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-zipkin-example/src/main/java/org/springframework/cloud/kubernetes/examples/ZipkinApplication.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2016 to the original authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.springframework.cloud.kubernetes.examples; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.EnableAspectJAutoProxy; -import org.springframework.scheduling.annotation.EnableAsync; -import org.springframework.web.client.RestTemplate; - -@SpringBootApplication -@EnableAspectJAutoProxy(proxyTargetClass = true) -@EnableAsync -public class ZipkinApplication { - - private static final Log log = LogFactory.getLog(ZipkinApplication.class); - - public static void main(String[] args) { - SpringApplication.run(ZipkinApplication.class, args); - } - - @Bean - public RestTemplate restTemplate() { - return new RestTemplate(); - } - -} diff --git a/spring-cloud-kubernetes-examples/kubernetes-zipkin-example/src/main/resources/application.yml b/spring-cloud-kubernetes-examples/kubernetes-zipkin-example/src/main/resources/application.yml deleted file mode 100644 index 8b972127..00000000 --- a/spring-cloud-kubernetes-examples/kubernetes-zipkin-example/src/main/resources/application.yml +++ /dev/null @@ -1,12 +0,0 @@ -spring: - application: - # This ends up as the service name in zipkin - name: sleuth-zipkin - sleuth: - sampler: - percentage: 1.0 - -sample: - zipkin: - # When enabled=false, traces log to the console. Comment to send to zipkin - enabled: true diff --git a/spring-cloud-kubernetes-examples/pom.xml b/spring-cloud-kubernetes-examples/pom.xml index 3c7d023b..935d1ba4 100644 --- a/spring-cloud-kubernetes-examples/pom.xml +++ b/spring-cloud-kubernetes-examples/pom.xml @@ -37,8 +37,6 @@ kubernetes-reload-example kubernetes-hello-world-example kubernetes-leader-election-example -