Docker & Kubernetes for Developers
Docker & Kubernetes for Developers
GANESHNIYER [Link]
Outline
• Dockers
• Need for Orchestration
• Kubernetes
How many worked on Kubernetes?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
Solution: Intermodal Shipping Container
Do I worry about
next to spices)
Multiplicity of
Goods
Can I transport
and transferred from one mode
train to truck)
Multiplicity of
methods for
quickly and
smoothly
of transport to another
This eliminated the M x N problem…
and spawned an Intermodal Shipping Container Ecosystem
Do services and
appropriately?
apps interact
Static website postgresql + pgv8 + v8
Queue Analytics DB
Multiplicity of
Redis + redis-sentinel
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
environments
Development VM
Multiplicity of
Public Cloud
hardware
Can I migrate
smoothly and
quickly?
QA server
Disaster recovery
Customer Data Center Contributor’s laptop
Production Servers
Results in M x N compatibility nightmare
Static website ? ? ? ? ? ? ?
Web frontend ? ? ? ? ? ? ?
Background workers ? ? ? ? ? ? ?
User DB ? ? ? ? ? ? ?
Analytics DB ? ? ? ? ? ? ?
Queue ? ? ? ? ? ? ?
Do services and
User DB Web frontend Queue
appropriately?
apps interact
Multiplicity of
Stacks
Can I migrate
consistently on virtually any
smoothly and
hardware platform
quickly
Development QA server Customer Data Public Cloud Contributor’s
Production Cluster
VM Center laptop
Or…put more simply
Static website Analytics DB
Do services and
User DB Web frontend Queue
appropriately?
apps interact
Multiplicity of
Stacks
Anything
Multiplicity of
hardware
Can I migrate
smoothly and
quickly
Development QA server Customer Data Public Cloud Contributor’s
Production Cluster
VM Center laptop
Docker solves the M x N problem
Static website
Web frontend
Background workers
User DB
Analytics DB
Queue
[Link]
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 entanglement executable and its package dependencies, which never need
of OS settings, system-installed dependencies, OS security to be installed on the host system. These processes run like
patches, and other easy-to-lose, hard-to-replicate ephemera native processes, and you can manage them individually
Why are Docker containers lightweight?
VMs Containers
App Δ
App App App
App App
A’ A A
A A
Bins/
/
Bins
Bins/ Bins/ Bins/
Libs Libs Libs Libs
Gues
t
Guest Guest Guest
OS
OS OS OS
Container A
Push Docker
Container
Image
Registry
Search
Pull
Build Run
Dockerfile
For
C
Container
A
Container
B
Container
A
Source
Code
Docker Engine
Repository Docker Engine
Host 1 OS (Linux)
Host 2 OS 2 (Windows / Linux)
Changes and Updates
Push
App Δ
App
A Docker
Container
Bins/
/
Bins
Image
Libs Registry
App Δ
Container Mod A’ Mod A’’
Update
Image
/
Bins
App App
A’’ A
Bins/
/
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
[Link]
Hybrid Cloud
[Link]
How does this help you build better software?
Accelerate Developer Onboarding
• The isolation capabilities of Docker containers free developers from the worries of using
“approved” language stacks and tooling
• Developers can use the best language and tools for their application service without
worrying about causing conflict issues
• 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
[Link]
In this session, I use Docker for Windows Desktop
Docker for
Windows
If your windows is not in latest version…
[Link]
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 [Link]
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
[Link]
• 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
[Link]. 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
Benefits
Isolation
Container Immutable infrastructure
Portability
Faster deployments Kubernetes
Versioning
Ease of sharing Orchestration of cluster of containers
across multiple hosts
• Automatic placements, networking,
Container deployments, scaling, roll-out/-back, A/B
Runtime Challenges testing
Host OS
Networking Declarative – not procedural
VM Deployments • Declare target state, reconcile to desired state
Service Discovery • Self-healing
Auto Scaling
Persisting Data Workload Portability
Logging, Monitoring • Abstract from cloud provider specifics
Access Control • Multiple container runtimes
Docker
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
ni_amrita@[Link]
[Link]@[Link]
GANESHNIYER