JHipster Microservices Example

使用 Spring Cloud、Spring Boot、Angular、Docker 和 Kubernetes 的 JHipster 微服务示例。「JHipster Microservices Example using Spring Cloud, Spring Boot, Angular, Docker, and Kubernetes」

Github stars Tracking Chart

JHipster 微服务示例

使用 JHipster 创建的微服务架构。 将 Spring Cloud、Spring Boot、Angular 和 MongoDB 用于简单的博客/商店应用程序。

请阅读 使用 JHipster 开发和部署微服务以了解如何创建此示例。

先决条件: Java 8, Node.js 6.11, Yarn, 和 Docker.

注意:如果您不在 Mac 或 Windows 上,则可能还需要安装 Docker Compose

Okta 具有身份验证和用户管理 API,可通过即时、可扩展的用户基础结构缩短开发时间。 Okta 直观的 API 和专家支持使开发人员可以轻松地验证,管理和保护任何应用程序中的用户和角色。

入门

要安装此示例应用程序,请运行以下命令:

git clone https://github.com/oktadeveloper/jhipster-microservices-example.git
cd jhipster-microservices-example
  1. 通过在注册表目录中运行 ./mvnw -Pprod 来启动注册表。
  2. Blog 目录中安装依赖项,构建 UI,然后运行 Spring Boot 应用程序。
    yarn
    ./mvnw    
  3. 使用 store 目录中的 Docker Compose 启动 MongoDB。
    docker-compose -f src/main/docker/mongodb.yml up    
  4. store 目录中安装依赖项,构建 UI,然后运行 Spring Boot 应用程序。
    yarn
    ./mvnw    

用 Docker Compose 运行

如果您不想使用 Maven 手动启动应用程序,则可以使用 Docker Compose 启动所有程序。

  1. 确保 Docker 正在运行。
  2. 通过在两个目录中运行以下命令,为 blog and store 应用构建 Docker 映像。
    ./mvnw package -Pprod docker:build    
  3. 打开一个终端,导航到该项目的 docker 目录,然后运行以下命令。如果您的计算机上有大量 RAM,则可能需要调整 Docker 的默认设置(2 GB)。
    docker-compose up -d    
    提示:如果要查看当前窗口中所有容器的日志,请从上面命令的末尾 Remove -d
  4. 使用 Kitematic 查看已部署服务的端口和日志。

要在 JHipster Console 的图表中创建活动(activity),请在 blog 和 store 项目中运行 Gatling 测试。

./mvnw gatling:execute

要删除所有 Docker 容器,请运行以下命令或使用 Kitematic 手动执行。

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

要查找 macOS 上正在运行的端口,请使用 sudo lsof -i :9092 #检查端口 9092。

与 Kubernetes 和 Minikube 一起运行

  1. 安装 kubectl, VirtualBox, and Minikube.
  2. minikube start 启动 Minikube。
  3. 为了能够使用 docker 守护程序,请确保 Docker 正在运行,然后在终端中运行以下命令:
    eval $(minikube docker-env)    
  4. 生成 blogstore 应用的 Docker 映像。
    ./mvnw package -Pprod docker:build    
  5. 导航到终端中的 kubernetes 目录,然后重新生成文件,使它们与您的 Docker 存储库名称匹配。
    jhipster kubernetes    
    按照说明标记和推送 Docker 映像。
    docker image tag blog {yourRepoName}/blog
    docker push {yourRepoName}/blog
    docker image tag store {yourRepoName}/store
    docker push {yourRepoName}/store    
  6. 使用 kubectl 部署到 Minikube。
    kubectl apply -f registry
    kubectl apply -f blog
    kubectl apply -f store    
    部署过程可能需要几分钟才能完成。 运行 minikube dashboard 以查看已部署的容器。 您还可以运行 kubectl get po -o wide --watch 查看每个 pod 的状态。
  7. 运行 minikube service blog 以查看博客应用程序。您应该能够登录并添加博客、条目和产品。

要删除所有已部署的容器,请运行以下命令:

kubectl delete deployment --all

要停止 Minikube,请运行 minikube stop。

注意:如果您运行 minikube delete 并在以后运行 minikube start 时遇到问题,请运行 rm -rf ~/.minikube。有关更多信息,请参见此问题

谷歌云(Google Cloud)

  1. 通过 console.cloud.google.com 创建一个 Google Cloud 项目。
  2. 导航到 https://console.cloud.google.com/kubernetes/list 初始化项目的容器引擎。
  3. 使用以下方法安装 Google Cloud SDK 并设置项目:
    gcloud config set project <project-name>
        
  4. 创建一个集群:
    gcloud container clusters create <cluster-name> --machine-type=n1-standard-2 --scopes cloud-platform --zone us-west1-a    
    要查看可能的 zones,运行 gcloud compute zones list
  5. 推送 blogstore 并将 Docker 映像到Docker Hub。您将需要创建一个帐户并运行 docker login 来推送您的映像。映像可以从任何目录运行。
    docker image tag blog mraible/blog
    docker push mraible/blog
    docker image tag store mraible/store
    docker push mraible/store    
  6. 运行 kubectl 命令进行部署。
    kubectl apply -f registry
    kubectl apply -f blog
    kubectl apply -f store    
  7. 使用端口转发在本地查看注册表应用程序。
    kubectl port-forward jhipster-registry-0 8761:8761    
  8. 运行 kubectl svc blog 察看 Google Cloud 上的 blog 应用。
  9. 使用 kubectl根据需要扩展微服务应用程序:
    kubectl scale --replicas=3 deployment/store    

要观看此过程的截屏视频,请观看此 YouTube 视频

AWS

如果您知道如何将此架构部署到 AWS,我很想听听它!我“气愤地尝试过”,但最终还是失败了。但最终失败了。

链接

这个例子使用了 JHipster 和一个很棒的项目,它允许您使用 Spring Boot 生成微服务架构。 有关使用 OAuth 和 Okta 的示例,请参见使用 OAuth 2.0 和 JHipster 开发微服务架构

帮助

请在博客文章中发表任何问题作为评论,或访问我们的 Okta 开发者论坛。如果要创建支持工单,也可以发送电子邮件至 developers@okta.com

许可

Apache 2.0,请参阅 LICENSE

(The first version translated by vz on 2020.08.08)

Overview

Name With Owneroktadev/jhipster-microservices-example
Primary LanguageJava
Program languageJavaScript (Language Count: 9)
PlatformDocker, Google Cloud Platform, Kubernetes, Linux, Mac, Windows
License:Apache License 2.0
Release Count0
Created At2017-05-03 01:53:47
Pushed At2023-01-12 10:23:05
Last Commit At2022-04-11 16:09:24
Stargazers Count126
Watchers Count13
Fork Count89
Commits Count76
Has Issues Enabled
Issues Count1
Issue Open Count0
Pull Requests Count44
Pull Requests Open Count3
Pull Requests Close Count17
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

JHipster Microservices Example

A microservice architecture created with JHipster. Uses Spring Cloud, Spring Boot, Angular, and MongoDB for a simple blog/store applications.

Please read Develop and Deploy Microservices with JHipster to see how this example was created.

Prerequisites: Java 8, Node.js 6.11, Yarn, and Docker.

NOTE: If you're not on Mac or Windows, you may need to install Docker Compose as well.

Okta has Authentication and User Management APIs that reduce development time with instant-on, scalable user infrastructure. Okta's intuitive API and expert support make it easy for developers to authenticate, manage and secure users and roles in any application.

Getting Started

To install this example application, run the following commands:

git clone https://github.com/oktadeveloper/jhipster-microservices-example.git
cd jhipster-microservices-example
  1. Start the registry by running ./mvnw -Pprod in the registry directory.

  2. Install dependencies in the blog directory, build the UI, and run the Spring Boot app.

    yarn
    ./mvnw 
    
  3. Start MongoDB using Docker Compose in the store directory.

    docker-compose -f src/main/docker/mongodb.yml up
    
  4. Install dependencies in the store directory, build the UI, and run the Spring Boot app.

    yarn
    ./mvnw 
    

You should be able to see the blog app at http://localhost:8080 and edit products (from the store app)

Run with Docker Compose

You can use Docker Compose to start everything if you don't want to start applications manually with Maven.

  1. Make sure Docker is running.

  2. Build Docker images for the blog and store applications by running the following command in both directories.

    ./mvnw package -Pprod docker:build
    
  3. Open a terminal, navigate to the docker directory of this project, and run the following command. If you have a lot
    of RAM on your machine, you might want to adjust Docker's default setting (2 GB).

    docker-compose up -d
    

    TIP: Remove -d from the end of the command above if you want to see logs from all containers in the current window.

  4. Use Kitematic to view the ports and logs for the services deployed.

To create activity in JHipster Console's charts, you run the Gatling tests in the blog and store projects.

./mvnw gatling:execute

To remove all Docker containers, run the following commands or do it manually using Kitematic.

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

To find what's running on a port on macOS, use sudo lsof -i :9092 # checks port 9092.

Run with Kubernetes and Minikube

  1. Install kubectl, VirtualBox, and Minikube.

  2. Start Minikube using minikube start.

  3. To be able to work with the docker daemon, make sure Docker is running, then run the following command in your terminal:

    eval $(minikube docker-env)
    
  4. Create Docker images of the blog and store applications:

    ./mvnw package -Pprod docker:build
    
  5. Navigate to the kubernetes directory in your terminal and re-generate the files so they match your Docker repository name.

    jhipster kubernetes
    

    Follow the instructions for tagging and pushing the Docker images.

    docker image tag blog {yourRepoName}/blog
    docker push {yourRepoName}/blog
    docker image tag store {yourRepoName}/store
    docker push {yourRepoName}/store
    
  6. Use kubectl to deploy to Minikube.

    kubectl apply -f registry
    kubectl apply -f blog
    kubectl apply -f store
    

    The deployment process can take several minutes to complete. Run minikube dashboard to see the deployed containers.
    You can also run kubectl get po -o wide --watch to see the status of each pod.

  7. Run minikube service blog to view the blog application. You should be able to login and add blogs, entries, and products.

To remove all deployed containers, run the following command:

kubectl delete deployment --all

To stop Minikube, run minikube stop.

NOTE: If you run minikube delete and have trouble running minikube start afterward, run rm -rf ~/.minikube.
See this issue for more information.

Google Cloud

  1. Create a Google Cloud project at console.cloud.google.com.

  2. Navigate to https://console.cloud.google.com/kubernetes/list to initialize the Container Engine for your project.

  3. Install Google Cloud SDK and set project using:

    gcloud config set project <project-name>
    
  4. Create a cluster:

    gcloud container clusters create <cluster-name> --machine-type=n1-standard-2 --scopes cloud-platform --zone us-west1-a
    

    To see a list of possible zones, run gcloud compute zones list.

  5. Push the blog and store docker images to Docker Hub. You will need to create an account
    and run docker login to push your images. The images can be run from any directory.

    docker image tag blog mraible/blog
    docker push mraible/blog
    docker image tag store mraible/store
    docker push mraible/store
    
  6. Run kubectl commands to deploy.

    kubectl apply -f registry
    kubectl apply -f blog
    kubectl apply -f store
    
  7. Use port-forwarding to see the registry app locally.

    kubectl port-forward jhipster-registry-0 8761:8761
    
  8. Run kubectl svc blog to view the blog application on Google Cloud.

  9. Scale microservice apps as needed with kubectl:

    kubectl scale --replicas=3 deployment/store
    

To see a screencast of this process, watch this YouTube video.

AWS

If you know how to deploy this architecture to AWS, I'd love to hear about it! I tried in anger, but ultimately failed.

This example uses JHipster, and awesome project that allows you to generate a microservices architecture with Spring Boot. See Develop a Microservices Architecture with OAuth 2.0 and JHipster for an example that uses OAuth and Okta.

Help

Please post any questions as comments on the blog post, or visit our Okta Developer Forums. You can also email developers@okta.com if would like to create a support ticket.

License

Apache 2.0, see LICENSE.

To the top