Used Software
- VirtualBox 6.1.30
- docker 20.10.7
- Ubuntu 20.04.3 LTS
- openjdk version “11.0.11” 2021-04-20
- Quarkus 2.5.0
- Quarkus Jib Extension to push images to your repository
- Quarkus
kubernetes
Extension: —> When this
extension is present basic resources like pods, ingresses and services are created. - Quarkus
kubernetes-client
extension : —> When this
extension is present, the kubernetes
extension is going to create additional resources like serviceaccounts automatically.
Bash env Variables
- export KUBERNETES_MASTER=https://127.0.0.1:6443
- export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
- export JAVA_HOME=”/usr/lib/jvm/java-11-openjdk-amd64″
Create Simple Quarkus Application
- Go to quarkus.io
- Select REASTEasy JAX-Rs package
- Press Generate your Application
- Donwload and Extract Zile
Start Application using maven
- Start Web-Server with : ./mvnw compile quarkus:dev
Testing Application
Get an Application Overview
What Extensions or used by our project ?
- Run ./mvnw compile quarkus:dev
- Check Iine Installed Features
- INFO [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, resteasy, smallrye-context-propagation, vertx]
Using Jib to deploy your image to a repository
Add jib Extension to your project
# ./mvnw quarkus:add-extension -Dextensions="container-image-jib"
Warning: JAVA_HOME environment variable is not set.
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< thn.com:first-quarkus-sample >--------------------
[INFO] Building first-quarkus-sample 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- quarkus-maven-plugin:2.5.0.Final:add-extension (default-cli) @ first-quarkus-sample ---
[INFO] Looking for the newly published extensions in registry.quarkus.io
[INFO] [SUCCESS] ✅ Extension io.quarkus:quarkus-container-image-jib has been installed
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.814 s
[INFO] Finished at: 2021-11-29T09:43:23+01:00
[INFO] -----------------------------------------------------------------
Edit your application.properties File
quarkus.container-image.registry=ghcr.io
quarkus.container-image.group=hhutzler
quarkus.container-image.name=quarkus-first-sample
quarkus.container-image.tag=latest
Login with docker into your Repostiory [ here we use a githup repo )
- For password use a Personal Access Token
- For details read:
# export CR_PAT=ghp.......
# echo $CR_PAT | /usr/bin/docker login ghcr.io -u USERNAME --password-stdin
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
Deploy Image to ghcr.io repostitory
- Note: Here we you use docker for our Github login
- You can run this sample without docker when providing your Personal Access Token in application.properties
# ./mvnw clean package -DskipTests -Dquarkus.container-image.push=true
Warning: JAVA_HOME environment variable is not set.
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< thn.com:first-quarkus-sample >--------------------
[INFO] Building first-quarkus-sample 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ first-quarkus-sample ---
[INFO] Deleting /home/helmut/dev/Quarkus/first-quarkus-sample/target
.....
[INFO] --- quarkus-maven-plugin:2.5.0.Final:build (default) @ first-quarkus-sample ---
[INFO] [org.jboss.threads] JBoss Threads version 3.4.2.Final
[INFO] [io.quarkus.container.image.jib.deployment.JibProcessor] Starting container image build
[WARNING] [io.quarkus.container.image.jib.deployment.JibProcessor] Base image 'fabric8/java-alpine-openjdk11-jre' does not use a specific image digest - build may not be reproducible
[INFO] [io.quarkus.container.image.jib.deployment.JibProcessor] LogEvent [level=INFO, message=Docker config auths section defines credentials for ghcr.io]
[INFO] [io.quarkus.container.image.jib.deployment.JibProcessor] LogEvent [level=LIFECYCLE, message=Using credentials from Docker config (/root/.docker/config.json) for ghcr.io/hhutzler/quarkus-first-sample]
[INFO] [io.quarkus.container.image.jib.deployment.JibProcessor] The base image requires auth. Trying again for fabric8/java-alpine-openjdk11-jre...
[INFO] [io.quarkus.container.image.jib.deployment.JibProcessor] Using base image with digest: sha256:b459cc59d6c7ddc9fd52f981fc4c187f44a401f2433a1b4110810d2dd9e98a07
[INFO] [io.quarkus.container.image.jib.deployment.JibProcessor] Container entrypoint set to [java, -Djava.util.logging.manager=org.jboss.logmanager.LogManager, -jar, quarkus-run.jar]
[INFO] [io.quarkus.container.image.jib.deployment.JibProcessor] Pushed container image ghcr.io/hhutzler/quarkus-first-sample (sha256:5fca910e578664cd091bc099c884ead333c3b17f2105119816e24706a8f8d64f)
[INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 13870ms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 26.168 s
[INFO] Finished at: 2021-11-29T09:46:56+01:00
[INFO] ------------------------------------------------------------------------
Validate Image in Github Repository
Test Github Image with Docker
Start docker image
docker run --rm -p 8085:8080 -p 5005:5005 -e JAVA_DEBUG=true ghcr.io/hhutzler/quarkus-first-sample
Unable to find image 'ghcr.io/hhutzler/quarkus-first-sample:latest' locally
latest: Pulling from hhutzler/quarkus-first-sample
cbdbe7a5bc2a: Pull complete
61307e9c6b82: Pull complete
d1def49a5d10: Pull complete
831aa72d60cb: Pull complete
f504a8475f3f: Pull complete
a0b68434dbbe: Pull complete
747652cba6e0: Pull complete
630f3b8fa30e: Pull complete
cd17c2b2f4ff: Pull complete
a9f1c271854a: Pull complete
1acd10e65f0d: Pull complete
c827592aa365: Pull complete
Digest: sha256:5fca910e578664cd091bc099c884ead333c3b17f2105119816e24706a8f8d64f
Status: Downloaded newer image for ghcr.io/hhutzler/quarkus-first-sample:latest
__ ____ __ _____ ___ __ ____ ______
--/ __ \/ / / / _ | / _ \/ //_/ / / / __/
-/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/
or that you did not make a typo
2021-11-29 08:54:01,536 INFO [io.quarkus] (main) first-quarkus-sample 1.0.0-SNAPSHOT on JVM (powered by Quarkus 2.5.0.Final) started in 2.223s. Listening on: http://0.0.0.0:8080
2021-11-29 08:54:01,537 INFO [io.quarkus] (main) Profile prod activated.
2021-11-29 08:54:01,537 INFO [io.quarkus] (main) Installed features: [cdi, resteasy, resteasy-jackson, smallrye-context-propagation, vertx]
Test Github Image with curl
# curl localhost:8085/hello
Hello RESTEasy
Stop Docker Image
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f1208d829b69 ghcr.io/hhutzler/quarkus-first-sample "java -Djava.util.lo…" 5 minutes ago Up 5 minutes 8778/tcp, 0.0.0.0:5005->5005/tcp, 9779/tcp, 0.0.0.0:8085->8080/tcp loving_yonath
# rm -f f1208d829b69
f1208d829b69
Deploy App to your Kubernets Cluster
Modify application.properties File
quarkus.container-image.registry=ghcr.io
quarkus.container-image.group=hhutzler
quarkus.container-image.name=quarkus-first-sample
quarkus.container-image.tag=latest
quarkus.kubernetes.namespace=quarkus-testing
# Not working with quarkus kubernetes-client
# quarkus.kubernetes.service-account=quarkus-sa
quarkus.kubernetes.ingress.host=app1.quarkus.com
quarkus.kubernetes.ingress.expose=true
# Deprecated
# quarkus.kubernetes.expose=true
Add kubernetes-client and kubernetes Extension to your project
# ./mvnw quarkus:add-extension -Dextensions="kubernetes-client"
Warning: JAVA_HOME environment variable is not set.
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< thn.com:first-quarkus-sample >--------------------
[INFO] Building first-quarkus-sample 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- quarkus-maven-plugin:2.5.0.Final:add-extension (default-cli) @ first-quarkus-sample ---
[INFO] [SUCCESS] ✅ Extension io.quarkus:quarkus-kubernetes-client has been installed
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.165 s
[INFO] Finished at: 2021-11-29T10:01:20+01:00
[INFO] ------------------------------------------------------------------------
# ./mvnw quarkus:add-extension -Dextensions="kubernetes"
Warning: JAVA_HOME environment variable is not set.
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< thn.com:first-quarkus-sample >--------------------
[INFO] Building first-quarkus-sample 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- quarkus-maven-plugin:2.5.0.Final:add-extension (default-cli) @ first-quarkus-sample ---
[INFO] [SUCCESS] ✅ Extension io.quarkus:quarkus-kubernetes has been installed
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.303 s
[INFO] Finished at: 2021-11-29T14:52:35+01:00
[INFO] ------------------------------------------------------------------------
Create new kubernetes yaml File
- Run # ./mvnw clean package -DskipTests -Dquarkus.container-image.push=true
- If build fails with bouncycastle related Exceptions read: http://www.helikube.de/quarkus-creating-kubernetes-yml-fails
- if build works check file : target/kubernetes/kubernetes.yml
- kubernetes.yml should create the following objects
- ServiceAccount
- Service
- RoleBinding
- Deployment
- Ingress
# ./mvnw clean package -DskipTests -Dquarkus.container-image.push=true
Warning: JAVA_HOME environment variable is not set.
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< thn.com:first-quarkus-sample >--------------------
[INFO] Building first-quarkus-sample 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ first-quarkus-sample ---
[INFO] Deleting /home/helmut/dev/Quarkus/first-quarkus-sample/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ first-quarkus-sample ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- quarkus-maven-plugin:2.5.0.Final:generate-code (default) @ first-quarkus-sample ---
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ first-quarkus-sample ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/helmut/dev/Quarkus/first-quarkus-sample/target/classes
[INFO]
[INFO] --- quarkus-maven-plugin:2.5.0.Final:generate-code-tests (default) @ first-quarkus-sample ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ first-quarkus-sample ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/helmut/dev/Quarkus/first-quarkus-sample/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ first-quarkus-sample ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /home/helmut/dev/Quarkus/first-quarkus-sample/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ first-quarkus-sample ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ first-quarkus-sample ---
[INFO] Building jar: /home/helmut/dev/Quarkus/first-quarkus-sample/target/first-quarkus-sample-1.0.0-SNAPSHOT.jar
[INFO]
[INFO] --- quarkus-maven-plugin:2.5.0.Final:build (default) @ first-quarkus-sample ---
[INFO] [org.jboss.threads] JBoss Threads version 3.4.2.Final
[WARNING] [io.quarkus.kubernetes.deployment.KubernetesConfigUtil] Usage of quarkus.kubernetes.expose is deprecated in favor of quarkus.kubernetes.ingress.expose
[INFO] Checking for existing resources in: /home/helmut/dev/Quarkus/first-quarkus-sample/src/main/kubernetes.
[INFO] [io.quarkus.container.image.jib.deployment.JibProcessor] Starting container image build
[WARNING] [io.quarkus.container.image.jib.deployment.JibProcessor] Base image 'fabric8/java-alpine-openjdk11-jre' does not use a specific image digest - build may not be reproducible
[INFO] [io.quarkus.container.image.jib.deployment.JibProcessor] LogEvent [level=INFO, message=Docker config auths section defines credentials for ghcr.io]
[INFO] [io.quarkus.container.image.jib.deployment.JibProcessor] LogEvent [level=LIFECYCLE, message=Using credentials from Docker config (/root/.docker/config.json) for ghcr.io/hhutzler/quarkus-first-sample]
[INFO] [io.quarkus.container.image.jib.deployment.JibProcessor] The base image requires auth. Trying again for fabric8/java-alpine-openjdk11-jre...
[INFO] [io.quarkus.container.image.jib.deployment.JibProcessor] Using base image with digest: sha256:b459cc59d6c7ddc9fd52f981fc4c187f44a401f2433a1b4110810d2dd9e98a07
[INFO] [io.quarkus.container.image.jib.deployment.JibProcessor] Container entrypoint set to [java, -Djava.util.logging.manager=org.jboss.logmanager.LogManager, -jar, quarkus-run.jar]
[INFO] [io.quarkus.container.image.jib.deployment.JibProcessor] Pushed container image ghcr.io/hhutzler/quarkus-first-sample (sha256:69b9b0ab327b6b32e393bfbe979e1bc45424adfb8f0aa278f909a9b5752b54e0)
[INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 14841ms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24.856 s
[INFO] Finished at: 2021-11-29T16:03:03+01:00
[INFO] ------------------------------------------------------------------------
Apply Yaml file to our Kubernetes Cluster and test Application
Create Application Namepace
# kubectl create namespace quarkus-testing
namespace/quarkus-testing created
Create Kubernetes Objects
# kubectl apply -f target/kubernetes/kubernetes.yml
serviceaccount/quarkus-first-sample created
service/quarkus-first-sample created
rolebinding.rbac.authorization.k8s.io/quarkus-first-sample-view created
deployment.apps/quarkus-first-sample created
ingress.networking.k8s.io/quarkus-first-sample created
Validate Kubernetes Setup
# kubectl get all -n quarkus-testing
NAME READY STATUS RESTARTS AGE
pod/quarkus-first-sample-67b7f758c-ctsn9 1/1 Running 0 22s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/quarkus-first-sample ClusterIP 10.43.217.143 <none> 80/TCP 22s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/quarkus-first-sample 1/1 1 1 22s
NAME DESIRED CURRENT READY AGE
replicaset.apps/quarkus-first-sample-67b7f758c 1 1 1 22s
Test Application via Ingress
# curl app1.quarkus.com/hello
Hello RESTEasy
Fix Error : “ghcr.io/hhutzler/quarkus-first-sample:latest”: failed to authorize
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 23m default-scheduler Successfully assigned quarkus-testing/quarkus-first-sample-67b7f758c-89w9n to helmut-virtualbox
Normal Pulling 22m (x4 over 23m) kubelet Pulling image "ghcr.io/hhutzler/quarkus-first-sample:latest"
Warning Failed 22m (x4 over 23m) kubelet Failed to pull image "ghcr.io/hhutzler/quarkus-first-sample:latest": rpc error: code = Unknown desc =
failed to pull and unpack image "ghcr.io/hhutzler/quarkus-first-sample:latest":
failed to resolve reference "ghcr.io/hhutzler/quarkus-first-sample:latest":
failed to authorize: failed to fetch anonymous token: unexpected status: 401 Unauthorized
Warning Failed 22m (x4 over 23m) kubelet Error: ErrImagePull
Warning Failed 22m (x6 over 23m) kubelet Error: ImagePullBackOff
Normal BackOff 3m49s (x85 over 23m) kubelet Back-off pulling image "ghcr.io/hhutzler/quarkus-first-sample:latest"
- Fix: Change Github package from private to public
Be First to Comment