Friday, July 21, 2023

CKA-EXAM-Reference

In this post i'm hosting the web application to refer the CKA document reference for Exam.


CKA-Exam-Bookmarks



Wednesday, January 20, 2021

Script to search a word/Parameter from file and append.

 In this post, i wanted to write a shell script to search a parameter/Word in a file and append the value if the word/parameter is not there in the file.

#!/bin/bash

 grep -i "Pasupula" /tmp/Sravan/info.txt

if [ $? == 0 ]

then

        echo " Already search content was there in the file"

else

        echo -e " Sravanakumar_Pasupula from bangalore" >> /tmp/Sravan/info.txt

fi

 here, info.txt is a file, under which i wanted to search a word "Pasupula", if the word is exists in the file nothing to append, if the word is not there in the file then execute the command by appending the Sravanakumar_Pasupula from Bangalore.


Saturday, November 28, 2020

Docker - Container Lifecycle

 In this post, we will explore in detail with different stages of  docker containers flow. From creating containers to  destroy containers,  there are several stages , all these stages we can call it as Docker -Containers lifecycle.

following illustration gives the entire lifecycle of docker container. 

Docker Container Lifecycle

  • When you execute docker create  with specific name and image, then container will be created with specified name, but not run the any container processes.(Created stage)
  • Then  run command will create a new container and run the image,  then container will goes to Running Stage and the container processes will run.
  • if we want to stop the running container processes, then the container stage will goes to Stopped stage and container processes will be stopped.
  • if we want to start the topped container processes, then the container stage will goes to Running stage and container processes will be run.
  • if we want to pause  the running container process, then the container stage will goes to Paused stage. in this stage container process will be suspended., but not be running.
  • if we want to unpause the suspended container process, then the container stage will goes to Running stage, and the container processes will run.
  • if we want to remove the stopped container, then the container stage will goes to deleted stage. the container will be removed.
Note:  docker kill command can be used to kill the  running container processes  immediately.

lets, have a practical stuff with these stages and get keen understandings.


1. Create container : 

docker create command will create a new Docker container with the specified image.

syntax : docker create --name <container name> <image name>

example: docker create --name cont-1 ubuntu 

Output: 


2. Run Container :

docker run command will create a new container and run the image in the newly created container. (docker run command will do the both “docker create” and “docker start” command)

syntax:  docker run -itd --name <container name> <image name>

example : docker run -itd --name cont-1 myubuntu:v1

Output : 




3. Stop Container :

docker stop command will use to stop the container which are in running stage.

syntax :  docker stop <container name>

example : docker stop cont-1

Output : 




4. Start Container :

docker start command will use to start the container which are in stopped stage.

syntax :  docker start <container name>

example : docker start cont-1

Output : 




5. Pause Container :

docker pause command will use to pause/suspend the container which are in Running stage.

syntax :  docker pause <container name>

example : docker pause cont-1

Output : 



6. Unpause Container :

docker unpause command will use to run the container which are in paused stage.

syntax :  docker unpause <container name>

example : docker unpause cont-1

Output : 




7. Remove Container :

docker rm command will use to delete the container which are in stopped or Created  stages.

syntax :  docker rm <container name>

example : docker rm cont-1

Output : 




docker rm -f command will use to delete the container which is in Running stage.

syntax :  docker rm -f  <container name>

example : docker rm -f  cont-1

Output : 







Tuesday, October 27, 2020

Ansible Gathering Facts

In this Post we will learn about the Ansible facts, and what are ansible facts ..

Ansible facts are nothing but information about the Managed Nodes like OS distribution, releases, processors,Domain,IP,..etc. ..

we can collect or gather these above piece of information running as a task in ansible controller .

the task of collecting the remote system information is called as gathering the Facts, we ca call it as variable.

we can gather/collect facts about the remote server information by using setup module in Ad-hoc commands.

Important thing here is , by default ansible playbooks will call the setup module and perform the gathering facts task.
  
syntax for this is  :  ansible group_name(in my case my-servers is the group name) -m setup

ansible my-servers -m setup












we will get the lot of info about the managed servers(nodes), we can call it as Dictionary, it consists of list of values or some text 

so setup module will help us to gather the info about the managed servers .

now lets see how we can see only some piece of info from the  above output, ie mount points need to be print .

ansible my-servers -m setup -a "filter=ansible_mounts"



















there are 2 types of ansible Facts or Variable for Managed Nodes

 they are: 

  1.  Default Facts
  2.  Custom Facts
Default Facts: this is nothing but if we run the setup module we will get some facts or some variables or some information  they are called simply Default facts

if we want some extra facts from our managed nodes for that we need to create a custom facts 

custom Facts will helps us to get the user defined required facts 

for example i would like to find the httpd version, weblogic version, db version,git version for all managed nodes on every week,  i can say some sort of inventory of my managed nodes , we can get these details with ad-hoc commands but those will be more, so if we define custom facts that our playbook will get  simple and easy.

Custom Facts are not mandatory, if we want we can define our own to custom facts , that will be use for  playbook. ( reduced the lines in the play book) 

we try to create a custom facts(required info), for now git version and httpd versions through ad-hoc command

steps to create Custom Facts:

step 1: Create folder facts.d  under /etc/ansible on Controlled Node

[ansible@control-server ansible]$ pwd
/etc/ansible
[ansible@control-server ansible]$sudo mkdir facts.d










step2: Inside of facts.d place one or more custom facts files with extension as .fact(it                    may be a shell/python or any) 

   Note: The output of fact file should be a Json.










step 3: .fact file should have execution permissions.

sudo chmod 755 version.fact








output of the .version.fact  file will be as below:









so we got the required output with the Custom facts, now we have to place this custom Facts in all the managed nodes.

create the file in to the remote managed nodes.

ansible all -m file -a "path=/etc/ansible/facts.d state=directory" -b


















Now copy the file from controller node  in to all other managed nodes.

 ansible all -m copy -a "src=/etc/ansible/facts.d/version.fact dest=/etc/ansible/facts.d/version.fact mode=0755" -b

















now we will run the command to get the details from managed nodes.

Custom Facts should be under "ansible_local" variable in the setup module output

for me getting error because of latest ansible used for this lab..















like this we can create our own custom facts and we can make use of it .

Monday, October 26, 2020

AWS Assignment

               AWS Assignment


Objective 


At the end of this assignment you will have created a web site using the following Amazon Web Services: EC2, EBS, ELB and S3. 

  

Stage 1: Building the EC2 web server. 


Launch an EC2 instance, based on Linux or Windows, to meet the following objectives: 

  •  the instance should be of type t2.micro.
  •  the instance should reside within region ap-south-1(Mumbai) within availability zone                   ap-south-1a.
  •  the instance should use a 1 GiB attached EBS volume and contain a valid partition                        table with  one partition. The partition should contain a valid file system, 
  •  the file system residing on the EBS volume should be mounted automatically upon  reboot of   the EC2 instance.  
  •  the instance should serve web pages via an appropriate service such as Apache or IIS ,This service should start automatically upon boot  
  •  the instance should serve a web page "index.html" containing well-formed HTML    displaying text "Hello AWS World" and display the screen shots created below in Stage 3(they will be hosted separately). HTML file should reside on the previously created EBS        volume and be served as the default document from web server root.  
  • the instance should use Security Groups effectively to allow administration and serve   HTTP requests only. 

 

Stage 2: Building and configuring the Elastic Load Balancer: 


 Create an Elastic Load Balancer (ELB) with the following specification: 

  • the ELB should be created in the Singapore region. 
  • the ELB should accept HTTP on port 80.  
  • the Healthy Threshold for the ELB to be set to 2 seconds 
  • deliver traffic to the EC2 instance created in Stage 1. 

   

Stage 3: Configuring S3 


 Create a Simple Storage Service (S3) bucket with the following specification: 

  • bucket should be created in the ap-south-1 region.  
  • bucket should be publicly readable. 

  

Place screenshots in the S3 bucket, in png format, clearly showing the following: 

  • The mounted EBS volume eg, using Windows Explorer or run from the console on a Linux host. This screen shot should be named as screen-shot1.  
  • The index.html file resides within EBS eg. using windows explorer or in Linux go to the mounted volume directory and run "pwd; ls –l". This screen shot should be named as screen-shot2.png  
  • The web server has been configured to serve index.html from the EBS volume as the default document eg the relevant section of the Apache configuration file or IIS Manager. This screen shot should be named as screenshot 3.png 

  

Remember to use the S3 URLS in the index.html file hosted on EC2 (see Stage 1).  

  

DELIVERABLES 

 Please provide to the communicated email id the following information 

  •  the public DNS entry/ Public IP for the EC2 instance  
  •  the public URL to the web page via the ELB 

   

Solution


Stage 1: Building the EC2 web server:

Creating EC2 instance in Mumbai region with availability zone  ap-south-1.









Select the instance type as t2.micro per the assignment.









As per the assignment chosen the availability zone as  ap-south-1a














As per the assignment  added new EBS volume as 1 GB.









add tag as per our naming convient.in my case i added Name as Apache instance.










As per the assignment  created the Security group and its traffic allow only on HTTP protocol. but added both http and https :)

Review and launch



























and use the pem key 



 







Login to the created EC2 instance with root user

For disk partition per assignment please follow below steps.

yum install lvm2*



 





lsblk









fdisk /dev/xvdb
















fdisk -l /dev/xvdb







lsblk







pvcreate /dev/xvdb1


vgcreatemyvg /dev/xvdb1





lvcreate -l 100%VG -n mylv myvg




lvs



mkfs.xfs /dev/myvg/myl







mkdir /appsdata


vi /etc/fstab

if you add the below entries in /etc/fstab, after reboot of the instance/machine the mount point will be exists.

 mount –a





df–hk







Compilation of apache software under the newly created /appsdata mount.

In order to compile the Source, I took the source file from the apache foundation website. And followed the below steps.

1. go to the link : https://archive.apache.org/dist/httpd/

2. copy the link which version you would like to download

3. wget https://archive.apache.org/dist/httpd/httpd-2.2.34.tar.gz

4. tar -xvzf httpd-2.2.34.tar.gz

5. cd /httpd-2.2.34

6. Required libraries has been installed to source execution.(gcc,apr)

7.  ./configure --prefix=/appsdata/apache2.2.34  --enable-modules=all

8. make

9. make install

By this we will finished the apache compilation successfully, now we have to bring it up from installed path

10. start apache services from the path: /appsdata/apache2.2/bin/ and execute the below command to start.

./apachectl  -k start

11. To deploy index.html on apache as below:

Go to the documentroot path :   /appsdata/apache2.2/htdocs

 

12. Create the index.html file and add the below content as per the assignment

Vi index.html

<html><body><h1>"Hello AWS World"</h1></body></html>

:wq!

13. now we have to provide the URL in browser to test the result.

         





By this stage 1 has been completed.

Before going to stage 2, I would like to create a AMI and copy to the Singapore region.









Copy AMI:








Copied AMI has to be launched in Singapore region by selecting the Singapore VPC and its availability zones.







Just Launch and follow the next steps to create the ec2 instance in Singapore region.

Stage:2 :Building and configuring the Elastic Load Balancer: 

 ELB created in the Singapore region.

Go to Ec2 dashboard then click on Elastic Loadbalencers then Create the new ELB.



 







In my case I have chosen CLB



 






define the loadbalencer and its security options.












choose the SG.







as we do not have any SSL settings , we can skip now for this step.




As per assignment healthy threefold set to 2 .








Add the instances which was already lunched from the mumbai region AMI.









Then click on the create.



 









Then try to access t the below URL

my-elb-1190623872.ap-southeast-1.elb.amazonaws.com:80

 






Now we have successfully completed the stage:2

Stage 3: Configuring S3 

 

 Created a Simple Storage Service (S3) bucket with the following specification from S3 dashboard: 

·         Bucket has been created in the ap-south-1(Mumbai) region.  

·         Bucket has been provisioned be publicly readable. 






Leave as is.


  It should be public need to uncheck Block all public access 




 























Just review and click on create bucket

 


 



















DELIVERABLES 

 Please provide to the communicated email id the following information 

·         the public DNS entry/ Public IP for the EC2 instance  (ec2-15-206-80-10.ap-south-1.compute.amazonaws.com)

·         the public URL to the web page via the ELB (http://my-elb-1190623872.ap-southeast-1.elb.amazonaws.com/)


 

https://my-s3-bucket1.s3.ap-south-1.amazonaws.com/screen-shot1.png




 

 

 





https://my-s3-bucket1.s3.ap-south-1.amazonaws.com/screen-shot2.png