Dockers and Kubernetes: A Way To Build Scalable and Portable Applications With Cloud
Dockers and Kubernetes: A Way To Build Scalable and Portable Applications With Cloud
transporting/storing
Goods
methods for
Multiplicity of
Multiplicity of
Also an M x N Matrix
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
Solution: Intermodal Shipping Container
Do I worry about
next to spices)
Multiplicity of
Goods
Can I transport
and transferred from one mode
Multiplicity of
train to truck)
methods for
quickly and
of transport to another
smoothly
This eliminated the M x N problem…
and spawned an Intermodal Shipping Container Ecosystem
Do services and
appropriately?
Static website
apps interact
postgresql + pgv8 +
Queue Analytics DB
Multiplicity of
v8
nginx 1.5 + modsecurity + openssl + bootstrap
Stacks
Web frontend
Background workers
Ruby + Rails + sass +
Python 3.0 + celery + pyredis + libcurl + ffmpeg + libopencv + nodejs Unicorn
+ phantomjs API
Python 2.7 + Flaskendpoint
+ pyredis + celery + psycopg + postgresql-
client
Production
Development
environments
Multiplicity of
Public Cluster
VM
Can I migrate
hardware
and quickly?
Cloud
smoothly
QA
server
Disaster
recovery
Customer Data Contributor’s laptop
Center Production
Servers
Results in M x N compatibility nightmare
Static website ? ? ? ? ? ? ?
Web frontend ? ? ? ? ? ? ?
Background workers ? ? ? ? ? ? ?
User DB ? ? ? ? ? ? ?
Analytics DB ? ? ? ? ? ? ?
Queue ? ? ? ? ? ? ?
Do services and
Web frontend
appropriately?
User DB Queue DB
apps interact
website
Multiplicity of
Stacks
Can I migrate
and quickly
hardware platform
smoothly
Developmen QA Customer Data Public Contributor’s
t server Production
Center Cloud Cluster laptop
VM
Or…put more simply
Static User Web Queu Analytics
Do services and
appropriately?
DB
apps interact
website DB frontend e
Multiplicity of
Stacks
Can I migrate
and quickly
smoothly
Developmen QA Customer Data Public Contributor’s
t server Production
Center Cloud Cluster laptop
VM
Docker solves the M x N problem
Static website
Web frontend
Background workers
User DB
Analytics DB
Queue
https://www.docker.com/whatisdocker/
Containers vs Virtual Machines
Virtual Machines Containers
Virtual machines run guest operating systems—note the OS Containers can share a single kernel, and the only
layer in each box. This is resource intensive, and the information that needs to be in a container image is the
resulting disk image and application state is an executable and its package dependencies, which never need
entanglement of OS settings, system-installed to be installed on the host system. These processes run like
dependencies, OS security patches, and other easy-to-lose, native processes, and you can manage them individually
hard-to-replicate ephemera
Why are Docker containers lightweight?
VMs Container
s
App Δ
App App App
App App
A’ A A
A A
Bins/ Bins/ Bins/ Bins/
Libs Libs Libs Libs
Gues
t
Guest Guest Guest
OS
OS OS OS
Container A
Pus Docker
h Container
Image
Registry
Searc
Pul
h
l
Buil Ru
Dockerfile d n
For
Container
Container
Container
A
C
B
Source
Code
Docker Engine
Repository Docker Engine
Host 1 OS (Linux)
Host 2 OS 2 (Windows / Linux)
Changes and Updates
App Pus
App Δ
A h Docker
Container
Bins/ Image
Libs Registry
App Δ
Containe r r
Updat
r Image Mod A’ Mod A’’
e
App App
A’’ A
Bins/ Bins/
Libs Libs
Deliver an IT secured and managed application environment for developers to build and deploy
applications in a self service manner
Typical Use cases
App Modernization
Continuous Integration and Deployment (CI / CD)
Microservices
https://mesosphere.com/blog/networking-docker-containers-part-ii-service-discovery-traditional-apps-microservices/
Hybrid Cloud
https://boxboat.com/2016/10/21/maintaining-docker-portability-multi-cloud-world/
How does this help you build better software?
Accelerate Developer Onboarding
• Stop wasting hours trying to setup developer environments
• Spin up new instances and make copies of production code to run locally
• With Docker, you can easily take copies of your live environment and run on any new
endpoint running Docker.
• By packaging up the application with its configs and dependencies together and shipping
as a container, the application will always work as designed locally, on another machine,
in test or production
• No more worries about having to install the same configs into a different environment
First Hand Experience
Setting up
• Before we get started, make sure your system has the latest version of
Docker installed.
• Docker is available in two editions: Community Edition
(CE) and Enterprise Edition (EE).
• Docker Community Edition (CE) is ideal for developers and small teams
looking to get started with Docker and experimenting with container-based
apps. Docker CE has two update channels, stable and edge:
– Stable gives you reliable updates every quarter
– Edge gives you new features every month
• Docker Enterprise Edition (EE) is designed for enterprise development
and IT teams who build, ship, and run business critical applications in
production at scale.
Supported Platforms
https://docs.docker.com/install/
In this session, I use Docker for Windows Desktop
Docker for
Windows
If your windows is not in latest version…
https://docs.docker.com/docker-for-windows/release-notes/#docker-community-edition-17062-ce-win27-2017-09-06-stable
Docker for Windows
Now would also be a good time to make sure you are using
version 1.13 or higher. Run docker --version to check it out.
Building an app the Docker way
• In the past, if you were to start writing a Python app, your first
order of business was to install a Python runtime onto your
machine
• But, that creates a situation where the environment on your machine
has to be just so in order for your app to run as expected; ditto for
the server that runs your app
• With Docker, you can just grab a portable Python runtime as an
image, no installation necessary
• Then, your build can include the base Python image right alongside
your app code, ensuring that your app, its dependencies, and the
runtime, all travel together
• These portable images are defined by something called a
Dockerfile
Define a container with a Dockerfile
• Dockerfile will define what goes on in the
environment inside your container
• Access to resources like networking interfaces and disk
drives is virtualized inside this environment, which is
isolated from the rest of your system, so you have to map
ports to the outside world, and be specific about what
files you want to “copy in” to that environment
• However, after doing that, you can expect that the build of
your app defined in this Dockerfile will behave
exactly the same wherever it runs
Dockerfile
• Create an empty directory
• Change directories (cd) into the new directory, create a
file called Dockerfile
Dockerfile
• In windows, open notepad, copy the content below, click on Save as, type “Dockerfile”
• You should see a notice that Python is serving your app at http://0.0.0.0:80.
But that message is coming from inside the container, which doesn’t know you
mapped port 80 of that container to 4000, making the correct URL
http://localhost:4000
• Go to that URL in a web browser to see the display content served up on a web
page, including “Hello World” text, the container ID, and the Redis error message
End the process
• You get the long container ID for your app and then are kicked back
to your terminal. Your container is running in the background. You
can also see the abbreviated container ID with docker container ls
(and both work interchangeably when running commands):
• docker container ls
Share image
• To demonstrate the portability of what we just created, let’s
upload our built image and run it somewhere else
• After all, you’ll need to learn how to push to registries when you
want to deploy containers to production
• A registry is a collection of repositories, and a repository is a
collection of images—sort of like a GitHub repository, except the
code is already built. An account on a registry can create many
repositories. The docker CLI uses Docker’s public registry by
default
• If you don’t have a Docker account, sign up for one at
cloud.docker.com. Make note of your username.
Login with your docker id
• Log in to the Docker public registry on your local machine.
• docker login
Tag the image
• Now, put it all together to tag the image. Run docker tag image
with your username, repository, and tag names so that the image will
upload to your desired destination. The syntax of the command is:
Tag the image
Publish the image
• Upload your tagged image to the repository
• docker push username/repository:tag
• Once complete, the results of this upload are publicly available. If you log
in to Docker Hub, you will see the new image there, with its pull
command
Publish the image
• Upload your tagged image to the repository
• docker push username/repository:tag
Orchestration
Systems
The Need for Orchestration Systems
• While Docker provided an open standard for packaging
and distributing containerized applications, there arose a
new problem
– How would all of these containers be coordinated and
scheduled?
– How do all the different containers in your application
communicate with each other?
– How can container instances be scaled?
Docke
r
Kubernetes
• Kubernetes is an open-source container cluster manager
– originally developed by Google, donated to the Cloud Native
Computing Foundation
– schedules & deploys containers onto a cluster of machines
• e.g. ensure that a specified number of instances of an application are running
– provides service discovery, distribution of configuration & secrets, ...
– provides access to persistent storage
• Pod
– smallest deployable unit of compute
– consists of one or more containers that are always co-located,
co- scheduled & run in a shared context
5
Why Kubernetes?
• It can be run anywhere
– on-premises
• bare metal, OpenStack, ...
– public clouds
• Google, Azure, AWS, ...
• Aim is to use Kubernetes as an abstraction layer
– migrate to containerised applications managed by Kubernetes & use only the
Kubernetes API
– can then run out-of-the-box on any Kubernetes cluster
• Avoid vendor lock-in as much as possible by not using any vendor specific
APIs or services
– except where Kubernetes provides an abstraction
• e.g. storage, load balancers
7
Kubernetes
Architecture
• minikube start
• minikube dashboard
https://tinyurl.com/anokadockers
[email protected]
u
[email protected]
GANESHNIYE
R