Quarkus Kubernetes Cheatsheet2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CHEAT SHEET

Quarkus & Kubernetes II

Th is ch eat sh eet covers more in tegration s th at you can n d in th e form of exten sion s betw een Qu arku s an d Ku bern etes.

Th e follow in g Qu arku s exten sion s agroal (datasou rce), kafka, mongoDB, neo4j,
CREATING THE PROJECT artemis, kafka-streams an d vault provide readin ess h ealth ch ecks by defau lt.
Th ey can be en abled/disabled by settin g quarkus.< component> .health.enabled
mvn "io.quarkus:quarkus-maven-plugin:1 .4.0.Final:create" \ to true/false.
-DprojectGroupId="org.acme" \ quarkus.kafka-streams.health.enabled=true
-DprojectArtifactId="greeting" \ quarkus.mongodb.health.enabled=false
-DprojectVersion="1 .0-SNAPSHOT" \
-DclassName="org.acme.GreetingResource" \
-Dextensions="kubernetes, kubernetes-client, health, kubernetes-config" \ KUBERNETES CONFIGURATION
-Dpath="/hello"
Ku bern etes Con g exten sion u ses Ku bern etes API Server to get `con g-
map`s an d in ject th eir key/valu e u sin g MicroPro le Con g spec.
You can gen erate th e project in h ttps://code.qu arku s.io/ an d You n eed to en able th e exten sion an d set n ame of th e `con g-map`s th at
Tip selectin g kubernetes, kubernetes-client, health an d kubernetes-config con tain s th e properties to in ject:
exten sion s. quarkus.kubernetes-config.enabled=true
quarkus.kubernetes-config.config-maps=cmap1 ,cmap2
KUBERNETES To in ject cmap1 an d cmap2 valu es, you n eed to set th e key n ame in th e
Qu arku s u se th e Dekorate project to gen erate Ku bern etes resou rces. @ ConfigProperty an n otation :
Ru n n in g ./mvnw package th e Ku bern etes resou rces are created at @ ConfigProperty(name = "some.prop1 ")
target/kubernetes/ directory. String someProp1 ;
@ ConfigProperty(name = "some.prop2")
String someProp2;
HEALTH CHECKS
Th e gen erated Ku bern etes resou rces are in tegrated w ith MicroPro le Health If th e con g key is a Qu arku s con gu ration le, application.properties or
spec, registerin g liven ess/readin ess probes based on th e h ealth ch ecks application.yaml, th e con ten t of th ese les is parsed an d each key/valu e of th e
de n ed u sin g th e spec. con gu ration le can be in jected as w ell.
If th e exten sion is presen t, a defau lt liven ess/readin ess probes are registered List of Ku bern etes Con g parameters.
at /health/live an d /health/ready en dpoin ts.
quarkus.kubernetes-config.enabled
You can implemen t a cu stom liven ess/readin ess probes:
import io.smallrye.health.HealthStatus; Th e application w ill attempt to look u p th e con gu ration from th e API
@ ApplicationScoped server, defau lts to false.
public class DatabaseHealthCheck { quarkus.kubernetes-config.fail-on-missing-config
@ Liveness
HealthCheck isAlive() { Th e application w ill n ot start if an y of th e con gu red con g sou rces can n ot
return HealthStatus.up("successful-live"); be located, defau lts to true.
} quarkus.kubernetes-config.config-maps
@ Readiness
Con gMaps to look for in th e n amespace th at th e Ku bern etes Clien t h as
HealthCheck isReady() {
been con gu red for. Su pports CSV format.
return HealthStatus.state("successful-read", this::isServiceReady)
}
private boolean isServiceReady() { KUBERNETES CLIENT
return true;
} Qu arku s in tegrates w ith Fabric8 Ku bern etes Clien t to access Ku bern etes
} Server API.
@ Inject
Qu arku s comes w ith th ree h ealth ch eck implemen tation s for ch eckin g th e KubernetesClient client;
service statu s. ServiceList myServices = client.services().list();
Service myservice = client.services()
SocketHealth Ch eck .inNamespace("default")
It ch ecks if th e h ost is reach able u sin g a socket. .withName("myservice")
.get();
UrlHealth Ch eck
It ch ecks if th e h ost is reach able u sin g a HTTP URL con n ection . Ku bern etes Clien t can be con gu red programmatically:
@ Dependent
In etAddressHealth Ch eck public class KubernetesClientProducer {
It ch ecks if h ost is reach able u sin g InetAddress.isReachable meth od. @ Produces
public KubernetesClient kubernetesClient() {
@ Readiness Config config = new ConfigBuilder()
HealthCheck isGoogleReady() { .withMasterUrl("https://mymaster.com")
return new UrlHealthCheck("https://www.google.com").name("Google-Check"); .build();
} return new DefaultKubernetesClient(config);
}
}

Build here. Go any where. developers.redhat.com | @RHdevelopers


CHEAT SHEET

Or also in application.properties.
By defau lt, Ku bern etes Clien t reads con n ection properties from th e
~/.kube/config folder bu t you can set th em too by u sin g some of th e
kubernetes-client properties:

quarkus.kubernetes-client.trust-certs
Tru st self-sign ed certi cates, defau lts to false.
quarkus.kubernetes-client.master-url
URL of Ku bern etes API server.
quarkus.kubernetes-client.namespace
Defau lt n amespace.
quarkus.kubernetes-client.ca-cert-file
CA certi cate data.
quarkus.kubernetes-client.client-cert-file
Clien t certi cate le.
quarkus.kubernetes-client.client-cert-data
Clien t certi cate data.
quarkus.kubernetes-client.client-key-data
Clien t key data.
quarkus.kubernetes-client.client-key-algorithm
Clien t key algorith m.
quarkus.kubernetes-client.username
Usern ame.
quarkus.kubernetes-client.password
Passw ord.

Author Alex Soto


Java Champion, Working at Red Hat

Build here. Go any where. developers.redhat.com | @RHdevelopers

You might also like