ebook img

Kubernetes Microservices with Docker PDF

440 Pages·2016·38.05 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Kubernetes Microservices with Docker

THE EXPERT’S VOICE® IN OPEN SOURCE Kubernetes Microservices with Docker — Deepak Vohra Foreword by Massimo Nardone Kubernetes Microservices with Docker Deepak Vohra Kubernetes Microservices with Docker Deepak Vohra White Rock, British Columbia Canada ISBN-13 (pbk): 978-1-4842-1906-5 ISBN-13 (electronic): 978-1-4842-1907-2 DOI 10.1007/978-1-4842-1907-2 Library of Congress Control Number: 2016937418 Copyright © 2016 by Deepak Vohra 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. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher's location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law. 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: Welmoed Spahr Lead Editor: Michelle Lowman Technical Reviewer: Massimo Nardone Editorial Board: Steve Anglin, Pramila Balan, Louise Corrigan, Jonathan Gennick, Robert Hutchinson, Celstin Suresh John, Michelle Lowman, James Markham, Susan McDermott, Matthew Moodie, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Gwenan Spearing Coordinating Editor: Mark Powers Compositor: SPi Global Indexer: SPi Global Artist: SPi Global Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. 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], or visit www.apress.com. Apress and friends of ED books 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 Special Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this text is available to readers at www.apress.com/9781484219065. For additional information about how to locate and download your book’s source code, go to www.apress.com/source-code/. Readers can also access source code at SpringerLink in the Supplementary Material section for each chapter. Printed on acid-free paper Contents at a Glance About the Author ...................................................................................................xvii About the Technical Reviewer ................................................................................xix Foreword ................................................................................................................xxi ■ Part I: Getting Started .........................................................................1 ■ Chapter 1: Installing Kubernetes Using Docker .....................................................3 ■ Chapter 2: Hello Kubernetes ................................................................................39 ■ Chapter 3: Using Custom Commands and Environment Variables ......................77 ■ Part II: Relational Databases ............................................................95 ■ Chapter 4: Using MySQL Database ......................................................................97 ■ Chapter 5: Using PostgreSQL Database .............................................................115 ■ Chapter 6: Using Oracle Database .....................................................................141 ■ Part III: NoSQL Database .................................................................165 ■ Chapter 7: Using MongoDB Database ................................................................167 ■ Chapter 8: Using Apache Cassandra Database ..................................................201 ■ Chapter 9: Using Couchbase ..............................................................................231 ■ Part IV: Apache Hadoop Ecosystem ................................................275 ■ Chapter 10: Using Apache Hadoop Ecosystem ..................................................277 ■ Chapter 11: Using Apache Solr ..........................................................................313 ■ Chapter 12: Using Apache Kafka .......................................................................347 iii ■ CONTENTS AT A GLANCE ■ Part V: Multi Containers and Nodes ................................................373 ■ Chapter 13: Creating a Multi-Container Pod ......................................................375 ■ Chapter 14: Installing Kubernetes on a Multi-Node Cluster ..............................399 Index .....................................................................................................................429 iv Contents About the Author ...................................................................................................xvii About the Technical Reviewer ................................................................................xix Foreword ................................................................................................................xxi ■ Part I: Getting Started .........................................................................1 ■ Chapter 1: Installing Kubernetes Using Docker .....................................................3 Setting the Environment ...................................................................................................4 Installing Docker ..............................................................................................................5 Installing Kubernetes .....................................................................................................15 Starting etcd ...................................................................................................................23 Starting Kubernetes Master ...........................................................................................25 Starting Service Proxy ....................................................................................................28 Listing the Kubernetes Docker Containers .....................................................................29 Installing kubectl ............................................................................................................32 Listing Services ..............................................................................................................35 Listing Nodes ..................................................................................................................36 Testing the Kubernetes Installation ................................................................................36 Summary ........................................................................................................................38 ■ Chapter 2: Hello Kubernetes ................................................................................39 Overview ........................................................................................................................39 What Is a Node? ....................................................................................................................................39 What Is a Cluster?.................................................................................................................................40 What Is a Pod? ......................................................................................................................................40 v ■ CONTENTS What Is a Service? ................................................................................................................................40 What Is a Replication Controller? .........................................................................................................40 What Is a Label? ...................................................................................................................................41 What Is a Selector? ...............................................................................................................................41 What Is a Name? ..................................................................................................................................41 What Is a Namespace? .........................................................................................................................41 What Is a Volume? ................................................................................................................................41 Why Kubernetes?..................................................................................................................................41 Setting the Environment .................................................................................................42 Creating an Application Imperatively ..............................................................................43 Creating a Service ................................................................................................................................44 Describing a Pod ...................................................................................................................................46 Invoking the Hello-World Application ....................................................................................................47 Scaling the Application .........................................................................................................................48 Deleting a Replication Controller ..........................................................................................................52 Deleting a Service ................................................................................................................................53 Creating an Application Declaratively .............................................................................53 Creating a Pod Defi nition ......................................................................................................................54 Creating a Service Defi nition ................................................................................................................58 Creating a Replication Controller Defi nition..........................................................................................61 Invoking the Hello-World Application ....................................................................................................64 Scaling the Application .........................................................................................................................68 Using JSON for the Resource Defi nitions .......................................................................70 Summary ........................................................................................................................76 ■ Chapter 3: Using Custom Commands and Environment Variables ......................77 Setting the Environment .................................................................................................77 The ENTRYPOINT and CMD Instructions .........................................................................78 The Command and Args Fields in a Pod Defi nition.........................................................79 Environment Variables ....................................................................................................80 vi ■ CONTENTS Using the Default ENTRYPOINT and CMD from a Docker Image .....................................81 Overriding Both the ENTRYPOINT and CMD ....................................................................84 Specifying both the Executable and the Parameters in the Command Mapping ...........87 Specifying Both the Executable and the Parameters in the Args Mapping ....................90 Summary ........................................................................................................................93 ■ Part II: Relational Databases ............................................................95 ■ Chapter 4: Using MySQL Database ......................................................................97 Setting the Environment .................................................................................................97 Creating a Service ..........................................................................................................99 Creating a Replication Controller..................................................................................100 Listing the Pods ............................................................................................................104 Listing Logs ..................................................................................................................104 Describing the Service .................................................................................................106 Starting an Interactive Shell .........................................................................................107 Starting the MySQL CLI ................................................................................................109 Creating a Database Table ............................................................................................110 Exiting the MySQL CLI and Interactive Shell .................................................................111 Scaling the Replicas .....................................................................................................111 Deleting the Replication Controller ...............................................................................113 Summary ......................................................................................................................114 ■ Chapter 5: Using PostgreSQL Database .............................................................115 Setting the Environment ...............................................................................................115 Creating a PostgreSQL Cluster Declaratively ...............................................................117 Creating a Service ..............................................................................................................................117 Creating a Replication Controller ........................................................................................................119 Getting the Pods .................................................................................................................................123 Starting an Interactive Command Shell ..............................................................................................123 vii ■ CONTENTS Starting the PostgreSQL SQL Terminal ...............................................................................................124 Creating a Database Table ..................................................................................................................125 Exiting the Interactive Command Shell ...............................................................................................126 Scaling the PostgreSQL Cluster ..........................................................................................................127 Listing the Logs ..................................................................................................................................128 Deleting the Replication Controller .....................................................................................................130 Stopping the Service ..........................................................................................................................131 Creating a PostgreSQL Cluster Imperatively ................................................................131 Creating a Replication Controller ........................................................................................................132 Getting the Pods .................................................................................................................................132 Creating a Service ..............................................................................................................................133 Creating a Database Table ..................................................................................................................134 Scaling the PostgreSQL Cluster ..........................................................................................................137 Deleting the Replication Controller .....................................................................................................138 Stopping the Service ..........................................................................................................................139 Summary ......................................................................................................................139 ■ Chapter 6: Using Oracle Database .....................................................................141 Setting the Environment ...............................................................................................141 Creating an Oracle Database Instance Imperatively ....................................................142 Listing Logs ........................................................................................................................................144 Creating a Service ..............................................................................................................................145 Scaling the Database ..........................................................................................................................146 Deleting the Replication Controller and Service .................................................................................147 Creating an Oracle Database Instance Declaratively ...................................................148 Creating a Pod ....................................................................................................................................148 Creating a Service ..............................................................................................................................150 Creating a Replication Controller ........................................................................................................153 Keeping the Replication Level ............................................................................................................156 Scaling the Database ..........................................................................................................................158 Starting the Interactive Shell ..............................................................................................................159 viii ■ CONTENTS Connecting to Database......................................................................................................................160 Creating a User ...................................................................................................................................161 Creating a Database Table ..................................................................................................................162 Exiting the Interactive Shell ................................................................................................................163 Summary ......................................................................................................................163 ■ Part III: NoSQL Database .................................................................165 ■ Chapter 7: Using MongoDB Database ................................................................167 Setting the Environment ...............................................................................................167 Creating a MongoDB Cluster Declaratively ...................................................................169 Creating a Service ..............................................................................................................................169 Creating a Replication Controller ........................................................................................................173 Creating a Volume ...............................................................................................................................176 Listing the Logs ..................................................................................................................................178 Starting the Interactive Shell for Docker Container ............................................................................180 Starting a Mongo Shell .......................................................................................................................182 Creating a Database ...........................................................................................................................182 Creating a Collection ..........................................................................................................................183 Adding Documents .............................................................................................................................184 Finding Documents .............................................................................................................................186 Finding a Single Document .................................................................................................................186 Finding Specifi c Fields in a Single Document ....................................................................................187 Dropping a Collection .........................................................................................................................188 Exiting Mongo Shell and Interactive Shell ..........................................................................................188 Scaling the Cluster .............................................................................................................................188 Deleting the Replication Controller .....................................................................................................189 Deleting the Service ...........................................................................................................................190 Using a Host Port ................................................................................................................................190 Creating a MongoDB Cluster Imperatively ....................................................................194 Creating a Replication Controller ........................................................................................................194 ix

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.