Skip to content

Commit d4af608

Browse files
author
Matt Raible
committed
Update READMEs for JHipster K8s
1 parent 53b7973 commit d4af608

File tree

5 files changed

+282
-44
lines changed

5 files changed

+282
-44
lines changed

README.md

Lines changed: 166 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1-
21
# Java Microservices with Spring Boot & Spring Cloud 🍃☁️
32

43
This repository contains examples of how to build a Java microservices architecture with Spring Boot, Spring Cloud, and Netflix Eureka.
54

6-
This repository has four examples in it:
5+
This repository has five examples in it:
76

87
1. The first is a bare-bones microservices architecture with Spring Boot, Spring Cloud, Eureka Server, and Zuul.
98
2. The second is one that's built with JHipster and configured centrally with Spring Cloud Config.
109
3. The third uses Spring Cloud Gateway and Spring WebFlux to show reactive microservices.
1110
4. The fourth uses JHipster 7 to generate a reactive microservices architecture with Spring Cloud Gateway and Spring WebFlux.
11+
5. The fifth uses JHipster 7 + Kubernetes and deploys to Google Cloud with sealed secrets.
1212

1313
We think you'll enjoy them all!
1414

15-
* See [Java Microservices with Spring Boot and Spring Cloud](https://developer.okta.com/blog/2019/05/22/java-microservices-spring-boot-spring-cloud) for an overview of the first example.
16-
* Read [Java Microservices with Spring Cloud Config and JHipster](https://developer.okta.com/blog/2019/05/23/java-microservices-spring-cloud-config) to learn about microservices with JHipster.
17-
* Refer to [Secure Reactive Microservices with Spring Cloud Gateway](https://developer.okta.com/blog/2019/08/28/reactive-microservices-spring-cloud-gateway) to learn about Spring Cloud Gateway and reactive microservices.
18-
* Refer to [Reactive Java Microservices with Spring Boot and JHipster](https://developer.okta.com/blog/2021/01/20/reactive-java-microservices) to see how JHipster makes reactive microservices a breeze.
15+
* See [Java Microservices with Spring Boot and Spring Cloud][blog-spring-boot-spring-cloud] for an overview of the first example.
16+
* Read [Java Microservices with Spring Cloud Config and JHipster][blog-spring-cloud-config] to learn about microservices with JHipster.
17+
* Refer to [Secure Reactive Microservices with Spring Cloud Gateway][blog-spring-cloud-gateway] to learn about Spring Cloud Gateway and reactive microservices.
18+
* Refer to [Reactive Java Microservices with Spring Boot and JHipster][blog-reactive-jhipster] to see how JHipster makes reactive microservices a breeze.
19+
* Peruse to [Kubernetes to the Cloud with Spring Boot and JHipster][blog-k8s] to see how JHipster simplifies Kubernetes deployments.
1920

2021
**Prerequisites:** [Java 11](https://sdkman.io/sdks#java) and an internet connection.
2122

2223
* [Spring Boot + Spring Cloud Example](#spring-boot--spring-cloud-example)
2324
* [JHipster + Spring Cloud Config Example](#jhipster--spring-cloud-config-example)
2425
* [Spring Cloud Gateway Example](#spring-cloud-gateway-example)
2526
* [Reactive Microservices with JHipster Example](#reactive-microservices-with-jhipster-example)
27+
* [Kubernetes to the Cloud Example](#kubernetes--reactive-java-with-jhipster-example)
2628
* [Links](#links)
2729
* [Help](#help)
2830
* [License](#license)
@@ -235,9 +237,159 @@ Now, open a new incognito browser window, go to `http://localhost:8080`, and sig
235237

236238
**TIP**: You can also run everything using Docker Compose. See the [blog post](https://developer.okta.com/blog/2021/01/20/reactive-java-microservices#run-your-microservices-stack-with-docker-compose) for how to do that.
237239

240+
## Kubernetes + Reactive Java with JHipster Example
241+
242+
To install this example, run the following commands:
243+
244+
```bash
245+
git clone https://github.com/oktadeveloper/java-microservices-examples.git
246+
cd java-microservices-examples/jhipster-k8s/k8s
247+
```
248+
249+
If you don't have JHipster installed, install it.
250+
251+
```shell
252+
npm i -g generator-jhipster@7
253+
```
254+
255+
Run JHipster's [Kubernetes sub-generator](https://www.jhipster.tech/kubernetes/).
256+
257+
```shell
258+
jhipster k8s
259+
```
260+
261+
You will be prompted with several questions. The answers will be pre-populated from choices I made when creating this app. Answer as follows, changing the Docker repository name to yours, or leaving it blank if you don't have one.
262+
263+
- Type of application: **Microservice application**
264+
- Root directory: **../**
265+
- Which applications? <select all>
266+
- Set up monitoring? **No**
267+
- Which applications with clustered databases? select **store**
268+
- Admin password for JHipster Registry: <generate one>
269+
- Kubernetes namespace: **demo**
270+
- Docker repository name: <your docker hub username>
271+
- Command to push Docker image: `docker push`
272+
- Enable Istio? **No**
273+
- Kubernetes service type? **LoadBalancer**
274+
- Use dynamic storage provisioning? **Yes**
275+
- Use a specific storage class? <leave empty>
276+
277+
### Install Minikube to Run Kubernetes Locally
278+
279+
If you have Docker installed, you can run Kubernetes locally with Minikube. Run `minikube start` to begin.
280+
281+
```shell
282+
minikube --memory 8g --cpus 8 start
283+
```
284+
285+
Now, you need to build Docker images for each app. In the {`gateway`, `blog`, `store` } directories, run the following Gradle command (where `<image-name>` is `gateway`, `store`, or `blog`).
286+
287+
```shell
288+
./gradlew bootJar -Pprod jib -Djib.to.image=<docker-repo-name>/<image-name>
289+
```
290+
291+
> You can also build your images locally and publish them to your Docker daemon. This is the default if you didn't specify a base Docker repository name.
292+
>
293+
> ```shell
294+
> # this command exposes Docker images to minikube
295+
> eval $(minikube docker-env)
296+
> ./gradlew -Pprod bootJar jibDockerBuild
297+
> ```
298+
>
299+
> Because this publishes your images locally to Docker, you'll need to make modifications to your Kubernetes deployment files to use `imagePullPolicy: IfNotPresent`.
300+
>
301+
> ```yaml
302+
> - name: gateway-app
303+
> image: gateway
304+
> imagePullPolicy: IfNotPresent
305+
> ```
306+
>
307+
> Make sure to add this `imagePullPolicy` to the following files:
308+
>
309+
> - `k8s/gateway-k8s/gateway-deployment.yml`
310+
> - `k8s/blog-k8s/blog-deployment.yml`
311+
> - `k8s/store-k8s/store-deployment.yml`
312+
313+
### Register an OIDC App for Auth
314+
315+
Install the Okta CLI using the instructions on [cli.okta.com](https://cli.okta.com) and come back here when you're done. If you don't have an Okta developer account, run `okta register`.
316+
317+
**NOTE**: You can also use your browser and Okta's developer console to register an app. See [JHipster's security documentation](https://www.jhipster.tech/security/#okta) for those instructions.
318+
319+
From the gateway project's directory, run `okta apps create jhipster`. Accept the default redirect URIs.
320+
321+
This process does several things:
322+
323+
1. Registers an OIDC app in Okta with JHipster's configured redirect URIs.
324+
2. Creates `ROLE_ADMIN` and `ROLE_USER` groups and adds your user to both.
325+
3. Creates a `groups` claim and adds it to ID tokens.
326+
4. Creates a `.okta.env` file with the values you'll need to talk to Okta.
327+
328+
Update `k8s/registry-k8s/application-configmap.yml` to contain your OIDC settings from the `.okta.env` file the Okta CLI just created. The Spring Cloud Config server reads from this file and shares the values with the gateway and microservices.
329+
330+
```yaml
331+
data:
332+
application.yml: |-
333+
...
334+
spring:
335+
security:
336+
oauth2:
337+
client:
338+
provider:
339+
oidc:
340+
issuer-uri: https://<your-okta-domain>/oauth2/default
341+
registration:
342+
oidc:
343+
client-id: <client-id>
344+
client-secret: <client-secret>
345+
```
346+
347+
To configure the JHipster Registry to use OIDC for authentication, modify `k8s/registry-k8s/jhipster-registry.yml` to enable the `oauth2` profile.
348+
349+
```yaml
350+
- name: SPRING_PROFILES_ACTIVE
351+
value: prod,k8s,oauth2
352+
```
353+
354+
Then, in the `k8s` directory, start your engines!
355+
356+
```shell
357+
./kubectl-apply.sh -f
358+
```
359+
360+
You can see if everything starts up using the following command.
361+
362+
```shell
363+
kubectl get pods -n default
364+
```
365+
366+
You can use the name of a pod with `kubectl logs` to tail its logs.
367+
368+
```shell
369+
kubectl logs <pod-name> --tail=-1 -n default
370+
```
371+
372+
You can use port-forwarding to see the JHipster Registry.
373+
374+
```shell
375+
kubectl port-forward svc/jhipster-registry -n default 8761
376+
```
377+
378+
Open a browser and navigate to `\http://localhost:8761`. You'll need to sign in with your Okta credentials.
379+
380+
Once all is green, use port-forwarding to see the gateway app.
381+
382+
```shell
383+
kubectl port-forward svc/gateway -n default 8080
384+
```
385+
386+
Then, go to `http://localhost:8080`, and you should be able to add blogs, posts, tags, and products.
387+
388+
Please read the [Kubernetes to the Cloud with Spring Boot and JHipster][blog-k8s] for more information.
389+
238390
## Links
239391

240-
These examples uses the following open source libraries:
392+
These examples use the following open source libraries:
241393

242394
* [Okta Spring Boot Starter](https://github.com/okta/okta-spring-boot)
243395
* [Spring Boot](https://spring.io/projects/spring-boot)
@@ -246,6 +398,7 @@ These examples uses the following open source libraries:
246398
* [Spring Security](https://spring.io/projects/spring-security)
247399
* [JHipster](https://www.jhipster.tech)
248400
* [OpenJDK](https://openjdk.java.net/)
401+
* [K9s](https://k9scli.io/)
249402

250403
## Help
251404

@@ -254,3 +407,9 @@ Please post any questions as comments on the example's blog post, or on the [Okt
254407
## License
255408

256409
Apache 2.0, see [LICENSE](LICENSE).
410+
411+
[blog-spring-boot-spring-cloud]: https://developer.okta.com/blog/2019/05/22/java-microservices-spring-boot-spring-cloud
412+
[blog-spring-cloud-config]: https://developer.okta.com/blog/2019/05/23/java-microservices-spring-cloud-config
413+
[blog-spring-cloud-gateway]: https://developer.okta.com/blog/2019/08/28/reactive-microservices-spring-cloud-gateway
414+
[blog-reactive-jhipster]: https://developer.okta.com/blog/2021/01/20/reactive-java-microservices
415+
[blog-k8s]: https://developer.okta.com/blog/2021/06/01/kubernetes-java-spring-boot

0 commit comments

Comments
 (0)