You are on page 1of 45

DEVOPS LAB MANUAL

K.MOUNIKA
M.tech,KITS(W)
ASSISTANT PROFESSOR

AS PER JNTUH
SYLLABUS-R18
lOMoAR cPSD| 16948736

lOMoAR cPSD| 16948736

DEVOPSLABMANUAL
HISTORY OF DEVOPS

DevOps, a portmanteau of "development" and "operations," is a software


development methodology that emphasizes collaboration and communication
between development and operations teams. The goal of DevOps is to create a
more efficient and reliable software development process that can rapidly deliver
high-quality software.

The origins of DevOps can be traced back to the early 2000s, when agile software
development methodologies were becoming popular. Agile development
emphasizes close collaboration between developers and business stakeholders,
and emphasizes iterative, incremental development.

In 2008, Patrick Debois organized the first "DevOpsDays" conference in Ghent,


Belgium. This conference brought together developers and operations
professionals to discuss the challenges of integrating their work and to explore
ways to improve collaboration.

Around the same time, companies like Amazon and Netflix were pioneering new
approaches to software development and deployment, including the use of cloud
computing and continuous delivery. These companies were able to rapidly iterate
on their software and deploy changes to production multiple times a day.

As DevOps continued to gain momentum, tools and practices emerged to support


the methodology. These include tools for continuous integration and continuous
delivery, as well as approaches like infrastructure as code and site reliability
engineering.

Today, DevOps is widely recognized as a best practice for software development


and operations. Companies of all sizes and industries are adopting DevOps to
increase the speed and reliability of their software development process.

BASIC UBUNTU COMMANDS:

1. cat: cat [filename] - to display the contents of a file, and cat > [filename] - to
create file,cat >> [filename] append contents to existing file, cat [newfilename]
>[existingfilename] - to create a new file and append its contents to an existing
file.
Ctrl+d-save file
2. touch: touch [filename] - to create a blank file.
3. nano: nano [filename] - to create and edit a file. :Ctrl+x,y-tos ave file

SIIET Page2
lOMoAR cPSD| 16948736

4. vi/vim: vi [filename] or vim [filename] - to create and edit a file. Esc:wq-to


save file

5. ls: ls - to list all files and directories in the current directory, ls -a - to show
hidden files and directories, and ls -la - to show all files and directories with
details.
6. cd: cd [directoryname] - to change directory to a specified directory.

7. pwd: pwd - to display the current working directory.

8. mkdir: mkdir [directoryname] - to create a directory with a specified name, and


mkdir -p [directoryname1]/[directoryname2] - to create multiple directories at
once.

9. cp: cp [sourcefile] [destinationfile] - to copy a file from source to destination.

10. mv: mv [sourcefile] [destinationfile] - to move a file from source to


destination.

11. mv: mv [oldfilename] [newfilename] - to rename a file.

12. rm: rm [filename] - to remove a file.

13. tree: tree - to display the directory structure in a tree-like format.

14. rm -rf: rm -rf [directoryname] - to remove a directory and all its contents
recursively.

15. grep: grep [searchterm] [filename] - to search for a specific string in a file and
print the matching lines.

16. less: less [filename] - to display the output of a command or file one page at a
time.

17. head: head [filename] - to display the first 10 lines of a file.

18. tail: tail [filename] - to display the last 10 lines of a file.

19. sort: sort [filename] - to display the contents of a file in alphabetical or


numerical order.
20. sudo: sudo [command] - to execute a command with root privileges.

SIIET Page3
lOMoAR cPSD| 16948736

21. apt: apt-get [option] [package] - to manage packages in Ubuntu. Common


options include install, update, and remove.

22. dpkg: dpkg [option] [package_file] - to install or manage a package file.

23. ifconfig: ifconfig [network_interface] - to display network interface


configuration.
EXPERIMENT NO: 1. Write code for a simple user registration
form for an event.
Aim: Write code for a simple user registration form for an event.

1. Open the terminal application


2. Login int to remote user
sudo su
3. Enterr password

Update ubuntu
4. apt-get update -y

SIIET Page4
lOMoAR cPSD| 16948736

5. Install apache2 application


apt-get install apache2
6. start apache2
Service apache2 start

7.Enter into root(/) directory


8. Enter into var directory
9. Enter into www directory

SIIET Page5
lOMoAR cPSD| 16948736

10. Enterinto html directory .


11. Create registration.html file
vi registration.html
Enter following html code:

<html>
<head>
<title>registration form</title>
</head>

<h2 ALIGN="CENTER">Registration form</h2>


<form action="success.html" method="post">
<table border="0" align="center">
<tbody>
<tr>
<td><label for="id">Id: </label></td>
<td><input id="id" maxlength="50" name="name" type="text" /></td>
</tr>
<tr>
<td><label for="name">Name: </label></td>
<td><input id="name" maxlength="50" name="name" type="text" /></td>
</tr>
<tr>
<td><label for="course">Course: </label></td>
SIIET Page6
lOMoAR cPSD| 16948736

<td><input id="course" maxlength="50" name="course" type="text"


/></td>
</tr>
<tr>
<td><label for="branch">Branch: </label></td>
<td><input id="branch" maxlength="50" name="branch" type="text"
/></td>
</tr>
<tr>
<td><label for="rolln0">Rollno: </label></td>
<td><input id="rollno" maxlength="50" name="rollno" type="text" /></td>
</tr>
<tr>
<td><label for="email">Email_Address:</label></td>
<td><input id="email" maxlength="50" name="email" type="text" /></td>
</tr>
<tr>
<td><label for="username">User_Name:</label></td>
<td><input id="username" maxlength="50" name="username" type="text"
/></td>
</tr>
<tr>
<td><label for="aboutus">About Us:</label></td>
<td valign="middle" align="center"><textarea></textarea></td>
</tr>

<tr>
<td><label for="password">Password:</label></td>
<td><input id="password" maxlength="50" name="password"
type="password" /></td>
</tr>

<tr>
<td align="right"><input name="Submit" type="Submit" value="Submit"
/></td>
</tr>

</tbody>
</table>
</form>
</html>
12. Create success.html
vi successs.html
<h2> registration success <h2>

OUT PUT:
SIIET Page7
lOMoAR cPSD| 16948736

 Open any web browser


 Enter following url address
Localhost:/registration.html

SIIET Page8
lOMoAR cPSD| 16948736

EXPERIMENTNO:2.ExploreGitandGitHubcommandsAim:E
xploreGitand GitHub commands
DESCRIPTION:
GitandGitHubaretwoofthemostpopulartoolsusedforversioncontroland
collaborationin softwaredevelopment.
HerearesomecommonGitandGitHubcommands:
• InitializingaGitrepository:$gitinit
• Checkingthestatusofyourrepository:$git status
• Addingfilestothestage:$gitadd <file-name>
• Committingchanges:$gitcommit-m"commitmessage"
• Checkingthe commithistory:$gitlog
• Undoingchanges:$gitcheckout<file-name>
• Creatinganewbranch:$gitbranch <branch-name>
• Switchingtoadifferentbranch:$gitcheckout<branch-name>
• Mergingtwobranches:$gitmerge<branch-name>
• Pushingchangestoaremoterepository:$gitpushorigin<branch-name>
• CloningarepositoryfromGitHub:$gitclone <repository-url>
• CreatingapullrequestonGitHub:GototherepositoryonGitHub,selectthebra
nchyouwanttomergeandclickthe"Newpullrequest"
button.
These are just a few of the many Git and GitHub commands available. Thereare
many other Git commands and functionalities that you can explore to
suityourneeds.

VIVAQUESTIONS

DefineGit
WhatisGitHub
DifferencebetweenGit&GitHub

SIIET Page9
lOMoAR cPSD| 16948736

Open Gitbash
Create directory:-$mkdir sriindu
Enter into directory:-$cd sriindu
Initializing a Git repository: $ git init
Checking the status of your repository: $ git status

Create new file $vi newfile

Addingfilestothestage:$gitadd newfile
Committing changes: $ git commit -m "commit message"

SIIET Page10
lOMoAR cPSD| 16948736

Checkingthe commithistory:$gitlog
Checking the commit history in one line: $git log --oneline
Display commit file data: $git show commitid

Creatinganewbranch:$gitbranch devops
Switchingtoadifferentbranch:$gitcheckoutdevops
Create devopsfile in devops branch and add to stage ,commit same file

SIIET Page11
lOMoAR cPSD| 16948736

Checkout from devops branch and enter into master(default)branch and


perform merge
Switchingtoadifferentbranch:$gitcheckoutmaster
Mergingtwobranches:$gitmergedevops

SIIET Page12
lOMoAR cPSD| 16948736

Adding remote repository


git remote add origin https://github.com/kmounikayadav/newrepository.git
Pushingchangestoaremoterepository:$gitpushoriginmaster

CloningarepositoryfromGitHub:$gitclone <repository-url>

SIIET Page13
lOMoAR cPSD| 16948736

SIIET Page14
lOMoAR cPSD| 16948736

EXPERIMENTNO:3.PracticeSourcecodemanagementonGitHub.Experi
mentwiththesource codewritten inexercise1

Aim:PracticeSourcecodemanagementonGitHub.Experim
entwiththesourcecodewritteninexercise1

Description:

TopracticesourcecodemanagementonGitHub,youcanfollowthesesteps:
• Createa GitHubaccountifyoudon'talreadyhave one.
• Createa newrepositoryonGitHub.
• Clone the repository to your local machine: $ git clone <repository-
url>
• Movetotherepository directory:$cd<repository-name>
• Create a new file in the repository and add the source code written
inexercise1.
• Stagethechanges:$gitadd<file-name>
• Commit the changes: $ git commit -m "Added source code for
asimpleuser registrationform"
• Pushthechangestotheremote repository:$gitpushoriginmaster
• Verify that the changes are reflected in the repository on
GitHub.ThesestepsdemonstratehowtouseGitHubforsourcecodemanagement.
You can use the same steps to manage any source code projects on
GitHub.Additionally, you can also explore GitHub features such as pull
requests,codereview,andbranchmanagementtoenhanceyoursourcecodemanag
ementworkflow.
Createa GitHubaccountifyoudon'talreadyhave one.
Createa newrepositoryonGitHub.

SIIET Page15
lOMoAR cPSD| 16948736

Clone the repository to your local machine: $ git clone <repository-url>


Movetotherepository directory:$cdnewrepository
Create a new file in the repository and add the source code written
inexercise2

• Stagethechanges:$gitaddnewfile
• Commit the changes: $ git commit -m "Added source code for
anewfile"
• Pushthechangestotheremote repository:$gitpushoriginmaster

SIIET Page16
lOMoAR cPSD| 16948736

• Verify that the changes are reflected in the repository on


GitHub.ThesestepsdemonstratehowtouseGitHubforsourcecodemanagement.
You can use the same steps to manage any source code projects on
GitHub.Additionally, you can also explore GitHub features such as pull
requests,codereview,andbranchmanagementtoenhanceyoursourcecodemanag
ementworkflow.

VIVAQUESTIONS

WhatisGitHubmanagement

SIIET Page17
lOMoAR cPSD| 16948736

EXPERIMENTNO:4.Jenkinsinstallationandsetup,exploretheenvironme
nt
Aim:Jenkinsinstallationandsetup,exploretheenvironment

DESCRIPTION

Jenkinsisapopularopen-
sourcetoolforContinuousIntegrationandContinuousDeployment(CI/CD)insoft
waredevelopment.Herearethestepstoinstalland setup Jenkins:
Downloadandinstall Jenkins:
• Download the Jenkins package for your operating system from
theJenkinswebsite.
• Followtheinstallationinstructionsforyouroperatingsystemtoinstall
Jenkins.
StarttheJenkinsservice:
• On Windows, use the Windows Services Manager to start the
Jenkinsservice.
• OnLinux,usethefollowing commandtostarttheJenkinsservice:
$ sudo service jenkins
startAccesstheJenkinswebinterfac
e:
• Openawebbrowserandnavigatetohttp://localhost:8080toaccess
theJenkinswebinterface.
• Ifthe Jenkinsserviceisrunning,youwillsee theJenkinslogin page.
InitializetheJenkinsenvironment:
• Follow the instructions on the Jenkins setup wizard to initialize
theJenkinsenvironment.
• Thisprocessinvolvesinstallingrecommendedplugins,settingupsecurity,
and creatingthe firstadmin user.

ExploretheJenkinsenvironment:
• Once the Jenkins environment is set up, you can explore the
variousfeaturesandfunctionalities available inthewebinterface.
• Jenkins has a rich user interface that provides access to features
suchasbuild history,buildstatistics,and system information.
These are the basic steps to install and set up Jenkins. Depending on your
usecase, you may need to customize your Jenkins environment further.
Forexample,youmayneedtoconfigurebuildagents,setupbuildpipelines,or

SIIET Page18
lOMoAR cPSD| 16948736

integrate with other tools. However, these steps should give you a
goodstarting point for using Jenkins for CI/CD in your software
developmentprojects.

Installing Jenkins over Windows


Step 1: First, we have to visit jenkins.io as shown in the figure
below:

Step 2: We have to click the download button for available download options.

Step 3: We will get a download page as shown above where we have windows
option and also generic package (war) option. We
SIIET Page19
lOMoAR cPSD| 16948736

can install Jenkins on Windows by both of these options.


Step 4: After download any of the two we get the following acknowledgment
page.

Step 5: Checking Java prerequisite: Before installing Jenkins we have to check


Java installation in our system.
Step 6: Check and install suitable Java version on your system(java 11 latest
version) and set environ variable as shown below:

Step 7: Also append Java path in the path variable there with Java path up to
bin subfolder.

SIIET Page20
lOMoAR cPSD| 16948736

Step 8: Reboot your system after setting environment variables


Step 9: When the system comes up again then check the Java version in your
command prompt with the command java – version
like this:

Step 10: Installing Jenkins with MSI installer option

After this installation is finished Jenkins will be available as windows service.

SIIET Page21
lOMoAR cPSD| 16948736

Step 11: Installation of a common part after any of the two options of
installation done up till now:
Now by any of the two above installation we have Jenkins service available
and running and our next task is two open a browser
window and type localhost:8080 and we will get the following screen:

Step 12: This is a security step as we have the option to start this service
through web from anywhere and to avoid security breach
we have to supply a number to the above textbox, this number is available at
user/username/, Jenkins/secret folder in a password
file, open that file and copy the number and paste it in the above textbox as
shown below:

SIIET Page22
lOMoAR cPSD| 16948736

Step 13: After admin configuration, we have to configure the necessary plugins
for which we will get the following screen and we
can choose either of the two options

Step 14: After choosing any one of the above options the plugins will start
installing as shown:

Step 15:After Installing plugins configure admin details.we have to create an


admin account as shown

SIIET Page23
lOMoAR cPSD| 16948736

Step 16: After plugins installation is over (we can add or remove plugins any
time) we will get the following screens and we are
ready to work on Jenkins in Windows.

VIVAQUESTIONS
DefineJenkins

SIIET Page24
lOMoAR cPSD| 16948736

EXPERIMENTNO:5.Demonstratecontinuousintegrationanddevelopmen
t using Jenkins.
Aim:DemonstratecontinuousintegrationanddevelopmentusingJenkins.
DESCRIPTION
ContinuousIntegration(CI)andContinuousDevelopment(CD)areimportantpra
cticesinsoftwaredevelopmentthatcanbeachievedusingJenkins.Here'sanexampl
eofhowyoucandemonstrateCI/CDusingJenkins:
CreateasimpleJavaapplication:

SIIET Page25
lOMoAR cPSD| 16948736

• CreateasimpleJavaapplicationthatyouwanttointegratewithJenkins.
• Theapplicationshouldhavesomebasicfunctionality,suchasprinting"Hel
loWorld" orperformingsimple calculations.
Committhecode toaGit repository:
• Create aGit repositoryfor theapplicationandcommitthecodeto
therepository.
• MakesurethattheGitrepositoryisaccessiblefromtheJenkinsserver.
Createa Jenkinsjob:
• Logintothe Jenkinswebinterfaceandcreate anewjob.
• ConfigurethejobtobuildtheJavaapplicationfromtheGitrepository.
• Specifythebuildtriggers,suchasbuildingaftereverycommittothereposito
ry.

Buildtheapplication:
• TriggerabuildoftheapplicationusingtheJenkinsjob.
• Thebuildshouldcompilethecode,runanytests,andproduceanexecutablej
arfile.
Monitorthebuild:
• MonitorthebuildprogressintheJenkinswebinterface.
• Thebuildshouldshowthebuildlog,testresults,andthestatusofthebuild.
Deploytheapplication:
• Ifthebuildissuccessful,configuretheJenkinsjobtodeploytheapplicationt
oaproductionenvironment.
• Thedeploymentcouldbeassimpleascopyingthejarfiletoaproductionserv
erorusingamoresophisticateddeploymentprocess,
suchasusingacontainerizationtechnologylikeDocker.
Repeatthe process:
• Repeattheprocessforsubsequentchangestotheapplication.

SIIET Page26
lOMoAR cPSD| 16948736

• Jenkins should automatically build and deploy the changes to


theproductionenvironment.
This is a basic example of how you can use Jenkins to demonstrate CI/CD
insoftware development. In a real-world scenario, you would likely have
morecomplexrequirements,suchasmultipleenvironments,differenttypesoftests
, and a more sophisticated deployment process. However, this
exampleshould give you a good starting point for using Jenkins for CI/CD in
yoursoftwaredevelopmentprojects.

VIVAQUESTIONS
DefineCD&CI

SIIET Page27
lOMoAR cPSD| 16948736

EXPERIMENT NO.: 6. Explore Docker commands


forcontentmanagement.

AIM:ExploreDockercommandsforcontentmanagement.

DESCRIPTION
Docker is a containerization technology that is widely used for
managingapplication containers. Here are some commonly used Docker
commands forcontentmanagement:

• Dockerrun:Runacommandinanewcontainer.
Forexample:$dockerrun--namemycontainer-itubuntu:16.04/bin/bash
ThiscommandrunsanewcontainerbasedontheUbuntu16.04imagean
dstartsashellsessioninthecontainer.

• Dockerstart:Startoneormorestoppedcontainers.For
example:$docker start mycontainer
Thiscommandstartsthecontainernamed"mycontainer".

• Dockerstop:Stoponeormore
runningcontainers.Forexample:$ dockerstop mycontainer
Thiscommandstopsthecontainernamed"mycontainer".

• Dockerrm:Remove oneormore
containers.Forexample:$docker rm mycontainer
Thiscommandremovesthecontainernamed"mycontainer".

SIIET Page28
lOMoAR cPSD| 16948736

• Dockerps:Listcontainers.F
orexample:$ dockerps
Thiscommandlistsallrunningcontainers.

• Dockerimages:Listimages.F
orexample: $ dockerimages
This commandlistsallimagesstoredlocally onthehost.

• Dockerpull:Pullanimageorarepositoryfromaregistry.Forex
ample:$ docker pull ubuntu:16.04
ThiscommandpullstheUbuntu16.04imagefromtheDockerHubregistry.

• Dockerpush:Pushanimageorarepositorytoaregistry.Forex
ample:$ docker push myimage
Thiscommandpushestheimagenamed"myimage"totheDockerHubregistry.

These are some of the basic Docker commands for managing containers
andimages. There are many other Docker commands and options that you
canuse for more advanced use cases, such as managing networks, volumes,
andconfiguration. However, these commands should give you a good
startingpointfor using Docker forcontentmanagement.

VIVAQUESTIONS

GivebrieflyaboutDockercommands

SIIET Page29
lOMoAR cPSD| 16948736

EXPERIMENTNO.:7.DevelopasimplecontainerizedapplicationusingDoc
ker

AIM:DevelopasimplecontainerizedapplicationusingDockerDE

SCRIPTION

Here'sanexampleofhowyoucandevelopasimplecontainerizedapplicationusing
Docker:

Chooseanapplication:

• Chooseasimpleapplicationthatyouwanttocontainerize.Forexample,
aPythonscriptthat prints"HelloWorld".
WriteaDockerfile:

• Createafilenamed"Dockerfile"inthesamedirectoryastheapplication.
In theDockerfile,specify the base image, copythe application
intothecontainer,andspecifythecommandtoruntheapplication.Here'sanexampl
e Dockerfilefor aPython script:

#UsetheofficialPythonimageasthebaseimageFRO
Mpython:3.9

#Copythe
PythonscriptintothecontainerCOPYhello.p
y/app/

SIIET Page30
lOMoAR cPSD| 16948736

# Set the working directory to


/app/WORKDIR/app/

#Runthe
PythonscriptwhenthecontainerstartsCMD["pytho
n", "hello.py"]

• BuildtheDockerimage:
Runthefollowingcommandtobuild theDockerimage:
$docker build-tmyimage.
ThiscommandbuildsanewDockerimageusingtheDockerfileandtagstheimagewit
hthename"myimage".

• RuntheDockercontainer:
Runthefollowingcommand tostartanewcontainerbasedontheimage:
$dockerrun--name mycontainermyimage
Thiscommandstartsanewcontainernamed"mycontainer"basedonthe"myimage"
image andrunsthePythonscriptinside thecontainer.

• Verifytheoutput:
Runthefollowing commandtoverifytheoutputofthecontainer:
$dockerlogsmycontainer
Thiscommanddisplaysthelogsofthecontainerandshouldshowthe"HelloWorld"o
utput.

This is a simple example of how you can use Docker to containerize


anapplication. In a real-world scenario, you would likely have more
complexrequirements,suchasrunningmultiplecontainers,managingnetworkco
nnections, and persisting data. However, this example should give you
agoodstartingpointforusingDockertocontainerize your applications.

VIVAQUESTIONS

NametheapplicationsusingDocker

SIIET Page31
lOMoAR cPSD| 16948736

EXPERIMENTNO.:8.IntegrateKubernetesandDockerAIM

:IntegrateKubernetesand Docker

DESCRIPTION:
KubernetesandDockerarebothpopulartechnologiesformanagingcontainers,but
theyareusedfordifferentpurposes.Kubernetesisanorchestration platform that
provides a higher-level abstractions for managingcontainers, while Docker is
a containerization technology that provides alower-levelruntimefor
containers.

To integrate Kubernetes and Docker, you need to use Docker to build


andpackage your application as a container image, and then use Kubernetes
tomanageandorchestratethecontainers.

Here'sahigh-leveloverviewofthestepstointegrateKubernetesandDocker:

• BuildaDockerimage:

SIIET Page32
lOMoAR cPSD| 16948736

Use Docker to build a Docker image of your application. You can use
aDockerfile to specify the base image, copy the application into the
container,and specify thecommand to run the application.

• PushtheDockerimage toaregistry:

PushtheDockerimagetoacontainerregistry,suchasDockerHuborGoogle
Container Registry, so that it can be easily accessed by Kubernetes.Deploy
theDocker imagetoaKubernetes cluster:

UseKubernetestodeploytheDockerimagetoacluster. Thisinvolvescreating a
deployment that specifies the number of replicas and the image tobeused,and
creatingaservicethatexposesthedeploymenttothe network.
Monitorandmanagethecontainers:

Use Kubernetes to monitor and manage the containers. This includes


scalingthe number of replicas, updating the image, and rolling out updates to
thecontainers.
• Continuouslyintegrateanddeploychanges:

Useacontinuousintegrationanddeployment(CI/CD)pipelinetoautomatically
build, push, and deploy changes to the Docker image and theKubernetes
cluster. This makes it easier to make updates to the
applicationandensuresthatthe latestversionisalwaysrunninginthe cluster.
ByintegratingKubernetesandDocker,youcanleveragethestrengthsofboth
technologies to manage containers in a scalable, reliable, and
efficientmanner.

SIIET Page33
lOMoAR cPSD| 16948736

Vivaquestions:
Define integrate
KubernetesWhatis Docker

SIIET Page34
lOMoAR cPSD| 16948736

EXPERIMENTNO.:9.Automatetheprocessofrunningcontainerizedapplic
ationdevelopedin exercise7 usingKubernetes

AIM:Automatetheprocessofrunningcontainerizedapplicationdevelopedin
exercise 7 using Kubernetes

DESCRIPTION
Toautomatetheprocessofrunningthecontainerizedapplicationdevelopedin
exercise 7 using Kubernetes, youcanfollowthesesteps:
• CreateaKubernetescluster:
CreateaKubernetesclusterusingacloudprovider,suchasGoogleCloudorAmazon
Web Services,orusingalocalinstallationofMinikube.
• PushtheDockerimage toaregistry:
PushtheDockerimageofyourapplicationtoacontainerregistry,suchasDockerHub
orGoogleContainer Registry.
• Createadeployment:
CreateadeploymentinKubernetesthatspecifiesthenumberofreplicasandthe
Docker image to use. Here's an example of a deployment YAML
file:apiVersion:apps/v1
kind:
Deploymentmeta
data:

SIIET Page35
lOMoAR cPSD| 16948736

name:
myappspec:
replicas:
3selector:
matchLabels:
app:myapp
template:
metadata:
labels:
app:myapp
spec:
containers:
- name:
myappimage:my
imageports:
-containerPort:80
• Createaservice:
CreateaserviceinKubernetesthatexposesthedeploymenttothenetwork.Here'sane
xampleofa serviceYAMLfile:
apiVersion:
v1kind:
Servicemetad
ata:
name:myapp-
servicespec:
selector:app:
myappports:
- name:
httpport:
80
SIIET Page36
lOMoAR cPSD| 16948736

targetPort:
80type:Cluster
IP
• Applythedeploymentandservicetothecluster:
Applythedeploymentandservicetotheclusterusingthekubectlcommand-
linetool.For example:
$kubectlapply-fdeployment.yaml
$kubectlapply-fservice.yaml
• Verifythedeployment:
Verifythedeploymentbycheckingthestatusofthepodsandtheservice.Forexampl
e:
$ kubectlgetpods
$kubectlgetservices
Thisisabasicexampleofhowtoautomatetheprocessofrunningacontainerized
application using Kubernetes. In a real-world scenario, youwould likely have
more complex requirements, such as managing persistentdata, scaling, and
rolling updates, but this example should give you a goodstartingpointfor
usingKubernetes to manageyourcontainers.

VIVAQUESTIONS
DefineKubernetes

SIIET Page37
lOMoAR cPSD| 16948736

EXPERIMENTNO.:10.InstallandExploreSeleniumforautomatedtesting

AIM:InstallandExploreSeleniumforautomatedtesting

DESCRIPTION:

ToinstallandexploreSeleniumforautomatedtesting,youcanfollowthesesteps:

InstallJavaDevelopmentKit(JDK):

• Selenium is written in Java, so you'll need to install JDK in order


torun it. You can download and install JDK from the official
Oraclewebsite.
• InstalltheSeleniumWebDriver:

• YoucandownloadthelatestversionoftheSeleniumWebDriverfromthe
Selenium website. You'll also need to download the
appropriatedriverforyourwebbrowserofchoice(e.g.ChromeDriverfor
GoogleChrome).
InstallanIntegratedDevelopmentEnvironment(IDE):

• To write and run Selenium tests, you'll need an IDE. Some


popularchoicesincludeEclipse,IntelliJ IDEA,andVisualStudioCode.

SIIET Page38
lOMoAR cPSD| 16948736

• Writeasimpletest:

• OnceyouhaveyourIDEsetup,youcanwriteasimpletestusingtheSeleniu
mWebDriver.Here'san exampleinJava:

importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;

publicclassMain {
public static void main(String[] args)
{System.setProperty("webdriver.chrome.driver","path/to/chromedriver");
WebDriver driver = new
ChromeDriver();driver.get("https://www.google.com");System.out.println
(driver.getTitle());
driver.quit();
}
}

• Runthe test:
RunthetestusingyourIDEorfromthecommandlineusingthefollowing
command:

$javacMain.java
$javaMain

This is a basic example of how to get started with Selenium for


automatedtesting. In a real-world scenario, you would likely write more
complex
testsandorganizeyourcodeintotestsuitesandtestcases,butthisexampleshouldgiv
eyouagoodstarting point forexploringSelenium.

VIVAQUESTIONS

SIIET Page39
lOMoAR cPSD| 16948736

EXPERIMENTNO.:11.WriteasimpleprograminJavaScriptandperform
testing using Selenium

AIM:WriteasimpleprograminJavaScriptandperformtestingusingSeleniu
m

PROGRAM:
• SimpleJavaScriptprogramthatyoucantestusingSelenium
<!DOCTYPEhtml>
<html>
<head>
<title>SimpleJavaScriptProgram</title>
</head>
<body>
<pid="output">0</p>
<buttonid="increment-button">Increment</button>
<script>
constoutput=document.getElementById("output");
const incrementButton
=document.getElementById("incre
ment-button");

SIIET Page40
lOMoAR cPSD| 16948736

letcount=0;
incrementButton.addEventListener("click",function(){
count+=1;
output.innerHTML=count;
});
</script>
</body>
</html>

• WriteatestcaseforthisprogramusingSelenium
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;i
mportorg.junit.After;
import
org.junit.Before;import
org.junit.Test;

publicclassMain {
privateWebDriverdriver;

@Before
publicvoid setUp(){
System.setProperty("webdriver.chrome.driver","path/to/chromedriver");driv
er = new ChromeDriver();
}

@Test
public void testIncrementButton()
{driver.get("file:///path/to/program.html");driver.findElemen
t(By.id("increment-button")).click();String result =
driver.findElement(By.id("output")).getText();assertresult.eq
uals("1");
}
SIIET Page41
lOMoAR cPSD| 16948736

@After
public void tearDown()
{driver.quit();
}
}
Youcanrunthetestcaseusingthefollowingcommand:
$javacMain.java
$javaMain
Theoutputofthetest caseshouldbe:
.
Time:0.189
OK(1test)

Thisoutputindicatesthatthetestcasepassed,andtheincrementbuttonwassuccessfu
lly clicked,causingtheoutputto beincrementedby 1.
VIVAQUESTIONS

Howcanjavacanbeusefulusingselenium

SIIET Page42
lOMoAR cPSD| 16948736

EXPERIMENTNO.:12.Developtestcasesfortheabovecontainerizedapplica
tionusing selenium

AIM:Developtestcasesfortheabovecontainerizedapplicationusingseleniu
m

PROGRAM:

Hereisanexampleofhowyoucouldwritetestcasesforthecontainerizedapplicationusing
Selenium

importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;i
mportorg.junit.After;
import
org.junit.Before;import
org.junit.Test;

publicclassMain {
privateWebDriverdriver;

@Before
publicvoid setUp(){
System.setProperty("webdriver.chrome.driver","path/to/chromedriver");driv
er = new ChromeDriver();

SIIET Page43
lOMoAR cPSD| 16948736

@Test
public void testHomePageLoads()
{driver.get("http://localhost:8080"
);Stringtitle=driver.getTitle();
asserttitle.equals("MyContainerizedApplication");
}

@Test
publicvoidtestSubmitForm(){driver.get("http://localhost:8080");d
river.findElement(By.name("name")).sendKeys("John Doe");
driver.findElement(By.name("email")).sendKeys("john.doe@example.co
m");
driver.findElement(By.name("submit")).click();
String result =
driver.findElement(By.id("result")).getText();assertresult.eq
uals("Formsubmitted successfully!");
}

@After
public void tearDown()
{driver.quit();
}
}
Youcanrunthetestcasesusingthefollowingcommand:
$javacMain.java
$javaMain
Theoutputofthetestcasesshouldbe:
..

Time:1.135

OK(2tests)
Thisoutputindicatesthatbothtestcasespassed,andthecontainerizedapplicationis
functioningas expected.

VIVAQUESTIONS

1. Defineselenium
2. Namethetestcasesusedinselenium

SIIET Page44
lOMoAR cPSD| 16948736

SIIET Page45

You might also like