Creating a Quarkus based project by using the `quarkus-maven-plugin` and then adding the `quarkus-kubernetes` extension
Quarkus has provided a quarkus-maven-plugin
:
It can help us to create a Quarkus based project. To do so, run the following command:
$ mvn io.quarkus:quarkus-maven-plugin:create \
-DprojectGroupId=io.weli \
-DprojectArtifactId=play-quarkus-k8s \
-DprojectVersion=0.1-SNAPSHOT \
-Dendpoint=/hello \
-DclassName=io.weli.Hello
And it will create a Quarkus based project. Now we can add the quarkus-kubernetes
extension:
➤ mvn quarkus:add-extension -Dextensions="io.quarkus:quarkus-kubernetes"
It will add the following dependency to the project pom.xml
:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes</artifactId>
</dependency>
Which is the quarkus-kubernetes
extension:
Note: The Quarkus
kubernetes
extension uses the Dekorate1 to do the Kubernetes manifest file generation. And here is the relative class file:
Here is the relative class diagram:
After the extension is added, we can generate the kubernetes
manifest file:
$ mvn package
After the above running process is done, the k8s manifest file is generated:
➤ ls target/kubernetes/
kubernetes.json
kubernetes.yml
Here is the generated content of kubernetes.yml
:
---
apiVersion: v1
kind: Service
metadata:
annotations:
app.quarkus.io/commit-id: 1a4b89f440ed9134fc03a556879a984196ca2ebe
app.quarkus.io/build-timestamp: 2023-09-10 - 16:37:04 +0000
labels:
app.kubernetes.io/name: play-quarkus-k8s
app.kubernetes.io/version: 0.1-SNAPSHOT
app.kubernetes.io/managed-by: quarkus
name: play-quarkus-k8s
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8080
selector:
app.kubernetes.io/name: play-quarkus-k8s
app.kubernetes.io/version: 0.1-SNAPSHOT
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
app.quarkus.io/commit-id: 1a4b89f440ed9134fc03a556879a984196ca2ebe
app.quarkus.io/build-timestamp: 2023-09-10 - 16:37:04 +0000
labels:
app.kubernetes.io/managed-by: quarkus
app.kubernetes.io/name: play-quarkus-k8s
app.kubernetes.io/version: 0.1-SNAPSHOT
name: play-quarkus-k8s
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: play-quarkus-k8s
app.kubernetes.io/version: 0.1-SNAPSHOT
template:
metadata:
annotations:
app.quarkus.io/commit-id: 1a4b89f440ed9134fc03a556879a984196ca2ebe
app.quarkus.io/build-timestamp: 2023-09-10 - 16:37:04 +0000
labels:
app.kubernetes.io/managed-by: quarkus
app.kubernetes.io/name: play-quarkus-k8s
app.kubernetes.io/version: 0.1-SNAPSHOT
spec:
containers:
- env:
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: weli/play-quarkus-k8s:0.1-SNAPSHOT
imagePullPolicy: Always
name: play-quarkus-k8s
ports:
- containerPort: 8080
name: http
protocol: TCP
To sum up, I have put the generated project here:
This post just shows the basic usage of quarkus-maven-plugin
, and I plan to write another post showing more usages of the extension.