Devops Lab programs
Devops Lab programs
This command starts a new container by named “mycontainer” based on the “myimage” image and
run the Python script inside the container.
Verify the output:
Run the following command to verify the output of the container:
$docker logs mycontainer
This command displays the logs of the container and should show the “Hello World” output.
This is the simple example of how you can use Docker to containerize an application. In the real-world
scenario, you would likely have more complex requirements such as running multiple containers,
managing network connections, and persisting data. However, this example should give you a good
starting point for using Docker to containerize your applications.
Experiment no: 8. Integrate Kubernetes and Docker
Aim: Integrate Kubernetes and Docker
Description: Kubernetes and Docker are both popular technologies for managing containers, but they
are used for different purposes. Kubernetes is an orchestration platform that provides a higher-level
abstraction for managing containers, while Docker is a containerization technology that provides a
lower-level runtime for containers.
To integrate Kubernetes and Docker, you need to use Docker to build and package the application as a
container image and then use Kubernetes to manage and orchestrate the containers.
Here’s a high-level overview of the steps to integrate Kubernetes and Docker:
Build a docker image:
Use Docker to build a Docker image of your application. You can use a Docker file to specify
the base image, copy the application into the container, and specify the command to run the
application.
Monitor and manage the containers: Use Kubernetes to monitor and manage the containers. This
includes the scaling the number of replicas, update the image, and rolling out updates to the
containers.
Continuously integrate and deploy changes: Use a continuous integration and deployment
(CI/CD) pipeline to automatically build, push and deploy changes to the docker image and
Kubernetes cluster.
This makes it easier to make updates to the application and ensure that the latest
version is always running in the cluster. By integrating Kubernetes and docker, you can leverage the
strength of both technologies to manage container in a scalable, reliable and efficient manner
Experiment no: 9. Automate the process of running containerized application developed in
exercise 7 using Kubernetes.
Aim: Automate the process of running containerized application developed in exercise 7
using Kubernetes
Description: To automate the process of running the containerized application developed in exercise7
using Kubernetes, you can follow these steps:
Create a Kubernetes cluster: Create a Kubernetes cluster that cloud provided such as google cloud
or amazon web services, or using local installation of Minikube.
Push the Docker image to registry: Push the Docker image of your application to a
container registry, such as Docker Hub or Google Container Registry.
Create a deployment: Create a deployment in Kubernetes that specifies the number of replicas
and the Docker image to use. Here’s an example of a deployment YAML file:
apiVersion:apps/v1
kind: Deployment
metadata:
name:myapp
spec:
replicas:3
selector:
matchLabels:
app:myapp
template:
metadata:
labels:
app:myapp
spec:
container:
-name: myapp
image:myimage
ports:
-containerPort:80
Create a service: Create a service in Kubernetes that exposes the deployment to the network.
Here’s an example of a service YAML file:
apiVersion:v1
kind: Service
metadata:
name:myapp-service
spec:
selector:
app:myapp
ports:
-name: http
Port:80
targetPort:80
Type:clusterIP
Apply the deployment and service to the cluster: Applying the deployment and service to the cluster
using the kubect1 command- line tool.
For example:
$kubect1apply-fdeployment.yaml
$kubect1apply-fservice.yaml
Verify the deployment: Verify the deployment by checking the status of the pods and the service.
For example:
$kubect1getpods
$kubect1getservices
This is the basic example of how to automate the process of running a containerized application using
Kubernetes. In the real-world scenarios, you would likely have more complex requirements. Such as
managing persistent data, scaling and rolling updates, but this example gives you a good starting point
for using Kubernetes to manage your containers.
Experiment no: 10. Install and explore selenium for automated testing
Aim: Install and explore selenium for automated testing
Description: To install and explore selenium for automated testing, you can follow the steps:
This is a basic example of how to get started with Selenium for automated testing. In a real-world
scenario, you would likely write more complex tests and organize your code into test suites and test
cases but this example should give you a good starting point for exploring Selenium.
Experiment no: 11.Write a simple program in JavaScript and perform testing using
Selenium Aim: Write a simple program in JavaScript and perform testing using Selenium
Program: Simple Java Script program that you can test using Selenium
<!DOCTYPE html>
<html>
<head>
<title> Simple Java Script Program </title>
</head>
<body>
<pid=”output”>0</p>
<button id=”increment-button”>Increment</button>
<script>
const output=document.getElementById(“output”);
const incrementButton=document.getElemetById(“increment-button’);
let count=0;
incrementButton.addEventListener(“click”, function(){
count +=1;
output.innerHTML=count;
});
</script>
</body>
</html>
You can run the test case using the following commands:
$javac Main.java
$javac Main
This output indicates the test case passed, and the increment button was successfully
Clicked, causing the output to be incremented by 1
Experiment: 12. Develop test cases for the above containerized application using Selenium.
Aim: Develop test cases for the above containerized application using
Selenium.
Program: Here is an example of how you could write test cases for the containerized
application using selenium.
Import org.openqa.selenium.By;
Import org.openqa.selenium.WebDriver;
Import org.openqa.selenium.chrome.ChromeDriver;
Import org.junit.After;
Import org.junit.Before;
Import org.junit.Test;
Public class Main
{
Private WebDriver driver;
@Before
Public void setUp()
{
System.setProperty(“webdriver.chrome.driver”, “path/to/chromedriver”);
driver=new ChromeDriver();
}
@Test
Public void testHomePageLoad()
{
driver.get(http://localhost:8080);
String title = driver getTitle();
assert title.equals(“My Containerized Application”);
}
@Test
Public void testSubmitForm()
{
driver.get(http://localhost:8080);
driver.findElement(By.name(“name”)).sendKeys(“JohnDeo”);
driver.findElement(By.name(“email”)).sendkeys(“[email protected]”);
driver.findElement(By.name(“submit”)).click();
String result=driver.findElement(By.id(“result”)).getText();
assert result.equals(“Formsubmitted successfully!”);
}
@After
Public void tearDown()
{ driver.quit(); }
}
You can run the test cases using the following command:
$javac Main.java
$javac Main
The output of test cases should be:
..
Time: 1.135
OK (2test)
This output indicates that both test cases passed, and the containerized application is functioning as
expected.