2. SOME CONTEXT : YOUR PRESENTER !
„Anthony Dahanne, Software Engineer
@Terracotta, a Software AG company
„Montréal JUG leader
„Working on Terracotta cloud deployments
(Docker, Kubernetes, AWS, etc.)
„Also working on Management and Monitoring for
Terracotta products
3. “The Cloud”
n
…
SOME CONTEXT : YOUR PRESENTER’S MISSION
PostgreSQL
Webapp with
Ehcache3 Clustered
Terracotta Server Terracotta Server
„Ehcache3 : Open Source caching library for Java „Terracotta Server : OSS clustered backend for Ehcache3
4. AGENDA
• It all started with Docker
• Then came Kubernetes
• But Helm too !
• Extending Kubernetes in Java ???
• What’s next ?
5. DOCKERFILE !
FROM openjdk:8-jdk-alpine
LABEL maintainers="Anthony Dahanne <anthony.dahanne@softwareag.com>"
RUN wget -q http://repo1.maven.org/maven2/3.6.1/ehcache-clustered-3.6.1-kit.tgz
&& tar xvzf ehcache-clustered-3.6.1-kit.tgz -C /terracotta
COPY conf/tc-config-active-passive.xml /terracotta/server/conf/tc-config-active-passive.xml
COPY entrypoint.sh /terracotta/entrypoint.sh
# all below commands will now be relative to this path
WORKDIR /terracotta/server
# the tsa port (used by the clients to connect to the cluster)
EXPOSE 9410
# the group port (used to sync the passives with the active)
EXPOSE 9430
ENV OFFHEAP_RESOURCE1_NAME "offheap-1"
ENV OFFHEAP_RESOURCE1_UNIT "MB"
ENV OFFHEAP_RESOURCE1_SIZE "512"
# before starting the terracotta server, we update the tc-config.xml configuration file
ENTRYPOINT /terracotta/entrypoint.sh
8. SED OR ITS KUBERNETES BROTHER, KUSTOMIZE
kustomize targets kubernetes; it understands and can patch kubernetes style API objects. It's like
make, in that what it does is declared in a file, and it's like sed, in that it emits editted text.
resources:
- kubernetes-complete-deployment.yaml
imageTags:
- name: terracotta/terracotta-server-oss
newTag: 5.4.3
kustomization.yaml
containers:
- name: terracotta
image: terracotta/terracotta-server-oss:5.5.1
my-deployment.yaml
kustomize build | kubectl apply -f -
containers:
- name: terracotta
image: terracotta/terracotta-server-oss:5.4.3
??????????????
???????????
?????????????
??????????????
9. KUBERNETES PACKAGING : HELM
• Helm is installed on the client, Tiller is the server side
• With Helm you deploy / create Charts that are run as Releases
• In a Chart, you package your Kubernetes manifests, and your dependencies
• A very notable feature is the “templatization“ of your Kubernetes manifests
APT / YUM FOR KUBERNETES
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ template "terracotta.fullname" . }}
labels:
app: {{ template "terracotta.name" . }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ template "terracotta.name" . }}
serviceName: {{ template "terracotta.fullname" . }}
spec:
{{- if .Values.nodeSelector }}
nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
{{- end }}
containers:
- name: {{ template "terracotta.fullname" . }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}”
10. QUICK BACK TO BASICS : KUBERNETES ARCHITECTURE
By Khtan66 - CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=53571935
11. WHAT IS AN OPERATOR ?
• An Operator is a method of packaging, deploying and managing a Kubernetes
application.
• To be able to make the most of Kubernetes, you need a set of cohesive APIs to
extend in order to service and manage your applications that run on Kubernetes.
You can think of Operators as the runtime that manages this type of application
on Kubernetes.
• Operators are purpose-built to run a Kubernetes application, with operational
knowledge baked in. They will be smarter and more tailored than generic tools.
from : https://coreos.com/operators/
12. KUBERNETES OPERATOR IN JAVA
• Operators (or controllers) provide better user experience for deploying and
managing complex applications like databases (PostgreSQL, Terracotta server, etc.)
• They can create and manage their own Custom Resource Definitions (CRDs)
- or provide a CLI or UI via their own REST endpoints
USING FABRIC8 OR KUBERNETES JAVA SDK
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<version>3.0.0-beta2</version>
</dependency>
Service tmcService = new ServiceBuilder()
.withNewMetadata()
.withName("tmc")
.endMetadata()
.withNewSpec()
.addNewPort()
.withName("tmc-port")
.withPort(9480)
.endPort()
.withType("LoadBalancer")
.addToSelector("app", "tmc")
.endSpec()
.build();
13. TERRACOTTA OPERATOR ARCHITECTURE
Kubernetes Cluster
Terracotta Operator
REST API
CLI / Web UI
K8S API Server
Java SDK
REST calls
tc-configs
operator config
Terracotta
ServerTerracotta
Server
ConfigMaps
Services,
StatefulSets
A PRIVILEGED POD THAT LISTENS TO THE USER
14. TERRACOTTA OPERATOR ARCHITECTURE
Kubernetes Cluster
Terracotta Operator
kubectl apply
K8S API Server
Java SDK
Watch
tc-configs
operator config
Terracotta
ServerTerracotta
Server
ConfigMaps
Services,
StatefulSets
A PRIVILEGED POD THAT LISTENS TO THE API SERVER
15. WHAT’S NEXT ?
• Kubectl plugins : to integrate your operator into kubectl
• Service catalog : to allow your users to just “require” your software
LINKS AND OTHER REFERENCES
• https://github.com/Terracotta-OSS/docker
• https://github.com/helm/charts/tree/master/stable/terracotta
• https://github.com/Terracotta-OSS/terracotta-operator
• The fullstack demo app (and its jib, kubernetes, helm, scaffold files) is on Github