SlideShare a Scribd company logo
Kubernetes tutorial
Kubernetes
i
AbouttheTutorial
Kubernetes is a container management technology developed in Google lab to manage
containerized applications in different kind of environments such as physical, virtual, and
cloud infrastructure. It is an open source system which helps in creating and managing
containerization of application.
This tutorial provides an overview of different kind of features and functionalities of
Kubernetes and teaches how to manage the containerized infrastructure and application
deployment.
Audience
This tutorial has been prepared for those who want to understand the containerized
infrastructure and deployment of application on containers. This tutorial will help in
understanding the concepts of container management using Kubernetes.
Prerequisites
We assume anyone who wants to understand Kubernetes should have an understating of
how the Docker works, how the Docker images are created, and how they work as a
standalone unit. To reach to an advanced configuration in Kubernetes one should
understand basic networking and how the protocol communication works.
Copyright&Disclaimer
 Copyright 2018 by Tutorials Point (I) Pvt. Ltd.
All the content and graphics published in this e-book are the property of Tutorials Point (I)
Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish
any contents or a part of contents of this e-book in any manner without written consent
of the publisher.
We strive to update the contents of our website and tutorials as timely and as precisely as
possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.
Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our
website or its contents including this tutorial. If you discover any errors on our website or
in this tutorial, please notify us at contact@tutorialspoint.com
Kubernetes
ii
TableofContents
About the Tutorial ..........................................................................................................................................i
Audience.........................................................................................................................................................i
Prerequisites...................................................................................................................................................i
Copyright & Disclaimer...................................................................................................................................i
Table of Contents........................................................................................................................................... ii
BASIC KUBERNETES.....................................................................................................................1
1. Kubernetes ─ Overview...........................................................................................................................2
2. Kubernetes ─ Architecture ......................................................................................................................3
Kubernetes ─ Cluster Architecture ................................................................................................................3
Kubernetes ─ Master Machine Components.................................................................................................3
Kubernetes ─ Node Components...................................................................................................................4
Kubernetes ─..................................................................................................................................................5
Master and Node Structure...........................................................................................................................5
3. Kubernetes ─ Setup.................................................................................................................................6
Prerequisites..................................................................................................................................................6
Install Docker Engine .....................................................................................................................................7
Install etcd 2.0 ...............................................................................................................................................7
Configure kube-apiserver ..............................................................................................................................9
Configure the kube Controller Manager........................................................................................................9
Kubernetes Node Configuration..................................................................................................................10
4. Kubernetes ─ Images.............................................................................................................................12
5. Kubernetes ─ Jobs .................................................................................................................................14
Creating a Job ..............................................................................................................................................14
Scheduled Job..............................................................................................................................................15
6. Kubernetes ─ Labels & Selectors ...........................................................................................................17
Labels...........................................................................................................................................................17
Selectors ......................................................................................................................................................17
7. Kubernetes ─ Namespace......................................................................................................................19
8. Kubernetes ─ Nodes..............................................................................................................................21
9. Kubernetes ─ Service.............................................................................................................................23
10. Kubernetes ─ Pod..................................................................................................................................26
Types of Pod ................................................................................................................................................26
11. Kubernetes ─ Replication Controller......................................................................................................28
12. Kubernetes – Replica Sets .....................................................................................................................30
Kubernetes
iii
13. Kubernetes – Deployments ...................................................................................................................32
14. Kubernetes – Volumes ..........................................................................................................................34
Persistent Volume and Persistent Volume Claim ........................................................................................35
15. Kubernetes ─ Secrets.............................................................................................................................39
Using Secrets ...............................................................................................................................................40
16. Kubernetes ─ Network Policy ................................................................................................................43
ADVANCED KUBERNETES..........................................................................................................45
17. Kubernetes ─ API...................................................................................................................................46
Adding API to Kubernetes............................................................................................................................46
API Changes .................................................................................................................................................46
API Versioning..............................................................................................................................................47
18. Kubernetes – Kubectl ............................................................................................................................48
Setting Kubectl.............................................................................................................................................48
Configuring Kubectl .....................................................................................................................................48
Verifying the Setup ......................................................................................................................................49
19. Kubernetes – Kubectl Commands..........................................................................................................50
20. Kubernetes – Creating an App...............................................................................................................58
21. Kubernetes – App Deployment .............................................................................................................61
22. Kubernetes ─ Autoscaling......................................................................................................................67
23. Kubernetes ─ Dashboard Setup.............................................................................................................69
24. Kubernetes ─ Monitoring ......................................................................................................................74
Kubernetes
1
Basic Kubernetes
Kubernetes
2
Kubernetes in an open source container management tool hosted by Cloud Native
Computing Foundation (CNCF). This is also known as the enhanced version of Borg which
was developed at Google to manage both long running processes and batch jobs, which
was earlier handled by separate systems.
Kubernetes comes with a capability of automating deployment, scaling of application, and
operations of application containers across clusters. It is capable of creating container
centric infrastructure.
Features of Kubernetes
Following are some of the important features of Kubernetes.
 Continues development, integration and deployment
 Containerized infrastructure
 Application-centric management
 Auto-scalable infrastructure
 Environment consistency across development testing and production
 Loosely coupled infrastructure, where each component can act as a separate unit
 Higher density of resource utilization
 Predictable infrastructure which is going to be created
One of the key components of Kubernetes is, it can run application on clusters of physical
and virtual machine infrastructure. It also has the capability to run applications on cloud.
It helps in moving from host-centric infrastructure to container-centric
infrastructure.
1. Kubernetes ─ Overview
Kubernetes
3
In this chapter, we will discuss the basic architecture of Kubernetes.
Kubernetes─ClusterArchitecture
As seen in the following diagram, Kubernetes follows client-server architecture. Wherein,
we have master installed on one machine and the node on separate Linux machines.
The key components of master and node are defined in the following section.
Kubernetes─MasterMachineComponents
Following are the components of Kubernetes Master Machine.
etcd
It stores the configuration information which can be used by each of the nodes in the
cluster. It is a high availability key value store that can be distributed among multiple
nodes. It is accessible only by Kubernetes API server as it may have some sensitive
information. It is a distributed key value Store which is accessible to all.
API Server
Kubernetes is an API server which provides all the operation on cluster using the API. API
server implements an interface, which means different tools and libraries can readily
2. Kubernetes ─ Architecture
Kubernetes
4
communicate with it. Kubeconfig is a package along with the server side tools that can
be used for communication. It exposes Kubernetes API.
Controller Manager
This component is responsible for most of the collectors that regulates the state of cluster
and performs a task. In general, it can be considered as a daemon which runs in non-
terminating loop and is responsible for collecting and sending information to API server. It
works toward getting the shared state of cluster and then make changes to bring the
current status of the server to the desired state. The key controllers are replication
controller, endpoint controller, namespace controller, and service account controller. The
controller manager runs different kind of controllers to handle nodes, endpoints, etc.
Scheduler
This is one of the key components of Kubernetes master. It is a service in master
responsible for distributing the workload. It is responsible for tracking utilization of working
load on cluster nodes and then placing the workload on which resources are available and
accept the workload. In other words, this is the mechanism responsible for allocating pods
to available nodes. The scheduler is responsible for workload utilization and allocating pod
to new node.
Kubernetes─NodeComponents
Following are the key components of Node server which are necessary to communicate
with Kubernetes master.
Docker
The first requirement of each node is Docker which helps in running the encapsulated
application containers in a relatively isolated but lightweight operating environment.
Kubelet Service
This is a small service in each node responsible for relaying information to and from control
plane service. It interacts with etcd store to read configuration details and wright values.
This communicates with the master component to receive commands and work. The
kubelet process then assumes responsibility for maintaining the state of work and the
node server. It manages network rules, port forwarding, etc.
Kubernetes Proxy Service
This is a proxy service which runs on each node and helps in making services available to
the external host. It helps in forwarding the request to correct containers and is capable
of performing primitive load balancing. It makes sure that the networking environment is
predictable and accessible and at the same time it is isolated as well. It manages pods on
node, volumes, secrets, creating new containers’ health checkup, etc.
Kubernetes
5
Kubernetes─MasterandNodeStructure
The following illustrations show the structure of Kubernetes Master and Node.
Kubernetes
6
It is important to set up the Virtual Datacenter (vDC) before setting up Kubernetes. This
can be considered as a set of machines where they can communicate with each other via
the network. For hands-on approach, you can set up vDC on PROFITBRICKS if you do
not have a physical or cloud infrastructure set up.
Once the IaaS setup on any cloud is complete, you need to configure the Master and the
Node.
Note: The setup is shown for Ubuntu machines. The same can be set up on other Linux
machines as well.
Prerequisites
Installing Docker: Docker is required on all the instances of Kubernetes. Following are
the steps to install the Docker.
Step 1: Log on to the machine with the root user account.
Step 2: Update the package information. Make sure that the apt package is working.
Step 3: Run the following commands.
$ sudo apt-get update
$sudo apt-get install apt-transport-https ca-certificates
Step 4: Add the new GPG key.
$ sudo apt-key adv 
--keyserver hkp://ha.pool.sks-keyservers.net:80 
--recv-keys 58118E89F3A912897C070ADBF76221572C52609D
$ echo "https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee
/etc/apt/sources.list.d/docker.list
Step 5: Update the API package image.
$ sudo apt-get update
Once all the above tasks are complete, you can start with the actual installation of the
Docker engine. However, before this you need to verify that the kernel version you are
using is correct.
3. Kubernetes ─ Setup
Kubernetes
7
InstallDockerEngine
Run the following commands to install the Docker engine.
Step 1: Logon to the machine.
Step 2: Update the package index.
$ sudo apt-get update
Step 3: Install the Docker Engine using the following command.
$ sudo apt-get install docker-engine
Step 4: Start the Docker daemon.
$ sudo apt-get install docker-engine
Step 5: To very if the Docker is installed, use the following command.
$ sudo docker run hello-world
Installetcd2.0
This needs to be installed on Kubernetes Master Machine. In order to install it, run the
following commands.
$ curl -L https://github.com/coreos/etcd/releases/download/v2.0.0/etcd
-v2.0.0-linux-amd64.tar.gz -o etcd-v2.0.0-linux-amd64.tar.gz ->1
$ tar xzvf etcd-v2.0.0-linux-amd64.tar.gz ------> 2
$ cd etcd-v2.0.0-linux-amd64 ------------>3
$ mkdir /opt/bin ------------->4
$ cp etcd* /opt/bin ----------->5
In the above set of command:
 First, we download the etcd. Save this with specified name.
 Then, we have to un-tar the tar package.
 We make a dir. inside the /opt named bin.
 Copy the extracted file to the target location.
Kubernetes
8
Now we are ready to build Kubernetes. We need to install Kubernetes on all the machines
on the cluster.
$ git clone https://github.com/GoogleCloudPlatform/kubernetes.git
$ cd kubernetes
$ make release
The above command will create a _output dir in the root of the kubernetes folder. Next,
we can extract the directory into any of the directory of our choice /opt/bin, etc.
Next, comes the networking part wherein we need to actually start with the setup of
Kubernetes master and node. In order to do this, we will make an entry in the host file
which can be done on the node machine.
$ echo "<IP address of master machine> kube-master
< IP address of Node Machine>" >> /etc/hosts
Following will be the output of the above command.
Now, we will start with the actual configuration on Kubernetes Master.
First, we will start copying all the configuration files to their correct location.
$ cp <Current dir. location>/kube-apiserver /opt/bin/
$ cp <Current dir. location>/kube-controller-manager /opt/bin/
$ cp <Current dir. location>/kube-kube-scheduler /opt/bin/
$ cp <Current dir. location>/kubecfg /opt/bin/
$ cp <Current dir. location>/kubectl /opt/bin/
$ cp <Current dir. location>/kubernetes /opt/bin/
The above command will copy all the configuration files to the required location. Now we
will come back to the same directory where we have built the Kubernetes folder.
Kubernetes
9
$ cp kubernetes/cluster/ubuntu/init_conf/kube-apiserver.conf /etc/init/
$ cp kubernetes/cluster/ubuntu/init_conf/kube-controller-manager.conf
/etc/init/
$ cp kubernetes/cluster/ubuntu/init_conf/kube-kube-scheduler.conf /etc/init/
$ cp kubernetes/cluster/ubuntu/initd_scripts/kube-apiserver /etc/init.d/
$ cp kubernetes/cluster/ubuntu/initd_scripts/kube-controller-manager
/etc/init.d/
$ cp kubernetes/cluster/ubuntu/initd_scripts/kube-kube-scheduler /etc/init.d/
$ cp kubernetes/cluster/ubuntu/default_scripts/kubelet /etc/default/
$ cp kubernetes/cluster/ubuntu/default_scripts/kube-proxy /etc/default/
$ cp kubernetes/cluster/ubuntu/default_scripts/kubelet /etc/default/
The next step is to update the copied configuration file under /etc. dir.
Configure etcd on master using the following command.
$ ETCD_OPTS="-listen-client-urls=http://kube-master:4001"
Configurekube-apiserver
For this on the master, we need to edit the /etc/default/kube-apiserver file which we
copied earlier.
$ KUBE_APISERVER_OPTS="--address=0.0.0.0 
--port=8080 
--etcd_servers=<The path that is configured in ETCD_OPTS> 
--portal_net=11.1.1.0/24 
--allow_privileged=false 
--kubelet_port= < Port you want to configure> 
--v=0"
ConfigurethekubeControllerManager
We need to add the following content in /etc/default/kube-controller-manager.
$ KUBE_CONTROLLER_MANAGER_OPTS="--address=0.0.0.0 
--master=127.0.0.1:8080 
--machines=kube-minion  -----> #this is the kubernatics node
Kubernetes
10
--v=0
Next, configure the kube scheduler in the corresponding file.
$ KUBE_SCHEDULER_OPTS="--address=0.0.0.0 
--master=127.0.0.1:8080 
--v=0"
Once all the above tasks are complete, we are good to go ahead by bring up the
Kubernetes Master. In order to do this, we will restart the Docker.
$ service docker restart
KubernetesNodeConfiguration
Kubernetes node will run two services the kubelet and the kube-proxy. Before moving
ahead, we need to copy the binaries we downloaded to their required folders where we
want to configure the kubernetes node.
Use the same method of copying the files that we did for kubernetes master. As it will only
run the kubelet and the kube-proxy, we will configure them.
$ cp <Path of the extracted file>/kubelet /opt/bin/
$ cp <Path of the extracted file>/kube-proxy /opt/bin/
$ cp <Path of the extracted file>/kubecfg /opt/bin/
$ cp <Path of the extracted file>/kubectl /opt/bin/
$ cp <Path of the extracted file>/kubernetes /opt/bin/
Now, we will copy the content to the appropriate dir.
$ cp kubernetes/cluster/ubuntu/init_conf/kubelet.conf /etc/init/
$ cp kubernetes/cluster/ubuntu/init_conf/kube-proxy.conf /etc/init/
$ cp kubernetes/cluster/ubuntu/initd_scripts/kubelet /etc/init.d/
$ cp kubernetes/cluster/ubuntu/initd_scripts/kube-proxy /etc/init.d/
$ cp kubernetes/cluster/ubuntu/default_scripts/kubelet /etc/default/
$ cp kubernetes/cluster/ubuntu/default_scripts/kube-proxy /etc/default/
Kubernetes
11
End of ebook preview
If you liked what you saw…
Buy it from our store @ https://store.tutorialspoint.com

More Related Content

PDF
Docker tutorial
PDF
Eclipse tutorial
PDF
Jqueryui tutorial
PDF
Javascript tutorial
PDF
Chef tutorial
PDF
Nodejs tutorial
PDF
Gwt tutorial
PDF
Scrapy tutorial
Docker tutorial
Eclipse tutorial
Jqueryui tutorial
Javascript tutorial
Chef tutorial
Nodejs tutorial
Gwt tutorial
Scrapy tutorial

Similar to Kubernetes tutorial (20)

DOCX
Mastering Kubernetes_ The Ultimate Guide for Modern DevOps.docx
PPTX
Introduction: Basic About Kubernetes Cluster
PDF
Nugwc k8s session-16-march-2021
PDF
Getting started with kubernetes
PDF
A Deeper Look Into How Kubernetes Works.pdf
PDF
Best online kubernetes course in H2KInfosys.pdf
PDF
Kubernetes Learning Path_Version 2.0.pdf
PDF
What is kubernet
PPTX
Kubernetes: A Top Notch Automation Solution
PPTX
Getting started with k8
PPTX
Docker and Kubernetes Training | Kubernetes Online Training
PDF
Using kubernetes to lose your fear of using containers
PPTX
TRAINING_ABOUT_KUBERNETES_Nguyen_Si_Nhan.pptx
PDF
stupid-simple-kubernetes-final.pdf
PPTX
Kubernetes for Beginners: An Introductory Guide
PDF
How to set up Kubernetes for all your machine learning workflows
PPTX
01. Kubernetes-PPT.pptx
PDF
One Kubernetes to rule them all (ZEUS 2019 Keynote)
PDF
Kubernetes Basics - ICP Workshop Batch II
PPTX
K8s in 3h - Kubernetes Fundamentals Training
Mastering Kubernetes_ The Ultimate Guide for Modern DevOps.docx
Introduction: Basic About Kubernetes Cluster
Nugwc k8s session-16-march-2021
Getting started with kubernetes
A Deeper Look Into How Kubernetes Works.pdf
Best online kubernetes course in H2KInfosys.pdf
Kubernetes Learning Path_Version 2.0.pdf
What is kubernet
Kubernetes: A Top Notch Automation Solution
Getting started with k8
Docker and Kubernetes Training | Kubernetes Online Training
Using kubernetes to lose your fear of using containers
TRAINING_ABOUT_KUBERNETES_Nguyen_Si_Nhan.pptx
stupid-simple-kubernetes-final.pdf
Kubernetes for Beginners: An Introductory Guide
How to set up Kubernetes for all your machine learning workflows
01. Kubernetes-PPT.pptx
One Kubernetes to rule them all (ZEUS 2019 Keynote)
Kubernetes Basics - ICP Workshop Batch II
K8s in 3h - Kubernetes Fundamentals Training
Ad

More from HarikaReddy115 (20)

PDF
Dbms tutorial
PDF
Data structures algorithms_tutorial
PDF
Wireless communication tutorial
PDF
Cryptography tutorial
PDF
Cosmology tutorial
PDF
Control systems tutorial
PDF
Computer logical organization_tutorial
PDF
Computer fundamentals tutorial
PDF
Compiler design tutorial
PDF
Communication technologies tutorial
PDF
Biometrics tutorial
PDF
Behavior driven development_tutorial
PDF
Basics of computers_tutorial
PDF
Basics of computer_science_tutorial
PDF
Basic electronics tutorial
PDF
Auditing tutorial
PDF
Artificial neural network_tutorial
PDF
Artificial intelligence tutorial
PDF
Antenna theory tutorial
PDF
Analog communication tutorial
Dbms tutorial
Data structures algorithms_tutorial
Wireless communication tutorial
Cryptography tutorial
Cosmology tutorial
Control systems tutorial
Computer logical organization_tutorial
Computer fundamentals tutorial
Compiler design tutorial
Communication technologies tutorial
Biometrics tutorial
Behavior driven development_tutorial
Basics of computers_tutorial
Basics of computer_science_tutorial
Basic electronics tutorial
Auditing tutorial
Artificial neural network_tutorial
Artificial intelligence tutorial
Antenna theory tutorial
Analog communication tutorial
Ad

Recently uploaded (20)

PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Pharma ospi slides which help in ospi learning
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Pre independence Education in Inndia.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
Business Ethics Teaching Materials for college
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
Microbial diseases, their pathogenesis and prophylaxis
VCE English Exam - Section C Student Revision Booklet
TR - Agricultural Crops Production NC III.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Insiders guide to clinical Medicine.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPH.pptx obstetrics and gynecology in nursing
Pharma ospi slides which help in ospi learning
STATICS OF THE RIGID BODIES Hibbelers.pdf
Cell Types and Its function , kingdom of life
102 student loan defaulters named and shamed – Is someone you know on the list?
Pre independence Education in Inndia.pdf
Cell Structure & Organelles in detailed.
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Business Ethics Teaching Materials for college
Abdominal Access Techniques with Prof. Dr. R K Mishra
Supply Chain Operations Speaking Notes -ICLT Program
Week 4 Term 3 Study Techniques revisited.pptx
O5-L3 Freight Transport Ops (International) V1.pdf

Kubernetes tutorial

  • 2. Kubernetes i AbouttheTutorial Kubernetes is a container management technology developed in Google lab to manage containerized applications in different kind of environments such as physical, virtual, and cloud infrastructure. It is an open source system which helps in creating and managing containerization of application. This tutorial provides an overview of different kind of features and functionalities of Kubernetes and teaches how to manage the containerized infrastructure and application deployment. Audience This tutorial has been prepared for those who want to understand the containerized infrastructure and deployment of application on containers. This tutorial will help in understanding the concepts of container management using Kubernetes. Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images are created, and how they work as a standalone unit. To reach to an advanced configuration in Kubernetes one should understand basic networking and how the protocol communication works. Copyright&Disclaimer  Copyright 2018 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at contact@tutorialspoint.com
  • 3. Kubernetes ii TableofContents About the Tutorial ..........................................................................................................................................i Audience.........................................................................................................................................................i Prerequisites...................................................................................................................................................i Copyright & Disclaimer...................................................................................................................................i Table of Contents........................................................................................................................................... ii BASIC KUBERNETES.....................................................................................................................1 1. Kubernetes ─ Overview...........................................................................................................................2 2. Kubernetes ─ Architecture ......................................................................................................................3 Kubernetes ─ Cluster Architecture ................................................................................................................3 Kubernetes ─ Master Machine Components.................................................................................................3 Kubernetes ─ Node Components...................................................................................................................4 Kubernetes ─..................................................................................................................................................5 Master and Node Structure...........................................................................................................................5 3. Kubernetes ─ Setup.................................................................................................................................6 Prerequisites..................................................................................................................................................6 Install Docker Engine .....................................................................................................................................7 Install etcd 2.0 ...............................................................................................................................................7 Configure kube-apiserver ..............................................................................................................................9 Configure the kube Controller Manager........................................................................................................9 Kubernetes Node Configuration..................................................................................................................10 4. Kubernetes ─ Images.............................................................................................................................12 5. Kubernetes ─ Jobs .................................................................................................................................14 Creating a Job ..............................................................................................................................................14 Scheduled Job..............................................................................................................................................15 6. Kubernetes ─ Labels & Selectors ...........................................................................................................17 Labels...........................................................................................................................................................17 Selectors ......................................................................................................................................................17 7. Kubernetes ─ Namespace......................................................................................................................19 8. Kubernetes ─ Nodes..............................................................................................................................21 9. Kubernetes ─ Service.............................................................................................................................23 10. Kubernetes ─ Pod..................................................................................................................................26 Types of Pod ................................................................................................................................................26 11. Kubernetes ─ Replication Controller......................................................................................................28 12. Kubernetes – Replica Sets .....................................................................................................................30
  • 4. Kubernetes iii 13. Kubernetes – Deployments ...................................................................................................................32 14. Kubernetes – Volumes ..........................................................................................................................34 Persistent Volume and Persistent Volume Claim ........................................................................................35 15. Kubernetes ─ Secrets.............................................................................................................................39 Using Secrets ...............................................................................................................................................40 16. Kubernetes ─ Network Policy ................................................................................................................43 ADVANCED KUBERNETES..........................................................................................................45 17. Kubernetes ─ API...................................................................................................................................46 Adding API to Kubernetes............................................................................................................................46 API Changes .................................................................................................................................................46 API Versioning..............................................................................................................................................47 18. Kubernetes – Kubectl ............................................................................................................................48 Setting Kubectl.............................................................................................................................................48 Configuring Kubectl .....................................................................................................................................48 Verifying the Setup ......................................................................................................................................49 19. Kubernetes – Kubectl Commands..........................................................................................................50 20. Kubernetes – Creating an App...............................................................................................................58 21. Kubernetes – App Deployment .............................................................................................................61 22. Kubernetes ─ Autoscaling......................................................................................................................67 23. Kubernetes ─ Dashboard Setup.............................................................................................................69 24. Kubernetes ─ Monitoring ......................................................................................................................74
  • 6. Kubernetes 2 Kubernetes in an open source container management tool hosted by Cloud Native Computing Foundation (CNCF). This is also known as the enhanced version of Borg which was developed at Google to manage both long running processes and batch jobs, which was earlier handled by separate systems. Kubernetes comes with a capability of automating deployment, scaling of application, and operations of application containers across clusters. It is capable of creating container centric infrastructure. Features of Kubernetes Following are some of the important features of Kubernetes.  Continues development, integration and deployment  Containerized infrastructure  Application-centric management  Auto-scalable infrastructure  Environment consistency across development testing and production  Loosely coupled infrastructure, where each component can act as a separate unit  Higher density of resource utilization  Predictable infrastructure which is going to be created One of the key components of Kubernetes is, it can run application on clusters of physical and virtual machine infrastructure. It also has the capability to run applications on cloud. It helps in moving from host-centric infrastructure to container-centric infrastructure. 1. Kubernetes ─ Overview
  • 7. Kubernetes 3 In this chapter, we will discuss the basic architecture of Kubernetes. Kubernetes─ClusterArchitecture As seen in the following diagram, Kubernetes follows client-server architecture. Wherein, we have master installed on one machine and the node on separate Linux machines. The key components of master and node are defined in the following section. Kubernetes─MasterMachineComponents Following are the components of Kubernetes Master Machine. etcd It stores the configuration information which can be used by each of the nodes in the cluster. It is a high availability key value store that can be distributed among multiple nodes. It is accessible only by Kubernetes API server as it may have some sensitive information. It is a distributed key value Store which is accessible to all. API Server Kubernetes is an API server which provides all the operation on cluster using the API. API server implements an interface, which means different tools and libraries can readily 2. Kubernetes ─ Architecture
  • 8. Kubernetes 4 communicate with it. Kubeconfig is a package along with the server side tools that can be used for communication. It exposes Kubernetes API. Controller Manager This component is responsible for most of the collectors that regulates the state of cluster and performs a task. In general, it can be considered as a daemon which runs in non- terminating loop and is responsible for collecting and sending information to API server. It works toward getting the shared state of cluster and then make changes to bring the current status of the server to the desired state. The key controllers are replication controller, endpoint controller, namespace controller, and service account controller. The controller manager runs different kind of controllers to handle nodes, endpoints, etc. Scheduler This is one of the key components of Kubernetes master. It is a service in master responsible for distributing the workload. It is responsible for tracking utilization of working load on cluster nodes and then placing the workload on which resources are available and accept the workload. In other words, this is the mechanism responsible for allocating pods to available nodes. The scheduler is responsible for workload utilization and allocating pod to new node. Kubernetes─NodeComponents Following are the key components of Node server which are necessary to communicate with Kubernetes master. Docker The first requirement of each node is Docker which helps in running the encapsulated application containers in a relatively isolated but lightweight operating environment. Kubelet Service This is a small service in each node responsible for relaying information to and from control plane service. It interacts with etcd store to read configuration details and wright values. This communicates with the master component to receive commands and work. The kubelet process then assumes responsibility for maintaining the state of work and the node server. It manages network rules, port forwarding, etc. Kubernetes Proxy Service This is a proxy service which runs on each node and helps in making services available to the external host. It helps in forwarding the request to correct containers and is capable of performing primitive load balancing. It makes sure that the networking environment is predictable and accessible and at the same time it is isolated as well. It manages pods on node, volumes, secrets, creating new containers’ health checkup, etc.
  • 9. Kubernetes 5 Kubernetes─MasterandNodeStructure The following illustrations show the structure of Kubernetes Master and Node.
  • 10. Kubernetes 6 It is important to set up the Virtual Datacenter (vDC) before setting up Kubernetes. This can be considered as a set of machines where they can communicate with each other via the network. For hands-on approach, you can set up vDC on PROFITBRICKS if you do not have a physical or cloud infrastructure set up. Once the IaaS setup on any cloud is complete, you need to configure the Master and the Node. Note: The setup is shown for Ubuntu machines. The same can be set up on other Linux machines as well. Prerequisites Installing Docker: Docker is required on all the instances of Kubernetes. Following are the steps to install the Docker. Step 1: Log on to the machine with the root user account. Step 2: Update the package information. Make sure that the apt package is working. Step 3: Run the following commands. $ sudo apt-get update $sudo apt-get install apt-transport-https ca-certificates Step 4: Add the new GPG key. $ sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D $ echo "https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list Step 5: Update the API package image. $ sudo apt-get update Once all the above tasks are complete, you can start with the actual installation of the Docker engine. However, before this you need to verify that the kernel version you are using is correct. 3. Kubernetes ─ Setup
  • 11. Kubernetes 7 InstallDockerEngine Run the following commands to install the Docker engine. Step 1: Logon to the machine. Step 2: Update the package index. $ sudo apt-get update Step 3: Install the Docker Engine using the following command. $ sudo apt-get install docker-engine Step 4: Start the Docker daemon. $ sudo apt-get install docker-engine Step 5: To very if the Docker is installed, use the following command. $ sudo docker run hello-world Installetcd2.0 This needs to be installed on Kubernetes Master Machine. In order to install it, run the following commands. $ curl -L https://github.com/coreos/etcd/releases/download/v2.0.0/etcd -v2.0.0-linux-amd64.tar.gz -o etcd-v2.0.0-linux-amd64.tar.gz ->1 $ tar xzvf etcd-v2.0.0-linux-amd64.tar.gz ------> 2 $ cd etcd-v2.0.0-linux-amd64 ------------>3 $ mkdir /opt/bin ------------->4 $ cp etcd* /opt/bin ----------->5 In the above set of command:  First, we download the etcd. Save this with specified name.  Then, we have to un-tar the tar package.  We make a dir. inside the /opt named bin.  Copy the extracted file to the target location.
  • 12. Kubernetes 8 Now we are ready to build Kubernetes. We need to install Kubernetes on all the machines on the cluster. $ git clone https://github.com/GoogleCloudPlatform/kubernetes.git $ cd kubernetes $ make release The above command will create a _output dir in the root of the kubernetes folder. Next, we can extract the directory into any of the directory of our choice /opt/bin, etc. Next, comes the networking part wherein we need to actually start with the setup of Kubernetes master and node. In order to do this, we will make an entry in the host file which can be done on the node machine. $ echo "<IP address of master machine> kube-master < IP address of Node Machine>" >> /etc/hosts Following will be the output of the above command. Now, we will start with the actual configuration on Kubernetes Master. First, we will start copying all the configuration files to their correct location. $ cp <Current dir. location>/kube-apiserver /opt/bin/ $ cp <Current dir. location>/kube-controller-manager /opt/bin/ $ cp <Current dir. location>/kube-kube-scheduler /opt/bin/ $ cp <Current dir. location>/kubecfg /opt/bin/ $ cp <Current dir. location>/kubectl /opt/bin/ $ cp <Current dir. location>/kubernetes /opt/bin/ The above command will copy all the configuration files to the required location. Now we will come back to the same directory where we have built the Kubernetes folder.
  • 13. Kubernetes 9 $ cp kubernetes/cluster/ubuntu/init_conf/kube-apiserver.conf /etc/init/ $ cp kubernetes/cluster/ubuntu/init_conf/kube-controller-manager.conf /etc/init/ $ cp kubernetes/cluster/ubuntu/init_conf/kube-kube-scheduler.conf /etc/init/ $ cp kubernetes/cluster/ubuntu/initd_scripts/kube-apiserver /etc/init.d/ $ cp kubernetes/cluster/ubuntu/initd_scripts/kube-controller-manager /etc/init.d/ $ cp kubernetes/cluster/ubuntu/initd_scripts/kube-kube-scheduler /etc/init.d/ $ cp kubernetes/cluster/ubuntu/default_scripts/kubelet /etc/default/ $ cp kubernetes/cluster/ubuntu/default_scripts/kube-proxy /etc/default/ $ cp kubernetes/cluster/ubuntu/default_scripts/kubelet /etc/default/ The next step is to update the copied configuration file under /etc. dir. Configure etcd on master using the following command. $ ETCD_OPTS="-listen-client-urls=http://kube-master:4001" Configurekube-apiserver For this on the master, we need to edit the /etc/default/kube-apiserver file which we copied earlier. $ KUBE_APISERVER_OPTS="--address=0.0.0.0 --port=8080 --etcd_servers=<The path that is configured in ETCD_OPTS> --portal_net=11.1.1.0/24 --allow_privileged=false --kubelet_port= < Port you want to configure> --v=0" ConfigurethekubeControllerManager We need to add the following content in /etc/default/kube-controller-manager. $ KUBE_CONTROLLER_MANAGER_OPTS="--address=0.0.0.0 --master=127.0.0.1:8080 --machines=kube-minion -----> #this is the kubernatics node
  • 14. Kubernetes 10 --v=0 Next, configure the kube scheduler in the corresponding file. $ KUBE_SCHEDULER_OPTS="--address=0.0.0.0 --master=127.0.0.1:8080 --v=0" Once all the above tasks are complete, we are good to go ahead by bring up the Kubernetes Master. In order to do this, we will restart the Docker. $ service docker restart KubernetesNodeConfiguration Kubernetes node will run two services the kubelet and the kube-proxy. Before moving ahead, we need to copy the binaries we downloaded to their required folders where we want to configure the kubernetes node. Use the same method of copying the files that we did for kubernetes master. As it will only run the kubelet and the kube-proxy, we will configure them. $ cp <Path of the extracted file>/kubelet /opt/bin/ $ cp <Path of the extracted file>/kube-proxy /opt/bin/ $ cp <Path of the extracted file>/kubecfg /opt/bin/ $ cp <Path of the extracted file>/kubectl /opt/bin/ $ cp <Path of the extracted file>/kubernetes /opt/bin/ Now, we will copy the content to the appropriate dir. $ cp kubernetes/cluster/ubuntu/init_conf/kubelet.conf /etc/init/ $ cp kubernetes/cluster/ubuntu/init_conf/kube-proxy.conf /etc/init/ $ cp kubernetes/cluster/ubuntu/initd_scripts/kubelet /etc/init.d/ $ cp kubernetes/cluster/ubuntu/initd_scripts/kube-proxy /etc/init.d/ $ cp kubernetes/cluster/ubuntu/default_scripts/kubelet /etc/default/ $ cp kubernetes/cluster/ubuntu/default_scripts/kube-proxy /etc/default/
  • 15. Kubernetes 11 End of ebook preview If you liked what you saw… Buy it from our store @ https://store.tutorialspoint.com