0% found this document useful (0 votes)
47 views

Kubernetes + Docker

This document outlines an assignment to deploy both stateless and stateful applications on a Kubernetes cluster. The objectives are to understand the concepts of stateless vs stateful apps in Kubernetes, set up a Kubernetes cluster using a preferred method, and verify successful deployment by accessing the application through Kubernetes services and testing functionality. Prerequisites include hardware capable of running VMs, Linux or Windows OS, virtualization software if using VMs, and Docker as the container runtime.

Uploaded by

Riddhi Sonawane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Kubernetes + Docker

This document outlines an assignment to deploy both stateless and stateful applications on a Kubernetes cluster. The objectives are to understand the concepts of stateless vs stateful apps in Kubernetes, set up a Kubernetes cluster using a preferred method, and verify successful deployment by accessing the application through Kubernetes services and testing functionality. Prerequisites include hardware capable of running VMs, Linux or Windows OS, virtualization software if using VMs, and Docker as the container runtime.

Uploaded by

Riddhi Sonawane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Assignment Number: 04

TITLE: To install docker on window/linux and build


docker image from docker hub.
OBJECTIVES:
1. To be able to understand the concept of Docker and its importance in
cloud computing environments.
2. To be familiar with fundamental Docker commands such as docker run,
docker build, docker pull, docker push, etc.
3. To understand the process of publishing the Docker image to Docker
Hub for sharing with others..

PREREQUISITES :

Hardware Prerequisites:

Processor:
For Linux: 64-bit processor with Intel VT-x or AMD-V support
For Windows: Intel processor with Virtualization Technology
(VT-x) and Execute Disable (XD) Bit functionality enabled in
BIOS/UEFI settings

Memory (RAM):
Minimum: 2 GB
Recommended: 4 GB or higher

Disk Space:
Minimum: 20 GB free disk space
Recommended: 40 GB or higher free disk space

Network:
A stable internet connection for downloading Docker
packages and images.

Software Prerequisites:

Operating System:
Ubuntu: 16.04 LTS or later, CentOS, Debian, Fedora, etc.
Windows 7/10/11 64-bit

Virtualization Technology:

For Windows:
Virtualization technology must be enabled in
BIOS/UEFI settings.
Hyper-V enabled (Docker Desktop for Windows uses
Hyper-V as the virtualization backend)
For Linux:
Kernel version 3.10 or higher with support for cgroups
and namespaces.

Applications:
Git Client : https://git-scm.com/downloads
Visual Studio Code : https://code.visualstudio.com/ [Or any
other code editor]

INSTALLATION PROCESS:

1. Visit following link : https://docs.docker.com/desktop/install/windows-install/

2. Click Docker Desktop For Windows button as shown below


3. After the download is complete, open the executable file and it will ask for
a change in configuration.

4. Installation of Docker Desktop is completed successfully and now click the


“Close” button
5. Accept the Terms and Conditions of Docker Desktop

6. Click the Sign Up button and it will open the browser window for traditional
signup page
BUILD IMAGE

Before you can run the application, you need to get the application
source code onto your machine.

1. Clone the getting-started-app repository using the following


command:

$ git clone https://github.com/docker/getting-started-app.git

2. To build the image, you'll need to use a Dockerfile.


a. A Dockerfile is simply a text-based file with no file
extension that contains a script of instructions. Docker uses
this script to build a container image.
b. Go to getting-started-app directory

c. Create Dockerfile [Name of File is Dockerfile with No


Extensions]
3. Using a text editor or code editor, add the following contents to the
Dockerfile:

# syntax=docker/dockerfile:1

FROM node:18-alpine
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
EXPOSE 3000

4. Build the image using the following command

docker build -t getting-started .


START AN APP CONTAINER

1. Run your container using the docker run command and specify the name of
the image you just created:

docker run -dp 127.0.0.1:3000:3000 getting-started

2. After a few seconds, open your web browser to http://localhost:3000. You


should see your app.
3. Add an item or two and see that it works as you expect. You can mark items
as complete and remove them. Your frontend is successfully storing items
in the backend.

LISTING DOCKER CONTAINERS

1. Command for Listing all containers:


docker ps
2. Also you can view containers on Docker Desktop by clicking on Containers
on the sidebar
.
SHARE THE APPLICATION

1. Sign up or Sign in to Docker Hub.


2. Select the Create Repository button.
3. For the repository name, use getting-started. Make sure the Visibility is
Public.
4. Select Create.

5. In the command line, run the docker push command that you see on
Docker Hub.
docker push docker/getting-started

6. You got an error “An image does not exist locally with the tag:
docker/getting-started”. Because the push command was looking for an
image named docker/getting-started, but didn't find one.
7. To fix it first Sign in to Docker Hub using the command docker login -u
YOUR-USER-NAME.
docker login -u YOUR-USER-NAME
8. Use the docker tag command to give the getting-started image a new
name. Replace YOUR-USER-NAME with your Docker ID.
docker tag getting-started YOUR-USER-NAME/getting-started
9. Now run the docker push command again.
docker push YOUR-USER-NAME/getting-started

10. You can view repository on Docker Hub


RUN IMAGE ON NEW INSTANCE

Now that your image has been built and pushed into a registry, try running your
app on a brand new instance that has never seen this container image.

1. Open your browser to Play with Docker


2. Select Login and then select docker from the drop-down list.
3. Sign in with your Docker Hub account and then select Start
4. Select the ADD NEW INSTANCE option on the left side bar. If you don't see
it, make your browser a little wider. After a few seconds, a terminal window
opens in your browser.

5. In the terminal, start your freshly pushed app.


docker run -dp 0.0.0.0:3000:3000 YOUR-USER-NAME/getting-started
6. Select the 3000 badge when it appears.
a. If the 3000 badge doesn't appear, you can select Open Port and
specify 3000.

7. Specify Port Number as shown in the image below

OUTPUT :
REFERENCES:

1. Docker Tutorial for Beginners

2. Docker Containers and Kubernetes Fundamentals – Full Hands-On C…

3. Learn Docker - DevOps with Node.js & Express

FAQs:

1. Why should I use Docker?


Docker offers numerous benefits such as improved consistency
between development, testing, and production environments,
increased efficiency through resource isolation, scalability, and
portability of applications, and simplified dependency management.

2. How do I install Docker on Windows/Linux?


Refer to the official Docker documentation for step-by-step
instructions tailored to your operating system. Generally, you'll
download and install Docker Desktop for Windows or Docker Engine
for Linux, ensuring your system meets the prerequisites.

3. What is Docker Hub?


Docker Hub is a cloud-based repository where Docker users can
find, store, and share Docker images. It hosts a vast collection of
pre-built images for popular software stacks, making it easy to
access and deploy containerized applications.

4. How do I pull an image from Docker Hub?


You can pull a Docker image from Docker Hub using the docker pull
command followed by the name of the image. For example, docker
pull ubuntu will fetch the latest Ubuntu image from Docker Hub.

5. How do I build a Docker image?


To build a Docker image, you need a Dockerfile, which contains
instructions for building the image. Use the docker build command
followed by the path to the directory containing the Dockerfile. For
example, docker build -t myimage:tag . will build an image tagged as
myimage:tag using the Dockerfile in the current directory.
6. Can I customize Docker images?
Yes, Docker images can be customized by modifying the Dockerfile
or by using additional commands during the image build process. This
allows you to add dependencies, configure settings, and tailor the image to
suit your specific requirements.
Assignment Number: 05

TITLE: Deploy a stateless/stateful application on


Kubernetes cluster.
OBJECTIVES:
1. Understand the concepts of stateless and stateful applications in the
context of Kubernetes.
2. Learn how to set up a Kubernetes cluster using a preferred deployment
method
3. Verify the successful deployment of the application by accessing it
through Kubernetes services and testing its functionality.

PREREQUISITES :

Hardware Prerequisites:

Processor:
For Linux: 64-bit processor with Intel VT-x or AMD-V support
For Windows: Intel processor with Virtualization Technology
(VT-x) and Execute Disable (XD) Bit functionality enabled in
BIOS/UEFI settings

Memory (RAM):
Minimum: 2 GB
Recommended: 4 GB or higher

Disk Space:
Minimum: 20 GB free disk space
Recommended: 40 GB or higher free disk space

Network:
A stable internet connection for downloading Docker
packages and images.

Software Prerequisites:

Operating System:
Ubuntu: 16.04 LTS or later, CentOS, Debian, Fedora, etc.
Windows 7/10/11 64-bit

Virtualization Software (if using VMs):

If setting up a Kubernetes cluster on local machines for


testing or development, virtualization software like VirtualBox
or VMware Workstation is required.

Container Runtime:

Docker: The most popular container runtime used with


Kubernetes. It needs to be installed on all cluster nodes.

Applications:
Git Client : https://git-scm.com/downloads
Visual Studio Code : https://code.visualstudio.com/ [Or any
other code editor]

INSTALLATION PROCESS:

1. Visit following link :


https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/ and click in
Link specified in red marker
2. After downloading is completed, open the exe file once and Kubernetes
will be installed in background
3. To verify if download is successful, use following command

kubectl version --client

4. Also we need to install Minikube, which is local Kubernetes, focusing on


making it easy to learn and develop for Kubernetes.
\
CREATE SAMPLE CLUSTER AND DEPLOY

1. To create minikube cluster use following command

minikube start

2. We can view dashboard in local computer by using following


commands

minikube dashboard

3. 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.

a. 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=registry.k8s.io/e2e-test-images/agnhost:2.39 -- /agnhost
netexec --http-port=8080

b. View the deployments

kubectl get deployments

REFERENCES

Kubernetes Tutorial For Beginners - Learn Kubernetes

Kubernetes Crash Course for Absolute Beginners [NEW]

Kubernetes vs. Docker: It's Not an Either/Or Question

FAQs

1. What are containers, and how do they relate to Kubernetes?

Containers are lightweight, portable, and isolated


environments that package application code and
dependencies. Kubernetes manages containers by
orchestrating their deployment, scaling, and lifecycle
management across a cluster of machines.

2. What are the key components of Kubernetes architecture?

Kubernetes architecture comprises several components,


including the master node (which manages the cluster), worker
nodes (which host the containers), etcd (a distributed key-value
store for cluster state), kubelet (agent running on each node),
kube-proxy (network proxy), and the Kubernetes API server.

3. What are Pods in Kubernetes?

Pods are the smallest deployable units in Kubernetes,


consisting of one or more containers that share network and
storage resources. They represent a single instance of a
running process in the cluster.

4. What is a Deployment in Kubernetes?

A Deployment is a Kubernetes resource used to manage the


lifecycle of pods and ensure their availability, scalability, and
fault tolerance. It allows declarative updates to application
configurations and handles rolling updates and rollbacks.

You might also like