Pro Devops With Google Cloud Platform: With Docker, Jenkins, and Kubernetes
Pro Devops With Google Cloud Platform: With Docker, Jenkins, and Kubernetes
Cloud Platform
With Docker, Jenkins, and Kubernetes
Pierluigi Riti
Pro DevOps with Google Cloud Platform: With Docker, Jenkins, and Kubernetes
Pierluigi Riti
Mullingar, Westmeath, Ireland
Acknowledgments���������������������������������������������������������������������������������������������������xv
Introduction�����������������������������������������������������������������������������������������������������������xvii
v
Table of Contents
vi
Table of Contents
Chapter 4: C
ontainerization with Docker and Kubernetes������������������������������������� 63
Introduction to Docker���������������������������������������������������������������������������������������������������������������� 63
Why Use Docker?������������������������������������������������������������������������������������������������������������������ 65
Using Docker in Google Cloud Platform�������������������������������������������������������������������������������������� 66
Introduction to Google Compute Engine�������������������������������������������������������������������������������� 66
Creating a Compute Engine Instance������������������������������������������������������������������������������������ 67
Instance Group���������������������������������������������������������������������������������������������������������������������� 74
Container Application in Google Cloud Platform������������������������������������������������������������������������� 75
What Is Kubernetes?������������������������������������������������������������������������������������������������������������������� 79
Using Kubernetes Engine to Deploy an Application�������������������������������������������������������������������� 82
Deploying Our First Kubernetes App�������������������������������������������������������������������������������������� 85
Conclusion���������������������������������������������������������������������������������������������������������������������������������� 96
Chapter 5: C
ontinuous Delivery with GCP and Jenkins������������������������������������������ 99
An Introduction to Jenkins���������������������������������������������������������������������������������������������������������� 99
Continuous Integration and Delivery with Jenkins������������������������������������������������������������������� 100
Code������������������������������������������������������������������������������������������������������������������������������������ 101
Unit Test������������������������������������������������������������������������������������������������������������������������������� 101
Code Integration������������������������������������������������������������������������������������������������������������������ 101
System Testing�������������������������������������������������������������������������������������������������������������������� 102
Stage Release���������������������������������������������������������������������������������������������������������������������� 102
User Acceptance������������������������������������������������������������������������������������������������������������������ 102
Production Release�������������������������������������������������������������������������������������������������������������� 102
Designing a Good Branching Strategy�������������������������������������������������������������������������������������� 103
Using Jenkins in GCP���������������������������������������������������������������������������������������������������������������� 104
Configuring Jenkins on Kubernetes������������������������������������������������������������������������������������ 105
Designing the Jenkins Architecture������������������������������������������������������������������������������������� 110
Namespaces, Pods, Services, Quotas, and Deployments in Kubernetes����������������������������� 112
Create Jenkins Service�������������������������������������������������������������������������������������������������������� 117
Deploying Jenkins on Kubernetes��������������������������������������������������������������������������������������� 124
vii
Table of Contents
Chapter 6: M
icroservices Architecture with GCP������������������������������������������������� 147
Introduction to Microservices Architecture������������������������������������������������������������������������������� 147
Implementing a Microservices Architecture������������������������������������������������������������������������ 149
Microservices Architecture with Docker and Kubernetes��������������������������������������������������� 150
Creating the Microservices Architecture in GCP������������������������������������������������������������������ 154
Creating the Services���������������������������������������������������������������������������������������������������������������� 155
Publishing the Image in the Registry����������������������������������������������������������������������������������� 157
Creating the Kubernetes Cluster����������������������������������������������������������������������������������������������� 161
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 163
Chapter 7: M
onitoring in GCP������������������������������������������������������������������������������� 165
What Is a Monitoring System?�������������������������������������������������������������������������������������������������� 165
Factors Involved in the Monitoring System������������������������������������������������������������������������� 167
Why Monitoring Is Important����������������������������������������������������������������������������������������������� 169
White-Box and Black-Box Monitoring��������������������������������������������������������������������������������������� 171
Latency�������������������������������������������������������������������������������������������������������������������������������� 172
Traffic���������������������������������������������������������������������������������������������������������������������������������� 172
Error������������������������������������������������������������������������������������������������������������������������������������� 172
Saturation���������������������������������������������������������������������������������������������������������������������������� 172
Building a Monitoring System��������������������������������������������������������������������������������������������� 173
Configuring Stackdriver on GCP������������������������������������������������������������������������������������������������ 174
Creating the Application������������������������������������������������������������������������������������������������������ 178
Log Analysis with Stackdriver��������������������������������������������������������������������������������������������� 181
Alerts in Stackdriver������������������������������������������������������������������������������������������������������������ 183
Policy Alert Configuration���������������������������������������������������������������������������������������������������� 185
viii
Table of Contents
Chapter 8: C
reating and Managing Infrastructure in GCP������������������������������������ 191
Infrastructure As Code�������������������������������������������������������������������������������������������������������������� 191
Infrastructure as Code Principles���������������������������������������������������������������������������������������� 192
Architecture for Infrastructure As Code������������������������������������������������������������������������������� 194
Infrastructure As Code in Google Cloud Platform���������������������������������������������������������������������� 195
Configuration����������������������������������������������������������������������������������������������������������������������� 196
Templates���������������������������������������������������������������������������������������������������������������������������� 197
Resource����������������������������������������������������������������������������������������������������������������������������� 201
Types����������������������������������������������������������������������������������������������������������������������������������� 201
Manifest������������������������������������������������������������������������������������������������������������������������������� 201
Deployment������������������������������������������������������������������������������������������������������������������������� 204
Starting with Google Cloud Deployment Manager�������������������������������������������������������������������� 205
Upgrading Our Infrastructure���������������������������������������������������������������������������������������������������� 209
Expanding and Customizing Our Deployment��������������������������������������������������������������������� 212
Creating a Template for Our Deployment���������������������������������������������������������������������������� 216
Defining the Template with the Environment Variable��������������������������������������������������������� 219
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 222
ix
Table of Contents
Chapter 10: N
etwork Configuration and Management in GCP������������������������������ 245
Fundamentals of Networking in GCP���������������������������������������������������������������������������������������� 245
Introduction to the Virtual Private Cloud����������������������������������������������������������������������������������� 247
Network and Subnets���������������������������������������������������������������������������������������������������������� 249
Defining the IP Range for the Subnet���������������������������������������������������������������������������������� 250
Routes and Firewalls����������������������������������������������������������������������������������������������������������������� 252
Tagging Network����������������������������������������������������������������������������������������������������������������� 254
Implementing a VPC Network���������������������������������������������������������������������������������������������� 255
Creating and Maintaining Firewall Rules����������������������������������������������������������������������������� 262
Creating and Maintaining Routes in GCP���������������������������������������������������������������������������������� 265
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 269
Index��������������������������������������������������������������������������������������������������������������������� 271
x
About the Author
Pierluigi Riti has more than 20 years of extensive experience in the design and
development of different scale applications, particularly in the telecommunications
and financial industries. He is a freelance consultant, with specialization in DevOps,
the cloud, and security. He has quality-development skills in the latest technologies,
including Java, J2EE, C#, F#, .NET, Spring .NET, EF, WPF, WF, WinForm, WebAPI,
MVC, Nunit, Scala, Spring, JSP, EJB, Struts, Struts2, SOAP, REST, C, C++, Hibernate,
NHibernate, Weblogic, XML, XSLT, Unix script, Ruby, and Python. He is the author of
Practical Scala DSL, also published by Apress. He can be contacted via his LinkedIn
profile page at w ww.linkedin.com/in/pierluigi-riti/.
xi
About the Technical Reviewer
David Gonzalez is a DevOps engineer who has written
three books about DevOps and microservices. He works
as a consultant, helping large companies to advance
their systems development, by tweaking related software
processes and tools. David is also a Google Developer Expert
(https://developers.google.com/experts/people/david-
gonzalez-gonzalez) in Kubernetes (Google Container Engine)
and a member of the Node.js foundation, working on security
in third-party npm packages. In his free time, he enjoys cycling
and walking with his dogs in the green fields of Ireland.
xiii
Acknowledgments
My thanks go to David Gonzalez, for the amazing feedback he provided during the
technical review of the text. Another big thank you to Steve, Matthew, and Mark, for their
support and help in completing this book.
xv
Introduction
Cloud technology is increasingly present in our daily lives. The intent of this book is to
introduce Google Cloud Platform, of cloud computing services, with an eye to DevOps
practices.
DevOps is currently a hot commodity in the information technology (IT) field,
and every day, a new company begins to adopt its practice. The cloud is a natural
environment for DevOps, because in the cloud environment, such practices as
infrastructure as code and continuous delivery can be adopted more efficiently. Thus,
the cloud is the natural environment in which DevOps can grow and be increasingly
effective.
In 2003, Google created Site Reliability Engineering (SRE). This represented a new
approach to the continuous large-scale release of product features. SRE shares many
concepts with DevOps. I use Google Cloud Platform, because it is one of the most highly
recommended by Gartner, particularly its use in infrastructure development. As with
the Gartner Magic Quadrant, Google offers strong network management, and with
the integration of Kubernetes, it is ideal for developing container and infrastructure
solutions. By adding code, Google Cloud Platform offers a complete solution for creating
the deployment management for release of infrastructure. In addition, Google Cloud
Platform has one of the highest levels of application programming interface (API)
available in the cloud environment.
All the code in this book can be accessed from the related GitHub site. Please feel
free to read that code and alter it for your personal use.
xvii