ICT role in 21st century education and its challenges
ApacheCon NA '19 - Apache karaf on cloud, the kloud initiative
1. Apache Karaf on cloud,
The kloud initiative
APACHECON North America Sept. 9-12, 2019
JB Onofré
jbonofre@apache.org
@jbonofre
1
2. Who am I ?
Jean-Baptiste Onofré <jbonofre@apache.org>
● Software Engineer/Fellow at Talend
● Member of the Apache Software Foundation
● PMC member and committer for ~ 20 Apache projects (Karaf, Camel, ActiveMQ, Felix,
Aries, Beam, Incubator, …)
3. Karaf track at ACNA ‘19 !
Full track about Apache Karaf with three talks:
1. Apache Karaf on Cloud, the kloud initiative (this talk)
2. Serverless: Multi-tenant Rule Engine Service powered by
Apache Karaf
3. Customer segmentation and personalization in
websites/PWAs using Apache Unomi
4. Why Apache Karaf on cloud ?
● Runtime addressing different use cases
● Provide bunch of “ready-to-use” features
● Can be used on premise or on cloud (easy “move”)
● Support different distribution and packaging to match your requirements
(devs/devops)
● Can leverage additional projects to provide extended features (monitoring, cluster, …)
5. Karaf use cases
● Applications (web, backend, …)
● IoT, messaging and integration (Camel, CXF, ActiveMQ, Kafka, ...)
● Micro-services
Transverse features:
● Monitoring/Alerting/BAM/Data Collection with Karaf Decanter
● Clustering with Karaf Cellar
● Artifacts repositories with Karaf Cave
● API management with Karaf Vineyard
● CDP with Unomi
● ...
6. Applications in Karaf
● Support applications “frameworks”: core Java, Spring,
WebApplication (not necessary OSGi !)
● Easy to migrate from a middleware to Karaf
● Support OSGi applications: micro-service approach internal
to Karaf runtime
● “Force” you to implement a clean design of your applications
(API, SPI, …)
● Support any OSGi programming model: pure “OSGi”,
blueprint, SCR
● Karaf features to extend and provision applications (JPA,
JTA, JMS, JDBC, …)
● Also possible to use hot deployment
7. Service based application example: API
module
public interface BookingService {
Collection<Booking> list();
Booking get(Long id);
void add(Booking booking);
}
public class Booking {
private Long id;
private String customer;
private String flight;
public Booking(String customer, String flight)
throws Exception {
this.id = new Random().nextLong();
this.customer = customer;
this.flight = flight;
}
…
}
8. Service based application example:
service impl (using SCR)
@Component
public class BookingServiceMemoryImpl implements BookingService {
private final Map<Long, Booking> bookings = new HashMap<>();
@Override
public Collection<Booking> list() {
return bookings.values();
}
@Override
public Booking get(Long id) {
return bookings.get(id);
}
@Override
public void add(Booking booking) {
bookings.put(booking.getId(), booking);
}
}
10. IoT and integration in Karaf
● Support Apache Camel as integration framework
○ Provide more than 100 of Camel components as Karaf
features
○ EIPs
○ Data Formats
● Easy to install and start with, supporting DSLs
● Use the same Karaf features provisioning mechanism
● Support hot deployment
● Support MoM with ActiveMQ, Kafka, …
● Support web/rest service with CXF
13. Microservice in Karaf
● OSGi service model fits perfectly with micro-service approach
● JAXRS whiteboard easily exposes OSGi services as REST services
● Leverage CXF under the hood with all great features supported by CXF
● Scale with Karaf Cellar DOSGi/RemoteImpl
● Karaf can mix integration/IoT/applications in the same platform
14. Microservice example: JAXRS
Whiteboard
@Path("/booking")
@Component(service = BookingServiceRest.class, property = {
"osgi.jaxrs.resource=true" })
public class BookingServiceRest implements BookingService {
private final Map<Long, Booking> bookings = new
HashMap<>();
@Override
@Path("/")
@Produces("application/json")
@GET
public Collection<Booking> list() {
return bookings.values();
}
@Override
@Path("/{id}")
@Produces("application/json")
@GET
public Booking get(@PathParam("id") Long id) {
return bookings.get(id);
}
@Override
@Path("/")
@Consumes("application/json")
@POST
public void add(Booking booking) {
bookings.put(booking.getId(), booking);
}
}
16. Dynamic, custom, static distributions
● You have different ways to use Karaf depending of the provisioning you want.
● Karaf and applications can be “assembly” in different kind of distributions
● Any distribution is available as a archive or can be packaged as a Docker image
● We can distinguish three kind of distributions:
○ Dynamic distribution (standard one)
○ Custom distribution (based on dynamic)
○ Static distribution
17. ● It’s the standard distribution you can download from Karaf website
● Fully administrable via the shell console (ssh) or web console
● The lifecycle is the following:
○ Download Apache Karaf from karaf.apache.org
○ Copy the archive where you want and extract
○ Run Karaf
○ Deploy applications on the running Karaf instance
$ curl -O https://www-eu.apache.org/dist/karaf/4.2.6/apache-karaf-4.2.6.tar.gz
$ tar zxvf apache-karaf-4.2.6.tar.gz
$ cd apache-karaf-4.2.6
$ ./bin/karaf
…
karaf@root()> feature:repo-add …
karaf@root()> feature:install ...
Dynamic distribution (mutable)
Download, run, deploy
18. Dynamic distribution and Docker
● Apache Karaf official Docker images available on Apache DockerHub
● You can create your Docker image based on any Karaf standard distribution thanks to
script provided: https://github.com/apache/karaf/tree/master/assemblies/docker
$ ./build.sh --from-release --karaf-version 4.2.6 --image-name my-karaf
Downloading apache-karaf-4.2.6.tar.gz from https://www-us.apache.org/dist/karaf/4.2.6/
Sending build context to Docker daemon 21.29MB
...
Successfully built d209a00ef33c
Successfully tagged my-karaf:latest
$ docker images|grep my-karaf
my-karaf latest d209a00ef33c About a minute ago 467MB
● You can create a Docker image directly on a running Karaf instance using the
docker:provision Karaf command
karaf@root()> feature:install docker
karaf@root()> docker:provision mykaraf
19. ● Similar to dynamic distribution but “pre-packaged” to include some “boot” applications
● It also support the deployment at runtime (like the dynamic distribution)
● Karaf tooling and features allows you to easily create your own custom distribution and
docker image
Custom distribution (mutable)
Download, extend, run, optionally deploy
20. Create your own custom dynamic
runtime powered by Apache Karaf
● Use an existing features.xml or generate a features XML for your application
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>features-generate-descriptor</goal>
</goals>
<configuration>
<includeProjectArtifact>true</includeProjectArtifact>
</configuration>
</execution>
</executions>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:features xmlns:ns2="http://karaf.apache.org/xmlns/features/v1.6.0"
name="karaf-acna-app">
<ns2:feature name="karaf-acna-app" version="1.0.SNAPSHOT">
<ns2:bundle>mvn:org.apache.acna/karaf-acna-app/1.0-SNAPSHOT</ns2:bundle>
</ns2:feature>
</ns2:features>
22. Dynamic runtime packages and run
● Ready to use tar.gz & zip archives
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
karaf-acna-dynamic latest 13fb21f44dfc 7 seconds ago 485MB
$ docker run --name mykaraf -a -t karaf-acna-dynamic
…
karaf@root()>
● Ready to use Dockerfile
● Ready to use Docker image
$ tar zxvf acna-dynamic.tar.gz && cd acna-dynamic
$ ./bin/karaf
...
karaf@root()>
23. ● This time, Karaf and your applications are packaged all together at build time
● Not deployment at runtime, all is prepared at build
● It’s similar to spring-boot approach
● Very convenient for docker/microservice provisioning
● Karaf tooling and features to easily create the static distribution and the docker image
Static distribution (immutable)
Build, run
24. Create your own static runtime
powered by Apache Karaf
● Can start like custom distribution using existing features or generating the features
descriptor for your application
● Karaf tooling package all in a “static” package and can create the Docker image
● Static means that all resolution is performed at build time: the execution is full static,
predictable, all resolved.
● It’s similar to spring-boot approach.
● We start from the same as dynamic distribution: a Karaf features XML
26. Static runtime packages and run
● Ready to use tar.gz & zip archives
● Ready to use Dockerfile
● Ready to use Docker image
$ tar zxvf acna-static.tar.gz && cd acna-static
$ ./bin/karaf run
Sep 06, 2019 9:08:55 AM org.apache.karaf.main.Main launch
...
$ docker run --name mykaraf -d karaf-docker-example-static-dist
karaf: Ignoring predefined value for KARAF_HOME
Sep 06, 2019 7:14:34 AM org.apache.karaf.main.Main launch
...
27. Karaf on cloud VM (EC2, …)
● Like on prem:
○ Create virtual machine
○ Upload Karaf
○ Start Karaf
● Can work with dynamic, custom, or static distribution
29. Karaf on EC2
ssh -i "karaf.pem" ec2-user@ec2-63-35-225-69.eu-west-1.compute.amazonaws.com
Last login: Thu Sep 5 13:11:24 2019 from 82-64-90-43.subs.proxad.net
__| __|_ )
_| ( / Amazon Linux 2 AMI
___|___|___|
https://aws.amazon.com/amazon-linux-2/
[ec2-user@ip-172-31-3-164 ~]$ cd karaf/bin
[ec2-user@ip-172-31-3-164 ~/karaf]$ ./karaf
30. Karaf on cloud VMs with Cellar (EC2, …)
● Several VMs with Karaf runtimes, install Cellar on each
instance
● No SPOF
● Cellar is able to sync (features, applications, configurations)
between Karaf runtimes
● Support cluster groups to target deployment
● Support RPC between Karaf runtimes
31. Karaf on Cloud (ECR/ECS, …)
Push your Karaf Docker image (dynamic or static) on a Docker Registry (for instance ECR)
● Create a ECR repository
42. Karaf with Kubernetes (EKS, …)
● Push your Karaf based runtime on Docker registry (ECR)
● Use or create a Kubernetes cluster
43. Karaf on Cloud - EKS
● Use the “regular” kubectl command to create the deployment
$ kubectl run karaf --image=aws...acna:latest --port=8181
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
karaf 1/1 1 1 44s
$ kubectl logs karaf-cc9c6bd5d-6wbzk
karaf: Ignoring predefined value for KARAF_HOME
Jun 25, 2019 12:52:29 PM org.apache.karaf.main.Main launch
● expose a service
$ kubectl expose deployment/karaf --type="NodePort" --port=8181
service/karaf exposed
● scale up and down
$ kubectl scale deployments/karaf --replicas=2
NAME READY UP-TO-DATE AVAILABLE AGE
karaf 2/2 2 2 4m34s
44. Karaf on cloud: current state and
roadmap
● Even easier way to create distributions/runtimes
● New tooling (CLI, Gradle, ..) in addition of the Karaf Maven plugin
● Tooling to create K8S deployment model (HELM packages ?)
● Improved K8S support in Cellar for even better scalability
45. Karaf Community
● WELCOME to Karaf !
● We love contributions and ideas !
● Updated website
● Periodical release cycle (~ every 3 months)