Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Kubernetes Cookbook
Kubernetes Cookbook

Kubernetes Cookbook: Practical solutions to container orchestration , Second Edition

Arrow left icon
Profile Icon Hideto Saito Profile Icon Ke-Jou Carol Hsu Profile Icon Hui-Chuan Chloe Lee
Arrow right icon
$24.99 $35.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (12 Ratings)
eBook May 2018 554 pages 2nd Edition
eBook
$24.99 $35.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Hideto Saito Profile Icon Ke-Jou Carol Hsu Profile Icon Hui-Chuan Chloe Lee
Arrow right icon
$24.99 $35.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (12 Ratings)
eBook May 2018 554 pages 2nd Edition
eBook
$24.99 $35.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$24.99 $35.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Kubernetes Cookbook

Walking through Kubernetes Concepts

In this chapter, we will cover the following recipes:

  • Linking Pods and containers
  • Managing Pods with ReplicaSets
  • Deployment API
  • Working with Services
  • Working with Volumes
  • Working with Secrets
  • Working with names
  • Working with Namespaces
  • Working with labels and selectors

Introduction

In this chapter, we will start by creating different kinds of resources on the Kubernetes system. In order to realize your application in a microservices structure, reading the recipes in this chapter will be a good start towards understanding the concepts of the Kubernetes resources and consolidating them. After you deploy applications in Kubernetes, you can work on its scalable and efficient container management, and also fulfill the DevOps delivering procedure of microservices.

An overview of Kubernetes

Working with Kubernetes is quite easy, using either a Command Line Interface (CLI) or API (RESTful). This section will describe Kubernetes control by CLI. The CLI we use in this chapter is version 1.10.2.

After you install Kubernetes master, you can run a kubectl command as follows. It shows the kubectl and Kubernetes master versions (both the API Server and CLI are v1.10.2):

$ kubectl version --short
Client Version: v1.10.2
Server Version: v1.10.2

kubectl connects the Kubernetes API server using the RESTful API. By default, it attempts to access the localhost if .kube/config is not configured, otherwise you need to specify the API server address using the --server parameter. Therefore, it is recommended to use kubectl on the API server machine for practice.

If you use kubectl over the network, you need to consider authentication and authorization for...

Linking Pods and containers

The Pod is a group of one or more containers and the smallest deployable unit in Kubernetes. Pods are always co-located and co-scheduled, and run in a shared context. Each Pod is isolated by the following Linux namespaces:

  • The process ID (PID) namespace
  • The network namespace
  • The interprocess communication (IPC) namespace
  • The unix time sharing (UTS) namespace

In a pre-container world, they would have been executed on the same physical or virtual machine.

It is useful to construct your own application stack Pod (for example, web server and database) that are mixed by different Docker images.

Getting ready

You must have a Kubernetes cluster and make sure that the Kubernetes node has accessibility...

Managing Pods with ReplicaSets

A ReplicaSet is a term for API objects in Kubernetes that refer to Pod replicas. The idea is to be able to control a set of Pods' behaviors. The ReplicaSet ensures that the Pods, in the amount of a user-specified number, are running all the time. If some Pods in the ReplicaSet crash and terminate, the system will recreate Pods with the original configurations on healthy nodes automatically, and keep a certain number of processes continuously running. While changing the size of set, users can scale the application out or down easily. According to this feature, no matter whether you need replicas of Pods or not, you can always rely on ReplicaSet for auto-recovery and scalability. In this recipe, you're going to learn how to manage your Pods with ReplicaSet:

ReplicaSet and their Pods on two nodes

The ReplicaSet usually handles a tier of...

Deployment API

The Deployment API was introduced in Kubernetes version 1.2. It is replacing the replication controller. The functionalities of rolling-update and rollback by replication controller, it was achieved with client side (kubectl command and REST API), that kubectl need to keep connect while updating a replication controller. On the other hand, Deployments takes care of the process of rolling-update and rollback at the server side. Once that request is accepted, the client can disconnect immediately.

Therefore, the Deployments API is designed as a higher-level API to manage ReplicaSet objects. This section will explore how to use the Deployments API to manage ReplicaSets.

Getting ready

In order to create Deployment...

Working with Services

The network service is an application that receives requests and provides a solution. Clients access the service by a network connection. They don't have to know the architecture of the service or how it runs. The only thing that clients have to verify is whether the endpoint of the service can be accessed, and then follow its usage policy to get the response of the server. The Kubernetes Service has similar ideas. It is not necessary to understand every Pod before reaching their functionalities. For components outside the Kubernetes system, they just access the Kubernetes Service with an exposed network port to communicate with running Pods. It is not necessary to be aware of the containers' IPs and ports. Behind Kubernetes Services, we can fulfill a zero-downtime update for our container programs without struggling:

Kubernetes Service-covered...

Working with volumes

Files in a container are ephemeral. When the container is terminated, the files are gone. Docker has introduced data volumes to help us persist data (https://docs.docker.com/engine/admin/volumes/volumes). However, when it comes to multiple hosts, as a container cluster, it is hard to manage volumes across all the containers and hosts for file sharing or provisioning volume dynamically. Kubernetes introduces volume, which lives with a Pod across a container life cycle. It supports various types of volumes, including popular network disk solutions and storage services in different public clouds. Here are a few:

Volume type

Storage provider

emptyDir

Localhost

hostPath

Localhost

glusterfs

GlusterFS cluster

downwardAPI

Kubernetes Pod information

nfs

NFS server

awsElasticBlockStore

Amazon Web Service Amazon Elastic Block...

Working with Secrets

Kubernetes Secrets manage information in key-value formats with the value encoded. It can be a password, access key, or token. With Secrets, users don't have to expose sensitive data in the configuration file. Secrets can reduce the risk of credential leaks and make our resource configurations more organized.

Currently, there are three types of Secrets:

Generic/Opaque is the default type that we're using in our application. Docker registry is used to store the credential of a private Docker registry. TLS Secret is used to store the CA certificate bundle for cluster administration.

Kubernetes creates built-in Secrets for the credentials that using to access API server.

...

Working with names

When you create any Kubernetes object, such as a Pod, Deployment, and Service, you can assign a name to it. The names in Kubernetes are spatially unique, which means you cannot assign the same name in the Pods.

Getting ready

Kubernetes allows us to assign a name with the following restrictions:

  • Up to 253 characters
  • Lowercase of alphabet and numeric characters
  • May contain special characters in the middle, but only dashs (-) and dots (.)

How to do it...

For assigning a name to the Pod, follow the following steps:

  1. The following example is the...

Working with Namespaces

In a Kubernetes cluster, the name of a resource is a unique identifier within a Namespace. Using a Kubernetes Namespace could separate user spaces for different environments in the same cluster. It gives you the flexibility of creating an isolated environment and partitioning resources to different projects and teams. You may consider Namespace as a virtual cluster. Pods, Services, and Deployments are contained in a certain Namespace. Some low-level resources, such as nodes and persistentVolumes, do not belong to any Namespace.

Before we dig into the resource Namespace, let's understand kubeconfig and some keywords first:

The relationship of kubeconfig components

kubeconfig is used to call the file which configures the access permission of Kubernetes clusters. As the original configuration of the system, Kubernetes takes $HOME/.kube/config as a kubeconfig...

Working with labels and selectors

Labels are a set of key/value pairs, which are attached to object metadata. We could use labels to select, organize, and group objects, such as Pods, ReplicaSets, and Services. Labels are not necessarily unique. Objects could carry the same set of labels.

Label selectors are used to query objects with labels of the following types:

  • Equality-based:
    • Use equal (= or ==) or not-equal (!=) operators
  • Set-based:
    • Use in or notin operators

Getting ready

Before you get to setting labels in the objects, you should consider the valid naming convention of key and value.

A valid key should follow these rules:

  • A name with an optional prefix, separated by a slash.
  • A prefix must be...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Use containers to manage, scale and orchestrate apps in your organization
  • Transform the latest concept of Kubernetes 1.10 into examples
  • Expert techniques for orchestrating containers effectively

Description

Kubernetes is an open source orchestration platform to manage containers in a cluster environment. With Kubernetes, you can configure and deploy containerized applications easily. This book gives you a quick brush up on how Kubernetes works with containers, and an overview of main Kubernetes concepts, such as Pods, Deployments, Services and etc. This book explains how to create Kubernetes clusters and run applications with proper authentication and authorization configurations. With real-world recipes, you'll learn how to create high availability Kubernetes clusters on AWS, GCP and in on-premise datacenters with proper logging and monitoring setup. You'll also learn some useful tips about how to build a continuous delivery pipeline for your application. Upon completion of this book, you will be able to use Kubernetes in production and will have a better understanding of how to manage containers using Kubernetes.

Who is this book for?

This book is for system administrators, developers, DevOps engineers, or any stakeholder who wants to understand how Kubernetes works using a recipe-based approach. Basic knowledge of Kubernetes and Containers is required.

What you will learn

  • Build your own container cluster
  • Deploy and manage highly scalable, containerized applications with Kubernetes
  • Build high-availability Kubernetes clusters
  • Build a continuous delivery pipeline for your application
  • Track metrics and logs for every container running in your cluster
  • Streamline the way you deploy and manage your applications with large-scale container orchestration

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 30, 2018
Length: 554 pages
Edition : 2nd
Language : English
ISBN-13 : 9781788836876
Vendor :
Google
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : May 30, 2018
Length: 554 pages
Edition : 2nd
Language : English
ISBN-13 : 9781788836876
Vendor :
Google
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 141.97
Kubernetes Cookbook
$43.99
Mastering Kubernetes
$48.99
Kubernetes for Developers
$48.99
Total $ 141.97 Stars icon
Banner background image

Table of Contents

10 Chapters
Building Your Own Kubernetes Cluster Chevron down icon Chevron up icon
Walking through Kubernetes Concepts Chevron down icon Chevron up icon
Playing with Containers Chevron down icon Chevron up icon
Building High-Availability Clusters Chevron down icon Chevron up icon
Building Continuous Delivery Pipelines Chevron down icon Chevron up icon
Building Kubernetes on AWS Chevron down icon Chevron up icon
Building Kubernetes on GCP Chevron down icon Chevron up icon
Advanced Cluster Administration Chevron down icon Chevron up icon
Logging and Monitoring Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8
(12 Ratings)
5 star 58.3%
4 star 16.7%
3 star 0%
2 star 0%
1 star 25%
Filter icon Filter
Top Reviews

Filter reviews by




Kindleのお客様 Jun 24, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
まだ読み始めて少しですが、環境構築(Mac,Windows/miniKube, CentOS, Ubuntu)を含め解りやすい内容で書かれています。実行例が豊富で、Kubernetesの基礎的なことから学べます。Dockerについては詳しく説明はされていないので最低限の知識を持っていた方が理解しやすいと思います。CNIはFlannelで無く、Calicoで説明されているので、その辺りはこれから勉強です。英文がさほど苦でなければ、Kubernetesの入門には良い書籍に思われます。
Amazon Verified review Amazon
William Feb 04, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a great book to learn k8s.With its step by step guide to do anything k8s, anyone should be able to pick it up real quick.Thank you authors.
Amazon Verified review Amazon
fasthall Aug 16, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a well-written book. Very clear and easy to read. I'd recommend it to either a novice or a developer/user who is already familiar with Kubernetes.
Amazon Verified review Amazon
Amazon Customer Jul 14, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
An useful book to learn docker and kubernetes!
Amazon Verified review Amazon
Anon Jan 04, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I purchased this directly from the publisher; excellent k8 resource. I'm surprised there aren't more reviews as there aren't many kubernetes books out there and this one is excellent.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.