Microsoft Azure forJava DevelopersDeploying Java Applications throughAzure WebApp, Azure KubernetesService, Azure Functions,and Azure Spring CloudAbhishek MishraMicrosoft Azure for Java Developers: Deploying Java Applications through AzureWebApp, Azure Kubernetes Service, Azure Functions, and Azure Spring Cloud Abhishek Mishra Navi Mumbai, India ISBN-13 (pbk): 978-1-4842-8250-2 ISBN-13 (electronic): 978-1-4842-8251-9 https://doi.org/10.1007/978-1-4842-8251-9 Copyright 2022 by Abhishek Mishra 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: Jonathan Gennick Development Editor: Laura Berendson Coordinating Editor: Jill Balzano Cover designed by eStudioCalamar Cover image designed by Freepik (www.freepik.com) Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@ springer-sbm.com, 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 booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com.
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 (https://github.com/Apress). For more detailed information, please visit http://www. apress.com/source-code.
Printed on acid-free paper This book is dedicated to my ever-supportingwife Suruchi and lovely daughter Aaria.Table of Contents About the Author xi About the Technical Reviewer xiii Acknowledgments xv Introduction xvii Part I: Building and Deploying Java Applications to Azure 1 Chapter 1: Getting Started with Java Development for Azure 3 Structure 3 Objectives 3 What Is Cloud Computing 4 Cloud Computing Basics 4 Cloud Service Types 5 Cloud Deployment Models 7 Introduction to Azure 10 Java Support on Azure 12 Summary 13 Chapter 2: Java for Azure WebApp 15 Structure 15 Objectives 15 Azure WebApp 16 App Service Plan 17 Shared Compute 17 Dedicated Compute 17 Isolated 18 v Table of ConTenTs Deploy Java Application on Azure WebApp 18 Create a Java Spring Boot Application 18 Create an Azure WebApp 25 Deploy the Application to Azure WebApp 29 Scaling Java Applications Hosted on Azure WebApp 34 Summary 37 Chapter 3: Java-Based Azure Functions 39 Structure 39 Objectives 40 Introduction to Serverless and Azure Functions 40 Azure Functions Use Cases 41 Hosting Plans 42 Consumption Plan 43 Premium Plan 43 Dedicated Plan 43 App Service Environment Plan 44 Kubernetes Plan 44 Triggers and Bindings 44 Build a Java-Based Azure Function 47 Summary 63 Chapter 4: Containerizing Java Applications with Azure Kubernetes Service 65 Structure 66 Objectives 66 Introduction to Containers 66 Understanding Azure Kubernetes Service 68 Containerize a Java Application and Run It on Azure Kubernetes Service 71 Create Azure Container Registry 71 Create an Azure Kubernetes Service 75 Containerize a Java Application 81 Run the Container on Azure Kubernetes Service 87 Summary 91 vi Table of ConTenTs Chapter 5: Running Java Applications on Azure Spring Cloud 93 Structure 93 Objectives 94 Introduction to Azure Spring Cloud 94 Create an Azure Spring Cloud Service 95 Deploy a Java Application on Azure Spring Cloud 104 Summary 111 Part II: Integrating Java Applications with Popular Azure Services 113 Chapter 6: Integrating with an Azure Storage Account 115 Structure 115 Objectives 116 Introduction to Azure Storage 116 Create an Azure Storage Account 118 Working with Azure Storage Blob 121 Working with Azure Storage Queue 127 Working with Table Storage 130 Summary 136 Chapter 7: Azure SQL from Java Applications 137 Structure 137 Objectives 137 Introduction to Azure SQL Database 138 Create an Azure SQL Database 139 Work with Azure SQL Database 147 Securing Azure Databases 156 Summary 158 vii Table of ConTenTs Chapter 8: Work with Azure Cosmos DB 161 Structure 161 Objectives 161 Introduction to Azure Cosmos DB 162 Create an SQL API Cosmos DB 163 Work with SQL API Cosmos DB 168 Summary 179 Chapter 9: Storing Runtime Data in Azure Redis Cache 181 Structure 181 Objectives 182 Introduction to Azure Redis Cache 182 Create Azure Redis Cache 184 Work with Azure Redis Cache 190 Using Console to Work with Redis Cache 193 Summary 195 Chapter 10: Sending Emails Using Graph API 197 Structure 197 Objectives 198 Introduction to Graph API 198 Steps to Send Mail Using Graph API 200 Send Mail Using Microsoft Graph API 201 Microsoft Graph API Explorer 216 Summary 219 Chapter 11: Debugging and Monitoring Using Azure Monitor and Application Insights 221 Structure 221 Objectives 222 Introduction to Azure Monitor and Application Insights 222 Configure Azure Monitor Metrics and Dashboard 224 viii Table of ConTenTs Create Performance Alerts 236 Work with Application Insights for Java Application 247 Summary 252 Chapter 12: Authentication and Authorization Using Azure Active Directory 253 Structure 253 Objectives 254 Introduction to Azure Active Directory 254 Configure Azure Active Directory for Authentication and Authorization 255 Create a User in Azure Active Directory 255 Register an Application in Azure Active Directory 258 Assign the User to the Application Role 267 Configure a Spring Boot Application 271 Authentication Scenarios for Azure AD 276 Web Browser to Web Application 276 Single Page Application 277 Native Application to Web API 277 Web Application to Web API 277 Server Application to Web API 278 Summary 278 Part III: DevOps and Best Practices 279 Chapter 13: Provisioning Resources with Azure DevOps and Azure CLI 281 Structure 281 Objectives 282 Introduction to Infrastructure as Code (IaC) on Azure 282 Create an Azure CLI Script to Spin Up Azure WebApp 283 Create an Azure DevOps Pipeline to Spin Up Azure WebApp 286 Summary 302 ix Table of ConTenTs Chapter 14: Building and Deploying Using Azure DevOps 305 Structure 305 Objectives 305 Create a Java Application and Commit It to Git- Based Azure Repos 306 Create a YAML-Based Pipeline 310 Summary 319 Chapter 15: A Near-Production Azure- Based Java Application 321 Structure 321 Objectives 321 Best Practices 322 Identify the Host Options 322 Modernize Application and Then Move to Azure 323 Choose the Right Azure Services for Your Application 323 Plan the Cloud Cost Meeting Your Need 323 Plan for Scalability, Availability, and Reliability 324 Have a Robust Debugging and Monitoring Strategy in Place 324 Secure Your Application on Azure 324 Automate Spinning Up Azure Services and Application Deployment 325 Have the Right Backup and Disaster Recovery Strategy in Place 325 Build a Near-Production Scenario 325 Problem Statement 325 Implementation: Create Infrastructure 326 Build the Application and Deploy It to Azure WebApp 336 Deploy the Application to Azure WebApp 343 Summary 349 Index 351 x
Next page