Preface

Welcome to Kubernetes Cookbook, and thanks for choosing it! With this book, we want to help you solve concrete problems around Kubernetes. We’ve compiled over 80 recipes covering topics such as setting up a cluster, managing containerized workloads using Kubernetes API objects, using storage primitives, security configurations, and extending Kubernetes itself. Whether you are very new to Kubernetes or have been using it for a while, we hope that you’ll find something useful here to improve your experience and use of Kubernetes.

Who Should Read This Book

You’re a developer going cloud-native, or a sysadmin, or maybe you’ve even found yourself in one of the newfangled DevOps roles? This book will help you navigate your way successfully through the Kubernetes jungle, from development to production. These recipes are not organized in a linear progression of the basic Kubernetes concepts; however, each chapter contains recipes that utilize core Kubernetes concepts and API primitives.

Why We Wrote This Book

Both of us have been using and contributing to Kubernetes for a few years and have seen the many issues beginners and even more advanced users run into. We wanted to share the knowledge we’ve gathered running Kubernetes in production, as well as developing on and in Kubernetes—i.e., contributing to the core codebase or the ecosystem and writing applications that run on Kubernetes.

Navigating This Book

This cookbook contains 14 chapters. Each chapter is composed of recipes written in the standard O’Reilly recipe format (Problem, Solution, Discussion). You can read this book from front to back or skip to a specific chapter or recipe. Each recipe is independent of the others, and when an understanding of concepts from other recipes are needed, appropriate references are provided. The index is also an extremely powerful resource because sometimes a recipe is also showcasing a specific command and the index highlights these connections.

A Note on Kubernetes Releases

At the time of writing, Kubernetes 1.7 was the latest stable version, released at the end of June 2017, and this is the version we’re using throughout the book as the baseline.1 However, the solutions presented here should, in general, work for older releases, at least down to Kubernetes 1.4; we will call it out explicitly if this is not the case, mentioning the minimum required version.

The Kubernetes release cadence as of 2017 is such that every quarter a new (minor or dot) release is cut; for example, 1.6 was released in March, 1.7 in June, 1.8 in September, and 1.9 in December, as this book was entering production. The Kubernetes release versioning guidelines indicate that you can expect support for a feature for three minor releases at a time.2 This means that the stable API objects in the 1.7 release will be supported until at least March 2018. However, because the recipes in this book most often only use stable APIs, if you use a newer Kubernetes release, the recipes should still work.

Technology You Need to Understand

This intermediate-level book requires a minimal understanding of a few development and system administration concepts. Before diving into the book, you might want to review the following:

bash (Unix shell)

This is the default Unix shell on Linux and macOS. Familiarity with the Unix shell, such as for editing files, setting file permissions and user priveleges, moving files around the filesystem, and doing some basic shell programming, will be beneficial. For a general introduction, consult books such as Cameron Newham’s Learning the bash Shell or JP Vossen and Carl Albing’s bash Cookbook, both from O’Reilly.

Package management

The tools in this book often have multiple dependencies that need to be met by installing some packages. Knowledge of the package management system on your machine is therefore required. It could be apt on Ubuntu/Debian systems, yum on CentOS/RHEL systems, or port or brew on macOS. Whatever it is, make sure that you know how to install, upgrade, and remove packages.

Git

Git has established itself as the standard for distributed version control. If you are already familiar with CVS and SVN but have not yet used Git, you should. Version Control with Git by Jon Loeliger and Matthew McCullough (O’Reilly) is a good place to start. Together with Git, the GitHub website is a great resource to get started with a hosted repository of your own. To learn about GitHub, check out http://training.github.com and the associated interactive tutorial.

Python

In addition to programming with C/C++ or Java, we always encourage students to pick up a scripting language of their choice. Perl used to rule the world, while these days, Ruby and Go seem to be prevalent. Most examples in this book use Python, but there are a few examples with Ruby, and one even uses Clojure. O’Reilly offers an extensive collection of books on Python, including Introducing Python by Bill Lubanovic, Programming Python by Mark Lutz, and Python Cookbook by David Beazley and Brian K. Jones.

Go

Kubernetes is written in Go. Over the last couple of years, Go has established itself as the new programming language of choice in many startups and for many systems-related open source projects. This cookbook is not about Go programming, but it shows how to compile a few Go projects. Some minimal understanding of how to set up a Go workspace will be handy. If you want to know more, a good place to start is the O’Reilly video training course “Introduction to Go Programming”.

Online Resources

Kubernetes manifests, code examples, and other scripts used in this book are available on GitHub. You can clone this repository, go to the relevant chapter and recipe, and use the code as is:

$ git clone https://github.com/k8s-cookbook/recipes
Note

The examples in this repo are not meant to represent optimized setups to be used in production. They give you the basic minimum required to run the examples in the recipes.

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 elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Also used for commands and command-line output.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.

Tip

This element signifies a tip or suggestion.

Note

This element signifies a general note.

Warning

This element indicates a warning or caution.

Using Code Examples

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 a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Kubernetes Cookbook by Sébastien Goasguen and Michael Hausenblas (O’Reilly). Copyright 2018 Sébastien Goasguen and Michael Hausenblas, 978-1-491-97968-6.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

O’Reilly Safari

Note

Safari (formerly Safari Books Online) is a membership-based training and reference platform for enterprise, government, educators, and individuals.

Members have access to thousands of books, training videos, Learning Paths, interactive tutorials, and curated playlists from over 250 publishers, including O’Reilly Media, Harvard Business Review, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Adobe, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, and Course Technology, among others.

For more information, please visit http://oreilly.com/safari.

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 http://bit.ly/kubernetes-cookbook.

To comment or ask technical questions about this book, send email to .

For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

Acknowledgments

Thank you to the entire Kubernetes community for developing such amazing software and for being a great bunch of people—open, kind, and always ready to help.

Writing this book turned out to be a much longer project than it should have been, but it is now finished and we are thankful to all the people who helped us. We are particularly in debt to the thorough reviews from Ihor Dvoretski, Liz Rice, and Ben Hall, who helped fix a good number of issues and suggested better organization and recipes that will help all readers.

Get Kubernetes Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.