Introduction to dockers and kubernetes. Learn how this helps you to build scalable and portable applications with cloud. It introduces the basic concepts of dockers, its differences with virtualization, then explain the need for orchestration and do some hands-on experiments with dockers
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Dockers and kubernetes
1. Dockers and Kubernetes
A way to build scalable and portable applications with Cloud
Dr Ganesh Neelakanta Iyer
Amrita Vishwa Vidyapeetham, Coimbatore
Associate Professor, Dept of Computer Science and Engg
2. About Me • Associate Professor, Amrita Vishwa Vidyapeetham
• Masters & PhD from National University of Singapore (NUS)
• Several years in Industry/Academia
• Sasken Communications, NXP Semiconductors, Progress
Software, IIIT-HYD, NUS (Singapore)
• Architect, Manager, Technology Evangelist, Visiting Faculty
• Talks/workshops in USA, Europe, Australia, Asia
• Cloud/Edge Computing, IoT, Game Theory, Software QA
• Kathakali Artist, Composer, Speaker, Traveler, Photographer
GANESHNIYER http://ganeshniyer.com
15. and spawned an Intermodal Shipping Container Ecosystem
• 90% of all cargo now shipped in a standard container
• Order of magnitude reduction in cost and time to load and unload ships
• Massive reduction in losses due to theft or damage
• Huge reduction in freight cost as percent of final goods (from >25% to <3%) massive globalizations
• 5000 ships deliver 200M containers per year
16. Static website
Web frontend
User DB
Queue Analytics DB
Background workers
API endpoint
nginx 1.5 + modsecurity + openssl + bootstrap 2
postgresql + pgv8 + v8
hadoop + hive + thrift + OpenJDK
Ruby + Rails + sass + Unicorn
Redis + redis-sentinel
Python 3.0 + celery + pyredis + libcurl + ffmpeg + libopencv + nodejs +
phantomjs
Python 2.7 + Flask + pyredis + celery + psycopg + postgresql-client
Development VM
QA server
Public Cloud
Disaster recovery
Contributor’s laptop
Production Servers
The Challenge
Multiplicityof
Stacks
Multiplicityof
hardware
environments
Production Cluster
Customer Data Center
Doservicesand
appsinteract
appropriately?
CanImigrate
smoothlyand
quickly?
17. Results in M x N compatibility nightmare
Static website
Web frontend
Background workers
User DB
Analytics DB
Queue
Development
VM
QA Server
Single Prod
Server
Onsite Cluster Public Cloud
Contributor’s
laptop
Customer
Servers
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
18. Static website Web frontendUser DB Queue Analytics DB
Development
VM
QA server Public Cloud Contributor’s
laptop
Docker is a shipping container system for
code
Multiplicityof
Stacks
Multiplicityof
hardware
environments
Production Cluster
Customer Data
Center
Doservicesand
appsinteract
appropriately?
CanImigrate
smoothlyand
quickly
…that can be manipulated using
standard operations and run
consistently on virtually any
hardware platform
An engine that enables any
payload to be encapsulated
as a lightweight, portable,
self-sufficient container…
19. Static website Web frontendUser DB Queue Analytics DB
Development
VM
QA server Public Cloud Contributor’s
laptop
Or…put more simply
Multiplicityof
Stacks
Multiplicityof
hardware
environments
Production Cluster
Customer Data
Center
Doservicesand
appsinteract
appropriately?
CanImigrate
smoothlyand
quickly
Operator: Configure Once, Run
Anything
Developer: Build Once, Run
Anywhere (Finally)
20. Static website
Web frontend
Background workers
User DB
Analytics DB
Queue
Development
VM
QA Server
Single Prod
Server
Onsite Cluster Public Cloud
Contributor’s
laptop
Customer
Servers
Docker solves the M x N problem
21. Docker containers
• Wrap up a piece of software in a
complete file system that contains
everything it needs to run:
– Code, runtime, system tools, system
libraries
– Anything you can install on a server
• This guarantees that it will always
run the same, regardless of the
environment it is running in
22. Why containers matter
Physical Containers Docker
Content Agnostic The same container can hold almost
any type of cargo
Can encapsulate any payload and its
dependencies
Hardware Agnostic Standard shape and interface allow
same container to move from ship to
train to semi-truck to warehouse to
crane without being modified or
opened
Using operating system primitives (e.g.
LXC) can run consistently on virtually
any hardware—VMs, bare metal,
openstack, public IAAS, etc.—without
modification
Content Isolation and
Interaction
No worry about anvils crushing
bananas. Containers can be stacked
and shipped together
Resource, network, and content
isolation. Avoids dependency hell
Automation Standard interfaces make it easy to
automate loading, unloading, moving,
etc.
Standard operations to run, start, stop,
commit, search, etc. Perfect for devops:
CI, CD, autoscaling, hybrid clouds
Highly efficient No opening or modification, quick to
move between waypoints
Lightweight, virtually no perf or start-up
penalty, quick to move and manipulate
Separation of duties Shipper worries about inside of box,
carrier worries about outside of box
Developer worries about code. Ops
worries about infrastructure.
23. Docker containers
Lightweight
• Containers running on
one machine all share
the same OS kernel
• They start instantly
and make more
efficient use of RAM
• Images are
constructed from
layered file systems
• They can share
common files, making
disk usage and image
downloads much
more efficient
Open
• Based on open
standards
• Allowing containers to
run on all major Linux
distributions and
Microsoft OS with
support for every
infrastructure
Secure
• Containers isolate
applications from
each other and the
underlying
infrastructure while
providing an added
layer of protection for
the application
24. Docker / Containers vs. Virtual Machine
https://www.docker.com/whatisdocker/
Containers have similar resource
isolation and allocation benefits as
VMs but a different architectural
approach allows them to be much
more portable and efficient
25. Virtual Machines
Virtual machines run guest operating systems—note the OS
layer in each box. This is resource intensive, and the
resulting disk image and application state is an entanglement
of OS settings, system-installed dependencies, OS security
patches, and other easy-to-lose, hard-to-replicate ephemera
Containers vs Virtual Machines
Containers
Containers can share a single kernel, and the only
information that needs to be in a container image is the
executable and its package dependencies, which never need
to be installed on the host system. These processes run like
native processes, and you can manage them individually
26. Why are Docker containers lightweight?
Bins/
Libs
App
A
Original App
(No OS to take
up space, resources,
or require restart)
AppΔ
Bins
/
App
A
Bins/
Libs
App
A’
Gues
t
OS
Bins/
Libs
Modified App
Union file system allows
us to only save the diffs
Between container A
and container
A’
VMs
Every app, every copy of an
app, and every slight modification
of the app requires a new virtual server
App
A
Guest
OS
Bins/
Libs
Copy of
App
No OS. Can
Share bins/libs
App
A
Guest
OS
Guest
OS
VMs Containers
27. What are the basics of the Docker system?
Source
Code
Repository
Dockerfile
For
A
Docker Engine
Docker
Container
Image
Registry
Build
Docker Engine
Host 2 OS 2 (Windows / Linux)
Container
A
Container
B
Container
C
ContainerA
Push
Search
Pull
Run
Host 1 OS (Linux)
28. Changes and Updates
Docker Engine
Docker
Container
Image
Registry
Docker Engine
Push
Update
Bins/
Libs
App
A
AppΔ
Bins
/
Base
Container
Image
Host is now running A’’
Container
Mod A’’
AppΔ
Bins
/
Bins/
Libs
App
A
Bins
/
Bins/
Libs
App
A’’
Host running A wants to upgrade to A’’.
Requests update. Gets only diffs
Container
Mod A’
29. Easily Share and Collaborate on Applications
• Distribute and share content
– Store, distribute and manage your Docker images in your Docker
Hub with your team
– Image updates, changes and history are automatically shared
across your organization.
• Simply share your application with others
– Ship your containers to others without worrying about different
environment dependencies creating issues with your application.
– Other teams can easily link to or test against your app without
having to learn or worry about how it works.
Docker creates a common framework for developers and sysadmins to work together on distributed
applications
30. Get Started with Docker
• Install Docker
• Run a software image in a container
• Browse for an image on Docker Hub
• Create your own image and run it in a
container
• Create a Docker Hub account and an
image repository
• Create an image of your own
• Push your image to Docker Hub for
others to use
https://www.docker.com/products/docker
https://www.docker.com/products/docker-toolbox
31. Docker Container as a Service (CaaS)
Deliver an IT secured and managed application environment for developers to build and deploy
applications in a self service manner
37. How does this help you build better software?
• 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.
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
Empower Developer Creativity
• 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
Eliminate Environment Inconsistencies
40. 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.
44. 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
45. Docker for Windows
When the whale in the status
bar stays steady, Docker is
up-and-running, and
accessible from any terminal
window.
46. Hello-world
• Open command prompt / windows power shell and run
docker run hello-world
▪ 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.
47. 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
48. 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
49. Dockerfile
• Create an empty directory
• Change directories (cd) into the new directory, create a
file called Dockerfile
50. Dockerfile
• In windows, open notepad, copy the content below, click on Save as, type “Dockerfile”
This Dockerfile refers to a couple of files we
haven’t created yet, namely app.py and
requirements.txt. Let’s create those next.
51. The app itself
• Create two more files,
requirements.txt and app.py, and
put them in the same folder with the
Dockerfile
• This completes our app, which as you
can see is quite simple
• When the above Dockerfile is built
into an image, app.py and
requirements.txt will be present
because of that Dockerfile’s ADD
command, and the output from app.py
will be accessible over HTTP thanks to
the EXPOSE command.
52. The App itself
Requirements.txt
app.py
That’s it! You don’t need Python
or anything in
requirements.txt on your
system, nor will building or
running this image install them
on your system. It doesn’t seem
like you’ve really set up an
environment with Python and
Flask, but you have.
53. Building the app
• We are ready to build the app. Make sure you are still at the
top level of your new directory. Here’s what ls should show
• Now run the build command. This creates a Docker image,
which we’re going to tag using -t so it has a friendly name.
56. Run the app
• Run the app, mapping your machine’s port 4000 to the container’s published port 80
using –p
• docker run -p 4000:80 friendlyhello
• 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
57.
58. End the process
• Hit CTRL+C in your terminal to quit
• Now use docker stop to end the process, using the
CONTAINER ID, like so
59. • Now let’s run the app in the background, in detached mode:
• docker run -d -p 4000:80 friendlyhello
• 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
60. 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.
61.
62.
63. Login with your docker id
• Log in to the Docker public registry on your local machine.
• docker login
64. Tag the image
• The notation for associating a local image with a repository on a
registry is username/repository:tag. The tag is optional, but
recommended, since it is the mechanism that registries use to give
Docker images a version. Give the repository and tag meaningful
names for the context, such as get-started:part1. This will put
the image in the get-started repository and tag it as part1.
• 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:
66. 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
67. 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
68.
69. Pull and run the image from the remote
repository
• From now on, you can use docker run and run your app on any
machine with this command:
• docker run -p 4000:80 username/repository:tag
• If the image isn’t available locally on the machine, Docker will pull it
from the repository.
• If you don’t specify the :tag portion of these commands, the tag of
:latest will be assumed, both when you build and when you run
images. Docker will use the last version of the image that ran without
a tag specified (not necessarily the most recent image).
No matter where executes, it pulls your image, along with Python and all the dependencies
from , and runs your code. It all travels together in a neat little package, and the host machine
doesn’t have to install anything but Docker to run it.
70. What have you seen so far?
• Basics of Docker
• How to create your first app in the Docker way
• Building the app
• Run the app
• Sharing and Publishing images
• Pull and run images
72. 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?
Dr Ganesh Neelakanta Iyer 72
74. From Containers to Kubernetes
VM
Host OS
Container
Runtime
Benefits
Isolation
Immutable infrastructure
Portability
Faster deployments
Versioning
Ease of sharing
Challenges
Networking
Deployments
Service Discovery
Auto Scaling
Persisting Data
Logging, Monitoring
Access Control
Kubernetes
Orchestration of cluster of containers
across multiple hosts
• Automatic placements, networking,
deployments, scaling, roll-out/-back, A/B
testing
Docker
Workload Portability
• Abstract from cloud provider specifics
• Multiple container runtimes
Declarative – not procedural
• Declare target state, reconcile to desired state
• Self-healing
Container Scheduler
Container
75. 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
76. 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
79. kube-apiserver
• The apiserver provides a forward facing REST interface
into the kubernetes control plane and datastore
• All clients, including nodes, users and other applications
interact with kubernetes strictly through the API Server
• It is the true core of Kubernetes acting as the gatekeeper
to the cluster by handling authentication and
authorization, request validation, mutation, and admission
control in addition to being the front-end to the backing
datastore
Dr Ganesh Neelakanta Iyer 79
80. etcd
• Etcd acts as the cluster datastore
• Providing a strong, consistent and highly available key-
value store used for persisting cluster state
Dr Ganesh Neelakanta Iyer 80
81. kube-controller-manager
• The controller-manager is the primary daemon that manages all core
component control loops
• It monitors the cluster state via the apiserver and steers the cluster
towards the desired state
• These controllers include:
– Node Controller: Responsible for noticing and responding when nodes go
down.
– Replication Controller: Responsible for maintaining the correct number of
pods for every replication controller object in the system.
– Endpoints Controller: Populates the Endpoints object (that is, joins
Services & Pods).
– Service Account & Token Controllers: Create default accounts and API
access tokens for new namespaces
Dr Ganesh Neelakanta Iyer 81
82. cloud-controller-manager
• cloud-controller-manager runs controllers that interact
with the underlying cloud providers
• cloud-controller-manager allows cloud vendors code and
the Kubernetes code to evolve independent of each other
Dr Ganesh Neelakanta Iyer 82
83. kube-scheduler
• Kube-scheduler is a verbose policy-rich engine that
evaluates workload requirements and attempts to place it
on a matching resource
• These requirements can include such things as general
hardware reqs, affinity, anti-affinity, and other custom
resource requirements
Dr Ganesh Neelakanta Iyer 83
84. Kubernetes Node
Dr Ganesh Neelakanta Iyer 84https://www.slideshare.net/janakiramm/kubernetes-architecture
85. Pod
• A Pod is the basic building block of Kubernetes–the smallest and
simplest unit in the Kubernetes object model that you create or
deploy
• A Pod represents a running process on your cluster
• A Pod encapsulates an application container (or, in some cases,
multiple containers), storage resources, a unique network IP, and
options that govern how the container(s) should run
• A Pod represents a unit of deployment: a single instance of an
application in Kubernetes, which might consist of either a single
container or a small number of containers that are tightly coupled
and that share resources
Dr Ganesh Neelakanta Iyer 85
86. kubelet
• An agent that runs on each node in the cluster. It makes
sure that containers are running in a pod.
• The kubelet takes a set of PodSpecs that are provided
through various mechanisms and ensures that the
containers described in those PodSpecs are running and
healthy. The kubelet doesn’t manage containers which
were not created by Kubernetes
Dr Ganesh Neelakanta Iyer 86
87. kube-proxy
• Enables the Kubernetes service abstraction by
maintaining network rules on the host and performing
connection forwarding
Dr Ganesh Neelakanta Iyer 87
88. Container Runtime
• The container runtime is the software that is responsible
for running containers
• Kubernetes supports several runtimes
– Docker, rkt, runc and any OCI runtime-spec implementation
Dr Ganesh Neelakanta Iyer 88
89. Kubernetes Cluster
Dr Ganesh Neelakanta Iyer 89
• Kubernetes coordinates
a highly available cluster
of computers that are
connected to work as a
single unit
• Kubernetes automates
the distribution and
scheduling of application
containers across a
cluster in a more
efficient way
90. Running Kubernetes Locally via Minikube
• Minikube is a tool that makes it easy to run Kubernetes
locally
• Minikube runs a single-node Kubernetes cluster inside a
VM on your laptop for users looking to try out Kubernetes
or develop with it day-to-day
Dr Ganesh Neelakanta Iyer 90
92. Hello Minicube
• This tutorial provides a container image built from the following files
Dr Ganesh Neelakanta Iyer 92
93. Create a minikube cluster
• minikube version
• minikube start
• minikube dashboard
Dr Ganesh Neelakanta Iyer 93
94. Create a Deployment
• A Kubernetes Pod is a group of one or more Containers,
tied together for the purposes of administration and
networking
• The Pod in this tutorial has only one Container
• A Kubernetes Deployment checks on the health of your
Pod and restarts the Pod’s Container if it terminates
• Deployments are the recommended way to manage the
creation and scaling of Pods
Dr Ganesh Neelakanta Iyer 94
95. Create a Deployment
• Use the kubectl create command to create a
Deployment that manages a Pod
• The Pod runs a Container based on the provided Docker
image
kubectl create deployment hello-node --image=
gcr.io/hello-minikube-zero-install/hello-node
Dr Ganesh Neelakanta Iyer 95
98. Create a deployment
• View cluster events
kubectl get events
• View the kubectl configuration
kubectl config view
Dr Ganesh Neelakanta Iyer 98
99. Create s Service
• By default, the Pod is only accessible by its internal IP
address within the Kubernetes cluster
• To make the hello-node Container accessible from outside
the Kubernetes virtual network, you have to expose the
Pod as a Kubernetes Service
• Expose the Pod to the public internet using the kubectl
expose command
kubectl expose deployment hello-node --type=LoadBalancer --port=8080
Dr Ganesh Neelakanta Iyer 99
100. Create a Service
• View the Service you just created
kubectl get services
Dr Ganesh Neelakanta Iyer 100
101. Run a Service
• Run the following command
minikube service hello-node
Dr Ganesh Neelakanta Iyer 101
104. Deploying PHP Guestbook application with
Redis
• This tutorial shows you how to build and deploy a simple,
multi-tier web application using Kubernetes and Docker
• This example consists of the following components:
– A single-instance Redis master to store guestbook entries
– Multiple replicated Redis instances to serve reads
– Multiple web frontend instances
Dr Ganesh Neelakanta Iyer 104
105. Objectives
• Start up a Redis master
• Start up Redis slaves
• Start up the guestbook frontend
• Expose and view the Frontend Service
Dr Ganesh Neelakanta Iyer 105
106. Start up the Redis Master
• The guestbook application uses Redis to store its data
• It writes its data to a Redis master instance and reads
data from multiple Redis slave instances
• Creating the Redis Master Deployment
• Copy the folder here to your system
https://tinyurl.com/anokadockers
Dr Ganesh Neelakanta Iyer 106
108. Start up the Redis Master
• Launch a terminal window in the directory you
downloaded the manifest files
• Apply the Redis Master Deployment from the redis-
master-deployment.yaml file
kubectl apply -f redis-master-deployment.yaml
Dr Ganesh Neelakanta Iyer 108
109. Start up the Redis Master
• Query the list of Pods to verify that the Redis Master Pod
is running:
kubectl get pods
Dr Ganesh Neelakanta Iyer 109
110. Run the following command to view the logs
from the Redis Master Pod
kubectl logs -f POD-NAME
Dr Ganesh Neelakanta Iyer 110
Replace POD-NAME with the
name of your Pod
111. Creating the Redis Master Service
• The guestbook applications needs to communicate to the Redis
master to write its data
• You need to apply a Service to proxy the traffic to the Redis master
Pod
• A Service defines a policy to access the Pods
• Launch a terminal window in the directory you downloaded the
manifest files
• Apply the Redis Master Service from the following redis-master-
service.yaml file
kubectl apply -f redis-master-service.yaml
Dr Ganesh Neelakanta Iyer 111
112. Creating the Redis Master Service
• Query the list of Services to verify that the Redis Master
Service is running
• kubectl get service
Dr Ganesh Neelakanta Iyer 112
113. Start up the Redis Slaves
• Although the Redis master is a single pod, you can make
it highly available to meet traffic demands by adding
replica Redis slaves
Dr Ganesh Neelakanta Iyer 113
114. Creating the Redis Slave Deployment
• Deployments scale based off of the configurations set in
the manifest file. In this case, the Deployment object
specifies two replicas
• If there are not any replicas running, this Deployment
would start the two replicas on your container cluster
• Conversely, if there are more than two replicas are
running, it would scale down until two replicas are running
Dr Ganesh Neelakanta Iyer 114
115. Creating the Redis Slave Deployment
• Apply the Redis Slave Deployment from the redis-slave-
deployment.yaml file
kubectl apply -f redis-slave-deployment.yaml
Dr Ganesh Neelakanta Iyer 115
116. Creating the Redis Slave Deployment
• Query the list of Pods to verify that the Redis Slave Pods
are running:
kubectl get pods
Dr Ganesh Neelakanta Iyer 116
117. Creating the Redis Slave Service
• The guestbook application needs to communicate to
Redis slaves to read data
• To make the Redis slaves discoverable, you need to set
up a Service
• A Service provides transparent load balancing to a set of
Pods
Dr Ganesh Neelakanta Iyer 117
118. Creating the Redis Slave Service
• Apply the Redis Slave Service from the following redis-
slave-service.yaml file
kubectl apply -f redis-slave-service.yaml
Dr Ganesh Neelakanta Iyer 118
119. Creating the Redis Slave Service
• Query the list of Services to verify that the Redis slave
service is running
kubectl get services
Dr Ganesh Neelakanta Iyer 119
120. Set up and Expose the Guestbook Frontend
• The guestbook application has a web frontend serving the
HTTP requests written in PHP
• It is configured to connect to the redis-master Service for
write requests and the redis-slave service for Read
requests
Dr Ganesh Neelakanta Iyer 120
121. Creating the Guestbook Frontend
Deployment
• Apply the frontend Deployment from the frontend-
deployment.yaml file
kubectl apply -f frontend-deployment.yaml
Dr Ganesh Neelakanta Iyer 121
122. Creating the Guestbook Frontend
Deployment
• Query the list of Pods to verify that the three frontend
replicas are running
kubectl get pods -l app=guestbook -l
tier=frontend
Dr Ganesh Neelakanta Iyer 122
123. Creating the frontend service
• The redis-slave and redis-master Services you applied are
only accessible within the container cluster because the
default type for a Service is ClusterIP
• ClusterIP provides a single IP address for the set of Pods the
Service is pointing to
• This IP address is accessible only within the cluster.
• If you want guests to be able to access your guestbook, you
must configure the frontend Service to be externally visible,
so a client can request the Service from outside the container
cluster
• Minikube can only expose Services through NodePort
Dr Ganesh Neelakanta Iyer 123
124. Creating the frontend service
• Apply the frontend Service from the frontend-service.yaml
file
kubectl apply -f frontend-service.yaml
Dr Ganesh Neelakanta Iyer 124
125. Creating the frontend service
• Query the list of Services to verify that the frontend
Service is running
kubectl get services
Dr Ganesh Neelakanta Iyer 125
126. Viewing the Frontend Service via NodePort
• If you deployed this application to Minikube or a local
cluster, you need to find the IP address to view your
Guestbook
• Run the following command to get the IP address for the
frontend Service
minikube service frontend --url
Dr Ganesh Neelakanta Iyer 126
127. Go to a browser and type that URL
Dr Ganesh Neelakanta Iyer 127
128. Viewing the Frontend Service via
LoadBalancer
• If you deployed the frontend-service.yaml manifest with
type: LoadBalancer you need to find the IP address to
view your Guestbook
• Run the following command to get the IP address for the
frontend Service
kubectl get service frontend
Dr Ganesh Neelakanta Iyer 128
129. Scale the Web Frontend
• Scaling up or down is easy because your servers are
defined as a Service that uses a Deployment controller
• Run the following command to scale up the number of
frontend Pods:
kubectl scale deployment frontend --replicas=5
• Query the list of Pods to verify the number of frontend
Pods running:
kubectl get pods
Dr Ganesh Neelakanta Iyer 129
130. Summary
• Kubernetes can help you
– Create clusters
– Deploy applications
– Scale your business
Dr Ganesh Neelakanta Iyer 130
131.
132.
133. Dr Ganesh Neelakanta Iyer
ni_amrita@cb.amrita.edu
ganesh.vigneswara@gmail.com
GANESHNIYER