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