SlideShare a Scribd company logo
1 of 44
Download to read offline
KUBERNETES FOR JAVA DEVELOPERS
ROBERT BARR
ABOUT ME
Java developer and engineering manager since Java 1.1.7
Engineering Lead for DevOps and Development Practices Group
Head of Development and Data Grid for Infrastructure Engineering Group
Co-organiser for the Docklands London Java Community
ABOUT ME
Java developer and engineering manager since Java 1.1.7
Engineering Lead for DevOps and Development Practices Group
Head of Development and Data Grid for Infrastructure Engineering Group
Co-organiser for the Docklands London Java Community
AGENDA Quarkus, Micronaut and Spring Boot
Docker recap
Why Kubernetes?
Kubernetes architectureand concepts
Running Kuberneteslocally
Related Kubernetesconcepts
Deployment pipelines
SAMPLE
APPLICATION
@RestController
public class HelloWorldController {
@RequestMapping("/hello")
public String sayHello() {
return "hi mum";
}
}
https://github.com/runesmith2013/k8s4j.git
QUARKUS VS MICRONAUT VS SPRING BOOT
Quarkus is a “supersonic subatomic Java”. It is a Kubernetes-native Java stack designed for OpenJDK HotSpot and GraalVM
and includes the best Java libraries and standards. One of the pros of Quarkus is its speedy start-up time.
Micronaut is a cloud-native JVM-based polyglot full-stack framework for building microservices and serverless applications. It
features low memory consumption, no matter the size of your codebase.
Spring Boot is an open source Java framework that makes it easy to create stand-alone production-grade Spring applications
and microservices with embedded Tomcat, Jetty, or Undertow. Spring Boot apps require little configuration so they can “just
run”.
Project Leyden: New OpenJDK project to address Java start up time
Static application binaries with faster startup and lower memory. Once approved and completed, this would enable developers
to compile Java code (just-in-time) to native applications (ahead-of-time), offering capabilities like GraalVM's native mode.
QUARKUS VS MICRONAUT VS SPRING BOOT
https://jaxenter.com/micronaut-speed-test-170870.html
Source: https://jaxenter.com/micronaut-speed-test-170870.html
Packages applications with their dependencies into a portable, lightweightcontainer
This container can run locally, on premise or on cloud hosted infrastructure such as AWS Elastic Container Service
Docker solves the issue of environmental differences between Prod, UAT and DEV
DOCKER TERMINOLOGY
 Docker Daemon – runs on your host and listens for Docker API requests. Manages
containers and images
 Docker Image – base for running an application
 Docker container - running instance of a Docker image
 Dockerfile – script defining how to construct a Docker image
 Docker hub - online repo for storing Docker images
SAMPLE
DOCKERFILE
FROM maven:3.5-jdk-8 as BUILD
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN mvn package
FROM openjdk:8-jre
EXPOSE 8080 5005
COPY --from=BUILD /usr/src/app/target /opt/target
WORKDIR /opt/target
ENV _JAVA_OPTIONS '-
agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005'
CMD ["java", "-jar", "helloworld.war"]
COMMON DOCKER COMMANDS
docker image build –t tag/tag:version .
Communicates with the docker daemon to construct an image based on the dockerfile.
docker image ls
Shows the images stored in the local repo
docker run –p 8080:8080 –d imagename
instantiate and run a container from an image, exposing ports and running in detached mode
docker push myrepo/myimage:2.0
Push an image to a registry
https://www.docker.com/sites/default/files/d8/2019-09/docker-cheat-sheet.pdf
DOCKER AND MAVEN: SPOTIFY PLUGIN
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>${dockerfile-maven-version}</version> <executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>spotify/foobar</repository>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
* requires docker
* requires a dockerfile
* mvn build creates an image
* mvn deploy pushes to repo
Project is MATURE and not adding new features
DOCKER AND MAVEN: JIB PLUGIN
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>2.5.0</version>
<configuration>
<to>
<image>${image.path}</image>
</to>
</configuration>
</plugin>
* does not require docker
* does not require a Dockerfile
* opinionated default options
* separates app into layers – classes, resources, dependencies
* only builds changed layers
WHY KUBERNETES?
Kubernetes is open source software for deploying, scaling and managing
containerized applications.
As an orchestrator,it handles the work of scheduling containers on a
cluster and manages the workloads to ensure they run as intended.
WHY KUBERNETES?
Portability
Kubernetes offers portability, and faster, simpler deployment times.
Scalability
With Kubernetes ability to run containers on one or more public cloud environments,
in virtual machines, or on bare metal means that it can be deployed almost
anywhere and scale to any extent.
WHY KUBERNETES?
High Availability
Kubernetes addresses high availability at both the application and the infrastructure
level.
OpenSource
Since Kubernetes is open source, you can take advantage of the vast ecosystem of
other open source tools designed specifically to work with Kubernetes without the
lock-in of a closed/proprietary system.
WHY KUBERNETES?
Proven, and Battle Tested
A huge ecosystem of developers and tools with 5,608 GitHub repositories and counting
means that you won’t be forging ahead into new territory without help.
Kubernetes 101 Architecture
Kubernetes can manage rolling updates, adapts to additional workloads by auto
scaling nodes to increase capacity and can self-heal in the case of a pod meltdown.
KUBERNETES CONTROL PLANE
ETCD
Etcd Storage
Is an open-source key-value data store
Stores configuration data of the cluster’s
state.
KUBERNETES CONTROL PLANE
ETCD
API
Server
Kube-API-Server – The API server
manages requests from the worker
nodes, receives REST requests
for modifications, and serves as a front-
end to control cluster.
KUBERNETES CONTROL PLANE
ETCD
API
Server
Scheduler
Kube-scheduler – Schedules the pods
on nodes based on resource
utilization and decides where services
are deployed:
Quality of Service requirements,
hardware, software, policy constraints,
affinity and anti-affinity requirements
KUBERNETES CONTROL PLANE
ETCD
API
Server
Scheduler
Controller
manager
Kube-controller-manager – A set
of distinct controller processes to
regulate the shared state of the cluster
and perform routine tasks.
When there is a change to a service, the
controller recognizes the change and
initiates an update to bring the cluster
up to the desired state.
Includes the replication controller,
endpoints controller and namespace
controller
KUBERNETES CONTROL PLANE
ETCD
API
Server
Scheduler
Controller
manager
Cloud
controller
Cloud controller manager
Embeds cloud specific control logic
KUBERNETES CONTROL PLANE
ETCD
API
Server
Scheduler
Controller
manager
Cloud
controller
Add
Ons
Add Ons
Extends the functionality of Kubernetes.
DNS is a recommended add-on, which
provides name resolution for objects
deployed in Kubernetes
KUBERNETES WORKER
Kubelet
Kubelet
Primary node agent that runs on each
node
Communicates with master and ensures
containers are running and healthy
KUBERNETES WORKER
Kubelet
Kube-proxy
Network proxy running on each node
Provides K8s networking services
Kube-proxy
KUBERNETES FLOW
kubectl Control Plane
Data Plane
kubectl apply –f resource.yaml
KUBERNETES
CONCEPTS
Containers
Typically Docker containers, but Kubernetes also supports a
variety of other container types
Pods
A pod is the basic building block for Kubernetes.
Pods are generally collections of related containers, but a pod
may also only have one container.
A pod shares network/storage and a specification for how to run
the containers.
KUBERNETES
CONCEPTS
Deployments
Describes a desired state of containers and pods
Supports:
- increasing the number of replicas in a set
- rolling out new states
- rolling back to older versions
- scaling up to facilitate more load
- pausing deployments
- clean up obsolete sets
KUBERNETES
CONCEPTS
Service
A Kubernetes Service is an abstraction layer which defines a logical set of
Pods and enables external traffic exposure, load balancing and service
discovery for those Pods.
The set of Pods targeted by a Service is usually determined by a selector.
KUBERNETES
CONCEPTS
Service Types
ClusterIP (default)
Exposes the Service on an internal IP in the cluster. This type makes the Service only reachable from
within the cluster.
NodePort
Exposes the Service on the same port of each selected Node in the cluster using NAT. Makes a Service
accessible from outside the cluster using <NodeIP>:<NodePort>
LoadBalancer
Creates an external load balancer in the current cloud (if supported) and assigns a fixed, external IP to
the Service
KUBERNETES RESOURCE MANIFEST: DEPLOYMENT
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello
spec:
replicas: 1
selector:
matchLabels:
app: hello
template:
metadata:
labels:
app: hello
spec:
containers:
- name: hello
image: runesmith/hello
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
name: "http"
- containerPort: 5005
name: "debug"
KUBERNETES RESOURCE MANIFEST: SERVICE
apiVersion: v1
kind: Service
metadata:
name: hello
spec:
selector:
app: hello
ports:
- name: http
protocol: TCP
port: 8080
targetPort: 8080
type: LoadBalancer
KUBERNETES JAVA CLIENT
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<version>10.0.0</version>
</dependency>
ApiClientclient = Config.defaultClient();
Configuration.setDefaultApiClient(client);
CoreV1Api api = new CoreV1Api();
V1Pod pod = new V1PodBuilder()
.withNewMetadata()
.withName("apod")
.endMetadata()
.withNewSpec()
.addNewContainer()
.withName("www")
.withImage("nginx")
.endContainer()
.endSpec()
.build();
api.createNamespacedPod("default", pod, null, null, null);
https://github.com/kubernetes-client/java/
KUBECTL COMMON COMMANDS
kubectl config get-contexts # display list of contexts
kubectl apply -f ./my-manifest.yaml # create resource(s)
kubectl get services, pods, deployments # report on status of services, pods, deployments
kubectl logs <pod> # display logs from given pod
kubectl rollout history deployment/frontend # Check the history of deployments including the revision
kubectl rollout undo deployment/frontend # Rollback to the previous deployment
kubectl rollout restart deployment/frontend # Rolling restart of the "frontend" deployment
kubectl autoscale deployment foo --min=2 --max=10
https://kubernetes.io/docs/reference/kubectl/cheatsheet/
WEB UI
Dashboard is a web-based Kubernetes
user interface.
Deploy containerized applications to a
Kubernetes cluster, troubleshoot your
containerized application, and
manage the cluster resources.
Get an overview of applications
running on your cluster
Scale a Deployment, initiate a rolling
update, restart a pod or deploy new
applications using a deploy wizard.
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
LOCAL K8S: MINIKUBE
1. InstallMinikube
brew install minikube
2. Start your cluster
minikube start
3. Interact with cluster
minikube kubectl -- get po –A // download kubectl
minikube dashboard // bundled kubernetes dashboard
kubectl get po –A // use kubectl to access cluster
LOCAL K8S: DOCKER DESKTOP
1. Click Docker Desktop icon
2. Click preferences
3. Enable Kubernetes
KATACODA: INTERACTIVE BROWSER-BASED
SCENARIOS
Launch a single node cluster
Launch a multi-node cluster using Kubeadm
Deploy Containers Using Kubectl
Deploy Containers Using YAML
https://www.katacoda.com/courses/kubernetes/playground
HELM: THE PACKAGE MANAGER FOR KUBERNETES
Packagemanager for Kubernetes
Allows you to deploy your app as a single package rather
than dealing with multiple manifest files
Allows us to manage multiple releases with different
configurations
Collection of YAML template files, so are text-based and
versionable
Analagous to apt, yum or homebrew for kubernetes
DEPLOYMENT PIPELINES: SKAFFOLD
SKAFFOLD
Skaffold is a command line tool that facilitates continuous developmentfor
Kubernetes-native applications. This enables you to focus on iterating on your
application locally while Skaffold continuously deploys to your local or remote
Kubernetes cluster.
ISTIO SERVICE MESH
Provides the fundamentals needed to successfully run a distributed
microservices architecture
Security
Authentication, authorisation and encryption of communication between
microservices
Observability
Provides tracing, monitoring and logging and performance analytics
Traffic management
Control traffic and API calls between services. Enables A/B testing, traffic
shaping and canary testing
RESOURCES
https://github.com/runesmith2013/k8s4j.git
Spring boot sample app using Docker, Kubernetes, Helm and Skaffold
https://www.katacoda.com/courses/kubernetes/playground
Browser-based kubernetes playground
https://github.com/kubernetes-client/java/
Kubernetes Java client library
https://www.docker.com/sites/default/files/d8/2019-09/docker-cheat-sheet.pdf
Docker commands cheat sheet
https://cloud.google.com/istio
Google cloud Istio project
https://www.redhat.com/en/topics/microservices/what-is-istio
Redhat resources on Istio
https://helm.sh/
Helm documentation
https://kubernetes.io/docs/reference/kubectl/cheatsheet/
Kubeclt commands cheat sheet
https://skaffold.dev/docs/
Skaffold
https://www.infoq.com/news/2020/05/java-leyden/
Project Leyden
RESOURCES
https://github.com/kelseyhightower/kubernetes-the-hard-way
in depth guide to setting up and running a k8s cluster
https://www.linkedin.com/learning/kubernetes-for-java-developers
Arun Gupta's course on Kubernetes for Java Developers
https://www.magalix.com/blog/create-a-ci/cd-pipeline-with-kubernetes-and-jenkins
Go-based tutorial on setting up a pipeline with kubernetes and jenkins

More Related Content

What's hot

Kubernetes: An Introduction to the Open Source Container Orchestration Platform
Kubernetes: An Introduction to the Open Source Container Orchestration PlatformKubernetes: An Introduction to the Open Source Container Orchestration Platform
Kubernetes: An Introduction to the Open Source Container Orchestration Platform
Michael O'Sullivan
 

What's hot (20)

Learn kubernetes in 90 minutes
Learn kubernetes in 90 minutesLearn kubernetes in 90 minutes
Learn kubernetes in 90 minutes
 
Integration kubernetes with docker private registry
Integration kubernetes with docker private registryIntegration kubernetes with docker private registry
Integration kubernetes with docker private registry
 
Secure container: Kata container and gVisor
Secure container: Kata container and gVisorSecure container: Kata container and gVisor
Secure container: Kata container and gVisor
 
SCALE 2011 Deploying OpenStack with Chef
SCALE 2011 Deploying OpenStack with ChefSCALE 2011 Deploying OpenStack with Chef
SCALE 2011 Deploying OpenStack with Chef
 
GKE vs OpenStack Magnum
GKE vs OpenStack MagnumGKE vs OpenStack Magnum
GKE vs OpenStack Magnum
 
Introduction and Deep Dive Into Containerd
Introduction and Deep Dive Into ContainerdIntroduction and Deep Dive Into Containerd
Introduction and Deep Dive Into Containerd
 
How to make cloud native platform by kubernetes
How to make cloud native platform by kubernetesHow to make cloud native platform by kubernetes
How to make cloud native platform by kubernetes
 
開放運算&GPU技術研究班
開放運算&GPU技術研究班開放運算&GPU技術研究班
開放運算&GPU技術研究班
 
[KubeConEU] Building images efficiently and securely on Kubernetes with BuildKit
[KubeConEU] Building images efficiently and securely on Kubernetes with BuildKit[KubeConEU] Building images efficiently and securely on Kubernetes with BuildKit
[KubeConEU] Building images efficiently and securely on Kubernetes with BuildKit
 
Kubernetes architecture
Kubernetes architectureKubernetes architecture
Kubernetes architecture
 
Why Go Lang?
Why Go Lang?Why Go Lang?
Why Go Lang?
 
Kubernetes
KubernetesKubernetes
Kubernetes
 
Kubernetes Basics
Kubernetes BasicsKubernetes Basics
Kubernetes Basics
 
kubernetes for beginners
kubernetes for beginnerskubernetes for beginners
kubernetes for beginners
 
Understanding Kubernetes
Understanding KubernetesUnderstanding Kubernetes
Understanding Kubernetes
 
DevOps in AWS with Kubernetes
DevOps in AWS with KubernetesDevOps in AWS with Kubernetes
DevOps in AWS with Kubernetes
 
Kubernetes 101
Kubernetes 101Kubernetes 101
Kubernetes 101
 
KubeCon EU 2016: A Practical Guide to Container Scheduling
KubeCon EU 2016: A Practical Guide to Container SchedulingKubeCon EU 2016: A Practical Guide to Container Scheduling
KubeCon EU 2016: A Practical Guide to Container Scheduling
 
Kubernetes: An Introduction to the Open Source Container Orchestration Platform
Kubernetes: An Introduction to the Open Source Container Orchestration PlatformKubernetes: An Introduction to the Open Source Container Orchestration Platform
Kubernetes: An Introduction to the Open Source Container Orchestration Platform
 
Making cloud native platform by kubernetes
Making cloud native platform by kubernetesMaking cloud native platform by kubernetes
Making cloud native platform by kubernetes
 

Similar to Kubernetes for Java developers

Similar to Kubernetes for Java developers (20)

Containerize! Between Docker and Jube.
Containerize! Between Docker and Jube.Containerize! Between Docker and Jube.
Containerize! Between Docker and Jube.
 
Getting started with google kubernetes engine
Getting started with google kubernetes engineGetting started with google kubernetes engine
Getting started with google kubernetes engine
 
DevJam 2019 - Introduction to Kubernetes
DevJam 2019 - Introduction to KubernetesDevJam 2019 - Introduction to Kubernetes
DevJam 2019 - Introduction to Kubernetes
 
Zero downtime-java-deployments-with-docker-and-kubernetes
Zero downtime-java-deployments-with-docker-and-kubernetesZero downtime-java-deployments-with-docker-and-kubernetes
Zero downtime-java-deployments-with-docker-and-kubernetes
 
Kubernetes Basics
Kubernetes BasicsKubernetes Basics
Kubernetes Basics
 
Containers and Kubernetes -Notes Leo
Containers and Kubernetes -Notes LeoContainers and Kubernetes -Notes Leo
Containers and Kubernetes -Notes Leo
 
Container Orchestration using kubernetes
Container Orchestration using kubernetesContainer Orchestration using kubernetes
Container Orchestration using kubernetes
 
How to Integrate Kubernetes in OpenStack
 How to Integrate Kubernetes in OpenStack  How to Integrate Kubernetes in OpenStack
How to Integrate Kubernetes in OpenStack
 
Mesos and Kubernetes ecosystem overview
Mesos and Kubernetes ecosystem overviewMesos and Kubernetes ecosystem overview
Mesos and Kubernetes ecosystem overview
 
Containers kuberenetes
Containers kuberenetesContainers kuberenetes
Containers kuberenetes
 
Containers kuberenetes
Containers kuberenetesContainers kuberenetes
Containers kuberenetes
 
Kubernetes
KubernetesKubernetes
Kubernetes
 
Kubernetes From Scratch .pdf
Kubernetes From Scratch .pdfKubernetes From Scratch .pdf
Kubernetes From Scratch .pdf
 
Containers kuberenetes
Containers kuberenetesContainers kuberenetes
Containers kuberenetes
 
Newesis - Introduction to Containers
Newesis -  Introduction to ContainersNewesis -  Introduction to Containers
Newesis - Introduction to Containers
 
Kubernetes extensibility
Kubernetes extensibilityKubernetes extensibility
Kubernetes extensibility
 
04_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
04_Azure Kubernetes Service: Basic Practices for Developers_GAB201904_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
04_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
 
SKILup Days Container Orchestration - Kubernetes Operators for Databases
SKILup Days Container Orchestration - Kubernetes Operators for DatabasesSKILup Days Container Orchestration - Kubernetes Operators for Databases
SKILup Days Container Orchestration - Kubernetes Operators for Databases
 
Salvatore Incandela, Fabio Marinelli - Using Spinnaker to Create a Developmen...
Salvatore Incandela, Fabio Marinelli - Using Spinnaker to Create a Developmen...Salvatore Incandela, Fabio Marinelli - Using Spinnaker to Create a Developmen...
Salvatore Incandela, Fabio Marinelli - Using Spinnaker to Create a Developmen...
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetes
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 

Kubernetes for Java developers

  • 1. KUBERNETES FOR JAVA DEVELOPERS ROBERT BARR
  • 2. ABOUT ME Java developer and engineering manager since Java 1.1.7 Engineering Lead for DevOps and Development Practices Group Head of Development and Data Grid for Infrastructure Engineering Group Co-organiser for the Docklands London Java Community
  • 3. ABOUT ME Java developer and engineering manager since Java 1.1.7 Engineering Lead for DevOps and Development Practices Group Head of Development and Data Grid for Infrastructure Engineering Group Co-organiser for the Docklands London Java Community
  • 4. AGENDA Quarkus, Micronaut and Spring Boot Docker recap Why Kubernetes? Kubernetes architectureand concepts Running Kuberneteslocally Related Kubernetesconcepts Deployment pipelines
  • 5. SAMPLE APPLICATION @RestController public class HelloWorldController { @RequestMapping("/hello") public String sayHello() { return "hi mum"; } } https://github.com/runesmith2013/k8s4j.git
  • 6. QUARKUS VS MICRONAUT VS SPRING BOOT Quarkus is a “supersonic subatomic Java”. It is a Kubernetes-native Java stack designed for OpenJDK HotSpot and GraalVM and includes the best Java libraries and standards. One of the pros of Quarkus is its speedy start-up time. Micronaut is a cloud-native JVM-based polyglot full-stack framework for building microservices and serverless applications. It features low memory consumption, no matter the size of your codebase. Spring Boot is an open source Java framework that makes it easy to create stand-alone production-grade Spring applications and microservices with embedded Tomcat, Jetty, or Undertow. Spring Boot apps require little configuration so they can “just run”. Project Leyden: New OpenJDK project to address Java start up time Static application binaries with faster startup and lower memory. Once approved and completed, this would enable developers to compile Java code (just-in-time) to native applications (ahead-of-time), offering capabilities like GraalVM's native mode.
  • 7. QUARKUS VS MICRONAUT VS SPRING BOOT https://jaxenter.com/micronaut-speed-test-170870.html Source: https://jaxenter.com/micronaut-speed-test-170870.html
  • 8. Packages applications with their dependencies into a portable, lightweightcontainer This container can run locally, on premise or on cloud hosted infrastructure such as AWS Elastic Container Service Docker solves the issue of environmental differences between Prod, UAT and DEV
  • 9. DOCKER TERMINOLOGY  Docker Daemon – runs on your host and listens for Docker API requests. Manages containers and images  Docker Image – base for running an application  Docker container - running instance of a Docker image  Dockerfile – script defining how to construct a Docker image  Docker hub - online repo for storing Docker images
  • 10. SAMPLE DOCKERFILE FROM maven:3.5-jdk-8 as BUILD COPY . /usr/src/app WORKDIR /usr/src/app RUN mvn package FROM openjdk:8-jre EXPOSE 8080 5005 COPY --from=BUILD /usr/src/app/target /opt/target WORKDIR /opt/target ENV _JAVA_OPTIONS '- agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005' CMD ["java", "-jar", "helloworld.war"]
  • 11. COMMON DOCKER COMMANDS docker image build –t tag/tag:version . Communicates with the docker daemon to construct an image based on the dockerfile. docker image ls Shows the images stored in the local repo docker run –p 8080:8080 –d imagename instantiate and run a container from an image, exposing ports and running in detached mode docker push myrepo/myimage:2.0 Push an image to a registry https://www.docker.com/sites/default/files/d8/2019-09/docker-cheat-sheet.pdf
  • 12. DOCKER AND MAVEN: SPOTIFY PLUGIN <plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>${dockerfile-maven-version}</version> <executions> <execution> <id>default</id> <goals> <goal>build</goal> <goal>push</goal> </goals> </execution> </executions> <configuration> <repository>spotify/foobar</repository> <tag>${project.version}</tag> <buildArgs> <JAR_FILE>${project.build.finalName}.jar</JAR_FILE> </buildArgs> </configuration> * requires docker * requires a dockerfile * mvn build creates an image * mvn deploy pushes to repo Project is MATURE and not adding new features
  • 13. DOCKER AND MAVEN: JIB PLUGIN <plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>jib-maven-plugin</artifactId> <version>2.5.0</version> <configuration> <to> <image>${image.path}</image> </to> </configuration> </plugin> * does not require docker * does not require a Dockerfile * opinionated default options * separates app into layers – classes, resources, dependencies * only builds changed layers
  • 14. WHY KUBERNETES? Kubernetes is open source software for deploying, scaling and managing containerized applications. As an orchestrator,it handles the work of scheduling containers on a cluster and manages the workloads to ensure they run as intended.
  • 15. WHY KUBERNETES? Portability Kubernetes offers portability, and faster, simpler deployment times. Scalability With Kubernetes ability to run containers on one or more public cloud environments, in virtual machines, or on bare metal means that it can be deployed almost anywhere and scale to any extent.
  • 16. WHY KUBERNETES? High Availability Kubernetes addresses high availability at both the application and the infrastructure level. OpenSource Since Kubernetes is open source, you can take advantage of the vast ecosystem of other open source tools designed specifically to work with Kubernetes without the lock-in of a closed/proprietary system.
  • 17. WHY KUBERNETES? Proven, and Battle Tested A huge ecosystem of developers and tools with 5,608 GitHub repositories and counting means that you won’t be forging ahead into new territory without help. Kubernetes 101 Architecture Kubernetes can manage rolling updates, adapts to additional workloads by auto scaling nodes to increase capacity and can self-heal in the case of a pod meltdown.
  • 18. KUBERNETES CONTROL PLANE ETCD Etcd Storage Is an open-source key-value data store Stores configuration data of the cluster’s state.
  • 19. KUBERNETES CONTROL PLANE ETCD API Server Kube-API-Server – The API server manages requests from the worker nodes, receives REST requests for modifications, and serves as a front- end to control cluster.
  • 20. KUBERNETES CONTROL PLANE ETCD API Server Scheduler Kube-scheduler – Schedules the pods on nodes based on resource utilization and decides where services are deployed: Quality of Service requirements, hardware, software, policy constraints, affinity and anti-affinity requirements
  • 21. KUBERNETES CONTROL PLANE ETCD API Server Scheduler Controller manager Kube-controller-manager – A set of distinct controller processes to regulate the shared state of the cluster and perform routine tasks. When there is a change to a service, the controller recognizes the change and initiates an update to bring the cluster up to the desired state. Includes the replication controller, endpoints controller and namespace controller
  • 23. KUBERNETES CONTROL PLANE ETCD API Server Scheduler Controller manager Cloud controller Add Ons Add Ons Extends the functionality of Kubernetes. DNS is a recommended add-on, which provides name resolution for objects deployed in Kubernetes
  • 24. KUBERNETES WORKER Kubelet Kubelet Primary node agent that runs on each node Communicates with master and ensures containers are running and healthy
  • 25. KUBERNETES WORKER Kubelet Kube-proxy Network proxy running on each node Provides K8s networking services Kube-proxy
  • 26. KUBERNETES FLOW kubectl Control Plane Data Plane kubectl apply –f resource.yaml
  • 27. KUBERNETES CONCEPTS Containers Typically Docker containers, but Kubernetes also supports a variety of other container types Pods A pod is the basic building block for Kubernetes. Pods are generally collections of related containers, but a pod may also only have one container. A pod shares network/storage and a specification for how to run the containers.
  • 28. KUBERNETES CONCEPTS Deployments Describes a desired state of containers and pods Supports: - increasing the number of replicas in a set - rolling out new states - rolling back to older versions - scaling up to facilitate more load - pausing deployments - clean up obsolete sets
  • 29. KUBERNETES CONCEPTS Service A Kubernetes Service is an abstraction layer which defines a logical set of Pods and enables external traffic exposure, load balancing and service discovery for those Pods. The set of Pods targeted by a Service is usually determined by a selector.
  • 30. KUBERNETES CONCEPTS Service Types ClusterIP (default) Exposes the Service on an internal IP in the cluster. This type makes the Service only reachable from within the cluster. NodePort Exposes the Service on the same port of each selected Node in the cluster using NAT. Makes a Service accessible from outside the cluster using <NodeIP>:<NodePort> LoadBalancer Creates an external load balancer in the current cloud (if supported) and assigns a fixed, external IP to the Service
  • 31. KUBERNETES RESOURCE MANIFEST: DEPLOYMENT apiVersion: apps/v1 kind: Deployment metadata: name: hello spec: replicas: 1 selector: matchLabels: app: hello template: metadata: labels: app: hello spec: containers: - name: hello image: runesmith/hello imagePullPolicy: IfNotPresent ports: - containerPort: 8080 name: "http" - containerPort: 5005 name: "debug"
  • 32. KUBERNETES RESOURCE MANIFEST: SERVICE apiVersion: v1 kind: Service metadata: name: hello spec: selector: app: hello ports: - name: http protocol: TCP port: 8080 targetPort: 8080 type: LoadBalancer
  • 33. KUBERNETES JAVA CLIENT <dependency> <groupId>io.kubernetes</groupId> <artifactId>client-java</artifactId> <version>10.0.0</version> </dependency> ApiClientclient = Config.defaultClient(); Configuration.setDefaultApiClient(client); CoreV1Api api = new CoreV1Api(); V1Pod pod = new V1PodBuilder() .withNewMetadata() .withName("apod") .endMetadata() .withNewSpec() .addNewContainer() .withName("www") .withImage("nginx") .endContainer() .endSpec() .build(); api.createNamespacedPod("default", pod, null, null, null); https://github.com/kubernetes-client/java/
  • 34. KUBECTL COMMON COMMANDS kubectl config get-contexts # display list of contexts kubectl apply -f ./my-manifest.yaml # create resource(s) kubectl get services, pods, deployments # report on status of services, pods, deployments kubectl logs <pod> # display logs from given pod kubectl rollout history deployment/frontend # Check the history of deployments including the revision kubectl rollout undo deployment/frontend # Rollback to the previous deployment kubectl rollout restart deployment/frontend # Rolling restart of the "frontend" deployment kubectl autoscale deployment foo --min=2 --max=10 https://kubernetes.io/docs/reference/kubectl/cheatsheet/
  • 35. WEB UI Dashboard is a web-based Kubernetes user interface. Deploy containerized applications to a Kubernetes cluster, troubleshoot your containerized application, and manage the cluster resources. Get an overview of applications running on your cluster Scale a Deployment, initiate a rolling update, restart a pod or deploy new applications using a deploy wizard. kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
  • 36. LOCAL K8S: MINIKUBE 1. InstallMinikube brew install minikube 2. Start your cluster minikube start 3. Interact with cluster minikube kubectl -- get po –A // download kubectl minikube dashboard // bundled kubernetes dashboard kubectl get po –A // use kubectl to access cluster
  • 37. LOCAL K8S: DOCKER DESKTOP 1. Click Docker Desktop icon 2. Click preferences 3. Enable Kubernetes
  • 38. KATACODA: INTERACTIVE BROWSER-BASED SCENARIOS Launch a single node cluster Launch a multi-node cluster using Kubeadm Deploy Containers Using Kubectl Deploy Containers Using YAML https://www.katacoda.com/courses/kubernetes/playground
  • 39. HELM: THE PACKAGE MANAGER FOR KUBERNETES Packagemanager for Kubernetes Allows you to deploy your app as a single package rather than dealing with multiple manifest files Allows us to manage multiple releases with different configurations Collection of YAML template files, so are text-based and versionable Analagous to apt, yum or homebrew for kubernetes
  • 40. DEPLOYMENT PIPELINES: SKAFFOLD SKAFFOLD Skaffold is a command line tool that facilitates continuous developmentfor Kubernetes-native applications. This enables you to focus on iterating on your application locally while Skaffold continuously deploys to your local or remote Kubernetes cluster.
  • 41.
  • 42. ISTIO SERVICE MESH Provides the fundamentals needed to successfully run a distributed microservices architecture Security Authentication, authorisation and encryption of communication between microservices Observability Provides tracing, monitoring and logging and performance analytics Traffic management Control traffic and API calls between services. Enables A/B testing, traffic shaping and canary testing
  • 43. RESOURCES https://github.com/runesmith2013/k8s4j.git Spring boot sample app using Docker, Kubernetes, Helm and Skaffold https://www.katacoda.com/courses/kubernetes/playground Browser-based kubernetes playground https://github.com/kubernetes-client/java/ Kubernetes Java client library https://www.docker.com/sites/default/files/d8/2019-09/docker-cheat-sheet.pdf Docker commands cheat sheet https://cloud.google.com/istio Google cloud Istio project https://www.redhat.com/en/topics/microservices/what-is-istio Redhat resources on Istio https://helm.sh/ Helm documentation https://kubernetes.io/docs/reference/kubectl/cheatsheet/ Kubeclt commands cheat sheet https://skaffold.dev/docs/ Skaffold https://www.infoq.com/news/2020/05/java-leyden/ Project Leyden
  • 44. RESOURCES https://github.com/kelseyhightower/kubernetes-the-hard-way in depth guide to setting up and running a k8s cluster https://www.linkedin.com/learning/kubernetes-for-java-developers Arun Gupta's course on Kubernetes for Java Developers https://www.magalix.com/blog/create-a-ci/cd-pipeline-with-kubernetes-and-jenkins Go-based tutorial on setting up a pipeline with kubernetes and jenkins