Table Of Content.d
e
vre
se
r sth
g
ir llA
.d
e
tim
iL
,g
n
ih
silb
u
P
tkca
P
.9
1
0
2
©
th
g
iryp
o
C
Yilmaz, Onur, and Suleyman Akbas. Introduction to DevOps with Kubernetes : Build Scalable Cloud-Native Applications Using DevOps Patterns Created with
Kubernetes, Packt Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5779693.
Created from nyulibrary-ebooks on 2022-10-16 18:50:04.
Introduction to
DevOps with
Kubernetes
Build scalable cloud-native applications using
DevOps patterns created with Kubernetes
Onur Yılmaz and Süleyman Akbaş
.d
e
vre
se
r sth
g
ir llA
.d
e
tim
iL
,g
n
ih
silb
u
P
tkca
P
.9
1
0
2
©
th
g
iryp
o
C
Yilmaz, Onur, and Suleyman Akbas. Introduction to DevOps with Kubernetes : Build Scalable Cloud-Native Applications Using DevOps Patterns Created with
Kubernetes, Packt Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5779693.
Created from nyulibrary-ebooks on 2022-10-16 18:50:04.
Introduction to DevOps with Kubernetes
Copyright © 2019 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,
and its dealers and distributors will be held liable for any damages caused or alleged to
be 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.
Authors: Onur Yılmaz and Süleyman Akbaş
Technical Reviewer: Hasan Turken
Managing Editor: Aditya Datar
Acquisitions Editor: Aditya Date
Production Editor: Samita Warang
Editorial Board: David Barnes, Mayank Bhardwaj, Ewan Buckingham, Simon Cox,
Mahesh Dhyani, Taabish Khan, Manasa Kumar, Alex Mazonowicz, Douglas Paterson,
Dominic Pereira, Shiny Poojary, Erol Staveley, Ankita Thakur, Mohita Vyas,
and Jonathan Wray
First Published: May 2019
.d
evre Production Reference: 1210519
se
r sth ISBN: 978-1-78980-828-5
g
ir llA
.d Published by Packt Publishing Ltd.
e
tim
iL ,g Livery Place, 35 Livery Street
n
ih
silb Birmingham B3 2PB, UK
u
P
tkca
P
.9
1
0
2
©
th
g
iryp
o
C
Yilmaz, Onur, and Suleyman Akbas. Introduction to DevOps with Kubernetes : Build Scalable Cloud-Native Applications Using DevOps Patterns Created with
Kubernetes, Packt Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5779693.
Created from nyulibrary-ebooks on 2022-10-16 18:50:04.
Table of Contents
Preface i
Introduction to DevOps 1
Introduction .................................................................................................... 2
DevOps' Effect on Industry ................................................................................. 3
DevOps Culture and its Benefits ........................................................................ 3
The DevOps Toolchain ................................................................................... 5
Plan ........................................................................................................................ 6
Exercise 1: Creating a Repository and Project Board on GitHub ................... 9
Create .................................................................................................................. 13
Exercise 2: Creating a DevOps Blog ................................................................. 16
Verify ................................................................................................................... 18
Exercise 3: Connecting the DevOps Blog to a CI/CD System ........................ 22
Package ............................................................................................................... 26
Release ................................................................................................................ 28
Exercise 4: Releasing the DevOps Blog ........................................................... 29
Configure ............................................................................................................ 32
.d
e
vrese Monitor ................................................................................................................ 32
r sth
gir llA Activity 1: CI/CD Pipeline for the DevOps Blog ............................................... 33
.de Summary ....................................................................................................... 36
tim
iL
,g
n
ih Introduction to Microservices and Containers 39
silb
u
P
tkca Introduction .................................................................................................. 40
P
.9
1
02 Introduction to Docker ................................................................................ 43
©
th
g
iryp The Fundamental Concepts of Docker ........................................................... 44
o
C
Exercise 5: Creating a "Hello World" Container in Docker ............................ 49
Yilmaz, Onur, and Suleyman Akbas. Introduction to DevOps with Kubernetes : Build Scalable Cloud-Native Applications Using DevOps Patterns Created with
Kubernetes, Packt Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5779693.
Created from nyulibrary-ebooks on 2022-10-16 18:50:04.
Building Docker Images .............................................................................. 51
Dockerfiles .......................................................................................................... 52
The Docker Registry ........................................................................................... 53
Exercise 6: Building a Docker Image and Pushing it to Docker Hub ............ 54
Running Docker Containers ........................................................................ 57
Exercise 7: Running Docker Containers, Volume Mapping,
and Port Sharing ................................................................................................ 60
Activity 2: Installing a WordPress Blog and Database Using Docker ........... 62
Summary ....................................................................................................... 66
Introduction to Kubernetes 69
Introduction .................................................................................................. 70
What is Kubernetes? .......................................................................................... 70
Kubernetes Architecture ............................................................................. 71
Master Components .......................................................................................... 72
Node Components ............................................................................................. 74
Exercise 8: Installing and Starting a Local Kubernetes Cluster .................... 75
Accessing Kubernetes Clusters .................................................................. 78
Exercise 9: Checking Application Status in Kubernetes Dashboard ............ 78
Exercise 10: Carrying Out Cluster Management Using kubectl ................... 82
.d
evre Fundamental Kubernetes Resources ........................................................ 85
se
r sth The Pod ................................................................................................................ 85
g
ir llA
.d Replication Sets .................................................................................................. 87
e
tim
iL ,g Deployment ........................................................................................................ 89
n
ih
silb Stateful Sets ........................................................................................................ 90
u
P
tkca Activity 3: Installing a WordPress Blog and Database on Kubernetes ........ 92
P
.9
1
02 Summary ....................................................................................................... 96
©
th
g
iryp
o
C
Yilmaz, Onur, and Suleyman Akbas. Introduction to DevOps with Kubernetes : Build Scalable Cloud-Native Applications Using DevOps Patterns Created with
Kubernetes, Packt Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5779693.
Created from nyulibrary-ebooks on 2022-10-16 18:50:04.
Creating a Kubernetes Cluster 99
Introduction ................................................................................................ 100
Manual Kubernetes Cluster Setup ........................................................... 100
Exercise 11: Creating a Kubernetes Cluster Using kubeadm .................... 102
Kubernetes Cluster Considerations ......................................................... 112
Development or Production-Ready Setup ................................................... 112
In-House or Managed Services ...................................................................... 112
On-Premises or Cloud Infrastructure ........................................................... 113
Vanilla Kubernetes or Custom Solutions ..................................................... 113
Kubernetes Platform Options .................................................................. 113
Local Machine Solutions ................................................................................ 114
Hosted Solutions ............................................................................................. 114
Turnkey Solutions ........................................................................................... 116
Heptio ............................................................................................................... 116
CoreOS Tectonic .............................................................................................. 117
Red Hat OpenShift .......................................................................................... 117
Exercise 12 – Creating Managed Kubernetes Clusters on GCP ................. 118
Activity 4: Migrating a Running Application in Kubernetes Cluster .......... 124
Summary ..................................................................................................... 127
.d
e
vre Deploy an Application to Kubernetes 129
se
r sth
g
ir llA Introduction ................................................................................................ 130
.d
e
tim Object Management in Kubernetes ........................................................ 130
iL
,g
n
ihsilb Imperative Commands ................................................................................... 131
u
P
tkca Imperative Configuration .............................................................................. 132
P
.91 Declarative Configuration .............................................................................. 134
0
2
©
thg Exercise 13: Deploying Applications Using kubectl .................................... 136
iryp
o
C
Yilmaz, Onur, and Suleyman Akbas. Introduction to DevOps with Kubernetes : Build Scalable Cloud-Native Applications Using DevOps Patterns Created with
Kubernetes, Packt Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5779693.
Created from nyulibrary-ebooks on 2022-10-16 18:50:04.
Service Discovery in Kubernetes .............................................................. 139
Exercise 14: Access Applications Using Services ......................................... 141
Kubernetes Package Manager: Helm ...................................................... 143
Exercise 15: Installing Helm in the Kubernetes Cluster ............................. 145
Activity 5: Installing and Scaling a WordPress Blog in Kubernetes
Using Helm ....................................................................................................... 147
Summary ..................................................................................................... 149
Configuration and Storage Management in Kubernetes 151
Configuration Management ..................................................................... 152
Infrastructure Configurations ....................................................................... 152
Runtime Configurations ................................................................................. 152
Configuration Management in Kubernetes ............................................ 153
Creating a ConfigMap ..................................................................................... 155
Updating a ConfigMap ................................................................................... 158
Consuming ConfigMaps from a Pod ............................................................ 158
Exercise 16: Create ConfigMaps from a Literal and a File .......................... 160
Secret Management .................................................................................. 163
Secret Management Best Practices ......................................................... 164
Identifying Secrets .......................................................................................... 165
.d
evre Decoupling Secrets from the Source Code .................................................. 165
se
r sth Rotating Secrets .............................................................................................. 165
g
ir llA
.d Principle of Least Privilege ............................................................................ 166
e
tim
iL ,g Preventing Printing Out Secrets on Application Logs ................................ 166
n
ih
silb Encryption at Rest ........................................................................................... 166
u
P
tkca Secret Management in Kubernetes .............................................................. 166
P
.9
1
0
2 Creating a Secret ............................................................................................ 168
©
th
g
iryp Updating a Secret ............................................................................................ 171
o
C
Consuming Secrets from a Pod ..................................................................... 171
Yilmaz, Onur, and Suleyman Akbas. Introduction to DevOps with Kubernetes : Build Scalable Cloud-Native Applications Using DevOps Patterns Created with
Kubernetes, Packt Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5779693.
Created from nyulibrary-ebooks on 2022-10-16 18:50:04.
Exercise 17: Create and Update a Secret ..................................................... 173
Activity 6: Updating Configurations on the Fly ............................................ 175
Storage Management ................................................................................ 176
Storage Management in Kubernetes ...................................................... 177
Volume ............................................................................................................. 177
emptyDir .......................................................................................................... 177
gcePersistentDisk ........................................................................................... 178
glusterfs ........................................................................................................... 179
Exercise 18: Use emptyDir Volume to Share Content
Between Containers ...................................................................................... 180
Persistent Volume (PV) ................................................................................... 181
Persistent Volume Claim (PVC) ...................................................................... 182
Access Modes .................................................................................................. 183
Storage Class ................................................................................................... 183
Activity 7: Running a Persistent Database on Kubernetes ................... 185
Summary ..................................................................................................... 186
Updating and Scaling an Application in Kubernetes 189
Updating an Application ........................................................................... 190
Blue-Green Deployments ............................................................................... 190
.d
evre Rolling Updates ............................................................................................... 192
se
r sth Canary Releases .............................................................................................. 194
g
ir llA
.d Dark Launches and Feature Toggles ............................................................ 196
e
tim
iL ,g Software Update versus Software Upgrade ................................................ 197
n
ih
silb Updating an Application in Kubernetes .................................................. 197
u
P
tkca StatefulSet Update Strategies ....................................................................... 197
P
.9
1
0
2 OnDelete .......................................................................................................... 197
©
th
g
iryp RollingUpdate .................................................................................................. 198
o
C
Deployment Update Strategies ..................................................................... 199
Yilmaz, Onur, and Suleyman Akbas. Introduction to DevOps with Kubernetes : Build Scalable Cloud-Native Applications Using DevOps Patterns Created with
Kubernetes, Packt Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5779693.
Created from nyulibrary-ebooks on 2022-10-16 18:50:04.
Recreate ........................................................................................................... 199
RollingUpdate .................................................................................................. 200
Performing Blue-Green Deployment in Kubernetes .................................. 201
Performing Rolling Updates in Kubernetes ................................................. 203
maxSurge ......................................................................................................... 203
maxUnavailable ............................................................................................. 203
Updating a Deployment Using a Rolling Update ........................................ 205
Updating an Application using Helm ............................................................ 206
Exercise 19: Updating a Deployment in Kubernetes Using
a Rolling Update .............................................................................................. 207
Scaling an Application .................................................................................... 209
Horizontal versus Vertical Scaling ................................................................ 210
Autoscaling ...................................................................................................... 212
Strong versus Eventual Consistency ............................................................. 212
Scaling an Application in Kubernetes ...................................................... 213
Exercise 20: Scaling a Deployment Up and Down in Kubernetes ............. 215
Horizontal Pod Auto-Scaler (HPA) ................................................................. 218
Activity 8: Enabling Autoscaling and Performing a Rolling Update .......... 219
Summary ..................................................................................................... 220
.d Troubleshooting Applications in Kubernetes 223
e
vre
se
r sth Introduction ................................................................................................ 224
g
ir llA .d Troubleshooting ......................................................................................... 224
e
tim
iL ,g Identifying the Problem ................................................................................. 225
n
ih
silb Improving Tests ............................................................................................... 225
u
P
tkca Documentation ............................................................................................... 225
P
.9
1
0
2 Tools ................................................................................................................. 226
©
th
g
iryp Logging ............................................................................................................. 226
o
C
Logging levels .................................................................................................. 226
Yilmaz, Onur, and Suleyman Akbas. Introduction to DevOps with Kubernetes : Build Scalable Cloud-Native Applications Using DevOps Patterns Created with
Kubernetes, Packt Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5779693.
Created from nyulibrary-ebooks on 2022-10-16 18:50:04.
Troubleshooting Applications in Kubernetes ......................................... 227
Pod Life Cycle .................................................................................................. 228
Pod Status ........................................................................................................ 228
Pod Conditions ................................................................................................ 229
Condition Types .............................................................................................. 229
Pod Phase ........................................................................................................ 230
Restart Policy ................................................................................................... 231
Container States ............................................................................................. 231
Auto Recovery ................................................................................................. 232
Health checks .................................................................................................. 232
Liveness Probe ................................................................................................ 232
Readiness Probe .............................................................................................. 234
Exercise 21: Using Liveness and Readiness Probes in Kubernetes ........... 235
Creating a Termination Log ........................................................................... 237
Handy Commands for Troubleshooting ....................................................... 239
Other Handy Commands ............................................................................... 241
Action Commands ........................................................................................... 242
Suggestions for Some Common Problems .................................................. 242
Lack of Resources ........................................................................................... 242
.d Image Pull Failure ........................................................................................... 243
e
vre
ser sth Exercise 22: Fixing a Pod Failure in Kubernetes .......................................... 243
g
ir llA Ask the Community ........................................................................................ 248
.d
e
tim Activity 9: Troubleshooting an Application in Kubernetes ........................ 248
iL
,g
n
ih Summary ..................................................................................................... 250
silb
u
P
tkca Monitoring Applications in Kubernetes 253
P
.9
1
0
2
© Monitoring .................................................................................................. 254
th
g
irypo Infrastructure Monitoring .............................................................................. 255
C
Yilmaz, Onur, and Suleyman Akbas. Introduction to DevOps with Kubernetes : Build Scalable Cloud-Native Applications Using DevOps Patterns Created with
Kubernetes, Packt Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5779693.
Created from nyulibrary-ebooks on 2022-10-16 18:50:04.