Previous Next

OpenShift for Developers A Guide for Impatient Beginners (Joshua Wood Brian Tannous) (z-library.sk, 1lib.sk, z-lib.sk)

Author: Joshua Wood, Brian Tannous

科学

Ready to build cloud native applications? Get a hands-on introduction to daily life as a developer crafting code on OpenShift, the open source container application platform from Red Hat. Creating and packaging your apps for deployment on modern distributed systems can be daunting. Too often, adding infrastructure value can complicate development. With this practical guide, you'll learn how to build, deploy, and manage a multitiered application on OpenShift. Authors Joshua Wood and Brian Tannous demonstrate how OpenShift speeds application development. With the Kubernetes container orchestrator at its core, OpenShift simplifies and automates the way you build, ship, and run code. You'll learn how to use OpenShift and the Quarkus Java framework to develop and deploy apps using proven enterprise technologies and practices that you can apply to code in any language. • Learn the development cycles for building and deploying on OpenShift, and the tools that drive them • Use OpenShift to build, deploy, and manage the ongoing lifecycle of an n-tier application • Create a continuous integration and deployment pipeline to turn your source code changes into production rollouts • Automate scaling decisions with metrics and trigger lifecycle events with webhooks

📄 File Format: PDF
💾 File Size: 17.9 MB
9
Views
0
Downloads
0.00
Total Donations

📄 Text Preview (First 20 pages)

ℹ️

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

📄 Page 1
Joshua Wood & Brian Tannous Second Edition OpenShift for Developers A Guide for Impatient Beginners
📄 Page 2
(This page has no text content)
📄 Page 3
Joshua Wood and Brian Tannous OpenShift for Developers A Guide for Impatient Beginners SECOND EDITION Boston Farnham Sebastopol TokyoBeijing
📄 Page 4
978-1-098-10336-1 [LSI] OpenShift for Developers by Joshua Wood and Brian Tannous Copyright © 2021 O’Reilly Media. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com. Acquisitions Editor: Suzanne McQuade Development Editor: Nicole Taché Production Editor: Katherine Tozer Copyeditor: Audrey Doyle Proofreader: Piper Editorial Consulting, LLC Indexer: Potomac Indexing, LLC Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Kate Dullea September 2021: Second Edition Revision History for the Second Edition 2021-09-02: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781098103361 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. OpenShift for Developers, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the authors, and do not represent the publisher’s views. While the publisher and the authors have used good-faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. This work is part of a collaboration between O’Reilly and Red Hat. See our statement of editorial inde‐ pendence.
📄 Page 5
To Randy Wood –Joshua To Skeeter –Brian
📄 Page 6
(This page has no text content)
📄 Page 7
Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix 1. A Kubernetes Application Platform. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Linux Containers 1 Kubernetes 2 What OpenShift Adds 3 Web Console 3 Curated Software Catalogs: An OpenShift App Store 4 CI/CD: Pipelines 5 Networking and Service Mesh 5 Integrated Prometheus Metrics, Monitoring, and Alerts 5 Summary 6 2. OpenShift Concepts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Projects Organize Applications and Teams 7 Projects and Applications 8 Application Components in OpenShift 9 Pods 10 Services 11 OpenShift Routes 11 Building Container Images 11 Deploying Applications 12 Interacting with OpenShift 12 oc 12 OpenShift Web Console 12 Summary 13 v
📄 Page 8
3. OpenShift Lab. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 CodeReady Containers 15 CRC Requirements 16 Installing CRC on Windows 17 CRC Always Wants More 20 Logging In to OpenShift 21 Log In to the Web Console 21 Log In on the Command Line 25 Summary 26 4. Deploying an Application on OpenShift. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 A Simple Sample Application 27 Git and GitHub 28 Building and Deploying the Application on OpenShift 28 Adding and Deploying a New Feature 32 Summary 36 5. OpenShift Pipelines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Tekton 37 OpenShift Pipelines Operator 38 Installing the Pipelines Operator 38 Pipelines in the Web Console 40 Using Pipelines 41 OpenShift Pipelines Resources 42 Command 43 Script 43 Summary 43 6. Developing and Deploying from Source Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Noted: A Cloud-Ready Notes Application 45 Application Topology 46 Fork the Backend Repository 47 Create a New Project for the Noted App 47 Deploy the Backend Component 48 Inspect the Backend Resources 50 Deploy the Frontend Component 53 A Running Noted Application 55 Automatic Pipeline Runs Using Tekton Triggers 56 Pipeline Triggers 56 The Forward Proxy Workaround 57 Deploy the ngrok Template 58 GitHub Webhook Configuration 59 vi | Table of Contents
📄 Page 9
The Reversed Text Quarkus-Backend Bug Fix 62 Summary 65 7. Evolving the Application: Data Persistence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Database Without Delay 67 Database Templates 68 Service Binding Operator 69 The Postgres Operator Designed for Service Binding 70 Add the Sample DB Operators OperatorSource 70 Install the PostgreSQL Database Operator 72 Verify Operator Installation 74 Deploy a PostgreSQL Database 74 Configure the pgsql quarkus-backend Branch 77 Inspect the quarkus-backend pgsql Branch 79 Service Binding Operator Usage 79 Configure a ServiceBinding 80 Test the ServiceBinding 81 Inspect the ServiceBinding Injection 82 Persistence in Action 86 Summary 87 8. Production Deployment and Scaling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Application Scaling 89 Manual Scaling 89 The Service Abstraction 90 Automatic Scaling 93 Health Checks 98 Health-Checking Probes 99 Configure the Health Checks in OpenShift 100 Production Deployment Strategies 102 Available Deployment Strategies on OpenShift 102 Configuring a Deployment Strategy 104 Deployment Rollbacks 104 Summary 105 9. Monitoring and Managing Applications on OpenShift. . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Listing and Detailing Resources 107 Using Labels to Filter Listed Resources 109 Describing Resources 109 Events and Logs 109 Debugging an Application in Its Container 110 oc rsh 110 Table of Contents | vii
📄 Page 10
oc exec 111 oc debug 112 OpenShift Monitoring 112 Monitoring in the Web Console Developer Perspective 114 Deleting Resources, Applications, and Projects 115 Summary 116 10. Templates, Operators, and OpenShift Automation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Templates 117 Templates in the OpenShift Web Console 118 Creating Your Own Templates 120 Operators 121 Operator Subscriptions and the Operator Lifecycle Manager 122 Operators from the Developer Perspective 122 Summary 122 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 viii | Table of Contents
📄 Page 11
Preface Software serves more people more critically than ever before. These two demands are generalized as scale and reliability. Over the past decade, the software industry has pursued scale and reliability with tactics, infrastructure, and cultural initiatives like DevOps, which sees developers share the operational responsibility of keeping appli‐ cations running. One set of tactics is the automation of operations chores: writing software to run your software. The automation of repetitive toil is among the keystones of Site Reliability Engineering (SRE), an IT discipline defined by the O’Reilly title of the same name. DevOps and its younger cousin GitOps both apply SRE’s automation ideas to devel‐ opment machinery and to the practice of building software. The simplest form might be the triggering of automatic construction and deployment processes whenever an application’s source code changes. Modern software infrastructure pursues scale and reliability through distributed com‐ puting. Despite all the syllables, distributed computing just means making many com‐ puters act like one big computer. The assembled system can do more work (scale), and it can cast understudies for potential points of failure (reliability). Kubernetes is a system for managing applications on distributed computers by encap‐ sulating them in discrete, interchangeable artifacts called containers. Kubernetes can manage where and when containers run without knowing all about them and their dependencies. Kubernetes is termed a container orchestrator. OpenShift uses Kubernetes orchestration at its core to harness computers together into a cluster. The computers that form the cluster are called nodes. OpenShift defines how those nodes relate and how work is performed on them. By packaging core dis‐ tributed computing primitives with tools, policies, and interfaces for using them, OpenShift helps teams adopt modern practices from DevOps and GitOps and auto‐ mate repetitive processes according to SRE precepts. ix
📄 Page 12
Who This Book Is For If you’re an application developer familiar with data structures and functions and how to build them into programs, but you’re new to containers, Kubernetes, and application platforms, this guide to OpenShift is for you. It will show you how to use OpenShift to build, deploy, scale, and manage your software, and how you can auto‐ mate those chores with OpenShift features such as build triggers, pipelines, and demand-driven autoscaling. You don’t need to have used Kubernetes or OpenShift before. What You Will Learn This book explains what OpenShift is and how to use it to build your applications, run them, and keep them running through changing demand, failure recovery, and a continuous stream of new releases as you iterate on their source code with new fixes and features. • Chapters 1 and 2 introduce OpenShift, its components, and its concepts. • Chapter 3 shows you how to run OpenShift on your computer so that you have a virtual cluster to conduct the book’s exercises. • In Chapter 4, you’ll configure OpenShift to fetch the source code for a simple Hello World application, build it into a container image, and run it. • Chapter 5 introduces OpenShift Pipelines, a framework for composing Continu‐ ous Integration and Continuous Deployment (CI/CD) routines, and shows you how to add Pipelines to your cluster. • In Chapter 6, you’ll deploy a more realistic application with a tiered architecture and multiple components. • In Chapter 7, you’ll augment the application’s backend to retain data between sessions. • Chapter 8 shows you how to examine, manipulate, and scale the running applica‐ tion both manually and automatically, how to set up OpenShift to periodically check application health, and how to govern the rollout of new versions of your application. • Chapter 9 is a high-level overview of OpenShift’s monitoring and alerting facilities. • Chapter 10 dissects OpenShift automation features you used along the way to set you on the path toward eliminating toil by letting the platform do the repetitive work. x | Preface
📄 Page 13
Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program ele‐ ments such as variable or function names, databases, data types, environment variables, statements, and keywords. Bold Shows commands or other text that should be typed literally by the user. This element signifies a tip or suggestion. This element signifies a general note. This element indicates a warning or caution. Using Code Examples Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/openshift-for-developers. If you have a technical question or a problem using the code examples, please send email to bookquestions@oreilly.com. This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from O’Reilly books does require permission. Answering a question by citing this book and quoting Preface | xi
📄 Page 14
example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require per‐ mission. We appreciate, but generally do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “OpenShift for Develop‐ ers, 2nd edition by Joshua Wood and Brian Tannous (O’Reilly). Copyright 2021 O’Reilly Media, 978-1-098-10336-1.” If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us at permissions@oreilly.com. O’Reilly Online Learning For more than 40 years, O’Reilly Media has provided technol‐ ogy and business training, knowledge, and insight to help companies succeed. Our unique network of experts and innovators share their knowledge and expertise through books, articles, and our online learning platform. O’Reilly’s online learning platform gives you on-demand access to live training courses, in-depth learning paths, interactive coding environments, and a vast collection of text and video from O’Reilly and 200+ other publishers. For more information, visit http://oreilly.com. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax) We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at https://oreil.ly/openshift-for-developers-2. Email bookquestions@oreilly.com to comment or ask technical questions about this book. For news and information about our books and courses, visit http://oreilly.com. Find us on Facebook: http://facebook.com/oreilly xii | Preface
📄 Page 15
Follow us on Twitter: http://twitter.com/oreillymedia Watch us on YouTube: http://www.youtube.com/oreillymedia Acknowledgments We’d like to thank the Red Hat OpenShift team, and especially the OpenShift Devel‐ oper Advocates group, specifically for their support as we created this text and gener‐ ally for their endless efforts to refine and augment OpenShift since its initial release in 2011. As OpenShift grew from pioneer platform to later adopt a Kubernetes core, its goal has remained the same: automate and streamline the work of running applica‐ tions on modern, massively scalable infrastructure to let developers focus on their code. This book shares that goal. We also thank those who edited, fact-checked, suggested, occasionally ridiculed, and in so many ways lent their time and minds to make this book more useful and consis‐ tent, among them Jason Dobies, Daniel Hinojosa, and Tero Ahonen. Sun Seng David Tan created the original code on which we based the book’s main example applica‐ tion, “Noted,” and our families and friends tolerated us while we wrote it. Preface | xiii
📄 Page 16
(This page has no text content)
📄 Page 17
CHAPTER 1 A Kubernetes Application Platform OpenShift gives your applications distributed computing power without forcing you to become a distributed computing expert. Translated into jargon, that means Open‐ Shift is a platform as a service (PaaS). OpenShift includes tools for building applications from source in composable pipe‐ lines. It adds a browser-based graphical interface, the OpenShift Web Console, for deploying and managing workloads. You can point and click to set up network con‐ nections, monitoring and alerts, and rules for automatically scaling workloads. An OpenShift cluster applies software updates to itself and its nodes without cluster downtime. OpenShift is a product from Red Hat. You can run it on your laptop, on a cluster of physical or virtual machines, on all the major cloud providers, and as a managed ser‐ vice. Like most software from Red Hat, OpenShift is developed as an open source project, the OpenShift Kubernetes Distribution (OKD). OpenShift is in turn built atop two open source keystones: application containers and the Kubernetes container orchestrator. Linux Containers Containers are an atomic unit of execution. Each running instance of a container is stamped from an Open Container Initiative (OCI) image that packages an application executable with all the pieces it needs to run. These dependencies can include shared libraries, auxiliary programs, language runtimes, and anything else the application requires. Such a self-contained parcel is easier to distribute among a team, in a con‐ tinuous series of releases on a server, and to arbitrary nodes in a cluster. Container images are stored in a repository often called a container registry. Linux kernel facilities isolate and mediate running containers. A running container has its 1
📄 Page 18
own filesystem and a defined share of the resources of the node where it runs. This isolation allows an orchestrator to schedule containers on a node with sufficient resources without evaluating every other workload running there for potential con‐ flicts in filenames, network port numbers, or other resources. Kubernetes OpenShift is a distribution of Kubernetes. Kubernetes is an open source project started at Google and developed by a group of companies and individuals since its release in 2014. This community has adopted formal governance through the Cloud Native Computing Foundation (CNCF). Red Hat has been a leading contributor to Kubernetes since the project began, and OpenShift is developed in collaboration with the Kubernetes community. Kubernetes in OpenShift is like the Linux kernel in a Linux distribution. A Linux dis‐ tribution combines the kernel with the more familiar programs you use directly. It also makes some basic choices about how you log in, where your files are stored, and what software is essential, letting you do useful work with the system without build‐ ing it entirely from scratch. Kubernetes defines a set of common resources and an API for manipulating them. Those resources describe the desired state and track the actual state of the cluster and the things running on it. Kubernetes tries to make the actual state of a resource match its desired state. It repeats this for the life of the cluster. This continuous cycle of watching and tending is called the reconcile loop. Kubernetes alone isn’t enough to sustain software in production. There are many decisions to make and components to configure before you can do much with it. Imagine you have the source code for an application and the job of deploying it on a Kubernetes cluster. How will you compile the source code or pair it with its inter‐ preter for packaging in a container image? Will your build process need other com‐ puting resources, such as a specialized build server? Once the image is constructed, where will it be stored so that your cluster can access it? A public container registry (and external dependency) like Docker Hub or Quay? Or will you need to run your own registry? Your program likely depends on other programs, like a database or application server. Where and how will those run? Can you run them on the cluster, or will you have to maintain another system? These are basic considerations. Addressing them yields a running pod and a new set of questions: How should your application connect with the outside world? How should the power to scale the appli‐ cation, or deploy new versions of it, be governed? 2 | Chapter 1: A Kubernetes Application Platform
📄 Page 19
What OpenShift Adds OpenShift builds atop its Kubernetes core to add features and the components that support them. Some of its original developers called Kubernetes “a platform for building platforms.” OpenShift took them up on it. It provides the automation and resilience of modern infrastructure while letting you stay focused on your application code (Figure 1-1). Figure 1-1. OpenShift around a Kubernetes core This book focuses on the features you’ll use to run your applications. It is not an OpenShift system administration guide. The next section previews some of Open‐ Shift’s developer features. You’ll use most of them in the following chapters. Web Console The OpenShift Web Console is a graphical view of the cluster and your applications. As the name suggests, it runs in a web browser. The Web Console lets you do every‐ thing necessary to deploy and run your software projects with graphical controls and forms for configuration, rather than sifting through so many lines and indentations of underlying YAML. The console depicts connections between services with a topological view of application components, and shows project, application, and con‐ tainer resource consumption with graphical gauges and charts (Figure 1-2). What OpenShift Adds | 3
📄 Page 20
Figure 1-2. OpenShift Web Console showing the topology of an application’s components Curated Software Catalogs: An OpenShift App Store The Web Console also aggregates software catalogs, from application templates to Kubernetes Operators. The OperatorHub inside the Web Console, for example, is like an app store for Kubernetes applications. You can use it to find and deploy databases, message queues, and other middleware—the kinds of components nearly all applica‐ tions rely on. Like apps on your mobile device, Operators keep their applications run‐ ning and updated with the latest features and fixes. 4 | Chapter 1: A Kubernetes Application Platform
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now

Recommended for You

Loading recommended books...
Failed to load, please try again later
Back to List