ebook img

Kubernetes Cookbook: Practical solutions to container orchestration PDF

546 Pages·2018·23.586 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 Cookbook: Practical solutions to container orchestration

Kubernetes Cookbook Second Edition Practical solutions to container orchestration Hideto Saito Hui-Chuan Chloe Lee Ke-Jou Carol Hsu BIRMINGHAM - MUMBAI Kubernetes Cookbook Second Edition Copyright © 2018 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Commissioning Editor: Gebin George Acquisition Editor: Divya Poojari Content Development Editor: Dattatraya More Technical Editor: Sayali Thanekar Copy Editor: Safis Editing Project Coordinator: Shweta H Birwatkar Proofreader: Safis Editing Indexer: Priyanka Dhadke Graphics: Jisha Chirayil Production Coordinator: Deepika Naik First published: June 2016 Second edition: May 2018 Production reference: 1290518 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78883-760-6 www.packtpub.com mapt.io Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website. Why subscribe? Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals Improve your learning with Skill Plans built especially for you Get a free eBook or video every month Mapt is fully searchable Copy and paste, print, and bookmark content PacktPub.com Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. Contributors About the authors Hideto Saito has around 20 years of experience in the computer industry. In 1998, while working for Sun Microsystems Japan, he was impressed by Solaris OS, OPENSTEP, and Sun Ultra Enterprise 10000 (also known as StarFire). He then decided to pursue UNIX and macOS operating systems. In 2006, he relocated to southern California as a software engineer to develop products and services running on Linux and macOS X. He was especially renowned for his quick Objective-C code when he was drunk. He is also an enthusiast of Japanese anime, drama, and motorsports, and he loves Japanese Otaku culture. Hui-Chuan Chloe Lee is a DevOps and software developer. She has worked in the software industry on a wide range of projects for over five years. As a technology enthusiast, she loves trying and learning about new technologies, which makes her life happier and more fulfilling. In her free time, she enjoys reading, traveling, and spending time with the people she loves. Ke-Jou Carol Hsu has three years of experience working as a software engineer and is currently a PhD student in the area of computer systems. Not only involved programming, she also enjoys getting multiple applications and machines perfectly working together to solve big problems. In her free time, she loves movies, music, cooking, and working out. About the reviewer Stefan Lapers started his career almost 20 years ago as a support engineer and quickly grew into Linux/Unix system engineering, security, and network positions. Over the years, he accumulated experience in developing, deploying, and maintaining hosted applications while working for great customers, such as MTV and TMF. In his spare time, he enjoys spending time with his family, tinkering with electronics, and flying model helicopters. Packt is searching for authors like you If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea. Table of Contents Preface 1 Chapter 1: Building Your Own Kubernetes Cluster 7 Introduction 7 Exploring the Kubernetes architecture 7 Getting ready 8 How to do it... 8 Kubernetes master 9 API server (kube-apiserver) 10 Scheduler (kube-scheduler) 10 Controller manager (kube-controller-manager) 10 Command-line interface (kubectl) 10 Kubernetes node 11 kubelet 12 Proxy (kube-proxy) 12 How it works... 13 etcd 13 Kubernetes network 14 See also 14 Setting up the Kubernetes cluster on macOS by minikube 14 Getting ready 16 How to do it... 16 How it works... 18 See also 21 Setting up the Kubernetes cluster on Windows by minikube 22 Getting ready 22 How to do it... 23 How it works... 27 See also 32 Setting up the Kubernetes cluster on Linux via kubeadm 33 Getting ready 33 How to do it... 35 Package installation 35 Ubuntu 35 CentOS 36 System configuration prerequisites 36 CentOS system settings 37 Booting up the service 37 Network configurations for containers 39 Getting a node involved 40 How it works... 41 Table of Contents See also 42 Setting up the Kubernetes cluster on Linux via Ansible (kubespray) 43 Getting ready 43 Installing pip 44 Installing Ansible 45 Installing python-netaddr 46 Setting up ssh public key authentication 46 How to do it... 48 Maintaining the Ansible inventory 49 Running the Ansible ad hoc command to test your environment 50 Ansible troubleshooting 51 Need to specify a sudo password 52 Need to specify different ssh logon user 53 Need to change ssh port 53 Common ansible issue 53 How it works... 54 See also 58 Running your first container in Kubernetes 58 Getting ready 58 How to do it... 60 Running a HTTP server (nginx) 61 Exposing the port for external access 62 Stopping the application 63 How it works… 63 See also 66 Chapter 2: Walking through Kubernetes Concepts 67 Introduction 67 An overview of Kubernetes 68 Linking Pods and containers 71 Getting ready 71 How to do it... 72 How it works... 74 See also 77 Managing Pods with ReplicaSets 78 Getting ready 79 How to do it... 80 Creating a ReplicaSet 80 Getting the details of a ReplicaSet 82 Changing the configuration of a ReplicaSet 83 Deleting a ReplicaSet 84 How it works... 85 There's more... 88 See also 88 Deployment API 89 Getting ready 89 How to do it... 91 [ ii ] Table of Contents How it works... 94 Using kubectl set to update the container image 95 Updating the YAML and using kubectl apply 96 See also 98 Working with Services 99 Getting ready 100 How to do it... 101 Creating a Service for different resources 102 Creating a Service for a Pod 102 Creating a Service for a Deployment with an external IP 104 Creating a Service for an Endpoint without a selector 105 Creating a Service for another Service with session affinity 107 Deleting a Service 108 How it works... 109 There's more... 111 See also 114 Working with volumes 115 Getting ready 116 How to do it... 116 emptyDir 116 hostPath 119 NFS 120 glusterfs 122 downwardAPI 124 gitRepo 127 There's more... 128 PersistentVolumes 128 Using storage classes 132 gcePersistentDisk 133 awsElasticBlockStore 136 See also 140 Working with Secrets 140 Getting ready 141 How to do it... 141 Creating a Secret 141 Working with kubectl create command line 141 From a file 142 From a directory 143 From a literal value 143 Via configuration file 144 Using Secrets in Pods 144 By environment variables 144 By volumes 145 Deleting a Secret 147 How it works... 147 There's more... 147 Using ConfigMaps 147 Mounting Secrets and ConfigMap in the same volume 149 See also 150 [ iii ] Table of Contents Working with names 150 Getting ready 150 How to do it... 151 How it works... 154 See also 155 Working with Namespaces 156 Getting ready 157 How to do it... 158 Creating a Namespace 158 Changing the default Namespace 159 Deleting a Namespace 161 How it works… 162 There's more... 162 Creating a LimitRange 162 Deleting a LimitRange 166 See also 166 Working with labels and selectors 166 Getting ready 167 How to do it... 167 How it works... 170 Equality-based label selector 171 Set-based label selector 172 There's more... 173 Linking Service to Pods or ReplicaSets using label selectors 173 Linking Deployment to ReplicaSet using the set-based selector 175 See also 177 Chapter 3: Playing with Containers 178 Introduction 178 Scaling your containers 178 Getting ready 179 How to do it... 180 Scale up and down manually with the kubectl scale command 180 Horizontal Pod Autoscaler (HPA) 182 How it works... 185 There is more… 185 See also 186 Updating live containers 186 Getting ready 186 How to do it... 187 Deployment update strategy – rolling-update 189 Rollback the update 193 Deployment update strategy – recreate 194 How it works... 195 There's more... 196 See also 198 [ iv ]

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.