Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp #3

Merged
merged 27 commits into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c2aa95b
ui application dependencies revamp
mrFlick72 Sep 30, 2022
5aa2a62
ui application dependencies revamp
mrFlick72 Sep 30, 2022
00184ca
message-service application dependencies revamp
mrFlick72 Sep 30, 2022
0a48aa9
message-service application dependencies revamp
mrFlick72 Sep 30, 2022
fd45997
message-service application dependencies revamp
mrFlick72 Sep 30, 2022
ac222ec
message-service application dependencies revamp
mrFlick72 Sep 30, 2022
49a4653
message-service application dependencies revamp
mrFlick72 Sep 30, 2022
13736c1
message-service application dependencies revamp
mrFlick72 Sep 30, 2022
915d1b1
message-service application dependencies revamp
mrFlick72 Sep 30, 2022
5408cf1
applications dependencies revamp
mrFlick72 Sep 30, 2022
ade44a8
[skip ci]
mrFlick72 Sep 30, 2022
6156545
[skip ci]
mrFlick72 Sep 30, 2022
e757e44
service acount
mrFlick72 Sep 30, 2022
2da7170
service acount
mrFlick72 Sep 30, 2022
72e19ff
service acount
mrFlick72 Sep 30, 2022
bff4aa2
service acount
mrFlick72 Sep 30, 2022
196f028
service acount
mrFlick72 Sep 30, 2022
ac584d8
service acount
mrFlick72 Sep 30, 2022
f87066e
service acount
mrFlick72 Sep 30, 2022
b62b63f
service acount
mrFlick72 Sep 30, 2022
4f0f6a5
service acount
mrFlick72 Sep 30, 2022
2544e23
[skip ci]
mrFlick72 Oct 1, 2022
0cc56ac
[skip ci]
mrFlick72 Oct 1, 2022
1c2cba9
password encoding
mrFlick72 Oct 1, 2022
2defa6c
password encoding
mrFlick72 Oct 1, 2022
9649aea
password encoding
mrFlick72 Oct 1, 2022
a4f114a
read me
mrFlick72 Oct 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions .circleci/config.yml

This file was deleted.

108 changes: 108 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: build

on:
push: { }
workflow_dispatch: { }

jobs:
build-ui:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2

- name: install openjdk
run: |
sudo apt-get update && sudo apt-get install openjdk-17-jdk
sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/java-17-openjdk-amd64/bin/javac
java -version

- name: Build
run: |
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
cd ui
mvn clean install -q

- name: docker push
run: |
cd ui
if [[ ${GITHUB_REF##*/} == 'master' ]]
then
DOCKER_TAG="latest"
else
DOCKER_TAG="${GITHUB_REF##*/}"
fi
echo "$DOCKER_TAG"
docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PASSWORD }}
docker build . -t mrflick72/ui-interface:$DOCKER_TAG
docker push mrflick72/ui-interface:$DOCKER_TAG

build-message-service:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2

- name: install openjdk
run: |
sudo apt-get update && sudo apt-get install openjdk-17-jdk
sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/java-17-openjdk-amd64/bin/javac
java -version

- name: Build
run: |
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
cd message-service
./gradlew build

- name: docker push
run: |
cd message-service
if [[ ${GITHUB_REF##*/} == 'master' ]]
then
DOCKER_TAG="latest"
else
DOCKER_TAG="${GITHUB_REF##*/}"
fi
echo "$DOCKER_TAG"
docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PASSWORD }}
docker build . -t mrflick72/message-service:$DOCKER_TAG
docker push mrflick72/message-service:$DOCKER_TAG

build-hello-service:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2

- name: install openjdk
run: |
sudo apt-get update && sudo apt-get install openjdk-17-jdk
sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/java-17-openjdk-amd64/bin/javac
java -version

- name: Build
run: |
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
cd hello-service
./gradlew build

- name: docker push
run: |
cd hello-service
if [[ ${GITHUB_REF##*/} == 'master' ]]
then
DOCKER_TAG="latest"
else
DOCKER_TAG="${GITHUB_REF##*/}"
fi
echo "$DOCKER_TAG"
docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PASSWORD }}
docker build . -t mrflick72/hello-service:$DOCKER_TAG
docker push mrflick72/hello-service:$DOCKER_TAG
43 changes: 11 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ In this project you can see used many technologies like:
* Spring Cloud LoadBalancer
* Spring Reactive Data Mongo
* Spring WebFlux
* Spring Boot 2.4.x
* Spring Boot 2.7.x
* Spring Session
* Spring Reactive Security
* Java/Kotlin
Expand Down Expand Up @@ -74,11 +74,12 @@ benefit of the *LoadBalancerExchangeFilterFunction* injected by spring for us. T

...

@Bean
@LoadBalanced
public WebClient webClient() {
return WebClient.builder().build();
}
@Bean
@LoadBalanced
public WebClient.Builder loadBalancedWebClientBuilder() {
return WebClient.builder();
}

}
```
#### service integration
Expand All @@ -101,8 +102,8 @@ class HelloService {
}
```

The application.yml configuration provided via config map for kubernetes profile and application-netflix.yml for netflix profile. The benefit of use configmap
with kubernetes is that configuring restart actuator endpoint with spring cloud kubernetes configuration in the bootstrap.yml, we can benefit of a hot reload configuration mechanism
The application.yml configuration provided via config map. The benefit of use configmap
with Spring Cloud Kubernetes is that configuring restart actuator endpoint with spring cloud kubernetes configuration in the application.yml, we can benefit of a hot reload configuration mechanism
via Spring application context restart.

The application is totally reactive and no blocking io. It involved:
Expand All @@ -122,7 +123,7 @@ you can use this command:
Remember to enable ingress with this command: ```minikube addons enable ingress -p spring-cloud-k8s```
In order to test on minikube you can use my docker images on docker hub and that's it install the kubernetes manifests under kubernetes folder.

Pay attention before to install all k8s descriptors is needed to apply a command like this: `kubectl create clusterrolebinding admin --clusterrole=cluster-admin --serviceaccount=default:default`
Pay attention before to install all k8s descriptors is needed to apply a command like this: `kubectl apply -f service-account.yml`
The command is needed due to Spring Cloud Kubernetes interacts with Kubernetes api, without run this command you will get an error like below:
```
There was an unexpected error (type=Internal Server Error, status=500).
Expand All @@ -136,26 +137,4 @@ Failure executing: GET at: https://10.96.0.1/api/v1/namespaces/default/endpoints
Forbidden!Configured service account doesn't have access.
Service account may have been revoked. endpoints "message-service" is forbidden:
User "system:serviceaccount:default:default" cannot get resource "endpoints" in API group "" in the namespace "default".
```
## Conclusion

Now!, what street choose?, Spring Cloud Netflix or Spring Cloud Kubernetes? Of course the right answer is it depends!

With Spring Cloud abstraction you can achieve many typical distributed system pattern like: service discovery, client side load balancing and configuration load in a Netflix or Kubernetes environment without
change one line of code, giving you the possibility to choose later the your way: K8S or not to K8S. Said that, the choice depends form
requirements, infrastructure already on place and many other concern. The my impression is: very cool the possibility of choose later and test in local, on premise or in the cloud with
Netflix or on K8s with the assurance that the application behaviour will be near the same, I have particularly appreciated the simple hot reload of application configuration on K8s.
But on the other hands using Spring Cloud Kubernetes for service discovery and client load balancing, that are the main features exposed by Spring Cloud Kubernetes,
it is an overkill especially considering that those features that are already built in in K8s.

Moreover considering that the application have to talk with master for applying the api, it can be quite dangerous due to too much knowledge on your application of infrastructure
and the risk of coupling your application framework with the infrastructure it is a bad thing in my opinion. The real power is choose later not copling for ever to a platform or to a framework.

At the end if your application run on a public cloud provider use Spring Cloud Netflix can be a very convenient choice otherwise use Kubernetes may be a real popular and farsighted choice,
especially considering the real cool project pluggable on top of Kubernetes like Istio, Knative and considering that more and more providers are adopting Kubernetes,
AWS EKS, Google Cloud GKE, Pivotal PKS and many other are an example.

Unfortunately there not exist a correct answer, there exist only use case in wich a choice fit or not. Like in many use case the
possibility of choice later and fast adopting a new way that is more capable for embrace business changing is a winner choice.

In this direction, in my opinion, Spring Cloud win due to give us the possibility to choose later if adopting Netflix or Kubernetes at any time and go up and forward in any time.
```
9 changes: 9 additions & 0 deletions hello-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM openjdk:17

ADD build/libs/hello-service.jar /usr/local/hello-service/

WORKDIR /usr/local/hello-service/

EXPOSE 8080

CMD ["java", "-jar", "hello-service.jar"]
47 changes: 21 additions & 26 deletions hello-service/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
plugins {
id 'org.springframework.boot' version '2.4.3'
id 'java'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'

id "com.palantir.docker" version "0.21.0"
id "org.springframework.boot" version "2.7.4"
id "io.spring.dependency-management" version "1.0.14.RELEASE"
id "java"
}

apply plugin: 'io.spring.dependency-management'
apply plugin: "io.spring.dependency-management"

group = 'it.valeriovaudi'
//version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
group = "it.valeriovaudi"
//version = "0.0.1-SNAPSHOT"
sourceCompatibility = "17"

jar {
archiveFileName = "hello-service"
Expand All @@ -21,22 +19,23 @@ repositories {
}

ext {
set('springCloudVersion', "2020.0.1")
set("springCloudVersion", "2021.0.4")
}

dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter'
implementation "org.springframework.cloud:spring-cloud-starter"

implementation "org.springframework.cloud:spring-cloud-starter-kubernetes-client-all"
implementation "org.springframework.cloud:spring-cloud-starter-kubernetes-client-loadbalancer"

implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes-client-all'
implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes-client-loadbalancer'
implementation "org.springframework.boot:spring-boot-starter-webflux"
implementation "org.springframework.boot:spring-boot-starter-actuator"

implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-actuator'

compile 'org.projectlombok:lombok:1.18.6'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
testImplementation "org.springframework.boot:spring-boot-starter-test"
testImplementation "io.projectreactor:reactor-test"
}

dependencyManagement {
Expand All @@ -46,10 +45,6 @@ dependencyManagement {
}


docker {
name 'mrflick72/hello-service:latest'
dockerfile file('src/main/docker/Dockerfile')
copySpec.from("build/libs/hello-service.jar").into("hello-service.jar")
pull true
noCache true
}
tasks.named("test") {
useJUnitPlatform()
}
Binary file modified hello-service/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion hello-service/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading