01-Kubernetes Intro
01-Kubernetes Intro
What is Kubernetes
2
What is Kubernetes
▪ Kubernetes cluster can start with one node until thousands of nodes
▪ Docker Swarm
▪ Mesos
2
Kubernetes Advantages
▪ Open Source
▪ Backed by Google
2
Digital Transformation
Digital Transformation
Requires an Evolution in...
2
Application Architecture
3
Development Process
INFRASTRUCTURE APPLICATIONS
Do services and
appropriately?
Static website
apps interact
postgresql + pgv8 + v8
Queue Analytics DB
Multiplicity of
Web frontend
Background workers
Ruby + Rails + sass + Unicorn
Python 3.0 + celery + pyredis + libcurl + ffmpeg + libopencv + nodejs +
phantomjs API endpoint
Python 2.7 + Flask + pyredis + celery + psycopg + postgresql-client
Production Cluster
Multiplicity of
environments
Development VM
Public Cloud
hardware
smoothly and
Can I migrate
quickly?
QA server
Disaster recovery
Customer Data Center Contributor’s laptop
Production Servers
The Challenge
User DB
Do services and
appropriately?
Static website
apps interact
postgresql + pgv8 + v8
Queue Analytics DB
Multiplicity of
Web frontend
Background workers
Ruby + Rails + sass + Unicorn
Python 3.0 + celery + pyredis + libcurl + ffmpeg + libopencv + nodejs +
phantomjs API endpoint
Python 2.7 + Flask + pyredis + celery + psycopg + postgresql-client
Production Cluster
Multiplicity of
environments
Development VM
Public Cloud
hardware
smoothly and
Can I migrate
quickly?
QA server
Disaster recovery
Customer Data Center Contributor’s laptop
Production Servers
The Matrix From Hell
Static website ? ? ? ? ? ? ?
Web frontend ? ? ? ? ? ? ?
Background workers ? ? ? ? ? ? ?
User DB ? ? ? ? ? ? ?
Analytics DB ? ? ? ? ? ? ?
Queue ? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
Solution: Intermodal Shipping Container
Do I worry about
next to spices)
A standard container that is
loaded with virtually any
goods, and stays sealed
until it reaches final delivery.
Can I transport
and transferred from one mode
train to truck)
Multiplicity of
methods for
quickly and
smoothly
of transport to another
Docker is a shipping container system for code
Analytics DB
Multiplicity of Stacks
Do services and
appropriately?
apps interact
An engine that enables any
payload to be encapsulated
as a lightweight, portable,
self-sufficient container…
environments
hardware
smoothly and
Can I migrate
hardware platform
quickly
Development QA server Customer Data Public Cloud Contributor’s
Production Cluster
VM Center laptop
Docker eliminates the matrix from Hell
Static website
Web frontend
Background workers
User DB
Analytics DB
Queue
* With the 0.7 release, we support any x86 server running a modern Linux kernel (3.2+ generally. 2.6.32+ for RHEL 6.5+, Fedora, &
related)
Why Devops Cares?
Configure once…run anything
• Make the entire lifecycle more efficient, consistent, and repeatable
• Increase the quality of code produced by developers.
• Eliminate inconsistencies between development, test, production, and customer environments
• Support segregation of duties
• Significantly improves the speed and reliability of continuous deployment and continuous
integration systems
• Because the containers are so lightweight, address significant performance, costs, deployment,
and portability issues normally associated with VMs
Why it works—separation of concerns
Prashant the Developer Amit the Ops Guy
WHY WHAT
• Run everywhere • High Level—It’s a lightweight VM
• Regardless of kernel version • Own process space
(2.6.32+)
• Own network interface
• Regardless of host distro
• Can run stuff as root
• Physical or virtual, cloud or not
• Can have its own /sbin/init
• Container and host architecture (different from host)
must match*
• <<machine container>>
• Run anything
• If it can run on the host, it can • Low Level—It’s chroot on steroids
run in the container • Can also not have its own
/sbin/init
• i.e. if it can run on a Linux
kernel, it can run • Container=isolated processes
• Share kernel with host
• No device emulation (neither
HVM nor PV) from host)
• <<application container>>
Containers vs. VMs
App App App
A A’ B
Containers are isolated,
but share OS and, where
Bins/ Bins/ Bins/
Libs Libs Libs
appropriate, bins/libraries
VM Gues Gues …result is significantly faster deployment,
t t much less overhead, easier migration,
Gues Gues
OS Gues
OS faster restart
t t t
OS OS OS
App B’
App B’
App A’
App B’
App A
App B
Docker
Container
Hypervisor (Type 2) Bins/Libs Bins/Libs
Host OS Host OS
Server Server
VIRTUAL MACHINES AND CONTAINERS
VIRTUAL MACHINES CONTAINERS
Hypervisor
Hardware
Hardware
Application
Application
OS dependencies
OS dependencies
Operating System
Container Host
Application Application
Clear ownership boundary Dev
IT Ops OS dependencies
between Dev and IT Ops OS dependencies
(and Dev, sort of)
drives DevOps adoption
Operating System and fosters agility Container Host
IT Ops
Infrastructure Infrastructure
App Δ
App App App
App
A’ A A
A A
Bins/ Bins/
Bins
Bins/ Bins/
/
Libs Libs Libs Libs
Gues
Gues Gues t
Gues
t t OS
t
OS OS OS
Original App Copy of Modified App
(No OS to take App
up space, resources, No OS. Can Copy on write
or require restart) Share bins/libs capabilities allow
us to only save the diffs
VMs Between container A
Every app, every copy of an and container
app, and every slight modification A’
of the app requires a new virtual server
What are the basics of the Docker system?
Push
Container A
Docker
Container
Image
Registry
Search
Pull
Build Run
Dockerfil
e
For
A
Container A
Source
Container
Container
Docker
Code
C
Repositor Docker Engine
y
Host 1 OS (Linux)
Host 2 OS (Linux)
Changes and Updates
App Push
App Δ
A
Docker
Bins/ Container
Bins
Image
/
Libs
Registry
App Δ
Container Mod A’ Mod A’’
Update
Image
Bins
/
App App
A’’ A
Bins/ Bins/
Bins
Libs
/
Libs
Docker Engine Docker Engine
Server:
Version: 1.9.1
API version: 1.21
Go version: go1.4.2
Git commit: a34a1d5
Built: Fri Nov 20 13:29:22 UTC 2015
OS/Arch: linux/amd64
[root@node1 ~]#
The docker group
Warning!
The docker user is root equivalent.
It provides root level access to the host.
You should restrict access to it like you would protect root.
$ docker login
Username: my_docker_hub_login Password:
Email: [email protected] Login Succeeded
User
amitvashist7/apache-ex1
Self-Hosted
registry.example.com:5000/my-private-image
Getting started with Images
Root namespace
The root namespace is for official images. They are put there by Docker Inc., but they are generally
authored and maintained by third parties.
Dockerizing an application is the process of converting an application to run within a Docker container.
Containers
Containers are created with the docker run command.
Containers have two modes they run in:
❑ Daemonized.
❑ Interactive.
A container to call your own
Daemonized containers
Runs in the background.
The docker run command is launched with the -d command line flag.
The container runs until it is stopped or killed.
Interactive containers
Runs in the foreground.
Attached a pseudo-terminal, i.e. let you get input and output from the container.
The container also runs until its controlling process stops or it is stopped or killed.
A container to call your own
Launching a container
Let's create a new container from the ubuntu image:
Container status
You can see container status using the docker ps command.
We can also use the docker ps command with the -a flag. The -a flag tells Docker to list all containers
both running and stopped.
A container to call your own
Container naming
You can now give memorable names to your containers using the new -name flag for docker run.
If no name is specified Docker will automatically generate a name.
docker run -itd --name job1 ubuntu /bin/bash
Here we've used the --format flag and specified a single value from our inspect hash result. This will
return its value, in this case a Boolean value for the container's status.
A container to call your own
The container will be restarted using the same options you launched it with.
Section summary
We've learned how to:
Understand the different types of containers.
Start a container.
See a container's status.
Inspect a container.
(Re)Start and attach to a container.
Working with Docker Images
Docker Image
Objectives
At the end of this lesson, you will be able to:
Understand the instructions for a Dockerfile.
Create your own Dockerfiles.
Build an image from a Dockerfile.
Pull and push images to the Docker Hub.
Docker Image
Docker Image
A Dockerfile which holds Docker image definitions. You can think of it as the "build recipe or manifest"
for a Docker image. It contains a series of instructions telling Docker how an image is constructed.
The docker build command which builds an image from a Dockerfile.
Docker Image
Our first Dockerfile
FROM specifies a source image for our new image. It's mandatory.
MAINTAINER tells us who maintains this image.
Each RUN instruction executes a command to build our image.
CMD defines the default command to run when a container is launched from this image.
EXPOSE lists the network ports to open when a container is launched from this image.
Docker Image
Building our Dockerfile
We use the docker build command to build images.
$ docker build -t="amitvashist7/apache-ex1" -f apache-ex1 .
In the last section we created a new image for our web application. This image would be useful to the
whole team but how do we share it? Using the Docker Hub!
Pulling images
$ docker pull ubuntu:14.04
This will connect to the Docker Hub and download the ubuntu:14.04 image to allow us to build
containers from it.
We can also do the reverse and push an image to the Docker Hub so that others can use it.
Docker Image