Reader small image

You're reading from  DevOps with Kubernetes. - Second Edition

Product typeBook
Published inJan 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781789533996
Edition2nd Edition
Languages
Concepts
Right arrow
Authors (3):
Hideto Saito
Hideto Saito
author image
Hideto Saito

Hideto Saito has around 20 years of experience in the computer industry. In 1998, while working for Sun Microsystems Japan, he was impressed by Solaris OS, OPENSTEP, and Sun Ultra Enterprise 10000 (also known as StarFire). He then decided to pursue UNIX and macOS operating systems. In 2006, he relocated to southern California as a software engineer to develop products and services running on Linux and macOS X. He was especially renowned for his quick Objective-C code when he was drunk. He is also an enthusiast of Japanese anime, drama, and motorsports, and loves Japanese Otaku culture.
Read more about Hideto Saito

Hui-Chuan Chloe Lee
Hui-Chuan Chloe Lee
author image
Hui-Chuan Chloe Lee

Hui-Chuan Chloe Lee is a DevOps and software developer. She has worked in the software industry on a wide range of projects for over five years. As a technology enthusiast, she loves trying and learning about new technologies, which makes her life happier and more fulfilling. In her free time, she enjoys reading, traveling, and spending time with the people she love
Read more about Hui-Chuan Chloe Lee

Cheng-Yang Wu
Cheng-Yang Wu
author image
Cheng-Yang Wu

Cheng-Yang Wu has been tackling infrastructure and system reliability since he received his master's degree in computer science from National Taiwan University. His laziness prompted him to master DevOps skills to maximize his efficiency at work so as to squeeze in writing code for fun. He enjoys cooking as it's just like working with software a perfect dish always comes from balanced flavors and fine-tuned tastes.
Read more about Cheng-Yang Wu

View More author details
Right arrow

Cluster Administration and Extension

In previous chapters, we familiarized ourselves with basic DevOps skills and Kubernetes objects. This included looking at many areas, such as how to containerize our application and deploy our containerized software into Kubernetes. It is now time to gain a deeper insight into Kubernetes cluster administration.

In this chapter, we'll learn about the following topics:

  • Utilizing namespaces to set administrative boundaries
  • Using kubeconfig to switch between multiple clusters
  • Kubernetes authentication
  • Kubernetes authorization
  • Dynamic admission control
  • Kubernetes Custom Resources Definition (CRD) and controllers

While minikube is a fairly simple environment, we will use the Google Kubernetes Engine (GKE) in this chapter. For cluster deployment in GKE, please refer to Chapter 11, Kubernetes on GCP.

...

Kubernetes namespaces

We already learned about Kubernetes namespaces in Chapter 3, Getting Started with Kubernetes, which are used to divide the resources from a cluster into multiple virtual clusters. Namespaces make each group share the same physical cluster with isolation. Each namespace provides the following:

  • A scope of names; the object name in each namespace is unique
  • Policies to ensure trusted authentication
  • The ability to set up resource quotas for resource management

Now, let's learn how to use context to switch between different namespaces.

Context

Context is the concept of the combination of cluster information, a user for authentication, and a namespace. For example, the following is the context information...

Kubeconfig

Kubeconfig is a file that you can use to switch multiple clusters by switching context. We can use kubectl config view to view the setting and the kubectl config current-context command to check the context you're currently using. The following is an example of a GCP cluster in a kubeconfig file:

# kubectl config view
apiVersion: v1
clusters:  
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://35.0.0.200
name: gke_devops-with-kubernetes_us-central1-b_cluster
contexts:
- context:
cluster: gke_devops-with-kubernetes_us-central1-b_cluster
user: gke_devops-with-kubernetes_us-central1-b_cluster
name: gke_devops-with-kubernetes_us-central1-b_cluster
current-context: gke_devops-with-kubernetes_us-central1-b_cluster
kind: Config
preferences: {}
users:
- name: gke_devops-with-kubernetes_us-central1-b_cluster
user:
auth-provider:
config:
...

Service account

In Kubernetes, there are two kinds of user account: service account and user account. All the requests to the API server are sent either by a service account or a user account. Service accounts are managed by the Kubernetes API. In contrast, user accounts are not managed and stored in Kubernetes. The following is a simple comparison of service and user accounts:

Service account User account
Scope Namespaced Global
Used by Processes Normal user
Created by API server or via API calls Administrators, not by API calls
Managed by API server Outside the cluster

By default, a Kubernetes cluster creates different service accounts for different purposes. In GKE, there are a bunch of service accounts that have been created:

// list service account across all namespaces
# kubectl get serviceaccount --all-namespaces
NAMESPACE     NAME                      ...

Authentication and authorization

Authentication and authorization are important components in Kubernetes. Authentication verifies users and checks that the user is who they claim to be. Authorization, on the other hand, checks what permission levels users have. Kubernetes supports different authentication and authorization modules.

The following is an illustration that shows how the Kubernetes API server processes access control when it receives a request:

Access control in the Kubernetes API server

When the request goes to the API server, first it establishes a TLS connection by validating the clients' certificate with the Certificate Authority (CA) in the API server. The CA in the API server is usually at /etc/kubernetes/, and the clients' certificate is usually at $HOME/.kube/config. After the handshake, it moves into the authentication stage. In Kubernetes, authentication...

Admission control

Admission control takes place before Kubernetes processes the request and after authentication and authorization is passed. It's enabled when launching an API server by adding the --admission-control parameter. Kubernetes recommends having the following plugins within the cluster if the cluster version is greater than or equal to 1.10.0:

--enable-admission-plugins=NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota

The following sections introduce these plugins and why we need them. For the latest information about supported admission control plugins, please visit the official documentation: https://kubernetes.io/docs/admin/admission-controllers.

NamespaceLifecycle...

Custom resources

Custom resources, which were first introduced in Kubernetes 1.7, were designed as an extension point to let users create custom API objects and act as native Kubernetes objects. This was done so that users could extend Kubernetes to support the custom objects for their application or specific use cases. Custom resources can be dynamically registered and unregistered. There are two ways to create custom resources: by using a CRD or aggregated API. CRDs are much easier, while an aggregated API requires additional coding in Go. In this section, we'll learn how to write a CRD from scratch.

Custom resources definition

Creating a Custom Resources Definition (CRD) object includes two steps: CRD registration...

Summary

In this chapter, we learned about what namespace and context are, including how they work, and a how to switch between a physical cluster and virtual cluster by setting the context. We then learned about an important object—service account, which provides the ability to identify processes that are running within a pod. Then, we familiarized ourselves with how to control access flow in Kubernetes. We learned what the difference is between authentication and authorization, and how these work in Kubernetes. We also learned how to leverage RBAC to have fine-grained permission for users. In addition, we looked at a couple of admission controller plugins and dynamic admission controls, which are the last goalkeepers in the access control flow. Finally, we learned about what the CRD is and implemented it and its controller via the operator SDK (https://github.com/operator...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
DevOps with Kubernetes. - Second Edition
Published in: Jan 2019Publisher: PacktISBN-13: 9781789533996
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (3)

author image
Hideto Saito

Hideto Saito has around 20 years of experience in the computer industry. In 1998, while working for Sun Microsystems Japan, he was impressed by Solaris OS, OPENSTEP, and Sun Ultra Enterprise 10000 (also known as StarFire). He then decided to pursue UNIX and macOS operating systems. In 2006, he relocated to southern California as a software engineer to develop products and services running on Linux and macOS X. He was especially renowned for his quick Objective-C code when he was drunk. He is also an enthusiast of Japanese anime, drama, and motorsports, and loves Japanese Otaku culture.
Read more about Hideto Saito

author image
Hui-Chuan Chloe Lee

Hui-Chuan Chloe Lee is a DevOps and software developer. She has worked in the software industry on a wide range of projects for over five years. As a technology enthusiast, she loves trying and learning about new technologies, which makes her life happier and more fulfilling. In her free time, she enjoys reading, traveling, and spending time with the people she love
Read more about Hui-Chuan Chloe Lee

author image
Cheng-Yang Wu

Cheng-Yang Wu has been tackling infrastructure and system reliability since he received his master's degree in computer science from National Taiwan University. His laziness prompted him to master DevOps skills to maximize his efficiency at work so as to squeeze in writing code for fun. He enjoys cooking as it's just like working with software a perfect dish always comes from balanced flavors and fine-tuned tastes.
Read more about Cheng-Yang Wu