Supersonic Subatomic Java A Kubernetes Native Java stack tailored for GraalVM & OpenJDK HotSpot, crafted from the best of breed Java libraries and standards
I tried Quarkus with the slogan. As shown in ↓, there are various articles that I have introduced or tried, so the difference is GKE (Google Kubernetes Engine). I tried to put it on.
-Java framework "Quarkus" is now available. Native binaries are generated from Java code, Java applications are started instantly, and optimization for containers is realized. Released by Red Hat -Quarkus: Introducing a new method to launch Java apps at high speed on a container
$ cat /etc/os-release NAME="Ubuntu" VERSION="18.04.2 LTS (Bionic Beaver)"
$ java -version openjdk version "10.0.2" 2018-07-17 OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4) OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode)
$ sudo docker version 〜〜〜 Server: Docker Engine - Community Engine: Version: 18.09.2 API version: 1.39 (minimum version 1.12) Go version: go1.10.6 Git commit: 6247962 Built: Sun Feb 10 03:42:13 2019 OS/Arch: linux/amd64 Experimental: false
$ mvn -version Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T03:41:47+09:00)
$ gcloud version Google Cloud SDK 240.0.0 〜〜〜 kubectl 2019.03.22
Gcloud auth
has been completed.Create a Maven project according to the tutorial below, and then just hit the mvnw
command included in the created project.
https://quarkus.io/guides/getting-started-guide
If you extract a part of the source, it will be Spring-like Web API code like ↓. When I tried to use GCP Cloud Endpoints, the code was still similar.
java:[org.acme.quickstart.GreetingResource]
@Path("/hello")
public class GreetingResource {
@Inject
GreetingService service;
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/greeting/{name}")
public String greeting(@PathParam("name") String name) {
return service.greeting(name);
}
}
This is also the same as the tutorial, but create the following Dockerfile under the project.
[Dockerfile]
FROM openjdk:11-jre-slim
RUN mkdir /app
COPY target/lib /app/lib
COPY target/*-runner.jar /app/application.jar
EXPOSE 8080
CMD ["java", "-jar", "/app/application.jar"]
, but I raised it to "11" because it did not start well when I tried
docker run` due to a problem with the version of Quarkus when I tried it.Create a Yaml file under the project to use Cloud Build as shown below.
[cloudbuild.yaml]
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/quarkus-microservice', '.' ]
images:
- 'gcr.io/$PROJECT_ID/quarkus-microservice'
Then run the build. Then, the completed container image will be uploaded to GCR (Google Container Registry).
$ gcloud builds submit --config cloudbuild.yaml .
Creating temporary tarball archive of 137 file(s) totalling 9.6 MiB before compression.
Uploading tarball of [.] to [gs://[GCP project ID]_cloudbuild/source/1553878212.23-a25ba1029b4a4979b2a049769da45570.tgz]
Created [https://cloudbuild.googleapis.com/v1/projects/[GCP project ID]/builds/1bff9b28-a9da-4113-9c41-c9de7f9af1d7].
〜〜〜
DONE
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ID CREATE_TIME DURATION SOURCE IMAGES STATUS
1bff9b28-a9da-4113-9c41-c9de7f9af1d7 2019-03-29T16:50:16+00:00 46S gs://[GCP project ID]_cloudbuild/source/1553878212.23-a25ba1029b4a4979b2a049769da45570.tgz gcr.io/[GCP project ID]/quarkus-microservice (+1 more) SUCCESS
Confirm with the GCP console that the build was actually successful and the container image was stored.
By the way, this procedure is based on the following past articles. GKE trial (Part 2: "To GitHub-> CSR. And to GCR by GCB")
To use k8s managed services on GCP, first create a cluster. You can also create it from the GCP console, but I'll leave it as a command as I'll create and delete it (to save money). Created preemptively because it is just for trial articles, not for service disclosure.
$ gcloud container clusters create clst-pe-01 --preemptible --machine-type=f1-micro --num-nodes=3 --disk-size=10
WARNING: In June 2019, node auto-upgrade will be enabled by default for newly created clusters and node pools. To disable it, use the `--no-enable-autoupgrade` flag.
〜〜〜
Creating cluster clst-pe-01 in asia-northeast1-c... Cluster is being health-checked (master is healthy)...done.
Created [https://container.googleapis.com/v1/projects/[GCP project ID]/zones/asia-northeast1-c/clusters/clst-pe-01].
To inspect the contents of your cluster, go to: https://console.cloud.google.com/kubernetes/workload_/gcloud/asia-northeast1-c/clst-pe-01?project=[GCP project ID]
kubeconfig entry generated for clst-pe-01.
NAME LOCATION MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS
clst-pe-01 asia-northeast1-c 1.11.7-gke.12 xx.xxx.xxx.xxx f1-micro 1.11.7-gke.12 3 RUNNING
Confirm that the cluster is actually created.
By the way, this procedure is based on the following past articles. GKE trial (3: "Create cluster") In addition, the following will be helpful for creating clusters to save money. Create an inexpensive GKE (k8s) cluster and use it for hobby development
$ kubectl run quarkus-microservice --image gcr.io/[GCP project ID]/quarkus-microservice@sha256:18a20d4307785a7aec3b19738a849430e2181720cb357d8a7ea6f8fe4ed1f850 --port 80
deployment.apps/quarkus-microservice created
Yes. You can deploy it.
If you can only deploy it, there is no access from the outside, so create a service for publication.
$ kubectl expose deployment quarkus-microservice --type "LoadBalancer"
service/quarkus-microservice exposed
Yes. The service is ready.
I don't know because it's too simple, but it's a success.
By the way, this procedure is based on the following past articles. [GKE trial (Part 4: "GKE deployment-> service release"](https://qiita.com/sky0621/items/aadeb53a5be2800066de#4 application released)
This time, I just put the first tutorial level automatic generation application on GKE. There are various sample code of GitHub such as JSON-REST, WebSocket, ORM, and validation. https://github.com/quarkusio/quarkus-quickstarts#getting-started-guides When I thought about the app to put on k8s, until now, "Golang "Let's write.", But thanks to the appearance of Kubernetes, Java that can use abundant existing assets may be a candidate in the future.
Recommended Posts