Saturday, October 26, 2019

How to Uninstall Docker in Ubuntu

To Uninstall Docker completely from Ubuntu machine

Method 1: 


To completely uninstall Docker:
Step 1
dpkg -l | grep -i docker

To identify what installed the package you have:
Step 2
sudo apt-get purge -y docker-engine docker docker.io docker-ce  
sudo apt-get autoremove -y --purge docker-engine docker docker.io docker-ce  

The above commands will not remove images, containers, volumes, or user-created configuration files on your host. If you wish to delete all images, containers, and volumes run the following commands:
sudo rm -rf /var/lib/docker /etc/docker
sudo rm /etc/apparmor.d/docker
sudo groupdel docker
sudo rm -rf /var/run/docker.sock
You have removed Docker from the system completely.
Method 2: 
 I find it much easier to uninstall docker if it is installed with snap. You simply do: (Source: Stackover flow)
sudo snap remove docker

and to delete all related files,
sudo find / -name "*docker*" -exec `rm -rf` {} +
Method 3: 
sudo apt-get purge -y docker.io docker-ce

sudo apt-get autoremove -y --purge docker.io docker-ce

sudo apt-get autoclean

sudo rm -rf /var/lib/docker

sudo rm -rf /etc/docker

sudo rm /etc/apparmor.d/docker

sudo apt-get purge runc containerd docker.io docker-ce
 this command to see if docker files are any where else:
sudo find / -name '*docker*'



Friday, October 25, 2019

How to Create Git Hub account


Step 1: Click on the link to navigate to Git hub account creation page, Sign Up Page for account creation

Step 2: Enter the details like desired username, registered emailid, and password (15 characters or 8 characters including 1 Lower case,1 Numeric value)
Step 3: Sign in to your git account with your Username and password and click on [Sign in]
Your git hub account created successfully and now you are able to create repositories in git hub.




Wednesday, October 23, 2019

Jenkins Setup - Install Java , Jenkins Slave machine on Ubuntu EC2 Instance

Basic information about Jenkins Master and Slave
Jenkins Master
Your main Jenkins server is the Master. The Master’s job is to handle:
  • Scheduling build jobs.
  • Dispatching builds to the slaves for the actual execution.
  • Monitor the slaves (possibly taking them online and offline as required).
  • Recording and presenting the build results.
  • A Master instance of Jenkins can also execute build jobs directly.
Jenkins Slave
A Slave is a Java executable that runs on a remote machine. Following are the characteristics of Jenkins Slaves:
  • It hears requests from the Jenkins Master instance.
  • Slaves can run on a variety of operating systems.
  • The job of a Slave is to do as they are told to, which involves executing build jobs dispatched by the Master.
  • You can configure a project to always run on a particular Slave machine, or a particular type of Slave machine, or simply let Jenkins pick the next available Slave.
Let's see how to configure both Jenkins master and slave nodes on Ubuntu EC2.

Jenkins Master Creation link: How to Create Jenkins Master

Step 1 : Create another Jenkins Slave machine instance in AWS EC2 

Create another user in the Jenkins Slave machine as Jenkins-slave and follow the below commands
Step 2 - $ sudo su
Step 3 -  sudo adduser --home /home/jenkins-slave --shell /bin/bash --ingroup admin jenkins-slave


Logged into  created user using
Step 4 - $ sudo su - jenkins-slave


Step 5 : Now type  ssh-keygen (and then simply enter four times, do not give any password)

Set no password authentication  in /etc/sudoers
Step 6 - vi /etc/sudoers and type the following command in the sudoers file, hit the "Esc" key from keyboard and save the file by typing "wq!"


Step 7 : Copy the "Private key (id_rsa)" from ~/.ssh/id_rsa file by typing below commad

         cat ~/.ssh/id_rsa  or Go To ---> .ssh folder "cd .ssh"
         

Step 8 : Go to Master Jenkins and type the jenkins URL like "http://3.19.211.7:8080/"

Step 9 : Add SSH Keys from Master to Slave

Execute the below command in Jenkins master Ec2.
sudo cat ~/.ssh/id_rsa.pub

Copy the output of the above command:

Step 10 : Now go to Slave node and execute the below command and paste the "id_rsa.pub" key to authorized_keys

jenkins-slave@ip-172-31-33-151:~/.ssh$ vi authorized_keys


Once you pasted the public keys in the above file in Slave, come out of the file by entering wq! and enter again

Now go into master node
ubuntu@ip-172-31-41-76:~$ sudo ssh jenkins-slave@172.31.33.151


this is to make sure the master is able to connect the slave node. once you are successfully logged into the slave, type exit to come out of the slave.

And type the below commands 




Step # Register slave node in Jenkins:
Now to go Jenkins Master, manage jenkins, manage nodes.












  1. Click on new node. 
  2. give the name and check permanent agent, 
  3. give a name and no of executors as 1 or 2 or based on your requirement. 
  4. enter /home/Jenkins-slave as a remote directory.
  5. select launch method as Launch slaves nodes via SSH.
  6. enter Slave node private ip address as Host.

       7. Click on [Add] and click on [Jenkins] it will redirect to another window




        8.  Select the "SSH Username with Private Key" and fill the necessary information as below image

   


    9. type the command cat ~/.ssh/id_rsa  looks like the below image (text hidden in the image) 
    (Make sure you copy the whole key including the below without missing anything)
-----BEGIN RSA PRIVATE KEY-----

-----END RSA PRIVATE KEY----


 10 . Paste in the "Private key" in the text area as mentioned in below image




11. After that Select the "Username" from [Credentials] drop-down list as shown in below image and click on [SAVE] button.


Step # : Create a new Jenkins Job in Jenkins Master 
Step #: Type Project Name and Project Type  and click on the [OK] button
Step #: Go To -> General tab and check the [Restrict where this project can be run] and enter the slave machine name

Step #: Click on "Build Environment" and select Build type as "Execute Shell" and click on [save] button by typing some as like in below 



Step #: Go To Jenkins Dashboard and click on [Build Now] to run the job and check the output


Step #: Go to Jenkins Slave Machine and type the below commands 
             sudo su - jenkins-slave and press "ls"


 Type "cd workspace" and press "ls"  select desired  like "Jenkins-Slave-job" and press "ls" again to verify the text file created or not.



Now you can kick start building the jobs, you will see Jenkins master runs jobs in slave nodes.



Tuesday, October 22, 2019

How To Install Docker on Ubuntu 18.04

Docker Installation Steps 

Install using the repository

Before you install Docker Engine - Community for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.
Step 1: Update your existing list of packages
    $ sudo apt-get update

Step 2: Next, install a few prerequisite packages which let apt use packages over HTTPS:
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Step 3: Then add the GPG key for the official Docker repository to your system:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Step 4: Add the Docker repository to APT sources:

$sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) 
 stable"

Step 5: Next, update the package database with the Docker packages from the newly added repo:

 $ sudo apt-get update

Step 6: Make sure you are about to install from the Docker repo instead of the default Ubuntu repo:
apt-cache policy docker-ce
You’ll see output like this, although the version number for Docker may be different:




Output:


Step 7: Notice that docker-ce is not installed, but the candidate for installation is from the Docker repository for Ubuntu 18.04

$ sudo apt install docker-ce


Step 8: Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running:
$ sudo systemctl status docker
The output should be similar to the following, showing that the service is active and running:
Executing the Docker Command Without Sudo (Optional)
If you want to avoid typing sudo whenever you run the docker command, add your username name to  the docker group:
$ sudo usermod -aG docker ${USER}


To apply for the new group membership, log out of the server and back in, or type the following:
$ su - ${USER}
You will be prompted to enter your user’s password to continue. Confirm that your user is now added to the docker group by typing:

$ id -nG

If you need to add a user to the docker group that you’re not logged in as, declare that username explicitly using:

$ sudo usermod -aG docker username

Eg: sudo usermod -aG docker ubuntu

Register for a Docker ID

Your Docker ID becomes your user namespace for hosted Docker services, and becomes your username on the Docker Forums.
  1. Enter a username that is also your Docker ID.
    Your Docker ID must be between 4 and 30 characters long, and can only contain numbers and lowercase letters.
  2. Enter a unique, valid email address.
  3. Enter a password between 6 and 128 characters long.
  4. Click Sign up.
    Docker sends a verification email to the address you provided.
  5. Click the link in the email to verify your address.
Note: You cannot log in with your Docker ID until you verify your email address.


Once Verification is done. Please try to login to Docker Hub with registered details
After successful login, click on "Create Repository" 
 Please provide the Repository name and other details and then click on the [Create] button



Verify the repository created successfully in Docker hub or not 
To push a new tag to this repository, use the below command

docker push krishnadasari610/testrepository:tagname










How to install and setup Kubernetes cluster using kOps in AWS environment

  Kops: Kops is also known as Kubernetes Operations, it is an open-source project which helps you to create, upgrade, destroy, and maintain ...