O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Docker and Kubernetes for Java Developers

Book Description

Leverage the lethal combination of Docker and Kubernetes to automate deployment and management of Java applications

About This Book

  • Master using Docker and Kubernetes to build, deploy and manage Java applications in a jiff
  • Learn how to create your own Docker image and customize your own cluster using Kubernetes
  • Empower the journey from development to production using this practical guide.

Who This Book Is For

The book is aimed at Java developers who are eager to build, deploy, and manage applications very quickly using container technology. They need have no knowledge of Docker and Kubernetes.

What You Will Learn

  • Package Java applications into Docker images
  • Understand the running of containers locally
  • Explore development and deployment options with Docker
  • Integrate Docker into Maven builds
  • Manage and monitor Java applications running on Kubernetes clusters
  • Create Continuous Delivery pipelines for Java applications deployed to Kubernetes

In Detail

Imagine creating and testing Java EE applications on Apache Tomcat Server or Wildfly Application server in minutes along with deploying and managing Java applications swiftly. Sounds too good to be true? But you have a reason to cheer as such scenarios are only possible by leveraging Docker and Kubernetes.

This book will start by introducing Docker and delve deep into its networking and persistent storage concepts. You will then proceed to learn how to refactor monolith application into separate services by building an application and then packaging it into Docker containers. Next, you will create an image containing Java Enterprise Application and later run it using Docker. Moving on, the book will focus on Kubernetes and its features and you will learn to deploy a Java application to Kubernetes using Maven and monitor a Java application in production. By the end of the book, you will get hands-on with some more advanced topics to further extend your knowledge about Docker and Kubernetes.

Style and approach

An easy-to-follow, practical guide that will help Java developers develop, deploy, and manage Java applications efficiently.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Downloading the color images of this book
      3. Errata
      4. Piracy
      5. Questions
  2. Introduction to Docker
    1. The idea behind Docker
    2. Virtualization and containerization compared
      1. Benefits from using Docker
    3. Docker concepts - images and containers
      1. Images
      2. Layers
      3. Containers
      4. Docker registry, repository, and index
    4. Additional tools
    5. Installing Docker
      1. Installing on macOS
      2. Installing on Linux
      3. Installing on Windows
    6. Summary
  3. Networking and Persistent Storage
    1. Networking
      1. Docker network types
        1. Bridge
        2. Host
        3. None
    2. Networking commands
    3. Creating and inspecting a network
    4. Connecting a container to the network
    5. Exposing ports and mapping ports
    6. Persistent storage
    7. Volume-related commands
    8. Creating a volume
    9. Removing a volume
    10. Volume drivers
    11. Summary
  4. Working with Microservices
    1. An introduction to microservices
    2. Monolithic versus microservices
      1. The monolithic architecture
      2. The microservices architecture
    3. Maintaining data consistency
    4. The Docker role
    5. Kubernetes' role
    6. When to use the microservice architecture
    7. Summary
  5. Creating Java Microservices
    1. Introduction to REST
      1. HTTP methods
    2. REST in Java
      1. Java EE7 - JAX-RS with Jersey
        1. JAX-RS annotations
      2. Spring Boot
    3. Coding the Spring Boot microservice
      1. Maven build file
        1. Application entry point
        2. Domain model and a repository
        3. REST controller
        4. Documenting the API
    4. Running the application
    5. Making calls
      1. Spring RestTemplate
      2. HTTPie
      3. Postman
      4. Paw for Mac
    6. Spring Initializr
    7. Summary
  6. Creating Images with Java Applications
    1. Dockerfile
    2. Dockerfile instructions
      1. FROM
      2. MAINTAINER
      3. WORKDIR
      4. ADD
      5. COPY
      6. RUN
      7. CMD
      8. The ENTRYPOINT
      9. EXPOSE
      10. VOLUME
      11. LABEL
      12. ENV
      13. USER
      14. ARG
      15. ONBUILD
      16. STOPSIGNAL
      17. HEALTHCHECK
      18. Creating an image using Maven
      19. Building the image
      20. Creating and removing volumes
    3. Summary
  7. Running Containers with Java Applications
    1. Starting and stopping containers
      1. Starting
      2. Stopping
      3. Listing the running containers
      4. Removing the containers
    2. Container running modes
      1. Foreground
      2. Detached
      3. Attaching to running containers
    3. Monitoring containers
      1. Viewing logs
      2. Inspecting a container
      3. Statistics
      4. Container events
    4. Restart policies
      1. no
      2. always
      3. on-failure
      4. unless-stopped
      5. Updating a restart policy on a running container
    5. Runtime constraints on resources
      1. Memory
      2. Processors
      3. Updating constraints on a running container
    6. Running with Maven
      1. Plugin configuration
      2. Starting and stopping containers
    7. Summary
  8. Introduction to Kubernetes
    1. Why do we need Kubernetes?
    2. Basic Kubernetes concepts
      1. Pods
      2. ReplicaSets
      3. Deployment
      4. Services
      5. kube-dns
      6. Namespace
      7. Nodes
        1. Kubelet
        2. Proxy
        3. Docker
      8. The Master node
        1. etcd
        2. The API server
        3. The scheduler
      9. Available tools
        1. kubectl
        2. Dashboard
        3. Minikube
    3. Summary
  9. Using Kubernetes with Java
    1. Installing Minikube
      1. Installing on Mac
      2. Installing on Windows
      3. Installing on Linux
      4. Starting up the local Kubernetes cluster
    2. Installing kubectl
      1. Installing on Mac
      2. Installing on Windows
      3. Installing on Linux
    3. Deploying on the Kubernetes cluster
      1. Creating a service
      2. Creating a deployment
      3. Interacting with containers and viewing logs
      4. Scaling manually
      5. Autoscaling
      6. Viewing cluster events
      7. Using the Kubernetes dashboard
    4. Minikube addons
    5. Cleaning up
    6. Summary
  10. Working with the Kubernetes API
    1. API versioning
      1. Alpha
      2. Beta
      3. Stable
    2. Authentication
      1. HTTP basic auth
      2. Static token file
      3. Client certificates
      4. OpenID
    3. Authorization
      1. Attribute-based access control 
      2. Role-based access control (RBAC)
      3. WebHook
      4. AlwaysDeny
      5. AlwaysAllow
    4. Admission control
    5. Using the API
      1. API operations
      2. Example calls
        1. Creating a service using the API
        2. Creating a deployment using the API
        3. Deleting a service and deployment
    6. Swagger docs
    7. Summary
  11. Deploying Java on Kubernetes in the Cloud
    1. Benefits of using the cloud, Docker, and Kubernetes
    2. Installing the tools
      1. Python and PIP
      2. AWS command-line tools
      3. Kops
      4. jq
    3. Configuring Amazon AWS
    4. Creating an administrative user
      1. Creating a user for kops
    5. Creating the cluster
      1. DNS settings
        1. Root domain on AWS hosted domain
        2. The subdomain of the domain hosted on AWS
        3. Route 53 for a domain purchased with another registrar
        4. Subdomain for cluster in AWS Route 53, the domain elsewhere
      2. Checking the zones' availability
      3. Creating the storage
      4. Creating a cluster
      5. Starting up clusters
      6. Updating a cluster
      7. Installing the dashboard
    6. Summary
  12. More Resources
    1. Docker
      1. Awesome Docker
      2. Blogs
      3. Interactive tutorials
    2. Kubernetes
      1. Awesome Kubernetes
      2. Tutorials
      3. Blogs
      4. Extensions
      5. Tools
        1. Rancher
        2. Helm and charts
        3. Kompose
        4. Kubetop
        5. Kube-applier