SlideShare a Scribd company logo
© 2018 Software AG. All rights reserved.
Anthony Dahanne
@anthonydahanne
blog.dahanne.net
December 3rd 2018
A KUBERNETES OPERATOR
WRITTEN IN JAVA ?
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
“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
AGENDA
• It all started with Docker
• Then came Kubernetes
• But Helm too !
• Extending Kubernetes in Java ???
• What’s next ?
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
ORCHESTRATION IN 2016 / 2017 ? DOCKERSWARM !
version: '3'
networks:
terracotta-net:
driver: overlay
services:
client:
image: terracotta/sample-ehcache-client:5.5.1
environment:
- TERRACOTTA_SERVER_URL=terracotta-1:9410,terracotta-2:9410
networks:
- terracotta-net
terracotta-1:
hostname: terracotta-1
image: terracotta/terracotta-server-oss:5.5.1
environment:
- TC_SERVER1=terracotta-1
- TC_SERVER2=terracotta-2
networks:
- terracotta-net
THEN CAME KUBERNETES
apiVersion: v1
kind: ConfigMap
metadata:
name: tc-config
data:
tc-config.xml: |
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<tc-config xmlns="http://www.terracotta.org/config">
<plugins>
<config>
<ohr:offheap-resources xmlns:ohr="http://www.terracotta.org/config/offheap-resource">
<ohr:resource name="offheap-1" unit="MB">512</ohr:resource>
<ohr:resource name="offheap-2" unit="MB">128</ohr:resource>
</ohr:offheap-resources>
</config>
</plugins>
<servers>
<server host="terracotta-0.terracotta" name="terracotta-0" bind="0.0.0.0">
<logs>stdout:</logs>
<tsa-port bind="0.0.0.0">9410</tsa-port>
<tsa-group-port bind="0.0.0.0">9430</tsa-group-port>
</server>
<server host="terracotta-1.terracotta" name="terracotta-1" bind="0.0.0.0">
<logs>/stdout:</logs>
<tsa-port bind="0.0.0.0">9410</tsa-port>
<tsa-group-port bind="0.0.0.0">9430</tsa-group-port>
</server>
<client-reconnect-window>120</client-reconnect-window>
</servers>
</tc-config>
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: caching-client
name: caching-client
spec:
selector:
matchLabels:
app: caching-client
replicas: 1
template:
metadata:
labels:
app: caching-client
spec:
containers:
- image: terracotta/sample-ehcache-client:5.5.1
name: caching-client
env:
- name: TERRACOTTA_SERVER_URL
value: "terracotta-0.terracotta:9410,terracotta-1.terracotta:9410"
---
apiVersion: v1
kind: Service
metadata:
name: terracotta
labels:
app: terracotta
annotations:
# see https://github.com/kubernetes/kubernetes/issues/39363 , to have dns entries available immediately
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
spec:
ports:
- name: terracotta-port
port: 9410
- name: sync-port
port: 9430
clusterIP: None
selector:
app: terracotta
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: terracotta
spec:
selector:
matchLabels:
app: terracotta
serviceName: terracotta
replicas: 2
template:
metadata:
labels:
app: terracotta
spec:
initContainers:
- name: init-terracotta
# be careful with busybox versions : https://github.com/docker-library/busybox/issues/48
image: busybox:1.28
# check service name resolution works fine; if it can't resolve the service, a split brain could occur
command: ['sh', '-c', 'until nslookup terracotta; do echo "waiting for terracotta to resolve"; sleep 2; done;']
containers:
- name: terracotta
image: terracotta/terracotta-server-oss:5.5.1
command: ["bin/start-tc-server.sh"]
args: ["-f", "/config/tc-config.xml", "-n", "$(POD_NAME)"]
imagePullPolicy: Always
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
ports:
- containerPort: 9410
name: terracotta-port
- containerPort: 9430
name: sync-port
volumeMounts:
- name: config-volume
mountPath: /config
volumes:
- name: config-volume
configMap:
name: tc-config
Very verbose
No templatization
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
??????????????
???????????
?????????????
??????????????
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 }}”
QUICK BACK TO BASICS : KUBERNETES ARCHITECTURE
By Khtan66 - CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=53571935
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/
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();
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
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
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
© 2017 Software AG. All rights reserved. For internal use only"16

More Related Content

PDF
Building kubectl plugins with Quarkus | DevNation Tech Talk
PDF
Kubernetes for java developers - Tutorial at Oracle Code One 2018
PDF
jbang: Unleash the power of Java for shell scripting
PDF
Kubernetes 101 and Fun
ODP
devops@cineca
PDF
Kubernetes for the PHP developer
PDF
Ninja, Choose Your Weapon!
PPTX
Kubernetes day 2 Operations
Building kubectl plugins with Quarkus | DevNation Tech Talk
Kubernetes for java developers - Tutorial at Oracle Code One 2018
jbang: Unleash the power of Java for shell scripting
Kubernetes 101 and Fun
devops@cineca
Kubernetes for the PHP developer
Ninja, Choose Your Weapon!
Kubernetes day 2 Operations

What's hot (20)

PDF
Kubelet with no Kubernetes Masters | DevNation Tech Talk
PDF
Kubernetes Architecture - beyond a black box - Part 2
PDF
KubeCon EU 2016: Kubernetes and the Potential for Higher Level Interfaces
PPTX
Introduction to Kubernetes
PDF
Container orchestration from theory to practice
PDF
A DevOps guide to Kubernetes
PDF
2014-10-30 Taverna as an Apache Incubator project
PPTX
Orchestration tool roundup kubernetes vs. docker vs. heat vs. terra form vs...
PDF
Language Server Protocol - Why the Hype?
PPTX
Going Reactive with Java
PDF
Cooking Perl with Chef
PDF
Kubernetes 101
PDF
Kubernetes - introduction
PDF
OpenShift In a Nutshell - Episode 04 - Infrastructure part II
PDF
WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...
PDF
Kayobe_desc
PDF
Scaling Docker with Kubernetes
PDF
System Hardening Using Ansible
PDF
Containerizing a Web Application with Vue.js and Java
Kubelet with no Kubernetes Masters | DevNation Tech Talk
Kubernetes Architecture - beyond a black box - Part 2
KubeCon EU 2016: Kubernetes and the Potential for Higher Level Interfaces
Introduction to Kubernetes
Container orchestration from theory to practice
A DevOps guide to Kubernetes
2014-10-30 Taverna as an Apache Incubator project
Orchestration tool roundup kubernetes vs. docker vs. heat vs. terra form vs...
Language Server Protocol - Why the Hype?
Going Reactive with Java
Cooking Perl with Chef
Kubernetes 101
Kubernetes - introduction
OpenShift In a Nutshell - Episode 04 - Infrastructure part II
WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...
Kayobe_desc
Scaling Docker with Kubernetes
System Hardening Using Ansible
Containerizing a Web Application with Vue.js and Java
Ad

Similar to Kubernetes Java Operator (20)

PDF
Kubernetes for Java Developers
PDF
Get you Java application ready for Kubernetes !
PDF
Microservices in Java
PPTX
What's New in Docker - February 2017
PPTX
Dockerization of Azure Platform
PDF
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
PPTX
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
PPTX
Weave User Group Talk - DockerCon 2017 Recap
PPTX
Dev opsec dockerimage_patch_n_lifecyclemanagement_
PDF
Cloud-native .NET Microservices mit Kubernetes
PDF
Federated Kubernetes: As a Platform for Distributed Scientific Computing
PPTX
Introduction to Kubernetes
PDF
給 RD 的 Kubernetes 初體驗
PPTX
Kubernetes @ meetic
PDF
Docker Application to Scientific Computing
PDF
Extending DevOps to Big Data Applications with Kubernetes
PPTX
Docker and kubernetes
PPTX
Docker San Francisco Meetup April 2015 - The Docker Orchestration Ecosystem o...
PPTX
Devoxx France 2015 - The Docker Orchestration Ecosystem on Azure
PDF
Come costruire una Platform As A Service con Docker, Kubernetes Go e Java
Kubernetes for Java Developers
Get you Java application ready for Kubernetes !
Microservices in Java
What's New in Docker - February 2017
Dockerization of Azure Platform
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Weave User Group Talk - DockerCon 2017 Recap
Dev opsec dockerimage_patch_n_lifecyclemanagement_
Cloud-native .NET Microservices mit Kubernetes
Federated Kubernetes: As a Platform for Distributed Scientific Computing
Introduction to Kubernetes
給 RD 的 Kubernetes 初體驗
Kubernetes @ meetic
Docker Application to Scientific Computing
Extending DevOps to Big Data Applications with Kubernetes
Docker and kubernetes
Docker San Francisco Meetup April 2015 - The Docker Orchestration Ecosystem o...
Devoxx France 2015 - The Docker Orchestration Ecosystem on Azure
Come costruire una Platform As A Service con Docker, Kubernetes Go e Java
Ad

More from Anthony Dahanne (19)

PDF
JDConf 2025 - Paketo Buildpacks : the best way to build Java container images
PPTX
Not a Kubernetes fan? The state of PaaS in 2025
PPTX
No More Dockerfiles! Buildpacks to Help You Ship Your Image!
PDF
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
PPTX
Not a Kubernetes fan? The state of PaaS in 2024
PPTX
No more Dockerfiles? Buildpacks to help you ship your image!
PPTX
CNCF Québec Meetup du 16 Novembre 2023
PDF
Buildpacks: the other way to build container images
PDF
Tu changes d'emploi - retour d'experience d'un développeur
PPTX
Java applications containerized and deployed
PDF
Contribuer à la traduction française de kubernetes
PDF
Caching in applications still matters
PDF
Docker and java
PDF
Terracotta Ehcache : Simpler, faster, distributed
PPTX
Docker and java, at Montréal JUG
PDF
Writing a Jenkins / Hudson plugin
PDF
Confoo2013 make your java-app rest enabled
ODP
Ci for-android-apps
ODP
Asynctasks
JDConf 2025 - Paketo Buildpacks : the best way to build Java container images
Not a Kubernetes fan? The state of PaaS in 2025
No More Dockerfiles! Buildpacks to Help You Ship Your Image!
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Not a Kubernetes fan? The state of PaaS in 2024
No more Dockerfiles? Buildpacks to help you ship your image!
CNCF Québec Meetup du 16 Novembre 2023
Buildpacks: the other way to build container images
Tu changes d'emploi - retour d'experience d'un développeur
Java applications containerized and deployed
Contribuer à la traduction française de kubernetes
Caching in applications still matters
Docker and java
Terracotta Ehcache : Simpler, faster, distributed
Docker and java, at Montréal JUG
Writing a Jenkins / Hudson plugin
Confoo2013 make your java-app rest enabled
Ci for-android-apps
Asynctasks

Recently uploaded (20)

PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Machine Learning_overview_presentation.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Electronic commerce courselecture one. Pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Encapsulation theory and applications.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Machine Learning_overview_presentation.pptx
Big Data Technologies - Introduction.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Chapter 3 Spatial Domain Image Processing.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Review of recent advances in non-invasive hemoglobin estimation
MIND Revenue Release Quarter 2 2025 Press Release
Mobile App Security Testing_ A Comprehensive Guide.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Electronic commerce courselecture one. Pdf
Empathic Computing: Creating Shared Understanding
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.
Spectral efficient network and resource selection model in 5G networks
Encapsulation theory and applications.pdf

Kubernetes Java Operator

  • 1. © 2018 Software AG. All rights reserved. Anthony Dahanne @anthonydahanne blog.dahanne.net December 3rd 2018 A KUBERNETES OPERATOR WRITTEN IN JAVA ?
  • 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 <[email protected]>" 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
  • 6. ORCHESTRATION IN 2016 / 2017 ? DOCKERSWARM ! version: '3' networks: terracotta-net: driver: overlay services: client: image: terracotta/sample-ehcache-client:5.5.1 environment: - TERRACOTTA_SERVER_URL=terracotta-1:9410,terracotta-2:9410 networks: - terracotta-net terracotta-1: hostname: terracotta-1 image: terracotta/terracotta-server-oss:5.5.1 environment: - TC_SERVER1=terracotta-1 - TC_SERVER2=terracotta-2 networks: - terracotta-net
  • 7. THEN CAME KUBERNETES apiVersion: v1 kind: ConfigMap metadata: name: tc-config data: tc-config.xml: | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <tc-config xmlns="http://www.terracotta.org/config"> <plugins> <config> <ohr:offheap-resources xmlns:ohr="http://www.terracotta.org/config/offheap-resource"> <ohr:resource name="offheap-1" unit="MB">512</ohr:resource> <ohr:resource name="offheap-2" unit="MB">128</ohr:resource> </ohr:offheap-resources> </config> </plugins> <servers> <server host="terracotta-0.terracotta" name="terracotta-0" bind="0.0.0.0"> <logs>stdout:</logs> <tsa-port bind="0.0.0.0">9410</tsa-port> <tsa-group-port bind="0.0.0.0">9430</tsa-group-port> </server> <server host="terracotta-1.terracotta" name="terracotta-1" bind="0.0.0.0"> <logs>/stdout:</logs> <tsa-port bind="0.0.0.0">9410</tsa-port> <tsa-group-port bind="0.0.0.0">9430</tsa-group-port> </server> <client-reconnect-window>120</client-reconnect-window> </servers> </tc-config> --- apiVersion: apps/v1 kind: Deployment metadata: labels: app: caching-client name: caching-client spec: selector: matchLabels: app: caching-client replicas: 1 template: metadata: labels: app: caching-client spec: containers: - image: terracotta/sample-ehcache-client:5.5.1 name: caching-client env: - name: TERRACOTTA_SERVER_URL value: "terracotta-0.terracotta:9410,terracotta-1.terracotta:9410" --- apiVersion: v1 kind: Service metadata: name: terracotta labels: app: terracotta annotations: # see https://github.com/kubernetes/kubernetes/issues/39363 , to have dns entries available immediately service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" spec: ports: - name: terracotta-port port: 9410 - name: sync-port port: 9430 clusterIP: None selector: app: terracotta --- apiVersion: apps/v1 kind: StatefulSet metadata: name: terracotta spec: selector: matchLabels: app: terracotta serviceName: terracotta replicas: 2 template: metadata: labels: app: terracotta spec: initContainers: - name: init-terracotta # be careful with busybox versions : https://github.com/docker-library/busybox/issues/48 image: busybox:1.28 # check service name resolution works fine; if it can't resolve the service, a split brain could occur command: ['sh', '-c', 'until nslookup terracotta; do echo "waiting for terracotta to resolve"; sleep 2; done;'] containers: - name: terracotta image: terracotta/terracotta-server-oss:5.5.1 command: ["bin/start-tc-server.sh"] args: ["-f", "/config/tc-config.xml", "-n", "$(POD_NAME)"] imagePullPolicy: Always env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name ports: - containerPort: 9410 name: terracotta-port - containerPort: 9430 name: sync-port volumeMounts: - name: config-volume mountPath: /config volumes: - name: config-volume configMap: name: tc-config Very verbose No templatization
  • 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
  • 16. © 2017 Software AG. All rights reserved. For internal use only"16