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
Conferences
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
€18.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (12 Ratings)
Paperback May 2018 554 pages 2nd Edition
eBook
€8.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Hideto Saito Profile Icon Ke-Jou Carol Hsu Profile Icon Hui-Chuan Chloe Lee
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (12 Ratings)
Paperback May 2018 554 pages 2nd Edition
eBook
€8.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781788837606
Vendor :
Google
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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
€264.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 106.97
Kubernetes Cookbook
€32.99
Mastering Kubernetes
€36.99
Kubernetes for Developers
€36.99
Total 106.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.