SlideShare a Scribd company logo
1 of 16
Download to read offline
© 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

What's hot

WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...
WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...
WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, an...
Brian Grant
 

What's hot (20)

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

Similar to Kubernetes Java Operator

Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
QAware GmbH
 
Kubernetes @ meetic
Kubernetes @ meeticKubernetes @ meetic
Kubernetes @ meetic
Sébastien Le Gall
 

Similar to Kubernetes Java Operator (20)

Kubernetes for Java Developers
Kubernetes for Java DevelopersKubernetes for Java Developers
Kubernetes for Java Developers
 
Get you Java application ready for Kubernetes !
Get you Java application ready for Kubernetes !Get you Java application ready for Kubernetes !
Get you Java application ready for Kubernetes !
 
Microservices in Java
Microservices in JavaMicroservices in Java
Microservices in Java
 
What's New in Docker - February 2017
What's New in Docker - February 2017What's New in Docker - February 2017
What's New in Docker - February 2017
 
Dockerization of Azure Platform
Dockerization of Azure PlatformDockerization of Azure Platform
Dockerization of Azure Platform
 
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
 
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
 
Weave User Group Talk - DockerCon 2017 Recap
Weave User Group Talk - DockerCon 2017 RecapWeave User Group Talk - DockerCon 2017 Recap
Weave User Group Talk - DockerCon 2017 Recap
 
Dev opsec dockerimage_patch_n_lifecyclemanagement_
Dev opsec dockerimage_patch_n_lifecyclemanagement_Dev opsec dockerimage_patch_n_lifecyclemanagement_
Dev opsec dockerimage_patch_n_lifecyclemanagement_
 
Cloud-native .NET Microservices mit Kubernetes
Cloud-native .NET Microservices mit KubernetesCloud-native .NET Microservices mit Kubernetes
Cloud-native .NET Microservices mit Kubernetes
 
Federated Kubernetes: As a Platform for Distributed Scientific Computing
Federated Kubernetes: As a Platform for Distributed Scientific ComputingFederated Kubernetes: As a Platform for Distributed Scientific Computing
Federated Kubernetes: As a Platform for Distributed Scientific Computing
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetes
 
給 RD 的 Kubernetes 初體驗
給 RD 的 Kubernetes 初體驗給 RD 的 Kubernetes 初體驗
給 RD 的 Kubernetes 初體驗
 
Kubernetes @ meetic
Kubernetes @ meeticKubernetes @ meetic
Kubernetes @ meetic
 
Docker Application to Scientific Computing
Docker Application to Scientific ComputingDocker Application to Scientific Computing
Docker Application to Scientific Computing
 
Extending DevOps to Big Data Applications with Kubernetes
Extending DevOps to Big Data Applications with KubernetesExtending DevOps to Big Data Applications with Kubernetes
Extending DevOps to Big Data Applications with Kubernetes
 
Docker and kubernetes
Docker and kubernetesDocker and kubernetes
Docker and kubernetes
 
Docker San Francisco Meetup April 2015 - The Docker Orchestration Ecosystem o...
Docker San Francisco Meetup April 2015 - The Docker Orchestration Ecosystem o...Docker San Francisco Meetup April 2015 - The Docker Orchestration Ecosystem o...
Docker San Francisco Meetup April 2015 - The Docker Orchestration Ecosystem o...
 
Devoxx France 2015 - The Docker Orchestration Ecosystem on Azure
Devoxx France 2015 - The Docker Orchestration Ecosystem on AzureDevoxx France 2015 - The Docker Orchestration Ecosystem on Azure
Devoxx France 2015 - The Docker Orchestration Ecosystem on Azure
 
Dessi docker kubernetes paas cloud
Dessi docker kubernetes paas cloudDessi docker kubernetes paas cloud
Dessi docker kubernetes paas cloud
 

More from Anthony Dahanne

Confoo2013 make your java-app rest enabled
Confoo2013 make your java-app rest enabledConfoo2013 make your java-app rest enabled
Confoo2013 make your java-app rest enabled
Anthony Dahanne
 

More from Anthony Dahanne (15)

Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024
 
No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!
 
CNCF Québec Meetup du 16 Novembre 2023
CNCF Québec Meetup du 16 Novembre 2023CNCF Québec Meetup du 16 Novembre 2023
CNCF Québec Meetup du 16 Novembre 2023
 
Buildpacks: the other way to build container images
Buildpacks: the other way to build container imagesBuildpacks: the other way to build container images
Buildpacks: the other way to build container images
 
Tu changes d'emploi - retour d'experience d'un développeur
Tu changes d'emploi - retour d'experience d'un développeurTu changes d'emploi - retour d'experience d'un développeur
Tu changes d'emploi - retour d'experience d'un développeur
 
Java applications containerized and deployed
Java applications containerized and deployedJava applications containerized and deployed
Java applications containerized and deployed
 
Contribuer à la traduction française de kubernetes
Contribuer à la traduction française de kubernetesContribuer à la traduction française de kubernetes
Contribuer à la traduction française de kubernetes
 
Caching in applications still matters
Caching in applications still mattersCaching in applications still matters
Caching in applications still matters
 
Docker and java
Docker and javaDocker and java
Docker and java
 
Terracotta Ehcache : Simpler, faster, distributed
Terracotta Ehcache : Simpler, faster, distributedTerracotta Ehcache : Simpler, faster, distributed
Terracotta Ehcache : Simpler, faster, distributed
 
Docker and java, at Montréal JUG
Docker and java, at Montréal JUGDocker and java, at Montréal JUG
Docker and java, at Montréal JUG
 
Writing a Jenkins / Hudson plugin
Writing a Jenkins / Hudson pluginWriting a Jenkins / Hudson plugin
Writing a Jenkins / Hudson plugin
 
Confoo2013 make your java-app rest enabled
Confoo2013 make your java-app rest enabledConfoo2013 make your java-app rest enabled
Confoo2013 make your java-app rest enabled
 
Ci for-android-apps
Ci for-android-appsCi for-android-apps
Ci for-android-apps
 
Asynctasks
AsynctasksAsynctasks
Asynctasks
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

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 <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
  • 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