├── Ansible ├── Ansible_install_on_RHEL.MD └── Ansible_installation.MD ├── Devops_course.PNG ├── Docker ├── DockerHub.MD ├── Docker_Commands.MD ├── Docker_Installation_Steps.MD ├── Dockerfile_Instructions.md ├── install_apache_dockerfile.txt └── tomcat_dockerfile ├── Jenkins ├── Ansible_integration.MD ├── Git_plugin_install.MD ├── Jenkins_Installation.MD └── maven_install.MD ├── Jenkins_Jobs ├── Deploy_on_Container.MD ├── Deploy_on_Container_using_Ansible.MD ├── Deploy_on_Docker.MD ├── Deploy_on_Tomcat_Server.MD ├── Dockerfile.txt ├── My_First_Maven_Build.MD ├── create-docker-container.yml ├── create-docker-image.yml └── simple-docker-project.yml ├── Kubernetes ├── Dockerfile ├── Integrating_Kubernetes_with_Ansible.MD ├── Integrating_Kubernetes_with_Jenkins.MD ├── Kubernetes_Setup_using_kops.md ├── Kubernetes_Setup_using_kubeadm.md ├── create-simple-devops-image.yml ├── create_image_regapp.yml ├── firstpod.yml ├── firstrs.yml ├── firstservice.yml ├── kube_deploy.yml ├── kubernetes-valaxy-deployment.yml ├── kubernetes-valaxy-service.yml ├── kubernetes_setup_using_eksctl.md ├── nginx-deploy.yaml ├── regapp-deploy.yml ├── regapp-service.yml ├── valaxy-deploy.yml └── valaxy-service.yml ├── README.md └── Tomcat └── tomcat_installation.MD /Ansible/Ansible_install_on_RHEL.MD: -------------------------------------------------------------------------------- 1 | #### On RHEL 8.x server 2 | 3 | 1. Install Python latest version (on Control node and Managed host) 4 | ```sh 5 | yum install python3 -y 6 | ``` 7 | 8 | 1. By default, python3 is the command to run python commands. to use just python, use "alternatives" command. (on Control node and Managed host) 9 | ```sh 10 | alternatives --set python /usr/bin/python3 11 | ``` 12 | 13 | 1. Check for Python version 14 | ```sh 15 | python --version 16 | ``` 17 | 1. Install python-pip package manager (on Control node) 18 | ```sh 19 | yum -y install python3-pip 20 | ``` 21 | 22 | 1. Create a new user for ansible administration & grant admin access to the user (on Control node and Managed host) 23 | ```sh 24 | useradd ansadmin 25 | passwd ansadmin 26 | ``` 27 | 1. Below command adds ansadmin to sudoers file. But we strongly recommended using "visudo" command if you are aware vi or nano editor. (on Control node and Managed host) 28 | ```sh 29 | echo "ansadmin ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers 30 | ``` 31 | 1. Using key-based authentication is advised. If you are still at the learning stage use password-based authentication (on Control node and Managed host) 32 | ```sh 33 | # sed command replaces "PasswordAuthentication no to yes" without editing file 34 | sed -ie 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config 35 | sudo service sshd reload 36 | ``` 37 | 38 | #### Install Ansible as a ansadmin user (on Control node) 39 | ```sh 40 | su - ansadmin 41 | pip3 install ansible --user 42 | ``` 43 | Note: Ansible must be installed as a user (here ansadmin) 44 | 1. check for ansible version 45 | ```sh 46 | ansible --version 47 | ``` 48 | 49 | 1. Log in as a ansadmin user on master and generate ssh key (on Control node) 50 | ```sh 51 | ssh-keygen 52 | ``` 53 | 1. Copy keys onto all ansible managed hosts (on Control node) 54 | ```sh 55 | ssh-copy-id ansadmin@ 56 | ``` 57 | ### Validation test 58 | 59 | 1. Create a directory /etc/ansible and create an inventory file called "hosts" add control node IP address in it. 60 | 61 | 1. Run ansible command as ansadmin user it should be successful (Master) 62 | ```sh 63 | ansible all -m ping 64 | ``` 65 | -------------------------------------------------------------------------------- /Ansible/Ansible_installation.MD: -------------------------------------------------------------------------------- 1 | # Ansible Installation 2 | 3 | Ansible is an open-source automation platform. It is very, very simple to set up and yet powerful. Ansible can help you with configuration management, application deployment, task automation. 4 | 5 | ### Pre-requisites 6 | 7 | 1. An AWS EC2 instance (on Control node) 8 | 9 | ### Installation steps: 10 | #### on Amazon EC2 instance 11 | 12 | 1. Install python and python-pip 13 | ```sh 14 | yum install python 15 | yum install python-pip 16 | ``` 17 | 1. Install ansible using pip check for version 18 | ```sh 19 | pip install ansible 20 | ansible --version 21 | ``` 22 | 23 | 1. Create a user called ansadmin (on Control node and Managed host) 24 | ```sh 25 | useradd ansadmin 26 | passwd ansadmin 27 | ``` 28 | 1. Below command grant sudo access to ansadmin user. But we strongly recommended using "visudo" command if you are aware vi or nano editor. (on Control node and Managed host) 29 | ```sh 30 | echo "ansadmin ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers 31 | ``` 32 | 33 | 1. Log in as a ansadmin user on master and generate ssh key (on Control node) 34 | ```sh 35 | sudo su - ansadmin 36 | ssh-keygen 37 | ``` 38 | 1. Copy keys onto all ansible managed hosts (on Control node) 39 | ```sh 40 | ssh-copy-id ansadmin@ 41 | ``` 42 | 43 | 1. Ansible server used to create images and store on docker registry. Hence install docker, start docker services and add ansadmin to the docker group. 44 | ```sh 45 | yum install docker 46 | 47 | # start docker services 48 | service docker start 49 | service docker start 50 | 51 | # add user to docker group 52 | usermod -aG docker ansadmin 53 | 54 | ``` 55 | 1. Create a directory /etc/ansible and create an inventory file called "hosts" add control node and managed hosts IP addresses to it. 56 | 57 | ### Validation test 58 | 59 | 60 | 1. Run ansible command as ansadmin user it should be successful (Master) 61 | ```sh 62 | ansible all -m ping 63 | ``` 64 | -------------------------------------------------------------------------------- /Devops_course.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yankils/Simple-DevOps-Project/427cfbcc580335631ff22bacffa6fbfe9340c714/Devops_course.PNG -------------------------------------------------------------------------------- /Docker/DockerHub.MD: -------------------------------------------------------------------------------- 1 | ## What is Docker Hub Registry 2 | 3 | Docker Hub is a cloud-based registry service which allows you to link to code repositories, build your images and test them, stores manually pushed images, and links to Docker Cloud so you can deploy images to your hosts. It provides a centralized resource for container image discovery, distribution and change management, user and team collaboration, and workflow automation throughout the development pipeline. 4 | 5 | ##### Ref URL : https://docs.docker.com/docker-hub/ 6 | 7 | 1. Create a docker hub account in https://hub.docker.com/ 8 | 9 | 1. Pull a docker image 10 | 11 | ```sh 12 | docker pull ubuntu 13 | ``` 14 | 15 | 1. pull a docker image with the old version 16 | 17 | ```sh 18 | docker pull ubuntu:16.04 19 | ``` 20 | 21 | 1. create a custom tag to the docker image 22 | ```sh 23 | docker tag ubuntu:latest valaxy/ubuntu:demo 24 | ``` 25 | 26 | 1. login to your docker hub registry 27 | ```sh 28 | docker login 29 | docker push valaxy/ubuntu:demo 30 | ``` 31 | 32 | ### testing 33 | 34 | 1. Remove all images in docker server 35 | ```sh 36 | docker image rm -f 37 | ``` 38 | 39 | 1. Pull your custom image from your docker account 40 | ```sh 41 | docker pull valaxy/ubuntu:demo 42 | ``` 43 | 44 | -------------------------------------------------------------------------------- /Docker/Docker_Commands.MD: -------------------------------------------------------------------------------- 1 | 2 | 1. how to search a docker image in hub.docker.com 3 | ```sh 4 | docker search httpd 5 | ``` 6 | 2. Download a docker image from hub.docker.com 7 | ```sh 8 | docker image pull : 9 | ``` 10 | 11 | 3. List out docker images from your local system 12 | ```sh 13 | docker image ls 14 | ``` 15 | 16 | 4. Create/run/start a docker container from image 17 | ```sh 18 | docker run -d --name : 19 | 20 | d - run your container in back ground (detached) 21 | ``` 22 | 23 | 5. Expose your application to host server 24 | ```sh 25 | docker run -d -p : --name : 26 | 27 | docker run -d --name httpd_server -p 8080:80 httpd:2.2 28 | ``` 29 | 30 | 6. List out running containers 31 | ```sh 32 | docker ps 33 | ``` 34 | 35 | 7. List out all docker container (running, stpooed, terminated, etc...) 36 | ```sh 37 | docker ps -a 38 | ``` 39 | 40 | 8. run a OS based container which interactive mode (nothing but login to container after it is up and running) 41 | 42 | ```sh 43 | docker run -i -t --name centos_server centos:latest 44 | i - interactive 45 | t - Terminal 46 | ``` 47 | 48 | 9. Stop a container 49 | ```sh 50 | docker stop 51 | ``` 52 | 53 | 10. Start a container which is in stopped or exit state 54 | 55 | ```sh 56 | docker start 57 | ``` 58 | 11. Remove a container 59 | 60 | ```sh 61 | docker rm 62 | ``` 63 | 64 | 12. login to a docker container 65 | ```sh 66 | docker exec -it /bin/bash 67 | ``` 68 | -------------------------------------------------------------------------------- /Docker/Docker_Installation_Steps.MD: -------------------------------------------------------------------------------- 1 | # Installing Docker on Amazon Linux server 2 | 3 | ### Pre-requisites 4 | 1. Amazon Linux EC2 Instance 5 | 6 | ## Installation Steps 7 | 8 | 1. Install docker and start docker services 9 | ```sh 10 | yum install docker -y 11 | docker --version 12 | 13 | # start docker services 14 | service docker start 15 | service docker status 16 | ``` 17 | 1. Create a user called dockeradmin 18 | ```sh 19 | useradd dockeradmin 20 | passwd dockeradmin 21 | ``` 22 | 1. add a user to docker group to manage docker 23 | ``` 24 | usermod -aG docker dockeradmin 25 | ``` 26 | ### Validation test 27 | 1. Create a tomcat docker container by pulling a docker image from the public docker registry 28 | ```sh 29 | docker run -d --name test-tomcat-server -p 8090:8080 tomcat:latest 30 | ``` 31 | 32 | ## Docker Installation on CentOS server 33 | ##### Referance URL : https://docs.docker.com/install/linux/docker-ce/centos/#install-using-the-repository 34 | ### Pre-requisites 35 | 36 | Please follow below steps to install docker CE on CentoOS server instance. For RedHat only Docker EE available 37 | 38 | 1. Install the required packages. 39 | 40 | ```sh 41 | sudo yum install -y yum-utils \ 42 | device-mapper-persistent-data \ 43 | lvm2 44 | ``` 45 | 46 | 1. Use the following command to set up the stable repository. 47 | 48 | ```sh 49 | sudo yum-config-manager \ 50 | --add-repo \ 51 | https://download.docker.com/linux/centos/docker-ce.repo 52 | ``` 53 | 54 | ### INSTALLING DOCKER CE 55 | 56 | 1. Install the latest version of Docker CE. 57 | ```sh 58 | sudo yum install docker-ce 59 | ``` 60 | 61 | Note: If prompted to accept the GPG key, verify that the fingerprint matches 62 | 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35, and if so, accept it. 63 | 64 | 1. Start Docker. 65 | ```sh 66 | sudo systemctl start docker 67 | ``` 68 | 69 | 1. Verify that docker is installed correctly by running the hello-world image. 70 | ```sh 71 | sudo docker run hello-world 72 | ``` 73 | -------------------------------------------------------------------------------- /Docker/Dockerfile_Instructions.md: -------------------------------------------------------------------------------- 1 | 2 | DockerFile 3 | 4 | 1. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. 5 | 2. The docker build command builds an image from a Dockerfile and a context. 6 | ```sh 7 | docker build . 8 | docker build -f /path/to/a/Dockerfile . 9 | docker build -t shykes/myapp . 10 | ``` 11 | 12 | 3. The Docker daemon runs the instructions in the Dockerfile one-by-one, committing the result of each instruction to a new image if necessary, before finally outputting the ID of your new image. 13 | 4. Whenever possible, Docker uses a build-cache to accelerate the docker build process significantly. 14 | 5. When you’re done with your build, you’re ready to look into scanning your image with docker scan 15 | ```sh 16 | docker scan hello-world 17 | 18 | ``` 19 | 20 | ## Dockerfile Creation 21 | 22 | Docker file format 23 | ```sh 24 | # Comment 25 | INSTRUCTION arguments 26 | ``` 27 | 28 | 1. A Dockerfile must begin with a FROM instruction. 29 | 30 | 2. Docker distributes official versions of the images that can be used for building Dockerfiles under docker/dockerfile repository on Docker Hub. 31 | 32 | - `FROM` - A valid Dockerfile must start with a FROM instruction. 33 | 34 | - `RUN` - The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile. 35 | 36 | - `CMD` - The main purpose of a CMD is to provide defaults for an executing container. 37 | 38 | `Note:` There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect. 39 | 40 | `Note` - Do not confuse RUN with CMD. RUN actually runs a command and commits the result; CMD does not execute anything at build time, but specifies the intended command for the image. 41 | 42 | - `LABEL` -The LABEL instruction adds metadata to an image. A LABEL is a key-value pair. T 43 | 44 | - `EXPOSE` 45 | 1. The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. 46 | 2. To set up port redirection on the host system, see using the -P flag. 47 | 3. The docker network command supports creating networks for communication among containers without the need to expose or publish specific ports, because the containers connected to the network can communicate with each other over any port. 48 | 49 | - `ENV` - The ENV instruction sets the environment variable to the value . 50 | 51 | - `ADD` - The ADD instruction copies new files, directories or remote file URLs from and adds them to the filesystem of the image at the path . 52 | 53 | If is a local tar archive in a recognized compression format (identity, gzip, bzip2 or xz) then it is unpacked as a directory. 54 | 55 | - `COPY` - The COPY instruction copies new files or directories from and adds them to the filesystem of the container at the path . 56 | 57 | - `ENTRYPOINT` - An ENTRYPOINT allows you to configure a container that will run as an executable. 58 | 59 | 1. ENTRYPOINT will override all elements specified using CMD 60 | 2. Both CMD and ENTRYPOINT instructions define what command gets executed when running a container. There are few rules that describe their co-operation. 61 | 62 | 3. Dockerfile should specify at least one of CMD or ENTRYPOINT commands. 63 | 64 | 4. ENTRYPOINT should be defined when using the container as an executable. 65 | 66 | 5. CMD should be used as a way of defining default arguments for an ENTRYPOINT command or for executing an ad-hoc command in a container. 67 | 68 | 6. CMD will be overridden when running the container with alternative arguments. 69 | 70 | - `VOLUME` - The VOLUME instruction creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers. 71 | 72 | - `USER` - The USER instruction sets the user name to use when running the image 73 | - `WORKDIR` - The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions 74 | 75 | - `ARG` - The ARG instruction defines a variable that users can pass at build-time to the builder with the docker build command using the --build-arg = flag. 76 | 77 | - `SHELL` - The SHELL instruction allows the default shell used for the shell form of commands to be overridden. 78 | 79 | 80 | -------------------------------------------------------------------------------- /Docker/install_apache_dockerfile.txt: -------------------------------------------------------------------------------- 1 | FROM ubuntu:12.04 2 | 3 | MAINTAINER Valaxy Technologies valaxytech@gmail.com 4 | 5 | LABEL version="1.1.0" \ 6 | app_name="Training registration application" \ 7 | release_date="9-Sep-2018" 8 | RUN apt-get update && apt-get install -y apache2 && apt-get clean 9 | 10 | ENV APACHE_RUN_USER www-data 11 | ENV APACHE_RUN_GROUP www-data 12 | ENV APACHE_LOG_DIR /var/log/apache2 13 | 14 | EXPOSE 80 15 | 16 | COPY index.html /var/www/html 17 | CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"] 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Docker/tomcat_dockerfile: -------------------------------------------------------------------------------- 1 | FROM centos 2 | RUN yum install java -y 3 | RUN mkdir /opt/tomcat/ 4 | WORKDIR /opt/tomcat 5 | ADD https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.54/bin/apache-tomcat-9.0.54.tar.gz /opt/tomcat 6 | RUN tar xvfz apache*.tar.gz 7 | RUN mv apache-tomcat-9.0.54/* /opt/tomcat 8 | EXPOSE 8080 9 | CMD ["/opt/tomcat/bin/catalina.sh", "run"] 10 | 11 | -------------------------------------------------------------------------------- /Jenkins/Ansible_integration.MD: -------------------------------------------------------------------------------- 1 | # Ansible integration with Jenkins 2 | 3 | Follow this on **[YouTube](https://www.youtube.com/watch?v=nE4b9mW2ym0)** 4 | 5 | ### Prerequisites: 6 | 1. Ansible server **[Get Help Here](https://www.youtube.com/watch?v=79xFyOc_eEY)** 7 | 2. Jenkins Server **[Get Help Here](https://www.youtube.com/watch?v=M32O4Yv0ANc)** 8 | 9 | ### Part-01 Integration Setps 10 | 11 | Install "publish Over SSH" 12 | - `Manage Jenkins` > `Manage Plugins` > `Available` > `Publish over SSH` 13 | 14 | Enable connection between Ansible and Jenkins 15 | - `Manage Jenkins` > `Configure System` > `Publish Over SSH` > `SSH Servers` 16 | 17 | - SSH Servers: 18 | - Hostname:`` 19 | - username: `ansadm` 20 | - password: `*******` 21 | 22 | Test the connection "Test Connection" 23 | -------------------------------------------------------------------------------- /Jenkins/Git_plugin_install.MD: -------------------------------------------------------------------------------- 1 | # Configure Git pulgin on Jenkins 2 | Git is one of the most popular tools for version control system. you can pull code from git repositories using jenkins if you use github plugin. 3 | 4 | 5 | #### Prerequisites 6 | 1. Jenkins server 7 | 8 | #### Install Git on Jenkins server 9 | 1. Install git packages on jenkins server 10 | ```sh 11 | yum install git -y 12 | ``` 13 | 14 | #### Setup Git on jenkins console 15 | - Install git plugin without restart 16 | - `Manage Jenkins` > `Jenkins Plugins` > `available` > `github` 17 | 18 | - Configure git path 19 | - `Manage Jenkins` > `Global Tool Configuration` > `git` 20 | 21 | -------------------------------------------------------------------------------- /Jenkins/Jenkins_Installation.MD: -------------------------------------------------------------------------------- 1 | # Install Jenkins on AWS EC2 2 | Jenkins is a self-contained Java-based program, ready to run out-of-the-box, with packages for Windows, Mac OS X and other Unix-like operating systems. As an extensible automation server, Jenkins can be used as a simple CI server or turned into the continuous delivery hub for any project. 3 | 4 | ### Follow this artical [On YouTube Channel](https://youtu.be/ERR7cqW28FY) 5 | 6 | ### Prerequisites 7 | 1. EC2 Instance 8 | - With Internet Access 9 | - Security Group with Port `8080` open for internet 10 | 1. Java 11 should be installed 11 | 12 | 13 | ## Install Jenkins 14 | You can install jenkins using the rpm or by setting up the repo. We will set up the repo so that we can update it easily in the future. 15 | 1. Get the latest version of jenkins from https://pkg.jenkins.io/redhat-stable/ and install 16 | ```sh 17 | sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo 18 | sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key 19 | amazon-linux-extras install epel 20 | amazon-linux-extras install java-openjdk11 21 | 22 | #on RedHat/CentOs 23 | #yum install epel-release # repository that provides 'daemonize' 24 | #yum install java-11-openjdk-devel 25 | #yum install jenkins 26 | ``` 27 | 28 | ### Start Jenkins 29 | ```sh 30 | # Start jenkins service 31 | service jenkins start 32 | 33 | # Setup Jenkins to start at boot, 34 | chkconfig jenkins on 35 | ``` 36 | 37 | ### Accessing Jenkins 38 | By default jenkins runs at port `8080`, You can access jenkins at 39 | ```sh 40 | http://YOUR-SERVER-PUBLIC-IP:8080 41 | ``` 42 | #### Configure Jenkins 43 | - The default Username is `admin` 44 | - Grab the default password 45 | - Password Location:`/var/lib/jenkins/secrets/initialAdminPassword` 46 | - `Skip` Plugin Installation; _We can do it later_ 47 | - Change admin password 48 | - `Admin` > `Configure` > `Password` 49 | - Configure `java` path 50 | - `Manage Jenkins` > `Global Tool Configuration` > `JDK` 51 | - Create another admin user id 52 | 53 | ### Test Jenkins Jobs 54 | 1. Create “new item” 55 | 1. Enter an item name – `My-First-Project` 56 | - Chose `Freestyle` project 57 | 1. Under the Build section 58 | Execute shell: echo "Welcome to Jenkins Demo" 59 | 1. Save your job 60 | 1. Build job 61 | 1. Check "console output" 62 | -------------------------------------------------------------------------------- /Jenkins/maven_install.MD: -------------------------------------------------------------------------------- 1 | # Install & configure Maven build tool on Jenkins 2 | Maven is a code build tool which used to convert your code to an artifact. this is a widely used plugin to build in continuous integration 3 | 4 | 5 | #### Prerequisites 6 | 1. Jenkins server 7 | 8 | #### Install Maven on Jenkins 9 | 1. Download maven packages https://maven.apache.org/download.cgi onto Jenkins server. In this case, I am using /opt/maven as my installation directory 10 | - Link : https://maven.apache.org/download.cgi 11 | ```sh 12 | # Creating maven directory under /opt 13 | mkdir /opt/maven 14 | cd /opt/maven 15 | # downloading maven version 3.6.0 16 | wget http://mirrors.estointernet.in/apache/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz 17 | tar -xvzf apache-maven-3.6.1-bin.tar.gz 18 | ``` 19 | 20 | 1. Setup M2_HOME and M2 paths in .bash_profile of the user and add these to the path variable 21 | ```sh 22 | vi ~/.bash_profile 23 | M2_HOME=/opt/maven/apache-maven-3.6.1 24 | M2=$M2_HOME/bin 25 | PATH=:$M2_HOME:$M2 26 | ``` 27 | #### Checkpoint 28 | 1. logoff and login to check maven version 29 | 30 | ```sh 31 | mvn --version 32 | ``` 33 | So far we have completed the installation of maven software to support maven plugin on the jenkins console. Let's jump onto Jenkins to complete the remaining steps. 34 | 35 | ### Setup maven on Jenkins console 36 | 1. Install maven plugin without restart 37 | - `Manage Jenkins` > `Jenkins Plugins` > `available` > `Maven Invoker` 38 | - `Manage Jenkins` > `Jenkins Plugins` > `available` > `Maven Integration` 39 | 40 | 2. Configure maven path 41 | - `Manage Jenkins` > `Global Tool Configuration` > `Maven` 42 | 43 | -------------------------------------------------------------------------------- /Jenkins_Jobs/Deploy_on_Container.MD: -------------------------------------------------------------------------------- 1 | # Deploy on a docker container using Jenkins 2 | # `Deploy_on_Container` 3 | 4 | ### Pre-requisites 5 | 6 | 1. Jenkins server 7 | 1. Docker-host server 8 | 1. `Dockerfile` under *`/home/dockeradmin`* in user home directory on docker host 9 | ```sh 10 | # Pull tomcat latest image from dockerhub 11 | From tomcat 12 | # Maintainer 13 | MAINTAINER "AR Shankar" 14 | 15 | # copy war file on to container 16 | COPY ./webapp.war /usr/local/tomcat/webapps 17 | ### Integration between Docker-host and Jenkins 18 | 19 | Install "publish Over SSH" 20 | - `Manage Jenkins` > `Manage Plugins` > `Available` > `Publish over SSH` 21 | 22 | Enable connection between Docker-host and Jenkins 23 | 24 | - `Manage Jenkins` > `Configure System` > `Publish Over SSH` > `SSH Servers` 25 | 26 | - SSH Servers: 27 | - Name: `docker-host` 28 | - Hostname:`` 29 | - username: `dockeradmin` 30 | 31 | - `Advanced` > chose `Use password authentication, or use a different key` 32 | - password: `*******` 33 | 34 | ### Steps to create "Deploy_on_Container" Jenkin job 35 | #### From Jenkins home page select "New Item" 36 | - Enter an item name: `Deploy_on_Container` 37 | - Copy from: `Deploy_on_Docker_Host` 38 | 39 | - *Source Code Management:* 40 | - Repository: `https://github.com/yankils/hello-world.git` 41 | - Branches to build : `*/master` 42 | - *Poll SCM* : - `* * * *` 43 | 44 | - *Build:* 45 | - Root POM:`pom.xml` 46 | - Goals and options: `clean install package` 47 | 48 | - *Post-build Actions* 49 | - Send build artifacts over SSH 50 | - *SSH Publishers* 51 | - SSH Server Name: `docker-host` 52 | - `Transfers` > `Transfer set` 53 | - Source files: `webapp/target/*.war` 54 | - Remove prefix: `webapp/target` 55 | - Remote directory: `//home//ansadmin` or `.` 56 | - Exec command: 57 | ```sh 58 | cd /home/dockeradmin; 59 | docker build -t simple-devops-image .; 60 | docker run -d --name simple-devops-container -p 8080:8080 simple-devops-image; 61 | ``` 62 | 63 | Save and run the job now. 64 | -------------------------------------------------------------------------------- /Jenkins_Jobs/Deploy_on_Container_using_Ansible.MD: -------------------------------------------------------------------------------- 1 | # Deploy on a docker container using Ansible 2 | # *Jenkins Job name:* `Deploy_on_Container_using_ansible` 3 | 4 | ### Pre-requisites 5 | 6 | 1. Jenkins server 7 | 1. Docker-host server 8 | 1. Ansible server 9 | 1. `Dockerfile` under *`/opt/docker`* on Ansible server **[Get Help Here]()** 10 | ```sh 11 | # Pull tomcat latest image from dockerhub 12 | From tomcat 13 | # Maintainer 14 | MAINTAINER "AR Shankar" 15 | 16 | # copy war file on to container 17 | COPY ./webapp.war /usr/local/tomcat/webapps 18 | 1. Create `create-docker-image.yml` unser *`/opt/docker`* on Ansible server **[Get Help Here]()** 19 | ```sh 20 | --- 21 | - hosts: all 22 | #ansadmin doesn't need root access to create an image 23 | become: true 24 | 25 | tasks: 26 | - name: building docker image 27 | command: "docker build -t simple-devops-image ." 28 | args: 29 | chdir: /opt/docker 30 | ``` 31 | 1. Create `create-docker-image.yml` under *`/opt/docker`* on Ansible server **[Get Help Here]()** 32 | ```ssh 33 | --- 34 | - hosts: all 35 | become: ture 36 | 37 | tasks: 38 | - name: creating docker image using docker command 39 | command: docker run -d --name simple-devops-container -p 8080:8080 simple-devops-image 40 | ``` 41 | 42 | ### Integration between Ansible-control-node and Jenkins 43 | 44 | Install "publish Over SSH" 45 | - `Manage Jenkins` > `Manage Plugins` > `Available` > `Publish over SSH` 46 | 47 | Enable connection between Ansible-control-node and Jenkins 48 | 49 | - `Manage Jenkins` > `Configure System` > `Publish Over SSH` > `SSH Servers` 50 | 51 | - SSH Servers: 52 | - Name: `ansible-server` 53 | - Hostname:`` 54 | - username: `ansadmin` 55 | 56 | - `Advanced` > chose `Use password authentication, or use a different key` 57 | - password: `*******` 58 | 59 | ### Steps to create "Deploy_on_Container_using_ansible" Jenkin job 60 | #### From Jenkins home page select "New Item" 61 | - Enter an item name: `Deploy_on_Container_using_ansible` 62 | - Copy from: `Deploy_on_Container` 63 | 64 | - *Source Code Management:* 65 | - Repository: `https://github.com/yankils/hello-world.git` 66 | - Branches to build : `*/master` 67 | - *Poll SCM* : - `* * * *` 68 | 69 | - *Build:* 70 | - Root POM:`pom.xml` 71 | - Goals and options: `clean install package` 72 | 73 | - *Post-build Actions* 74 | - Send build artifacts over SSH 75 | - *SSH Publishers* 76 | - SSH Server Name: `ansible-server` 77 | - `Transfers` > `Transfer set` 78 | - Source files: `webapp/target/*.war` 79 | - Remove prefix: `webapp/target` 80 | - Remote directory: `//opt//docker` 81 | - Exec command: 82 | ```sh 83 | ansible-playbook -i /opt/docker/hosts /opt/docker/create-docker-image.yml; 84 | ``` 85 | 86 | Save and run the job now. 87 | -------------------------------------------------------------------------------- /Jenkins_Jobs/Deploy_on_Docker.MD: -------------------------------------------------------------------------------- 1 | # Deploy on Docker host server using Jenkins 2 | # *Jenkins Job name:* `Deploy_on_Docker_Host` 3 | 4 | ### Pre-requisites 5 | 6 | 1. Jenkins server 7 | 1. Docker-host Server 8 | 9 | ### Integration between Docker-host and Jenkins 10 | 11 | Install "publish Over SSH" 12 | - `Manage Jenkins` > `Manage Plugins` > `Available` > `Publish over SSH` 13 | 14 | Enable connection between Docker-host and Jenkins 15 | 16 | - `Manage Jenkins` > `Configure System` > `Publish Over SSH` > `SSH Servers` 17 | 18 | - SSH Servers: 19 | - Name: `docker-host` 20 | - Hostname:`` 21 | - username: `dockeradmin` 22 | 23 | - `Advanced` > chose `Use password authentication, or use a different key` 24 | - password: `*******` 25 | 26 | ### Steps to create "Deploy_on_Docker_Host" Jenkin job 27 | #### From Jenkins home page select "New Item" 28 | - Enter an item name: `Deploy_on_Docker_Host` 29 | - Copy from: `Deploy_on_Tomcat_Server` 30 | 31 | - *Source Code Management:* 32 | - Repository: `https://github.com/yankils/hello-world.git` 33 | - Branches to build : `*/master` 34 | - *Poll SCM* : - `* * * *` 35 | 36 | - *Build:* 37 | - Root POM:`pom.xml` 38 | - Goals and options: `clean install package` 39 | 40 | - *Post-build Actions* 41 | - Send build artifacts over SSH 42 | - *SSH Publishers* 43 | - SSH Server Name: `docker-host` 44 | - `Transfers` > `Transfer set` 45 | - Source files: `webapp/target/*.war` 46 | - Remove prefix: `webapp/target` 47 | - Remote directory: `//home//ansadmin` or `.` 48 | 49 | 50 | Save and run the job now. -------------------------------------------------------------------------------- /Jenkins_Jobs/Deploy_on_Tomcat_Server.MD: -------------------------------------------------------------------------------- 1 | # Deploy on a Tomcat server 2 | # *Jenkins Job name:* `Deploy_on_Tomcat_Server` 3 | 4 | ### Pre-requisites 5 | 6 | 1. Jenkins server 7 | 2. Tomcat Server 8 | 9 | ### Adding Deployment steps 10 | 11 | 1. Install 'deploy to container' plugin. This plugin needs to deploy on tomcat server. 12 | 13 | - Install 'deploy to container' plugin without restart 14 | - `Manage Jenkins` > `Jenkins Plugins` > `available` > `deploy to container` 15 | 16 | 2. Jenkins should need access to the tomcat server to deploy build artifacts. setup credentials to enable this process. use credentials option on Jenkins home page. 17 | 18 | - setup credentials 19 | - `credentials` > `jenkins` > `Global credentials` > `add credentials` 20 | - Username : `deployer` 21 | - Password : `deployer` 22 | - id : `deployer` 23 | - Description: `user to deploy on tomcat vm` 24 | 25 | ### Steps to create "Deploy_on_Tomcat_Server" Jenkin job 26 | #### From Jenkins home page select "New Item" 27 | - Enter an item name: `Deploy_on_Tomcat_Server` 28 | - Copy from: `My_First_Maven_Build` 29 | 30 | - *Source Code Management:* 31 | - Repository: `https://github.com/yankils/hello-world.git` 32 | - Branches to build : `*/master` 33 | - *Poll SCM* : - `* * * *` 34 | 35 | - *Build:* 36 | - Root POM:`pom.xml` 37 | - Goals and options: `clean install package` 38 | 39 | - *Post-build Actions* 40 | - Deploy war/ear to container 41 | - WAR/EAR files : `**/*.war` 42 | - Containers : `Tomcat 8.x` 43 | - Credentials: `deployer` (user created on above) 44 | - Tomcat URL : `http://:8080` 45 | 46 | Save and run the job now. -------------------------------------------------------------------------------- /Jenkins_Jobs/Dockerfile.txt: -------------------------------------------------------------------------------- 1 | # Pull tomcat latest image from dockerhub 2 | From tomcat:latest 3 | 4 | # Maintainer 5 | MAINTAINER "AR Shankar" 6 | 7 | # copy war file on to container 8 | COPY ./webapp.war /usr/local/tomcat/webapps -------------------------------------------------------------------------------- /Jenkins_Jobs/My_First_Maven_Build.MD: -------------------------------------------------------------------------------- 1 | # Create a First Maven Jenkins job to build hello-world project 2 | # *Jenkins Job name:* `My_First_Maven_Build` 3 | 4 | We know how to use work with each and Git, Jenkins independently. What if you want to collaborate these two? that is where Simple DevOps project helps you. Follow the below steps if you are a new guy to DevOps. You love it. 5 | 6 | 7 | #### Pre-requisites 8 | 9 | 1. Jenkins server 10 | 11 | 12 | ### Steps to create "My_First_Maven_Build" Jenkin job 13 | 1. Login to Jenkins console 14 | 1. Create *Jenkins job*, Fill the following details, 15 | - *Source Code Management:* 16 | - Repository: `https://github.com/yankils/hello-world.git` 17 | - Branches to build : `*/master` 18 | - *Build:* 19 | - Root POM:`pom.xml` 20 | - Goals and options: `clean install package` -------------------------------------------------------------------------------- /Jenkins_Jobs/create-docker-container.yml: -------------------------------------------------------------------------------- 1 | # Option-1 : Createting docker container using command module 2 | --- 3 | - hosts: all 4 | become: true 5 | 6 | tasks: 7 | - name: creating docker image using docker command 8 | command: docker run -d --name simple-devops-container -p 8080:8080 simple-devops-image 9 | 10 | # option-2 : creating docker container using docker_container module 11 | # tasks: 12 | # - name: create simple-devops-container 13 | # docker_container: 14 | # name: simple-devops-container 15 | # image: simple-devops-image 16 | # state: present 17 | # recreate: yes 18 | # ports: 19 | # - "8080:8080" 20 | -------------------------------------------------------------------------------- /Jenkins_Jobs/create-docker-image.yml: -------------------------------------------------------------------------------- 1 | # Option-1 : Createting docker image using command module 2 | --- 3 | - hosts: all 4 | become: true 5 | tasks: 6 | - name: building docker image 7 | command: docker build -t simple-devops-image . 8 | args: 9 | chdir: /opt/docker 10 | 11 | # option-2 : creating docker image using docker_image module 12 | 13 | # tasks: 14 | # - name: building docker image 15 | # docker_image: 16 | # build: 17 | # path: /opt/docker 18 | # name: simple-devops-image 19 | # tag: v1 20 | # source: build 21 | -------------------------------------------------------------------------------- /Jenkins_Jobs/simple-docker-project.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: all 3 | become: true 4 | tasks: 5 | - name: stop if we have old docker container 6 | command: docker stop simple-devops-container 7 | ignore_errors: yes 8 | 9 | - name: remove stopped docker container 10 | command: docker rm simple-devops-container 11 | ignore_errors: yes 12 | 13 | - name: remove current docker image 14 | command: docker rmi simple-devops-image 15 | ignore_errors: yes 16 | # register: result 17 | # failed_when: 18 | # - result.rc == 0 19 | # - '"docker" not in result.stdout' 20 | 21 | 22 | - name: building docker image 23 | command: docker build -t simple-devops-image . 24 | args: 25 | chdir: /opt/docker 26 | 27 | - name: creating docker image 28 | command: docker run -d --name simple-devops-container -p 8080:8080 simple-devops-image 29 | 30 | -------------------------------------------------------------------------------- /Kubernetes/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tomcat:latest 2 | 3 | MAINTAINER AR Shankar 4 | 5 | COPY ./webapp.war /usr/local/tomcat/webapps 6 | 7 | -------------------------------------------------------------------------------- /Kubernetes/Integrating_Kubernetes_with_Ansible.MD: -------------------------------------------------------------------------------- 1 | # Integrating Kubernetes cluster with Ansible 2 | 3 | 1. Login to ansible server and copy public key onto kubernetes cluseter master account 4 | 5 | 1. Update hosts file with new group called kubernetes and add kubernetes master in that. 6 | 7 | 1. Create ansible playbooks to create **[deployment](https://github.com/yankils/Simple-DevOps-Project/blob/master/Kubernetes/kubernetes-valaxy-deployment.yml)** and **[services](https://github.com/yankils/Simple-DevOps-Project/blob/master/Kubernetes/kubernetes-valaxy-service.yml)** 8 | 9 | 1. Check for pods, deployments and services on kubernetes master 10 | ```sh 11 | kubectl get pods -o wide 12 | kubectl get deploy -o wide 13 | kubectl get service -o wide 14 | ``` 15 | 16 | 1. Access application suing service IP 17 | ```sh 18 | wget :31200 19 | ``` 20 | -------------------------------------------------------------------------------- /Kubernetes/Integrating_Kubernetes_with_Jenkins.MD: -------------------------------------------------------------------------------- 1 | ## Integration Kubernetes with Jenkins 2 | 3 | # *Jenkins CI Job:* `Deploy_on_Kubernetes-CI` 4 | 5 | ### Pre-requisites 6 | 7 | 1. Jenkins server 8 | 1. Ansible server 9 | 1. Kubernetes cluster 10 | 11 | ### Steps to create "Deploy_on_Kubernetes_CI" Jenkin job 12 | #### From Jenkins home page select "New Item" 13 | - Enter an item name: `Deploy_on_Kubernetes_CI` 14 | - Copy from: `Deploy_on_Docker_Container_using_Ansible_playbooks` 15 | 16 | - *Source Code Management:* 17 | - Repository: `https://github.com/yankils/hello-world.git` 18 | - Branches to build : `*/master` 19 | - *Poll SCM* : - `* * * *` 20 | 21 | - *Build:* 22 | - Root POM:`pom.xml` 23 | - Goals and options: `clean install package` 24 | 25 | - *Post-build Actions* 26 | - Send build artifacts over SSH 27 | - *SSH Publishers* 28 | - SSH Server Name: `ansible-server` 29 | - `Transfers` > `Transfer set` 30 | - Source files: `webapp/target/*.war` 31 | - Remove prefix: `webapp/target` 32 | - Remote directory: `//opt//docker` 33 | - Exec command: 34 | ```sh 35 | ansible-playbook -i /opt/docker/hosts /opt/docker/create-simple-devops-image.yml --limit localhost; 36 | ``` 37 | 38 | Save and run the job. 39 | 40 | # *Jenkins CD Job:* `Deploy_on_Kubernetes-CD` 41 | 42 | ### Steps to create "Deploy_on_Kubernetes_CI" Jenkin job 43 | #### From Jenkins home page select "New Item" 44 | - Enter an item name: `Deploy_on_Kubernetes_CI` 45 | - Freestyle Project 46 | 47 | - *Post-build Actions* 48 | - Send build artifacts over SSH 49 | - *SSH Publishers* 50 | - Exec command: 51 | ```sh 52 | ansible-playbook -i /opt/docker/hosts /opt/docker/kubernetes-valaxy-deployment.yml; 53 | ansible-playbook -i /opt/docker/hosts /opt/docker/kubernetes-valaxy-service.yml; 54 | ``` 55 | Save and run the job. 56 | -------------------------------------------------------------------------------- /Kubernetes/Kubernetes_Setup_using_kops.md: -------------------------------------------------------------------------------- 1 | # Setup Kubernetes (K8s) Cluster on AWS 2 | 3 | 4 | 1. Create Ubuntu EC2 instance 5 | 1. install AWSCLI 6 | ```sh 7 | curl https://s3.amazonaws.com/aws-cli/awscli-bundle.zip -o awscli-bundle.zip 8 | sudo apt update 9 | sudo apt install unzip python 10 | unzip awscli-bundle.zip 11 | #sudo apt-get install unzip - if you dont have unzip in your system 12 | ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws 13 | ``` 14 | 15 | 1. Install kubectl on ubuntu instance 16 | ```sh 17 | curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl 18 | chmod +x ./kubectl 19 | sudo mv ./kubectl /usr/local/bin/kubectl 20 | ``` 21 | 22 | 1. Install kops on ubuntu instance 23 | ```sh 24 | curl -LO https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64 25 | chmod +x kops-linux-amd64 26 | sudo mv kops-linux-amd64 /usr/local/bin/kops 27 | ``` 28 | 1. Create an IAM user/role with Route53, EC2, IAM and S3 full access 29 | 30 | 1. Attach IAM role to ubuntu instance 31 | ```sh 32 | # Note: If you create IAM user with programmatic access then provide Access keys. Otherwise region information is enough 33 | aws configure 34 | ``` 35 | 36 | 1. Create a Route53 private hosted zone (you can create Public hosted zone if you have a domain) 37 | ```sh 38 | Routeh53 --> hosted zones --> created hosted zone 39 | Domain Name: valaxy.net 40 | Type: Private hosted zone for Amzon VPC 41 | ``` 42 | 43 | 1. create an S3 bucket 44 | ```sh 45 | aws s3 mb s3://demo.k8s.valaxy.net 46 | ``` 47 | 1. Expose environment variable: 48 | ```sh 49 | export KOPS_STATE_STORE=s3://demo.k8s.valaxy.net 50 | ``` 51 | 52 | 1. Create sshkeys before creating cluster 53 | ```sh 54 | ssh-keygen 55 | ``` 56 | 57 | 1. Create kubernetes cluster definitions on S3 bucket 58 | ```sh 59 | kops create cluster --cloud=aws --zones=ap-south-1b --name=demo.k8s.valaxy.net --dns-zone=valaxy.net --dns private 60 | ``` 61 | 62 | 1. If you wish to update the cluster worker node sizes use below command 63 | ```sh 64 | kops edit ig --name=CHANGE_TO_CLUSTER_NAME nodes 65 | ``` 66 | 67 | 1. Create kubernetes cluser 68 | ```sh 69 | kops update cluster demo.k8s.valaxy.net --yes 70 | ``` 71 | 72 | 1. Validate your cluster 73 | ```sh 74 | kops validate cluster 75 | ``` 76 | 77 | 1. To list nodes 78 | ```sh 79 | kubectl get nodes 80 | ``` 81 | 82 | 1. To delete cluster 83 | ```sh 84 | kops delete cluster demo.k8s.valaxy.net --yes 85 | ``` 86 | 87 | #### Deploying Nginx pods on Kubernetes 88 | 1. Deploying Nginx Container 89 | ```sh 90 | kubectl create deploy sample-nginx --image=nginx --replicas=2 --port=80 91 | # kubectl deploy simple-devops-project --image=yankils/simple-devops-image --replicas=2 --port=8080 92 | kubectl get all 93 | kubectl get pod 94 | ``` 95 | 96 | 1. Expose the deployment as service. This will create an ELB in front of those 2 containers and allow us to publicly access them. 97 | ```sh 98 | kubectl expose deployment sample-nginx --port=80 --type=LoadBalancer 99 | # kubectl expose deployment simple-devops-project --port=8080 --type=LoadBalancer 100 | kubectl get services -o wide 101 | ``` 102 | -------------------------------------------------------------------------------- /Kubernetes/Kubernetes_Setup_using_kubeadm.md: -------------------------------------------------------------------------------- 1 | # Kubernetes Cluster installation using kubeadm 2 | Follow this documentation to set up a Kubernetes cluster on __CentOS__ 7 machines. 3 | 4 | This documentation guides you in setting up a cluster with one master node and two worker nodes. 5 | 6 | ## Prerequisites: 7 | 1. System Requirements 8 | >Master: t2.medium (2 CPUs and 2GB Memory) 9 | >Worker Nodes: t2.micro 10 | 11 | 1. Open Below ports in the Security Group. 12 | #### Master node: 13 | `6443 14 | 32750 15 | 10250 16 | 4443 17 | 443 18 | 8080 ` 19 | 20 | ##### On Master node and Worker node: 21 | `179` 22 | 23 | ### `On Master and Worker:` 24 | 1. Perform all the commands as root user unless otherwise specified 25 | 26 | Install, Enable and start docker service. 27 | Use the Docker repository to install docker. 28 | > If you use docker from CentOS OS repository, the docker version might be old to work with Kubernetes v1.13.0 and above 29 | 30 | ```sh 31 | yum install -y -q yum-utils device-mapper-persistent-data lvm2 > /dev/null 2>&1 32 | yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo > /dev/null 2>&1 33 | yum install -y -q docker-ce >/dev/null 2>&1 34 | ``` 35 | 1. Start Docker services 36 | ```sh 37 | systemctl enable docker 38 | systemctl start docker 39 | ``` 40 | 1. Disable SELinux 41 | ```sh 42 | setenforce 0 43 | sed -i --follow-symlinks 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux 44 | ``` 45 | 1. Disable Firewall 46 | ```sh 47 | systemctl disable firewalld 48 | systemctl stop firewalld 49 | ``` 50 | 1. Disable swap 51 | ```sh 52 | sed -i '/swap/d' /etc/fstab 53 | swapoff -a 54 | ``` 55 | 1. Update sysctl settings for Kubernetes networking 56 | ```sh 57 | cat >> /etc/sysctl.d/kubernetes.conf <>/etc/yum.repos.d/kubernetes.repo< --pod-network-cidr=192.168.0.0/16 90 | ``` 91 | 1. Create a user for kubernetes administration and copy kube config file. 92 | ``To be able to use kubectl command to connect and interact with the cluster, the user needs kube config file.`` 93 | In this case, we are creating a user called `kubeadmin` 94 | ```sh 95 | useradd kubeadmin 96 | mkdir /home/kubeadmin/.kube 97 | cp /etc/kubernetes/admin.conf /home/kubeadmin/.kube/config 98 | chown -R kubeadmin:kubeadmin /home/kubeadmin/.kube 99 | ``` 100 | 1. Deploy Calico network as a __kubeadmin__ user. 101 | > This should be executed as a user (heare as a __kubeadmin__ ) 102 | 103 | ```sh 104 | sudo su - kubeadmin 105 | kubectl create -f https://docs.projectcalico.org/v3.9/manifests/calico.yaml 106 | ``` 107 | 108 | 1. Cluster join command 109 | ```sh 110 | kubeadm token create --print-join-command 111 | ``` 112 | ## `On Worker Node:` 113 | 1. Add worker nodes to cluster 114 | > Use the output from __kubeadm token create__ command in previous step from the master server and run here. 115 | 116 | 1. Verifying the cluster 117 | To Get Nodes status 118 | ```sh 119 | kubectl get nodes 120 | ``` 121 | To Get component status 122 | ```sh 123 | kubectl get cs 124 | ``` 125 | 126 | -------------------------------------------------------------------------------- /Kubernetes/create-simple-devops-image.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: ansible-server 3 | become: true 4 | 5 | tasks: 6 | - name: create docker image using war file 7 | command: docker build -t simple-devops-image:latest . 8 | args: 9 | chdir: /opt/k8s-lab 10 | 11 | - name: create tag to image 12 | command: docker tag simple-devops-image yankils/simple-devops-image 13 | 14 | - name: push image on to dockerhub 15 | command: docker push yankils/simple-devops-image 16 | 17 | - name: remove docker images form ansible server 18 | command: docker rmi simple-devops-image:latest yankils/simple-devops-image 19 | ignore_errors: yes 20 | -------------------------------------------------------------------------------- /Kubernetes/create_image_regapp.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: ansible 3 | 4 | tasks: 5 | - name: create docker image 6 | command: docker build -t regapp:latest . 7 | args: 8 | chdir: /opt/docker 9 | 10 | - name: create tag to push image onto dockerhub 11 | command: docker tag regapp:latest valaxy/regapp:latest 12 | 13 | - name: push docker image 14 | command: docker push valaxy/regapp:latest 15 | 16 | -------------------------------------------------------------------------------- /Kubernetes/firstpod.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: nginx-pod 5 | labels: 6 | app: demo-app 7 | 8 | spec: 9 | containers: 10 | - name: nginx-container 11 | image: nginx 12 | ports: 13 | - name: nginx 14 | containerPort: 80 15 | -------------------------------------------------------------------------------- /Kubernetes/firstrs.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ReplicaSet 3 | metadata: 4 | name: demo-app 5 | spec: 6 | replicas: 1 7 | template: 8 | metadata: 9 | labels: 10 | app: demo-app 11 | 12 | spec: 13 | containers: 14 | - name: demo-app 15 | image: nginx 16 | 17 | 18 | -------------------------------------------------------------------------------- /Kubernetes/firstservice.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: demo-service 5 | 6 | spec: 7 | ports: 8 | - name: demo-service 9 | port: 80 10 | targetPort: 80 11 | 12 | selector: 13 | app: demo-app 14 | 15 | type: LoadBalancer 16 | 17 | kubectl expose webapp --type=NodePort --targerPort=80 -- -------------------------------------------------------------------------------- /Kubernetes/kube_deploy.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: kubernetes 3 | # become: ture 4 | user: root 5 | 6 | tasks: 7 | - name: deploy regapp on kubernetes 8 | command: kubectl apply -f regapp-deployment.yml 9 | 10 | - name: create service for regapp 11 | command: kubectl apply -f regapp-service.yml 12 | 13 | - name: update deployment with new pods if image updated in docker hub 14 | command: kubectl rollout restart deployment.apps/valaxy-regapp 15 | 16 | -------------------------------------------------------------------------------- /Kubernetes/kubernetes-valaxy-deployment.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Create pods using deployment 3 | hosts: kubernetes 4 | # become: true 5 | user: ubuntu 6 | 7 | tasks: 8 | - name: create a deployment 9 | command: kubectl apply -f valaxy-deploy.yml 10 | 11 | - name: update deployment with new pods if image updated in docker hub 12 | command: kubectl rollout restart deployment.v1.apps/valaxy-deployment 13 | -------------------------------------------------------------------------------- /Kubernetes/kubernetes-valaxy-service.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: create service for deployment 3 | hosts: kubernetes 4 | # become: true 5 | user: ubuntu 6 | 7 | tasks: 8 | - name: create a service 9 | command: kubectl apply -f valaxy-service.yml 10 | 11 | -------------------------------------------------------------------------------- /Kubernetes/kubernetes_setup_using_eksctl.md: -------------------------------------------------------------------------------- 1 | # Setup Kubernetes on Amazon EKS 2 | 3 | You can follow same procedure in the official AWS document [Getting started with Amazon EKS – eksctl](https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html) 4 | 5 | #### Pre-requisites: 6 | - an EC2 Instance 7 | - Install AWSCLI latest verison 8 | 9 | 1. Setup kubectl 10 | a. Download kubectl version 1.21 11 | b. Grant execution permissions to kubectl executable 12 | c. Move kubectl onto /usr/local/bin 13 | d. Test that your kubectl installation was successful 14 | 15 | ```sh 16 | curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.21.2/2021-07-05/bin/linux/amd64/kubectl 17 | chmod +x ./kubectl 18 | mv ./kubectl /usr/local/bin 19 | kubectl version --short --client 20 | ``` 21 | 2. Setup eksctl 22 | a. Download and extract the latest release 23 | b. Move the extracted binary to /usr/local/bin 24 | c. Test that your eksclt installation was successful 25 | 26 | ```sh 27 | curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp 28 | sudo mv /tmp/eksctl /usr/local/bin 29 | eksctl version 30 | ``` 31 | 32 | 3. Create an IAM Role and attache it to EC2 instance 33 | `Note: create IAM user with programmatic access if your bootstrap system is outside of AWS` 34 | IAM user should have access to 35 | IAM 36 | EC2 37 | CloudFormation 38 | Note: Check eksctl documentaiton for [Minimum IAM policies](https://eksctl.io/usage/minimum-iam-policies/) 39 | 40 | 4. Create your cluster and nodes 41 | ```sh 42 | eksctl create cluster --name cluster-name \ 43 | --region region-name \ 44 | --node-type instance-type \ 45 | --nodes-min 2 \ 46 | --nodes-max 2 \ 47 | --zones , 48 | 49 | example: 50 | eksctl create cluster --name valaxy-cluster \ 51 | --region ap-south-1 \ 52 | --node-type t2.small \ 53 | ``` 54 | 55 | 5. To delete the EKS clsuter 56 | ```sh 57 | eksctl delete cluster valaxy --region ap-south-1 58 | ``` 59 | 60 | 6. Validate your cluster using by creating by checking nodes and by creating a pod 61 | ```sh 62 | kubectl get nodes 63 | kubectl run tomcat --image=tomcat 64 | ``` 65 | 66 | #### Deploying Nginx pods on Kubernetes 67 | 1. Deploying Nginx Container 68 | ```sh 69 | kubectl create deployment demo-nginx --image=nginx --replicas=2 --port=80 70 | # kubectl deployment regapp --image=valaxy/regapp --replicas=2 --port=8080 71 | kubectl get all 72 | kubectl get pod 73 | ``` 74 | 75 | 1. Expose the deployment as service. This will create an ELB in front of those 2 containers and allow us to publicly access them. 76 | ```sh 77 | kubectl expose deployment demo-nginx --port=80 --type=LoadBalancer 78 | # kubectl expose deployment regapp --port=8080 --type=LoadBalancer 79 | kubectl get services -o wide 80 | ``` 81 | 82 | -------------------------------------------------------------------------------- /Kubernetes/nginx-deploy.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | labels: 6 | app: nginx 7 | spec: 8 | replicas: 2 9 | selector: 10 | matchLabels: 11 | app: nginx 12 | template: 13 | metadata: 14 | labels: 15 | app: nginx 16 | spec: 17 | containers: 18 | - name: nginx 19 | image: nginx:1.14.2 20 | ports: 21 | - containerPort: 80 22 | -------------------------------------------------------------------------------- /Kubernetes/regapp-deploy.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: valaxy-regapp 5 | labels: 6 | app: regapp 7 | 8 | spec: 9 | replicas: 2 10 | selector: 11 | matchLabels: 12 | app: regapp 13 | 14 | template: 15 | metadata: 16 | labels: 17 | app: regapp 18 | spec: 19 | containers: 20 | - name: regapp 21 | image: valaxy/regapp 22 | imagePullPolicy: Always 23 | ports: 24 | - containerPort: 8080 25 | strategy: 26 | type: RollingUpdate 27 | rollingUpdate: 28 | maxSurge: 1 29 | maxUnavailable: 1 -------------------------------------------------------------------------------- /Kubernetes/regapp-service.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: valaxy-service 5 | labels: 6 | app: regapp 7 | spec: 8 | selector: 9 | app: regapp 10 | 11 | ports: 12 | - port: 8080 13 | targetPort: 8080 14 | 15 | type: LoadBalancer -------------------------------------------------------------------------------- /Kubernetes/valaxy-deploy.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 2 | kind: Deployment 3 | metadata: 4 | name: valaxy-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: valaxy-devops-project 9 | replicas: 2 # tells deployment to run 2 pods matching the template 10 | strategy: 11 | type: RollingUpdate 12 | rollingUpdate: 13 | maxSurge: 1 14 | maxUnavailable: 1 15 | 16 | template: 17 | metadata: 18 | labels: 19 | app: valaxy-devops-project 20 | spec: 21 | containers: 22 | - name: valaxy-devops-project 23 | image: yankils/simple-devops-image 24 | imagePullPolicy: Always 25 | ports: 26 | - containerPort: 8080 27 | -------------------------------------------------------------------------------- /Kubernetes/valaxy-service.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: valaxy-service 5 | labels: 6 | app: valaxy-devops-project 7 | spec: 8 | selector: 9 | app: valaxy-devops-project 10 | type: LoadBalancer 11 | ports: 12 | - port: 8080 13 | targetPort: 8080 14 | nodePort: 31200 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple DevOps Project 2 | 3 | [![Image](https://github.com/yankils/Simple-DevOps-Project/blob/master/Devops_course.PNG "DevOps Project - CI/CD with Jenkins Ansible Docker Kubernetes ")](https://www.udemy.com/course/valaxy-devops/?referralCode=8147A5CF4C8C7D9E253F) 4 | 5 | This Repository is a collection of Implementation documents. 6 | 7 | ### Purpose: 8 | By following this repository you can able to setup a DevOps CI/CD Pipeline using 9 | - git 10 | - Jenkins 11 | - Maven 12 | - Ansible 13 | - Docker & 14 | - Kubernetes 15 | 16 | -------------------------------------------------------------------------------- /Tomcat/tomcat_installation.MD: -------------------------------------------------------------------------------- 1 | # Tomcat installation on EC2 instance 2 | - Follow this video lecture in Valaxy Technologies **[YouTube Channel](https://youtu.be/68WNroQBUts)** 3 | - Complete DevOps Project course on [Udemy](https://www.udemy.com/course/valaxy-devops/?referralCode=8147A5CF4C8C7D9E253F) 4 | ### Pre-requisites 5 | 1. EC2 instance with Java 11 6 | ### Install Apache Tomcat 7 | 1. Download tomcat packages from https://tomcat.apache.org/download-80.cgi onto /opt on EC2 instance 8 | > Note: Make sure you change `` with the tomcat version which you download. 9 | ```sh 10 | # Create tomcat directory 11 | cd /opt 12 | wget http://mirrors.fibergrid.in/apache/tomcat/tomcat-8/v8.5.35/bin/apache-tomcat-8.5.35.tar.gz 13 | tar -xvzf /opt/apache-tomcat-.tar.gz 14 | ``` 15 | 1. give executing permissions to startup.sh and shutdown.sh which are under bin. 16 | ```sh 17 | chmod +x /opt/apache-tomcat-/bin/startup.sh 18 | chmod +x /opt/apache-tomcat-/bin/shutdown.sh 19 | ``` 20 | > Note: you may get below error while starting tomcat incase if you dont install Java 21 | `Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program` 22 | 1. create link files for tomcat startup.sh and shutdown.sh 23 | ```sh 24 | ln -s /opt/apache-tomcat-/bin/startup.sh /usr/local/bin/tomcatup 25 | ln -s /opt/apache-tomcat-/bin/shutdown.sh /usr/local/bin/tomcatdown 26 | tomcatup 27 | ``` 28 | #### Check point : 29 | access tomcat application from browser on port 8080 30 | - http://:8080 31 | 32 | Using unique ports for each application is a best practice in an environment. But tomcat and Jenkins runs on ports number 8080. Hence lets change tomcat port number to 8090. Change port number in conf/server.xml file under tomcat home 33 | ```sh 34 | cd /opt/apache-tomcat-/conf 35 | # update port number in the "connecter port" field in server.xml 36 | # restart tomcat after configuration update 37 | tomcatdown 38 | tomcatup 39 | ``` 40 | #### Check point : 41 | Access tomcat application from browser on port 8090 42 | - http://:8090 43 | 44 | 1. now application is accessible on port 8090. but tomcat application doesnt allow to login from browser. changing a default parameter in context.xml does address this issue 45 | ```sh 46 | #search for context.xml 47 | find / -name context.xml 48 | ``` 49 | 1. above command gives 3 context.xml files. comment () `Value ClassName` field on files which are under webapp directory. 50 | After that restart tomcat services to effect these changes. 51 | At the time of writing this lecture below 2 files are updated. 52 | ```sh 53 | /opt/tomcat/webapps/host-manager/META-INF/context.xml 54 | /opt/tomcat/webapps/manager/META-INF/context.xml 55 | 56 | # Restart tomcat services 57 | tomcatdown 58 | tomcatup 59 | ``` 60 | 1. Update users information in the tomcat-users.xml file 61 | goto tomcat home directory and Add below users to conf/tomcat-users.xml file 62 | ```sh 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | ``` 71 | 1. Restart serivce and try to login to tomcat application from the browser. This time it should be Successful 72 | 73 | --------------------------------------------------------------------------------