Pro Java Microservices with Quarkus and Kubernetes a Hands-On Guide
Total Page:16
File Type:pdf, Size:1020Kb
Pro Java Microservices with Quarkus and Kubernetes A Hands-on Guide Nebrass Lamouchi Pro Java Microservices with Quarkus and Kubernetes: A Hands-on Guide Nebrass Lamouchi Paris, France ISBN-13 (pbk): 978-1-4842-7169-8 ISBN-13 (electronic): 978-1-4842-7170-4 https://doi.org/10.1007/978-1-4842-7170-4 Copyright © 2021 by Nebrass Lamouchi This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Steve Anglin Development Editor: Matthew Moodie Coordinating Editor: Mark Powers Cover designed by eStudioCalamar Cover image by Robert Shunev on Unsplash (www.unsplash.com) Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004, U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www. springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected]; for reprint, paperback, or audio rights, please e-mail [email protected]. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/9781484271698. For more detailed information, please visit http://www.apress.com/source-code. Printed on acid-free paper To Mom, it’s impossible to thank you adequately for everything you’ve done. To the soul of Dad, I miss you every day… To Firass, you are the best, may God bless you… To my sweetheart, since you’ve come into my life, there are so many new emotions and feelings begging to come out… Table of Contents About the Author ..................................................................................................... xi About the Technical Reviewer ............................................................................... xiii Acknowledgments ...................................................................................................xv Preface ..................................................................................................................xvii Introduction ............................................................................................................xxi Chapter 1: Getting Started with Containerization ..................................................... 1 Introducing Containerization ......................................................................................................... 1 Introducing Docker ........................................................................................................................ 2 The Dockerfile ......................................................................................................................... 3 Images and Containers ............................................................................................................ 3 Installing Docker ........................................................................................................................... 3 Running Your First Container ........................................................................................................ 4 Understanding the Docker Architecture ........................................................................................ 6 Docker Objects ........................................................................................................................ 7 Docker Machine ....................................................................................................................... 7 Diving Into Docker Containers ....................................................................................................... 8 Docker Containers in Development Environments .................................................................. 8 Define a Container with Dockerfile .......................................................................................... 8 Play with Google Jib .............................................................................................................. 20 Meeting the Docker Services ...................................................................................................... 22 Create the First docker-compose.yml File ............................................................................. 23 Achieving More with Docker ....................................................................................................... 24 Get the Needed Tools Quickly ................................................................................................ 24 Unleash the Requirements Chains ........................................................................................ 26 v TABLE OF CONTENTS Containerization Is Not Docker Only ............................................................................................ 29 What Are Docker’s Limitations? ............................................................................................. 29 Meet Podman and Buildah .................................................................................................... 30 Conclusion .................................................................................................................................. 33 Chapter 2: Introduction to the Monolithic Architecture .......................................... 35 Introduction to an Actual Situation .............................................................................................. 35 Presenting the Context ................................................................................................................ 36 Solving These Issues ................................................................................................................... 38 Chapter 3: Coding a Monolithic Application ........................................................... 39 Presenting the Domain ................................................................................................................ 39 Use Case Diagram ................................................................................................................. 39 Class Diagram ....................................................................................................................... 41 Sequence Diagram ................................................................................................................ 42 Coding the Application ................................................................................................................ 42 Presenting the Technology Stack .......................................................................................... 43 Implementing the QuarkuShop .............................................................................................. 47 Conclusion ................................................................................................................................ 111 Chapter 4: Upgrading a Monolithic Application .................................................... 113 Implementing QuarkuShop Tests .............................................................................................. 113 Introducing Tests Libraries in Quarkus ................................................................................ 113 Writing the First Tests .......................................................................................................... 119 Discovering SonarQube ....................................................................................................... 127 Building and Running QuarkuShop ........................................................................................... 135 Building the QuarkuShop ....................................................................................................