1. Deploy Native Application to Kubernetes (Minikube)
1.1. Create a new Project
create-quarkus-kubernetes.sh
mvn io.quarkus:quarkus-maven-plugin:2.16.4.Final:create \
-DprojectGroupId=at.htl \
-DprojectArtifactId=quarkus-kubernetes \
-DclassName="at.htl.WeatherResource" \
-Dpath="/weather" \
-Dextensions="kubernetes, docker"
chmod +x create-quarkus-kubernetes.sh
./create-quarkus-kubernetes.sh
1.2. Start minikube
minikube start
minikube start
There is minikube in the Docker menu. (MacUser can also use home brew) |
docker ps
terminal output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8fed5e8cff30 registry:2 "/entrypoint.sh /etc…" 39 hours ago Up 39 hours 0.0.0.0:5000->5000/tcp registry
Now we will change the context of docker to minikube. When you close the shell, you are back to your "normal" docker.
This are the kubernetes images
eval $(minikube docker-env)
1.3. Package the App
cd quarkus-kubernetes
./mvnw clean package
target/kubernetes/kubernetes.yml
---
apiVersion: v1
kind: ServiceAccount
metadata:
annotations:
app.quarkus.io/vcs-url: https://github.com/htl-leonding-college/quarkus-lecture-notes.git
app.quarkus.io/build-timestamp: 2020-09-02 - 10:48:37 +0000
app.quarkus.io/commit-id: 7d68d95df5a5d5499903639c6dfc92e0e5486be7
labels:
app.kubernetes.io/name: quarkus-kubernetes
app.kubernetes.io/version: 1.0-SNAPSHOT
name: quarkus-kubernetes
---
apiVersion: v1
kind: Service
metadata:
annotations:
app.quarkus.io/vcs-url: https://github.com/htl-leonding-college/quarkus-lecture-notes.git
app.quarkus.io/build-timestamp: 2020-09-02 - 10:48:37 +0000
app.quarkus.io/commit-id: 7d68d95df5a5d5499903639c6dfc92e0e5486be7
labels:
app.kubernetes.io/name: quarkus-kubernetes
app.kubernetes.io/version: 1.0-SNAPSHOT
name: quarkus-kubernetes
spec:
ports:
- name: http
port: 8080
targetPort: 8080
selector:
app.kubernetes.io/name: quarkus-kubernetes
app.kubernetes.io/version: 1.0-SNAPSHOT
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
app.quarkus.io/vcs-url: https://github.com/htl-leonding-college/quarkus-lecture-notes.git
app.quarkus.io/build-timestamp: 2020-09-02 - 10:48:37 +0000
app.quarkus.io/commit-id: 7d68d95df5a5d5499903639c6dfc92e0e5486be7
labels:
app.kubernetes.io/name: quarkus-kubernetes
app.kubernetes.io/version: 1.0-SNAPSHOT
name: quarkus-kubernetes
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: quarkus-kubernetes
app.kubernetes.io/version: 1.0-SNAPSHOT
template:
metadata:
annotations:
app.quarkus.io/vcs-url: https://github.com/htl-leonding-college/quarkus-lecture-notes.git
app.quarkus.io/build-timestamp: 2020-09-02 - 10:48:37 +0000
app.quarkus.io/commit-id: 7d68d95df5a5d5499903639c6dfc92e0e5486be7
labels:
app.kubernetes.io/name: quarkus-kubernetes
app.kubernetes.io/version: 1.0-SNAPSHOT
spec:
containers:
- env:
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: stuetz/quarkus-kubernetes:1.0-SNAPSHOT
imagePullPolicy: IfNotPresent
name: quarkus-kubernetes
ports:
- containerPort: 8080
name: http
protocol: TCP
serviceAccount: quarkus-kubernetes
src/main/resources/application.properties
quarkus.kubernetes.image-pull-policy=ifNotPresent (1)
quarkus.kubernetes.service-type=LoadBalancer (2)
1 | The image will not pulled to the docker registry, when already existing |
2 | the options for the service type are
|
1.4. Deploy the App
./mvnw clean package -Dquarkus.kubernetes.deploy=true
... [INFO] [io.quarkus.kubernetes.deployment.KubernetesDeployer] Deploying to kubernetes server: https://192.168.64.2:8443/ in namespace: default. [INFO] [io.quarkus.kubernetes.deployment.KubernetesDeployer] Applied: ServiceAccount quarkus-kubernetes. [INFO] [io.quarkus.kubernetes.deployment.KubernetesDeployer] Applied: Service quarkus-kubernetes. [INFO] [io.quarkus.kubernetes.deployment.KubernetesDeployer] Applied: Deployment quarkus-kubernetes. [INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 103962ms [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 01:51 min [INFO] Finished at: 2020-09-02T17:26:16+02:00 [INFO] ------------------------------------------------------------------------
view pods
kubectl get pods
NAME READY STATUS RESTARTS AGE quarkus-kubernetes-678d45d8f9-sbdkh 1/1 Running 0 5m47s
view services
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 93d quarkus-kubernetes LoadBalancer 10.98.231.29 <pending> 8080:31532/TCP 8m21s
view services
kubectl get all
NAME READY STATUS RESTARTS AGE pod/quarkus-kubernetes-678d45d8f9-sbdkh 1/1 Running 0 9m42s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 93d service/quarkus-kubernetes LoadBalancer 10.98.231.29 <pending> 8080:31532/TCP 12m NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/quarkus-kubernetes 1/1 1 1 12m NAME DESIRED CURRENT READY AGE replicaset.apps/quarkus-kubernetes-5c6c7cf987 0 0 0 12m replicaset.apps/quarkus-kubernetes-678d45d8f9 1 1 1 9m42s
open service in browser
minikube service quarkus-kubernetes
|-----------|--------------------|-------------|---------------------------| | NAMESPACE | NAME | TARGET PORT | URL | |-----------|--------------------|-------------|---------------------------| | default | quarkus-kubernetes | http/8080 | http://192.168.64.2:31532 | |-----------|--------------------|-------------|---------------------------| 🎉 Opening service default/quarkus-kubernetes in default browser...
minikube service quarkus-kubernetes --url
http://192.168.64.2:31532