diff --git a/.gitignore b/.gitignore index 524f096..001a1d8 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,70 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* replay_pid* +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log + +# Ignore any .tfvars files that are generated automatically for each Terraform run. Most +# .tfvars files are managed as part of configuration and so should be included in +# version control. +# +# example.tfvars + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Include override files you do wish to add to version control using negated pattern +# +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* +# Ansible +*.retry +*.log + +# Terraform +.terraform +*.tfstate +*.tfstate.backup +*.tfplan + +# Java +target/ +*.class +*.jar + +# Python +__pycache__/ +*.pyc +*.pyo +*.egg-info/ +dist/ +build/ +*.egg +*.log +*.retry + +# Docker +*.dockerignore +.docker/ +docker-compose.yml +docker-compose.yaml +docker-compose.override.yml +docker-compose.override.yaml +*.env + +# PHP +vendor/ +composer.lock diff --git a/1-Linux_Tutorial/History.txt b/1-Linux_Tutorial/History.txt new file mode 100644 index 0000000..92667c7 --- /dev/null +++ b/1-Linux_Tutorial/History.txt @@ -0,0 +1,32 @@ +# Linux tutorial + +## Basic Commands: + +``` + +s +ls -l +clear +pwd +ls +cd Desktop/ +ls +ll +pwd +cd /home/varunmanikoutlo/ +pwd +ll +ls -l +ll +ls -la +ls -lar +ls -lart +ls -larth +cd /home/varunmanikoutlo/ +pwd +cd Desktop/ +cd ../ +history +history | cut -c 8- + +``` diff --git a/1-Linux_Tutorial/README.md b/1-Linux_Tutorial/README.md new file mode 100644 index 0000000..f6432d8 --- /dev/null +++ b/1-Linux_Tutorial/README.md @@ -0,0 +1,332 @@ +# Linux Basic Commands + +This README file provides a brief introduction to some essential Linux commands for beginners. + +## Table of Contents +1. [Navigating the File System](#navigating-the-file-system) +2. [File Management](#file-management) +3. [Directory Management](#directory-management) +4. [Permissions](#permissions) +5. [Viewing File Contents](#viewing-file-contents) +6. [System Information](#system-information) + +### Navigating the File System + +- To print the current working directory: + + ``` + pwd + ``` + +- To change the current working directory: + + ``` + cd [directory] + ``` + +- To list the contents of a directory: + + ``` + ls [options] [directory] + ``` + +### File Management + +- To create a new file: + + ``` + touch [file] + ``` + +- To copy a file: + + ``` + cp [source] [destination] + ``` + +- To move a file: + + ``` + mv [source] [destination] + ``` + +- To remove a file: + + ``` + rm [file] + ``` + +### Directory Management + +- To create a new directory: + + ``` + mkdir [directory] + ``` + +- To remove an empty directory: + + ``` + rmdir [directory] + ``` + +- To remove a non-empty directory: + + ``` + rm -r [directory] + ``` + +### Permissions + +- To change file or directory permissions: + + ``` + chmod [permissions] [file or directory] + ``` + +- To change file or directory ownership: + + ``` + chown [owner] [file or directory] + ``` + +### Viewing File Contents + +- To display the contents of a file: + + ``` + cat [file] + ``` + +- To display the first few lines of a file: + + ``` + head [file] + ``` + +- To display the last few lines of a file: + + ``` + tail [file] + ``` + +### System Information + +- To display system information: + + ``` + uname -a + ``` + +- To display disk usage: + + ``` + df -h + ``` + +- To display memory usage: + + ``` + free -h + ``` + + +# Linux Basic Commands - chmod and chown + +This section provides an in-depth explanation of the `chmod` and `chown` commands, including examples. + +## chmod - Change File and Directory Permissions + +### Symbolic Mode + +| Operator | Description | +| -------- | ----------- | +| `u` | User | +| `g` | Group | +| `o` | Others | +| `a` | All (User, Group, and Others) | + +| Permission | Description | +| ---------- | ----------- | +| `r` | Read | +| `w` | Write | +| `x` | Execute | + +| Action | Description | +| ------ | ----------- | +| `+` | Add permission | +| `-` | Remove permission | +| `=` | Set permission | + +### Example + +To add execute permission for the user: + + +``` +chmod u+x [file or directory] +``` + +To remove write permission for the group and others: + +``` +chmod go-w [file or directory] +``` + + +To set read and execute permissions for the user, and read permission for the group and others: + + +``` +chmod u=rw,g=r,o=r [file or directory] +``` + +## Octal Mode + +| Octal Value | Permission | +| ----------- | ------------------- | +| `0` | No permission | +| `1` | Execute | +| `2` | Write | +| `3` | Write and Execute | +| `4` | Read | +| `5` | Read and Execute | +| `6` | Read and Write | +| `7` | Read, Write, Execute| + + +## Octal Permissions and Examples + +| Octal Value | Permission | Description | Example | +| ----------- | ------------------- | ---------------------------------------- | ---------------------------- | +| `0` | No permission | No permissions are granted | `chmod 000 file.txt` | +| `1` | Execute | Execute permission only | `chmod 111 script.sh` | +| `2` | Write | Write permission only | `chmod 222 file.txt` | +| `3` | Write and Execute | Write and execute permissions | `chmod 333 script.sh` | +| `4` | Read | Read permission only | `chmod 444 file.txt` | +| `5` | Read and Execute | Read and execute permissions | `chmod 555 script.sh` | +| `6` | Read and Write | Read and write permissions | `chmod 666 file.txt` | +| `7` | Read, Write, Execute| All permissions (read, write, and execute)| `chmod 777 script.sh` | + +To set permissions using octal values, use the `chmod` command followed by the octal value for user, group, and others: +``` +chmod [user][group][others] [file or directory] +``` +Example: + +To set read, write, and execute permissions for the user, read and execute permissions for the group, and read permissions for others: +``` +chmod 754 script.sh +``` +## Combining Octal Permissions + +You can combine octal permissions to create custom permission sets for your files and directories. Each digit in the octal value represents the permissions for the user, group, and others, respectively. + +### Examples + +1. To set read and write permissions for the user, and read permissions for the group and others: + +``` +chmod 644 file.txt +``` + +2. To set read, write, and execute permissions for the user, and read permissions for the group and others: +``` +chmod 744 script.sh +``` + +3. To set read and execute permissions for the user, group, and others: +``` +chmod 555 script.sh +``` + +Remember to carefully choose permissions based on the security requirements +### Example + +To set read, write, and execute permissions for the user, read and write permissions for the group, and read permission for others: + +``` +chmod 764 [file or directory] +``` + + +## chown - Change File and Directory Ownership + +### Syntax + +``` +chown [owner]:[group] [file or directory] +``` + +### Example + +To change the owner of a file or directory to `newuser` and the group to `newgroup`: + +``` +chown newuser:newgroup [file or directory] +``` + +To change only the owner to `newuser`: + +``` +chown newuser [file or directory] +``` + +To change only the group to `newgroup`: + +``` +chown :newgroup [file or directory] +``` + +## chmod Examples for Different File Types + +1. Set read-only permission for a `.pem` file: + +``` +chmod 400 private_key.pem +``` +This restricts the `.pem` file to be readable only by the owner, ensuring the private key remains secure. + +2. Set read, write, and execute permissions for the owner, and read and execute permissions for the group and others on a `script.sh` file: + +``` +chmod 755 script.sh + +``` +This allows the owner to read, write, and execute the script, while others can only read and execute it. + +3. Set read, write, and execute permissions for the owner, group, and others on a `script.sh` file: + +``` +chmod 777 script.sh +``` + +This allows everyone to read, write, and execute the script, which can be a security risk and is generally not recommended. + +## Additional Notes + +- The `chmod` and `chown` commands can be used recursively with the `-R` option to change permissions or ownership for a directory and its contents: + + +``` +chmod -R [permissions] [directory] +chown -R [owner]:[group] [directory] +``` + + +- You can use the `umask` command to set default file permissions for newly created files: + +``` +umask [octal value] +``` + +- You can use the `id` command to display information about the current user and group: + +``` +id +``` +For more information and examples, consult the `man` pages for each command: +``` +man chmod +man chown +``` \ No newline at end of file diff --git a/1-Linux_Tutorial/history-of-jan-06-2024.txt b/1-Linux_Tutorial/history-of-jan-06-2024.txt new file mode 100644 index 0000000..b843b88 --- /dev/null +++ b/1-Linux_Tutorial/history-of-jan-06-2024.txt @@ -0,0 +1,104 @@ + + 1 cat /etc/issue + 2 clear + 3 ls + 4 pwd + 5 ls -l + 6 date + 7 ls -l + 8 cat hello > a.txt + 9 ll + 10 date + 11 clear + 12 ls -la + 13 ls -lah + 14 ls -lh + 15 ls -lht + 16 ls -lhtr + 17 ls -larth + 18 mkdir devops + 19 ll + 20 mkdir -p mgmt/dev/non-prod/code + 21 ll + 22 cd mgmt/ + 23 ll + 24 ll * + 25 ll ** + + 28 ll * + 29 tree + 30 apt install tree + 31 sudo apt install tree + 32 tree + 33 sudo -i + 34 sudo su + 35 cd dev/non-prod/ + 36 cd /home/varunmanikoutlo/mgmt/dev/ + 37 cd non-prod/ + 38 cd .. + 39 cd mgmt/dev/non-prod/ + 40 cd ../../ + 41 cd - + 42 tree + 43 rmdir -r dev + 44 rm -rf dev + 45 tree + 46 touch calc.java + 47 ls + 48 cat calc.java + 49 cat calc.java index.html calc.py + 50 touch calc.java index.html calc.py + 51 ls + 52 rm calc.java + 53 ls + 54 rm * + 55 ll + 56 cat Hi, we are learning Linux. + 57 cat Hi, we are learning Linux. > index.html + 58 cat "Hi, we are learning Linux." > index.html + 59 echo "Hi, we are learning Linux." > index.html + 60 echo "my name is: XYZ" + 61 ls + 62 cat index.html + 63 ll + 64 vim contacts.html + 65 ls + 66 nano aboutus.html + 67 ll + 68 cat aboutus.html + 69 history + 70 nano sales.html + 71 ls + 72 history + 73 ll + 74 vim install.sh + 75 ll + 76 chmod u+x + 77 chmod u+x install.sh + 78 ls + 79 ll + 80 chmod ug+x install.sh + 81 ll + 82 chmod ug-w install.sh + 83 ll + 84 mkdir test + 85 mv install.sh test/ + 86 cd test/ + 87 ll + 88 user>group>others chmod 777 install.sh + 89 chmod 777 install.sh + 90 ll + 91 chmod 774 install.sh + 92 ll + 93 echo "hi this is php page" > index.php + 94 ll + 97 + 101 cat /etc/passwd | grep -i tomcat + 102 ll + 103 + 110 sudo chown tomcat:tomcat index.php + 111 ll + 112 sudo chown tomcat: install.sh + 113 ll + 114 history | cut -8 + 115 history > jan-06-2024.txt diff --git a/2-Git/README.md b/2-Git/README.md new file mode 100644 index 0000000..01d195a --- /dev/null +++ b/2-Git/README.md @@ -0,0 +1,590 @@ +# Version Control System + +## Introduction + +Version control systems (VCS) are essential tools for tracking changes in software projects, allowing you to maintain a complete history of modifications made to your codebase. This enables developers to easily collaborate, track progress, and revert changes if needed. + +## Working with Git + +Git is a popular distributed version control system designed for handling projects of all sizes with speed and efficiency. It is widely used by developers around the world and has become the de facto standard for version control. + +### Unassisted Practice: Install Git on Linux + +To install Git on a Linux system, follow these steps: + +1. Open a terminal. +2. Update the package list by running: + +``` +sudo apt update +``` +3. Install Git with the following command: + + +``` +sudo apt install git +``` + +4. Verify the installation by checking the Git version: + +``` +git --version + +``` + +5. Configure your Git username, email & Editor: + +``` +git config --global user.name "Your Name" + +git config --global user.email "youremail@example.com" + +git config --global core.editor "code --wait" + + +``` + +You have now successfully installed Git on your Linux system. + +# Part 2 + +## GitHub as an SCM Tool + +GitHub is a web-based platform for version control and collaboration using Git. It provides a simple and user-friendly interface for managing and collaborating on software projects. + +### Assisted Practice: Create and Clone a GitHub Repository + +1. Sign up for a GitHub account or sign in to your existing account. +2. Click on the "+" icon in the upper-right corner, and select "New repository." +3. Enter a repository name, add an optional description, choose visibility (public or private), and click "Create repository." +4. Copy the repository URL from the "Quick setup" section. +5. On your local machine, open a terminal and navigate to the directory where you want to clone the repository. +6. Run the following command to clone the repository: + +``` +git clone [repository URL] +``` + +You have now created a GitHub repository and cloned it to your local machine. + +## Fork, Push, and Pull in Git + +### Assisted Practice: Create a Pull Request in Git + +1. Fork a repository on GitHub by clicking the "Fork" button at the top right corner of the repository page. + +2. Clone the forked repository to your local machine: + +``` +git clone [forked repository URL] +``` + +3. Create a new branch for your changes: + +``` +git checkout -b [new branch name] +``` + +4. Make changes to the files and commit them: + +``` +git add . +git commit -m "Your commit message" +``` + +5. Push your changes to your forked repository: + +``` +git push origin [new branch name] +``` + +6. Go to the original repository on GitHub, and click on the "Pull Requests" tab. + +7. Click on the "New Pull Request" button, and choose the branch you just pushed from your forked repository. + +8. Review your changes and click "Create Pull Request." + +You have now created a pull request in Git. + + +# Part 3 + +### Assisted Practice: Push file to GitHub Repository + +1. Navigate to your local repository in the terminal. +2. Create or modify a file in the repository. +3. Stage the changes using: + +``` +git add [file name] +``` +To stage all changes in the repository, use: +``` +git add . + +``` + +4. Commit the changes with a meaningful commit message: + +``` +git commit -m "Your commit message" +``` + +5. Push the changes to the remote repository on GitHub: + +``` +git push origin [branch name] +``` + +Your changes are now pushed to the GitHub repository. + +## Branching in Git + +Branching allows you to create a separate line of development within a repository, enabling you to work on features or fixes independently from the main branch. This makes it easier to manage and maintain code, especially in large projects with multiple contributors. + +### Assisted Practice: Create a Branch in Git + +1. Navigate to your local repository in the terminal. +2. Create a new branch with a descriptive name: + +``` +git checkout -b [new branch name] +``` + +3. Verify that you have switched to the new branch: + +``` +git branch +``` + +You have now created a new branch in Git. + +## Switching Branches in Git + +Switching branches allows you to move between different lines of development in your repository. + +### Assisted Practice: Switching Branches in Git + +1. List all branches in your local repository: + +``` +git branch +``` + +2. Switch to an existing branch: + +``` +git checkout [existing branch name] +``` + +3. Verify that you have switched to the desired branch: + +``` +git branch +``` + +You have now successfully switched branches in Git. + +## Merging Branches in Git + +Merging branches in Git is the process of combining changes from one branch into another. This is commonly done when a feature or fix is completed and ready to be integrated into the main branch. + +### Assisted Practice: Merging Branches in Git + +1. Ensure that you have committed all changes in the branch you want to merge. +2. Switch to the target branch: + +``` +git checkout [target branch name] +``` + +3. Merge the changes from the source branch into the target branch: + +``` +git merge [source branch name] +``` + +4. Resolve any merge conflicts if they occur, and commit the changes. +5. Push the updated target branch to the remote repository: + +``` +git push origin [target branch name] +``` + +You have now successfully merged branches in Git. + +This completes the content for your README.md file on version control systems, Git, and GitHub. + + +## Using "git switch" Command + +The "git switch" command is an alternative way to switch branches in Git, introduced in Git version 2.23.0. It provides a more straightforward and user-friendly method for switching branches compared to the "git checkout" command. + +### Assisted Practice: Switching Branches Using "git switch" + +1. List all branches in your local repository: + +``` +git branch +``` + +2. Switch to an existing branch using the "git switch" command: + +``` +git switch [existing branch name] +``` + + +3. Verify that you have switched to the desired branch: +``` +git branch +``` + +You have now successfully switched branches using the "git switch" command. + +### Creating a New Branch with "git switch" + +You can also create a new branch and switch to it using the "git switch" command in a single step: +``` +git switch -c [new branch name] +``` +This command will create a new branch with the specified name and switch + +# Git Switch vs git Checkout + +| Operation | Description | Usage | +|------------------|-----------------------------------------------------------------------------|---------------------------------------------------------------------------------------------| +| **Git Switch** | Switches to a different branch or commit, creating a new branch if needed. +| | | git switch | +| | | git switch -c | +| | | git switch --detach | +| | | | +| **Git Checkout** | Switches to a different branch or commit, creating a new branch if needed. | | +| | | git checkout | +| | | git checkout -b | +| | | git checkout | +| | | | + + +# SSH Connectivity to your Simplilearn lab VM + +- Step 1: Loging to github +- Step 2: Create a Repo +- Step 3: Click on your user profile and clicl on stetting +- step 4: Click on ssh key +- step 5: Copy and paste your pub key +- Step 6: Click OK +- Step 7: Clone your repo + +## Create ssh key in your lab vm + +- Step 1: Login to lab VM and open terminal +- Step 2: runthe following command + +``` +ssh-keygen +``` +Enter three time to create the public & private key + +- Step 3 : copy the content of you `id_rsa.pub` key + +``` +cat ~/.ssh/id_rsa.pub +``` +- Step 4 : Paste the content in privious step 6 + + +# Common error while setting the above steps + +``` +git clone git@github.com:sindhugowda1991/java.calculatore-delete.git +Cloning into 'java.calculatore-delete'... +The authenticity of host 'github.com (140.82.114.4)' can't be established. +ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM. +Are you sure you want to continue connecting (yes/no/[fingerprint])? y +Please type 'yes', 'no' or the fingerprint: y +Please type 'yes', 'no' or the fingerprint: y +Please type 'yes', 'no' or the fingerprint: n +Please type 'yes', 'no' or the fingerprint: y +Warning: Permanently added 'github.com,140.82.114.4' (ECDSA) to the list of known hosts. +git@github.com: Permission denied (publickey). +fatal: Could not read from remote repository. + +Please make sure you have the correct access rights +and the repository exists. +``` +## Solution +1. Open the `known_hosts` file using a text editor like `nano` or `vim`: + + ``` + nano ~/.ssh/known_hosts + ``` + +2. Locate the entry for the host you want to delete. The entry will start with the hostname (e.g., `github.com`) or the IP address, followed by the public key and some other information. Delete the entire line containing the entry, save the changes, and close the text editor. + +----------------------------------------------------------------------------------------------------------- + + +# Git Branch Guide + +This is a step-by-step guide to help you understand and work with Git branches. Branches are a fundamental feature of Git that allows developers to work on multiple tasks simultaneously without interfering with each other. + +## Table of Contents + +1. [Purpose of Git Branches](#purpose-of-git-branches) +2. [Creating a Branch](#creating-a-branch) +3. [Switching Between Branches](#switching-between-branches) +4. [Merging Branches](#merging-branches) +5. [Deleting a Branch](#deleting-a-branch) + +## Purpose of Git Branches + +Git branches allow you to separate different features or bug fixes into their own isolated environments. This makes it easier to manage, test, and collaborate on code without causing conflicts. + +## Creating a Branch + +To create a new branch, use the following command: + +``` +git checkout -b +``` + +This will create a new branch and switch to it. + +## Switching Between Branches + +To switch between branches, use the following command: + +``` +git checkout +``` + +This will switch to the specified branch. + +## Merging Branches + +To merge one branch into another, first switch to the branch you want to merge into: + +``` +git checkout +``` + +Then, use the following command to merge the other branch: + +``` +git merge +``` + +This will merge the changes from the source branch into the target branch. + +## Deleting a Branch + +To delete a branch, use the following command: + +``` +git branch -d +``` + +This will delete the specified branch. + +## Git Merge, Reset, and Rebase + +These operations are used to manipulate the commit history and combine changes from different branches. + +### Git Merge + +Git merge combines the changes from one branch into another. To perform a merge, follow these steps: + +1. Switch to the target branch: + + ``` + git checkout + ``` + +2. Merge the source branch into the target branch: + + ``` + git merge + ``` + +### Git Reset + +Git reset is used to undo commits or move the branch pointer to a different commit. There are three modes: soft, mixed (default), and hard. + +1. Soft reset: + + ``` + git reset --soft + ``` + + This will move the branch pointer to the specified commit, but keep the changes in the staging area. + +2. Mixed reset (default): + + ``` + git reset + ``` + + This will move the branch pointer to the specified commit and unstage the changes. + +3. Hard reset: + + ``` + git reset --hard + ``` + + This will move the branch pointer to the specified commit and discard all changes. + +### Git Rebase + +Git rebase is used to apply a series of commits from one branch onto another, creating a linear history. To perform a rebase, follow these steps: + +1. Switch to the branch that has the commits you want to apply: + + ``` + git checkout + ``` + +2. Rebase the source branch onto the target branch: + + ``` + git rebase + ``` + + This will apply the commits from the source branch on top of the target branch. + +Note: Be cautious when using `git rebase` as it can rewrite the commit history. It's recommended to use it only on local branches that haven't been pushed to a remote repository. + + +| Operation | Description | Usage | +|-----------------|---------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------| +| **Git Revert** | Creates a new commit that undoes the changes made in a specific commit. | ``` | +| | | git revert | +| | | ``` | +| **Git Reset** | Moves the branch pointer to a specified commit. Soft, mixed (default), or hard mode. | Soft reset: | +| | | ``` | +| | | git reset --soft | +| | | ``` | +| | | Mixed reset (default): | +| | | ``` | +| | | git reset | +| | | ``` | +| | | Hard reset: | +| | | ``` | +| | | git reset --hard | +| | | ``` | +| **Git Rebase** | Applies a series of commits from one branch onto another, creating a linear history. | ``` | +| | | git checkout | +| | | git rebase | +| | | ``` | + +## Components of the .git Folder + +The `.git` folder is the heart of a Git repository, and it contains all the metadata and objects required for version control. Here's an overview of its components: + +### HEAD + +``` +.git/HEAD +``` + +The `HEAD` file is a reference to the currently checked-out commit. It usually points to the tip of the current branch. + +### config + +``` +.git/config +``` + +The `config` file contains repository-specific configuration settings. These settings override global and system-wide settings. + +### description + +``` +.git/description +``` + +The `description` file contains a brief text description of the repository. This file is used primarily by the GitWeb program and is not essential for Git functionality. + +### hooks + +``` +.git/hooks +``` + +The `hooks` directory contains script files that can be executed automatically when certain Git events occur, such as pre-commit, post-commit, or pre-receive. These scripts can be used to enforce coding standards, send notifications, or perform other custom tasks. + +### info + +``` +.git/info +``` + +The `info` directory contains additional metadata about the repository. The `exclude` file within this directory allows you to specify files or patterns to be ignored by Git, similar to a `.gitignore` file. + +### objects + +``` +.git/objects +``` + +The `objects` directory stores all the data for your Git repository in a compressed format. It includes commits, trees, and blobs. + +### refs + +``` +.git/refs +``` + +The `refs` directory contains pointers to commits. It includes references to branches (under `refs/heads`) and tags (under `refs/tags`). + +### branches, index, and logs (optional) + +``` +.git/branches +.git/index +.git/logs +``` + +- The `branches` directory is used for storing legacy branch references and is rarely used in modern Git workflows. +- The `index` file contains staging area information, which is used to build the next commit. +- The `logs` directory contains a record of all updates made to the refs. + +## Table +| Component | Description | +|----------------|-----------------------------------------------------------------------------------------------------------------------------------| +| **HEAD** | A reference to the currently checked-out commit, usually pointing to the tip of the current branch. | +| **config** | Contains repository-specific configuration settings that override global and system-wide settings. | +| **description**| Contains a brief text description of the repository, primarily used by the GitWeb program. | +| **hooks** | A directory with script files that can be executed automatically when certain Git events occur, such as pre-commit or post-commit.| +| **info** | Contains additional metadata about the repository. The `exclude` file within allows specifying files or patterns to be ignored. | +| **objects** | Stores all the data for your Git repository in a compressed format, including commits, trees, and blobs. | +| **refs** | Contains pointers to commits, including references to branches (under `refs/heads`) and tags (under `refs/tags`). | +| **branches** | Used for storing legacy branch references, rarely used in modern Git workflows. | +| **index** | Contains staging area information, used to build the next commit. | +| **logs** | Contains a record of all updates made to the refs. | + + + +# Disclaimer +
+ +Please note that the entire repository is owned and maintained by [Varun Kumar Manik](https://www.linkedin.com/in/vkmanik/). While every effort has been made to ensure the accuracy and reliability of the information and resources provided in this repository, Varun Kumar Manik takes full responsibility for any errors or inaccuracies that may be present. + +Simplilearn is not responsible for the content or materials provided in this repository and disclaims all liability for any issues, misunderstandings, or claims that may arise from the use of the information or materials provided. By using this repository, you acknowledge that Varun Kumar Manik is solely accountable for its content, and you agree to hold Simplilearn harmless from any claims or liabilities that may arise as a result of your use or reliance on the information provided herein. + +It is important to understand that this repository contains educational materials for a training course, and users are expected to apply their own judgment and discretion when utilizing the provided resources. Neither Varun Kumar Manik nor Simplilearn can guarantee specific results or outcomes from following the materials in this repository. + +
+ +## Connect & Follow + +For more info, please connect and follow me: + +- Github: [https://github.com/manikcloud](https://github.com/manikcloud) +- LinkedIn: [https://www.linkedin.com/in/vkmanik/](https://www.linkedin.com/in/vkmanik/) +- Email: [varunmanik1@gmail.com](mailto:varunmanik1@gmail.com) +- Facebook: [https://www.facebook.com/cloudvirtualization/](https://www.facebook.com/cloudvirtualization/) +- YouTube: [https://bit.ly/32fknRN](https://bit.ly/32fknRN) +- Twitter: [https://twitter.com/varunkmanik](https://twitter.com/varunkmanik) + diff --git a/2-Git/history.txt b/2-Git/history.txt new file mode 100644 index 0000000..3b3b7d8 --- /dev/null +++ b/2-Git/history.txt @@ -0,0 +1,145 @@ +ls +ls -l +clear +pwd +ls +cd Desktop/ +ls +ll +pwd +cd /home/varunmanikoutlo/ +pwd +ll +ls -l +ll +ls -la +ls -lar +ls -lart +ls -larth +cd /home/varunmanikoutlo/ +pwd +cd Desktop/ +cd ../ +history +history | cut -c 8- +history +history | cut -c 8- +man cut +man +man ls +man cut +ll +mkdir varun +ll +mkdir -p /opt/one/two/tree/four +mkdir -p ./one/two/tree/four +ll +ll one/ +ll one/two/ +ll one/two/tree/ +tree +apt install tree +sudo -i +sudo su +sudo apt install tree +htop +sudo apt install elinks +apt install elinks +sudo apt install elinks +sudo visudo +touch one/one.txt +tree one/ +tree one/two/index.html +touch one/two/index.html +tree one/two/index.html +tree one/ +cd one/ +touch a.txt b.txt c.txt d.log +ll +vim a.txt +ll +echo "hi this is for file b.txt" +echo "hi this is for file b.txt" > b.txt +cat b.txt +cat a.txt +history +history > history.txt +ll +cat history.txt +ll +rm a.txt +ll +rm *.txt +ll +tree +rm two/ +rmdir two/ +rmdir two/ -r +rmdir two/ -f +rmdir two +rmdir -f two +rmdir -rf two +rm -rf two +tree +ls +cd .. +ll +rm -rf one/ +history +history | cut -c 8- +ehoc "hi" > index.html +echo "hi" > index.html +cat index.html +echo "hi i am good " >> index.html +cat index.html +echo "hi i am good. How are you ? " >> index.html +cat index.html +ll +touch varun/a.txt +uname -a +date +cat /etc/issue +apt install git +sudo apt install git +cat /etc/os-release +cd varun/ +git clone https://github.com/manikcloud/java-calculator-delete.git +ll +cd java-calculator-delete/ +ll +vim README.md +git add README.md +git commit -am"first upload" +git push +cd .. +rm -rf java-calculator-delete/ +ll +git clone git@github.com:manikcloud/java-calculator-delete.git +ssh-keygen +cd ~/.ssh/ +ll +cat id_rsa +cat id_rsa.pub +llcd - +cd - +git clone git@github.com:manikcloud/java-calculator-delete.git +ll +cd java-calculator-delete/ +vim README.md +git add . +git push +git config --global user.email varunmanik1@gmail.com +git config --global user.name varun-sl +git push +git status +git commit -am"hi" +gitpush +git push +cd .. +git clone git@github.com:manikcloud/DevOps-Tutorial.git +ll +cd DevOps-Tutorial/ +ll +cd 2-Git/ +history +history | cut -c 8- > history.txt diff --git a/2-Git/ssh-command-details b/2-Git/ssh-command-details new file mode 100644 index 0000000..d0eb36d --- /dev/null +++ b/2-Git/ssh-command-details @@ -0,0 +1,26 @@ +ssh-keygen +cd ~/.ssh/ +ll +cat id_rsa.pub +cd - +git clone git@github.com:manikcloud/java-calculator-delete.git +ll +cd java-calculator-delete/ +vim README.md +git add . +git push +git config --global user.email varunmanik1@gmail.com +git config --global user.name varun-sl +git push +git status +git commit -am"hi" +gitpush +git push +cd .. +git clone git@github.com:manikcloud/DevOps-Tutorial.git +ll +cd DevOps-Tutorial/ +ll +cd 2-Git/ +history +history | cut -c 8- > history.txt diff --git a/5-jenkins/5.2-simple-java-program/HelloWorld.java b/5-jenkins/5.2-simple-java-program/HelloWorld.java new file mode 100644 index 0000000..3d090dc --- /dev/null +++ b/5-jenkins/5.2-simple-java-program/HelloWorld.java @@ -0,0 +1,5 @@ +public class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello, World From Varun Manik on date MaJan 13 2024"); + } +} \ No newline at end of file diff --git a/5-jenkins/5.2-simple-java-program/README.md b/5-jenkins/5.2-simple-java-program/README.md new file mode 100644 index 0000000..0e859ec --- /dev/null +++ b/5-jenkins/5.2-simple-java-program/README.md @@ -0,0 +1,16 @@ + + + +## Copy & paste this commands in your Jenkins, build option, execute shell + +``` +cd 5-jenkins/5.2-simple-java-program + +ls -l + +javac HelloWorld.java + + +java HelloWorld + +``` \ No newline at end of file diff --git a/5-jenkins/5.3-maven-project/README.md b/5-jenkins/5.3-maven-project/README.md new file mode 100644 index 0000000..94df37e --- /dev/null +++ b/5-jenkins/5.3-maven-project/README.md @@ -0,0 +1,15 @@ + + + +## Copy & paste this commands in your Jenkins, build option, execute shell + +``` +cd 5-jenkins/5.3-maven-project/my-app + +mvn clean install + +tree + +java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App + +``` \ No newline at end of file diff --git a/5-jenkins/5.3-maven-project/my-app/pom.xml b/5-jenkins/5.3-maven-project/my-app/pom.xml new file mode 100644 index 0000000..9da641f --- /dev/null +++ b/5-jenkins/5.3-maven-project/my-app/pom.xml @@ -0,0 +1,83 @@ + + + + 4.0.0 + + com.mycompany.app + my-app + 1.0-SNAPSHOT + + my-app + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + 11 + + + + + + + junit + junit + 4.11 + test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/5-jenkins/5.3-maven-project/my-app/src/main/java/com/mycompany/app/App.java b/5-jenkins/5.3-maven-project/my-app/src/main/java/com/mycompany/app/App.java new file mode 100644 index 0000000..cff2a1a --- /dev/null +++ b/5-jenkins/5.3-maven-project/my-app/src/main/java/com/mycompany/app/App.java @@ -0,0 +1,13 @@ +package com.mycompany.app; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World! From Varun Manik in Simplilearn class on date Jan 13 2024" ); + } +} diff --git a/5-jenkins/5.3-maven-project/my-app/src/test/java/com/mycompany/app/AppTest.java b/5-jenkins/5.3-maven-project/my-app/src/test/java/com/mycompany/app/AppTest.java new file mode 100644 index 0000000..81ac345 --- /dev/null +++ b/5-jenkins/5.3-maven-project/my-app/src/test/java/com/mycompany/app/AppTest.java @@ -0,0 +1,20 @@ +package com.mycompany.app; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/5-jenkins/5.3-maven-project/my-app/target/maven-archiver/pom.properties b/5-jenkins/5.3-maven-project/my-app/target/maven-archiver/pom.properties new file mode 100644 index 0000000..d6071b5 --- /dev/null +++ b/5-jenkins/5.3-maven-project/my-app/target/maven-archiver/pom.properties @@ -0,0 +1,4 @@ +#Created by Apache Maven 3.6.3 +groupId=com.mycompany.app +artifactId=my-app +version=1.0-SNAPSHOT diff --git a/5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..de9dba0 --- /dev/null +++ b/5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1 @@ +com/mycompany/app/App.class diff --git a/5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..384d5a8 --- /dev/null +++ b/5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/home/varunmanikoutlo/varun/DevOps-Tutorial/5-jenkins/5.3-maven-project/my-app/src/main/java/com/mycompany/app/App.java diff --git a/5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..6348184 --- /dev/null +++ b/5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +com/mycompany/app/AppTest.class diff --git a/5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..9ff666c --- /dev/null +++ b/5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +/home/varunmanikoutlo/varun/DevOps-Tutorial/5-jenkins/5.3-maven-project/my-app/src/test/java/com/mycompany/app/AppTest.java diff --git a/5-jenkins/5.3-maven-project/my-app/target/surefire-reports/TEST-com.mycompany.app.AppTest.xml b/5-jenkins/5.3-maven-project/my-app/target/surefire-reports/TEST-com.mycompany.app.AppTest.xml new file mode 100644 index 0000000..dac6ed8 --- /dev/null +++ b/5-jenkins/5.3-maven-project/my-app/target/surefire-reports/TEST-com.mycompany.app.AppTest.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/5-jenkins/5.3-maven-project/my-app/target/surefire-reports/com.mycompany.app.AppTest.txt b/5-jenkins/5.3-maven-project/my-app/target/surefire-reports/com.mycompany.app.AppTest.txt new file mode 100644 index 0000000..efc88dd --- /dev/null +++ b/5-jenkins/5.3-maven-project/my-app/target/surefire-reports/com.mycompany.app.AppTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: com.mycompany.app.AppTest +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.042 s - in com.mycompany.app.AppTest diff --git a/5-jenkins/5.4-ant-java/HelloWorldAnt/build.xml b/5-jenkins/5.4-ant-java/HelloWorldAnt/build.xml new file mode 100644 index 0000000..cce072a --- /dev/null +++ b/5-jenkins/5.4-ant-java/HelloWorldAnt/build.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/5-jenkins/5.4-ant-java/HelloWorldAnt/src/HelloWorld.java b/5-jenkins/5.4-ant-java/HelloWorldAnt/src/HelloWorld.java new file mode 100644 index 0000000..70fd330 --- /dev/null +++ b/5-jenkins/5.4-ant-java/HelloWorldAnt/src/HelloWorld.java @@ -0,0 +1,5 @@ +public class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +} diff --git a/5-jenkins/5.4-ant-java/README.md b/5-jenkins/5.4-ant-java/README.md new file mode 100644 index 0000000..e081579 --- /dev/null +++ b/5-jenkins/5.4-ant-java/README.md @@ -0,0 +1,62 @@ +# Hello World Java Program with Ant on Linux. + +## Introduction +This tutorial guides you through creating and running a simple "Hello World" Java program using Apache Ant on a Linux system. + +## Prerequisites +- Java Development Kit (JDK) +- Apache Ant + +Ensure both are installed on your system. You can verify by running `java -version` and `ant -version` in your terminal. + +## Setup + +### Step 1: Project Structure +Create a project directory and set up the following structure: + + + +Navigate to your project directory: +```bash +mkdir HelloWorldAnt +cd HelloWorldAnt +``` + +- Step 2: Java Source File +Inside the src directory, create a file HelloWorld.java: + + + +``` +public class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +} +``` +- Step 3: Ant Build File +Create build.xml at the root of your project with the following content: + +``` + + + + + + + + + + + +``` + + +- Running the Program +To build and run your program, execute: + +``` +ant run +``` + +You should see Hello, World! printed in the console. diff --git a/5-jenkins/README.md b/5-jenkins/README.md new file mode 100644 index 0000000..8e3b6ad --- /dev/null +++ b/5-jenkins/README.md @@ -0,0 +1,121 @@ +# DevOps-Tutorial for Jenkins 1 +DevOps-Tutorial +# Caltech-DevOps Simplilearn PG Program + +This repository contains course materials for the Caltech-DevOps Simplilearn Postgraduate Program. + +## Course Contents + +1. **Course Introduction** + - Overview of the program + - Objectives and outcomes + +2. **Basic Linux** + - Introduction to Linux + - File system and basic commands + - Shell scripting + +3. **Introduction to DevOps** + - DevOps concepts and principles + - DevOps practices and tools + +4. **Version Control System** + - Introduction to Git + - Git workflow + - Branching and merging strategies + +5. **CI/CD Pipeline with Jenkins** + - Introduction to Jenkins + - Configuring and managing Jenkins + - Building and deploying pipelines + +6. **Configuration Management with Ansible** + - Introduction to Ansible + - Writing Ansible playbooks + - Ansible roles and best practices + +7. **Infrastructure as Code with Terraform** + - Introduction to Terraform + - Writing Terraform configurations + - Terraform modules and best practices + +8. **Containerization with Docker** + - Introduction to Docker + - Dockerfile and Docker Compose + - Docker networking and storage + +9. **Container Orchestration with Kubernetes** + - Introduction to Kubernetes + - Kubernetes objects and resources + - Kubernetes networking and storage + +10. **Continuous Monitoring** + - Introduction to monitoring + - Monitoring tools and techniques + - Integrating monitoring with CI/CD pipelines + +11. **Centralized Notification System** + - Introduction to centralized notifications + - Notification tools and techniques + - Integrating notifications with CI/CD pipelines + +12. **AWS Cloud** + - Introduction to AWS + - AWS services and best practices + - Deploying and managing applications on AWS + +13. **Real-Time Project** + - Working with Java, Maven, and Tomcat + - Building a complete CI/CD pipeline + - Applying DevOps principles and practices + +--------------------------------------------------------------------------------------------------- +## How to Use This Repository + +This repository contains course materials, example projects, and code snippets. Use it as a reference while working through the Caltech-DevOps Simplilearn Postgraduate Program. + + + +# Getting Started + +To get started, you will need to clone the repository to your local machine. Follow the instructions below: + +1. Open a terminal or Git Bash. +2. Navigate to the directory where you want to clone the repository. +3. Run the following command to clone the repository: + +``` +git clone git@github.com:manikcloud/devops-project.git +``` + +4. Change into the cloned repository directory: +``` +cd devops-project +``` + + +You have now successfully cloned the repository to your local machine. You can start working on the project and use Git to track your changes. + +## Contributing to the Project + +Before making any changes, create a new branch based on the master branch. This will help keep the master branch clean and make it easier to collaborate with others. + +1. Ensure you are in the `devops-project` directory. +2. Run the following command to create a new branch: + +``` +git checkout -b your_branch_name +``` +3. Make your changes, commit them, and push them to the remote repository: +``` +git add . +git commit -m "Your commit message" +git push origin your_branch_name +``` + + +When you are ready to merge your changes with the master branch, create a pull request on GitHub. This will allow others to review your changes before merging them. + +Remember to always keep your local repository up to date by fetching and merging changes from the remote repository. + +Happy coding! diff --git a/5-jenkins/terraform-jenkins-pipeline/Jenkinsfile b/5-jenkins/terraform-jenkins-pipeline/Jenkinsfile new file mode 100644 index 0000000..0a9d382 --- /dev/null +++ b/5-jenkins/terraform-jenkins-pipeline/Jenkinsfile @@ -0,0 +1,35 @@ +pipeline { + agent any + + environment { + AWS_REGION = 'us-east-1' + AWS_ACCESS_KEY_ID = "" + AWS_SECRET_ACCESS_KEY = "" + } + + stages { + stage('Checkout') { + steps { + checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/vijeshnair89/terraform-jenkins-pipeline.git']]) + } + } + + stage('Terraform Init') { + steps { + sh 'terraform init' + } + } + + stage('Terraform Plan') { + steps { + sh 'terraform plan' + } + } + + stage('Terraform Apply') { + steps { + sh 'terraform apply -auto-approve' + } + } + } +} diff --git a/5-jenkins/terraform-jenkins-pipeline/main.tf b/5-jenkins/terraform-jenkins-pipeline/main.tf new file mode 100644 index 0000000..553af60 --- /dev/null +++ b/5-jenkins/terraform-jenkins-pipeline/main.tf @@ -0,0 +1,8 @@ +resource "aws_instance" "public_instance" { + ami = var.ami + instance_type = var.instance_type + + tags = { + Name = var.name_tag, + } +} \ No newline at end of file diff --git a/5-jenkins/terraform-jenkins-pipeline/output.tf b/5-jenkins/terraform-jenkins-pipeline/output.tf new file mode 100644 index 0000000..5d746db --- /dev/null +++ b/5-jenkins/terraform-jenkins-pipeline/output.tf @@ -0,0 +1,9 @@ +output "public_ip" { + value = aws_instance.public_instance.public_ip + description = "Public IP Address of EC2 instance" +} + +output "instance_id" { + value = aws_instance.public_instance.id + description = "Instance ID" +} \ No newline at end of file diff --git a/5-jenkins/terraform-jenkins-pipeline/provider.tf b/5-jenkins/terraform-jenkins-pipeline/provider.tf new file mode 100644 index 0000000..b21d3b6 --- /dev/null +++ b/5-jenkins/terraform-jenkins-pipeline/provider.tf @@ -0,0 +1 @@ +provider "aws" {} diff --git a/5-jenkins/terraform-jenkins-pipeline/variables.tf b/5-jenkins/terraform-jenkins-pipeline/variables.tf new file mode 100644 index 0000000..84d2520 --- /dev/null +++ b/5-jenkins/terraform-jenkins-pipeline/variables.tf @@ -0,0 +1,17 @@ +variable "ami" { + type = string + description = "Ubuntu AMI ID" + default = "ami-03f4878755434977f" +} + +variable "instance_type" { + type = string + description = "Instance type" + default = "t2.micro" +} + +variable "name_tag" { + type = string + description = "Name of the EC2 instance" + default = "Terraform" +} diff --git a/6-ansible-terraform/6.2-node-ansible-playbook/README.md b/6-ansible-terraform/6.2-node-ansible-playbook/README.md new file mode 100644 index 0000000..49f69a6 --- /dev/null +++ b/6-ansible-terraform/6.2-node-ansible-playbook/README.md @@ -0,0 +1,310 @@ +# Create EC2 instances with Terraform + +This branch contains Terraform code to create EC2 instances in AWS. + +## Related Blog Posts By Author: + +- [DevSecOps CI/CD Java Tomcat Project](https://varunmanik1.medium.com/devsecops-cicd-java-tomcat-project-141d6b73e436) +- [DevOps Jenkins AWS Series Part 1: How to Install Jenkins on AWS Ubuntu 22.04](https://varunmanik1.medium.com/devops-jenkins-aws-series-part-1-how-to-install-jenkins-on-aws-ubuntu-22-04-cb0c3cdb055) +- [DevOps Jenkins AWS Series Part 2: Setup AWS CloudShell, Install Terraform in Persistent](https://varunmanik1.medium.com/devops-jenkins-aws-series-part-2-setup-aws-cloudshell-install-terraform-in-persistent-425dc0537cf5) + + +## Prerequisites + +Before you start, make sure you have the following: + +- An AWS account, with ec2 full access permission +- And Linux Terminal, wher you can run all these commands + +## Files + +- `README.md`: This file, providing an overview of the branch. +- `deployer` and `deployer.pub`: SSH keys for accessing the EC2 instances. +- `history.txt`: A text file with a record of changes to this project. +- `jenkins-installation-ubuntu.sh`: A shell script to install Jenkins on the EC2 instance. +- `main.tf`: The main Terraform configuration file that creates the AWS resources. +- `slave-vm.tf`: A Terraform configuration file that creates a Jenkins slave instance. +- `tf-cli-installation.sh`: A shell script to install the Terraform CLI on the EC2 instance. +- `ubuntu-vm.tf`: A Terraform configuration file that creates an Ubuntu EC2 instance. + +## Usage + +To create EC2 instances with Terraform, follow these steps: + +1. Clone this repository to your local machine by running the command: `git clone https://github.com/manikcloud/Jenkins-cicd.git`. +2. Switch to the `0.1_create_ec2_tf` branch by running the command: `git checkout 0.1_create_ec2_tf`. +3. Navigate to the `terraform` directory by running the command: `cd terraform`. +4. Initialize Terraform by running the command: `terraform init`. +5. Create an execution plan by running the command: `terraform plan`. +6. Apply the execution plan by running the command: `terraform apply`. + +You will be prompted to enter values for the variables defined in the `variables.tf` file. + + +Create an AWS Account + +1. Go to the AWS website and click on the "Create an AWS Account" button. +2. Follow the on-screen instructions to create your account. +3. Once your account is created, log in to the AWS Management Console. + +### Create Access Keys in IAM + +1. In the AWS Management Console, navigate to the IAM service. +2. Click on "Users" in the left sidebar, and then click on the "Add User" button. +3. Enter a user name and select "Programmatic Access" as the access type. +4. Click on the "Next: Permissions" button. +5. Choose the appropriate permissions for your user, or attach an existing policy. +6. Click on the "Next: Tags" button. +7. Add any tags (optional) and click on the "Next: Review" button. +8. Review your settings and click on the "Create User" button. +9. Once the user is created, take note of the access key ID and secret access key. You will need these later to configure the AWS CLI. + +### Install AWS CLI and Configure it + +1. Install AWS CLI using the following command: +``` +sudo apt-get install awscli +``` +2. Run the command `aws configure` to configure your access key ID, secret access key, default region, and output format. + +## Install Terraform from SH Script + +``` +sudo chmod 755 chmod 755 tf-cli-installation.sh +sudo sh chmod 755 tf-cli-installation.sh + +``` +# OR + +## Install Terraform Manual +1. Set the desired Terraform version: `TERRAFORM_VERSION="1.4.5"` +2. Download Terraform: +``` +wget "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" +``` +3. Install unzip if not installed: +``` +sudo apt-get update && sudo apt-get install -y unzip +``` +4. Unzip the Terraform package: +``` +unzip "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" +``` +5. Move the Terraform binary to the /usr/local/bin folder: +``` +sudo cp terraform /usr/local/bin/ && sudo mv terraform /usr/bin/ +``` +6. Clean up the downloaded zip file: +``` +rm "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" +``` +7. Verify the installation: +``` +terraform --version +``` +That's it! With an AWS account, access keys, AWS CLI, and Terraform installed and configured, you're ready to use Terraform to create AWS resources. + + +After the Terraform code has finished executing, you can choose one of the following options to install Jenkins: + +### Option 1.1 : Install Jenkins by SH Script + +``` +chmod 755 jenkins-installation-ubuntu.sh +sudo sh jenkins-installation-ubuntu.sh +``` + +### Option 1.2 : Manually Install Jenkins + +To manually install Jenkins, follow these steps: + +1. SSH into the Ubuntu EC2 instance created by Terraform by running the command: + `ssh -i deployer ubuntu@`. + +2. Install Java by running the command: + `sudo apt-get update && sudo apt-get install default-jdk`. + +3. Add the Jenkins repository key by running the command: + +4. Add the Jenkins repository by running the command: + +``` + +sudo mkdir -p /usr/share/keyrings + +sudo curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null + +sudo echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null + +``` +5. Update the package list by running the command, + +6. Install Jenkins by running the command: + +``` +sudo apt-get update +sudo apt-get install jenkins + ``` +### Option 2: Use Terraform to Install Jenkins + +To use Terraform to install Jenkins, follow these steps: + +1. SSH into the Ubuntu EC2 instance created by Terraform by running the command: +`ssh -i deployer ubuntu@`. + +2. Run the Jenkins installation script by running the command: +`sudo sh /home/ubuntu/jenkins-installation-ubuntu.sh`. + +3. The script will install Jenkins and its dependencies. Once the installation is complete, Jenkins will be running on the EC2 instance. + +## Clean Up + +To destroy the EC2 instances and associated resources, run the command: `terraform destroy` + +Note: This will delete all resources created by Terraform in this branch. + + +## For More info on lab machine plz expend below: + +
+# Jenkins-cicd +PG DO - CI/CD Pipeline with Jenkins Simplilearn + +# AWS Ubuntu VM Provisioning steps +- Step 1: Click on Launch Instance +- Step 2 : Click on Software Image (AMI) +- Select Ubuntu +- Step 4: Key pair name – required +- Click on Create new key pair +- Put key pair name Jenkins-sl +- & Download it +- Step 5 : Click on Launch Instance +- Step 6 : Select your VM and Click connect +- Step 7 : You can see the terminal +- Step: Showing Github example + +# Git Status +``` +git --version +``` +## cretae Dir +``` +mkdir demo +cd demo +``` +## GIT & Ubuntu SSH connection +``` +ssh-keygen + +"Hit enter button 3 time" + +cat ~/.ssh/id_rsa.pub +git clone git@github.com:manikcloud/Jenkins-cicd.git +history +history | cut -c 8- +``` + +# Jenkins installation on UBUNTU 18.04 & Ubuntu 22.04 + +### Step 1 +``` +sudo apt-get update -y && sudo apt install openjdk-8-jdk -y +``` +### Step 2: Downloading Key +``` +sudo wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add +``` + +### Step 3: Adding Key +``` +sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' +``` + +### Step 4: Jenkins Package installation +``` +sudo apt-get update -y && sudo apt install jenkins -y +sudo /etc/init.d/jenkins start +sudo service jenkins status +``` +### Step 5: Jenkins default password +``` +sudo cat /home/labsuser/jenkins/secrets/initialAdminPassword +``` +### Step 6: History command + +``` +history | cut -c 8- + +``` +# Jenkins URL with port 8080 +- http://x.x.x.x:8080/ + +Replace x with your ip + +# Change Security group rule for Jenkins +``` +- Select your instance +- Down below select your security tab +- Click on the Security groups sg-0c51908b5fa4abf75 (launch-wizard-2) +- Click on the action +- Click on EDIT INBOUND RULE +- Select custom TCP and put port 8080 +- Custom ip should be 0.0.0.0/0 +- Click on Save the rule +``` + +# Common error + +``` +getting "E: Unable to locate package openjdk-8-jdk" message on java update +``` + +# Resolution +Run this command + +``` +sudo apt update -y +``` +# Plugin Installation +dashboard>manage>jenkins>manage plugins>maven integration + + + +# Jenkins Setting + +``` +Java_Home +/usr/lib/jvm/java-8-openjdk-amd64/ +``` + +# Post Build Step + +``` +java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App + +``` + +# This project is parameterized +``` +echo "User First name is : $First_Name" +echo "User Last name is : $Last_Name" +echo "User Gender is : $Sex" + +``` +
+ +# References: +1. https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html +2. https://maven.apache.org/download.cgi + +## Connect & Follow + +For more info, please connect and follow me: + +- Github: [https://github.com/manikcloud](https://github.com/manikcloud) +- LinkedIn: [https://www.linkedin.com/in/vkmanik/](https://www.linkedin.com/in/vkmanik/) +- Email: [varunmanik1@gmail.com](mailto:varunmanik1@gmail.com) +- Facebook: [https://www.facebook.com/cloudvirtualization/](https://www.facebook.com/cloudvirtualization/) +- YouTube: [https://bit.ly/32fknRN](https://bit.ly/32fknRN) +- Twitter: [https://twitter.com/varunkmanik](https://twitter.com/varunkmanik) + diff --git a/6-ansible-terraform/6.2-node-ansible-playbook/node.yml b/6-ansible-terraform/6.2-node-ansible-playbook/node.yml new file mode 100644 index 0000000..8fdf448 --- /dev/null +++ b/6-ansible-terraform/6.2-node-ansible-playbook/node.yml @@ -0,0 +1,19 @@ +--- +- hosts: webservers + become: true + tasks: + - name: add apt key for nodesource + become: true + apt_key: + url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key + + - name: add repo for nodesource + become: true + apt_repository: + repo: 'deb https://deb.nodesource.com/node_0.10 {{ ansible_distribution_release }} main' + update_cache: no + + - name: install nodejs + become: true + apt: + name: nodejs diff --git a/6-ansible-terraform/6.3-apache-ansible-playbook/apache.yaml b/6-ansible-terraform/6.3-apache-ansible-playbook/apache.yaml new file mode 100644 index 0000000..fe5703d --- /dev/null +++ b/6-ansible-terraform/6.3-apache-ansible-playbook/apache.yaml @@ -0,0 +1,13 @@ +hosts: webservers +become: true +tasks: + - name: install apache2 + apt: name=apache2 update_cache=no state=latest + - name: enabled mod_rewrite + apache2_module: name=rewrite state=present + notify: + - restart apache2 + +handlers: + - name: restart apache2 + service: name=apache2 state=restarted diff --git a/6-ansible-terraform/6.4-ansible-module/README.md b/6-ansible-terraform/6.4-ansible-module/README.md new file mode 100644 index 0000000..a9a02fc --- /dev/null +++ b/6-ansible-terraform/6.4-ansible-module/README.md @@ -0,0 +1,60 @@ +# README + +## Lesson 06 Demo 4 - Ansible Modules + +This document provides the steps to execute Ansible modules on a local server. + +### Steps to be performed: + +1. Execute Ansible modules on a local server. + +#### Step 1: Executing Ansible modules with local server + +1.1 Run the below commands in the given sequence to execute different Ansible modules. + +``` +ansible -m setup all +ansible all -m shell -a 'hostname' +ansible webservers -m apt -a 'name=git state=present' --become +ansible webservers -m file -a 'dest=/root/sample.txt state=touch mode=600 owner=root group=root' --become +``` + +## description of the commands used in the README: + +- ansible -m setup webservers: This command uses the setup module to gather facts about the remote hosts listed under the [webservers] group in the Ansible inventory file. The setup module collects a wide range of system information such as OS version, IP addresses, disk space, memory usage, etc. + +- ansible webservers -m shell -a 'hostname': This command uses the shell module to execute the hostname command on the remote hosts listed under the [webservers] group in the Ansible inventory file. The shell module allows running shell commands on the remote hosts. + +- ansible webservers -m apt -a 'name=git state=present' --become: This command uses the apt module to install the git package on the remote hosts listed under the [webservers] group in the Ansible inventory file. The apt module provides a way to manage packages on Debian-based systems. The --become flag is used to elevate privileges and run the command as the root user. + +- ansible webservers -m file -a 'dest=/root/sample.txt state=touch mode=600 owner=root group=root' --become: This command uses the file module to create a new file named sample.txt with root as the owner and group, and the file mode set to 600 on the remote hosts listed under the [webservers] group in the Ansible inventory file. The file module provides a way to manage files and directories on remote hosts. The --become flag is used to elevate privileges and run the command as the root user. + + +# Step 1: Ansible Ad-hoc Command without Configuration Files +``` +ansible all -i '18.209.59.137,' -m ping -u ubuntu --private-key ../deployer +``` + +# Step 2: Add Inventory File (inventory.ini) +echo "[my_servers]\nmy_server ansible_host=18.209.59.137" > inventory.ini +``` + +ansible my_servers -i inventory.ini -m ping -u ubuntu --private-key ../deployer +``` + + +# Step 3: Add Ansible Configuration File (ansible.cfg) + +echo -e "[defaults]\ninventory = inventory.ini\nremote_user = ubuntu\nprivate_key_file = ../deployer\nhost_key_checking = False\nretry_files_enabled = False" > ansible.cfg +``` + +ansible my_servers -m ping +``` + + +# Step 4: Simplified Ansible Command with Configuration Files +``` + +ansible my_servers -m ping +``` + diff --git a/6-ansible-terraform/6.5-ansible-role/README.md b/6-ansible-terraform/6.5-ansible-role/README.md new file mode 100644 index 0000000..83ce99c --- /dev/null +++ b/6-ansible-terraform/6.5-ansible-role/README.md @@ -0,0 +1,176 @@ +## Lesson 06 Demo 5 - Creating and Working with Ansible Roles + +This document provides the steps to create and work with Ansible roles. + +### Steps to be performed: + +1. Install Ansible on Ubuntu, and establish connectivity between Ansible controller and node machine (You can skip this step in case Ansible is already installed) +2. Create Ansible Role +3. Create Ansible tasks +4. Create Ansible template +5. Create Ansible variable +6. Remove unwanted directory +7. Create Ansible role playbook +8. Deploy Ansible role playbook + +## Step 1: Install Ansible on Ubuntu, and establish connectivity between Ansible controller and node machine + +If Ansible is not installed on the Ubuntu system, use the following commands to install Ansible: + +``` +sudo apt-get install -f +sudo apt-get install software-properties-common +sudo apt-add-repository ppa:ansible/ansible +sudo apt-get update +sudo apt-get install ansible +``` + +## Step 2: Create Ansible Role + 2.1 Once we have our Ansible environment ready, create a new project directory. I will create a new project named base to demonstrate Ansible roles example: + + + +``` + +mkdir base +cd base +``` + +2.2 To create an Ansible role, use ansible-galaxy init to create the role directory structure: + +``` + +cd roles +ansible-galaxy init demor +cd demor +``` + + +2.3 You can use the ls command to list the Ansible role directory structure. + +## Step 3: Create Ansible Tasks +3.1 Now update the /etc/motd file using Ansible playbook roles. Create tasks to use the main.yml file present inside the tasks folder. + + +``` + + +cd tasks +ls +vi main.yml +``` + +3.2 Enter the following code: + + +# tasks file for demor +``` + +- name: copy demor file + template: + src: templates/demor.j2 + dest: /etc/demor + owner: root + group: root + mode: 0444 +``` + +## Step 4: Create Ansible Template +4.1 Create the template content which will be used to update /etc/motd in our Ansible roles examples. Create a new template file under the templates directory using some variables. + + + +``` + +cd .. +cd templates +vi demor.j2 +``` + +4.2 Enter the following details: + + +``` + +Welcome to {{ ansible_hostname }} + +This file was created on {{ ansible_date_time.date }} +Go away if you have no business being here + +Contact {{ system_manager }} if anything is wrong +``` + +## Step 5: Create Ansible Variable +5.1 We will use the defaults folder to define custom variables which are used in our template file templates/demor.j2. + + + +``` + +cd .. +cd defaults +ls +vi main.yml +``` + +5.2 Enter the following details in the file: + +``` +# defaults file for demor +system_manager: admin@golinuxcloud.com +``` + +## Step 6: Remove unwanted directories (Optional) +6.1 This step is completely optional. In this Ansible roles example, we will not use other directories so we are deleting them. After deleting the additional directories you can use the tree command to list the directory structure of motd roles. + + +``` + + +cd .. +rm -rf handlers tests vars +``` + + +## Step 7: Create an Ansible Role Playbook + +7.1 Now after you create an Ansible role structure, we need a playbook file that will deploy the role to our managed hosts. I will create my playbook file `demor-role.yml` under the `base` project directory. + +``` +cd .. +cd .. +sudo vi demor-role.yml +``` + + +7.2 Enter the following code in the file: + +``` + + +--- +- name: use demor role playbook + hosts: webservers + user: ansible + become: true + + roles: + - role: demor + system_manager: admin@golinuxcloud.com +``` + +## Step 8: Deploy Ansible Role Playbook +8.1 Execute the following command: + + +``` + + +ansible-playbook demor-role.yml +``` + +Note: In case you get an error asking you to install sshpass program, execute the command: sudo apt install sshpass and then run the ansible-playbook demor-role.yml command. + + + + diff --git a/6-ansible-terraform/6.5-ansible-role/ansible.cfg b/6-ansible-terraform/6.5-ansible-role/ansible.cfg new file mode 100644 index 0000000..3b6c7ec --- /dev/null +++ b/6-ansible-terraform/6.5-ansible-role/ansible.cfg @@ -0,0 +1,6 @@ +[defaults] +inventory = inventory.ini +remote_user = ubuntu +private_key_file = ./deployer +host_key_checking = False +retry_files_enabled = False diff --git a/6-ansible-terraform/6.5-ansible-role/demor-role.yml b/6-ansible-terraform/6.5-ansible-role/demor-role.yml new file mode 100644 index 0000000..b42b276 --- /dev/null +++ b/6-ansible-terraform/6.5-ansible-role/demor-role.yml @@ -0,0 +1,11 @@ + + +--- +- name: use demor role playbook + hosts: localhost + user: ubuntu + become: true + + roles: + - role: demor + system_manager: admin@golinuxcloud.com diff --git a/6-ansible-terraform/6.5-ansible-role/demor/.travis.yml b/6-ansible-terraform/6.5-ansible-role/demor/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/6-ansible-terraform/6.5-ansible-role/demor/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/6-ansible-terraform/6.5-ansible-role/demor/README.md b/6-ansible-terraform/6.5-ansible-role/demor/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/6-ansible-terraform/6.5-ansible-role/demor/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/6-ansible-terraform/6.5-ansible-role/demor/defaults/main.yml b/6-ansible-terraform/6.5-ansible-role/demor/defaults/main.yml new file mode 100644 index 0000000..2c95bf8 --- /dev/null +++ b/6-ansible-terraform/6.5-ansible-role/demor/defaults/main.yml @@ -0,0 +1,2 @@ +# defaults file for demor +system_manager: admin@golinuxcloud.com diff --git a/6-ansible-terraform/6.5-ansible-role/demor/meta/main.yml b/6-ansible-terraform/6.5-ansible-role/demor/meta/main.yml new file mode 100644 index 0000000..0dbdfb9 --- /dev/null +++ b/6-ansible-terraform/6.5-ansible-role/demor/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: Varun + description: Cloud Engineer + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/6-ansible-terraform/6.5-ansible-role/demor/tasks/main.yml b/6-ansible-terraform/6.5-ansible-role/demor/tasks/main.yml new file mode 100644 index 0000000..7f9b97c --- /dev/null +++ b/6-ansible-terraform/6.5-ansible-role/demor/tasks/main.yml @@ -0,0 +1,8 @@ + +- name: copy demor file + template: + src: templates/demor.j2 + dest: /etc/demor + owner: root + group: root + mode: 0444 diff --git a/6-ansible-terraform/6.5-ansible-role/demor/templates/demor.j2 b/6-ansible-terraform/6.5-ansible-role/demor/templates/demor.j2 new file mode 100644 index 0000000..6a7c197 --- /dev/null +++ b/6-ansible-terraform/6.5-ansible-role/demor/templates/demor.j2 @@ -0,0 +1,7 @@ + +Welcome to {{ ansible_hostname }} + +This file was created on {{ ansible_date_time.date }} +Go away if you have no business being here + +Contact {{ system_manager }} if anything is wrong diff --git a/6-ansible-terraform/6.5-ansible-role/deployer b/6-ansible-terraform/6.5-ansible-role/deployer new file mode 100644 index 0000000..2b6525d --- /dev/null +++ b/6-ansible-terraform/6.5-ansible-role/deployer @@ -0,0 +1,38 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn +NhAAAAAwEAAQAAAYEAw/IExD9MHaiZx5FQ3OyDMxcoKbIm03pmcpWb5OIHBommvmF/P1aV +BMjq6mDoP/DqzgLHUAqT3HPCdwIVAUr4I3inO7CWdDfL/gDip1UA54v8vvZlg+qBjrM8x+ +g1X6BzstR0WQGxep/sRZJNA3orEidxbBlUCvyea2IF1QgSYot+Ji9PgzgaIMS72vLQ3C4F +i8/qsbPEHB+IYKx5HU/MIQSnynMqSAhkuFP1oFxVuTN6TeDsp0s3qifYF59BW6udCf7egq +Z6+sKpc0c6HADF55YK3IWGVmSYEy91vM64NRce0Qct3wGxMlqMq5AfXBSD0pJolGRvcVIY +qyODG3YB1TZZKe8VNFeinwkZUzRPsc1pWz0oGu5I5aoos4w6Ee8RMSjS2zbYQep5TSBMF/ +hZY7YK06jFdsOpPB98X64XRtPfdxJzDMHT1ZpbRIyXmfpdwRE1HImyhhRXOYskffVuzSoa +4h+Xejr213r+yZm6rF68J/K57t2rgxibO2GiMM5pAAAFmKv3VXqr91V6AAAAB3NzaC1yc2 +EAAAGBAMPyBMQ/TB2omceRUNzsgzMXKCmyJtN6ZnKVm+TiBwaJpr5hfz9WlQTI6upg6D/w +6s4Cx1AKk9xzwncCFQFK+CN4pzuwlnQ3y/4A4qdVAOeL/L72ZYPqgY6zPMfoNV+gc7LUdF +kBsXqf7EWSTQN6KxIncWwZVAr8nmtiBdUIEmKLfiYvT4M4GiDEu9ry0NwuBYvP6rGzxBwf +iGCseR1PzCEEp8pzKkgIZLhT9aBcVbkzek3g7KdLN6on2BefQVurnQn+3oKmevrCqXNHOh +wAxeeWCtyFhlZkmBMvdbzOuDUXHtEHLd8BsTJajKuQH1wUg9KSaJRkb3FSGKsjgxt2AdU2 +WSnvFTRXop8JGVM0T7HNaVs9KBruSOWqKLOMOhHvETEo0ts22EHqeU0gTBf4WWO2CtOoxX +bDqTwffF+uF0bT33cScwzB09WaW0SMl5n6XcERNRyJsoYUVzmLJH31bs0qGuIfl3o69td6 +/smZuqxevCfyue7dq4MYmzthojDOaQAAAAMBAAEAAAGBAIVNW7LKwRSYQ+4BzTpO6L7ULS +2YllNevN2NLF5c6pym/rocB/5l/8EekrparQX69zKpr0CjwY3DbvOZhgK4JvGyvkqcSu7L +msq1fXyLFq9vi8W6SLuiyPr0sw/oyI7C0JNDd9epkD01GP8Hlb8c2Lpj/QSmgodq7rdtGz +yfXiqObYa6vuQtQZEzZf2BHVf9Mya3jxnPi0X6qcPi8g5f4CZCTYgsKwKQOz0vWTX8OxFg +lP7wWu9A+6CVtKv1WvhrWZy0g68CaMsBRZ2weZ1K4ScqbZvJdvWPfJzY0rJgJk7wNPA5Ak +QEG+IaMtmFQ5phGEcxqXkoGcSlLEW7P8XMwLHTWdlFAgVwrWsvmU8dzZ+tOa82ZY8tIF+B +wzzYgFZoO3H4fFXd3sXx7f/ME5a1NTTiEU/8I16omN8xdrDSVHbJd4stljpUGda6iTgF2s +khXmZ7dxCq/ZDlbCQwsumzbmPz+ass13/bP/PG7e92CRhwxrRELQij0DWpRiLPc13c0QAA +AMEAg+5tOG/WZA1P8KfeDmZXImTWOuTnaOZzYRI9ZXFpF9gUa+zYO/0l5br4I0/SKQJs0Y +C+XIamiN7HoOjH4MDkqTHrmkliGsJ0Z5Ag/u6eEEvXqMqkdJ8dbhP9aHVUhPUJ9AuJ7Bsf +Jgy/hgjkntf165K83Gkrgmcql+iPOxA9EjrWFRuWdTrMFRJgqTirtwMPI7ywKXkXKB5tX+ +AqgpPb2s7cj00B4pQku9RA0apE0UOcRzEiAMUpP9egTHBIN1XzAAAAwQDnJbhvuZkZxKjD +KMJsta1nom0+TLNxix7y/oOaX+YRmYY+6vS7WHCY5qg/7wUNd6npTS/QU1FoL0HsQalVwy +YDYoUAbmfdT2xQEUesO6cKpFNfI+ToolsZppp+Nuqi60FEFE+S/pV/4gMxQnt0DcQ/Wumu +R/eBTBdjbFh4ZkedPIulue6XxtBmhfzor8IGNklChWrKib47D0/LN5AJA62uriQmo23yKG +AVDYuhSnEOt4yPZgW5e0tVrajkUti0cpUAAADBANkDXzsfmG1GyF9I68NdLhDfU0huxRWs +8bVPX92eKI2HKZ/ZzHx9s3gwkz/nj2iCmIKOEI0S7qNkGGjt+vQ+qH7oxWhjW4t8S7b/pe +JBVDvRUGNk2XIYk5Jdcgv+VPJDrfe51IV6cXxxkmOU5asMgvlsMue8pKuiBw/HgdmNOQBp +9Y/NSXLTUDh0jOwFyryYZKDZPSaP/iWN38Y3v6UHwa9wz0AnL1Iv1sT12sui9dEQ9hdTDd +thvT0LVaxmsBlrhQAAACB2YXJ1bm1hbmlrb3V0bG9AaXAtMTcyLTMxLTE3LTIwNgE= +-----END OPENSSH PRIVATE KEY----- diff --git a/6-ansible-terraform/6.5-ansible-role/deployer.pub b/6-ansible-terraform/6.5-ansible-role/deployer.pub new file mode 100644 index 0000000..d149548 --- /dev/null +++ b/6-ansible-terraform/6.5-ansible-role/deployer.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDD8gTEP0wdqJnHkVDc7IMzFygpsibTemZylZvk4gcGiaa+YX8/VpUEyOrqYOg/8OrOAsdQCpPcc8J3AhUBSvgjeKc7sJZ0N8v+AOKnVQDni/y+9mWD6oGOszzH6DVfoHOy1HRZAbF6n+xFkk0DeisSJ3FsGVQK/J5rYgXVCBJii34mL0+DOBogxLva8tDcLgWLz+qxs8QcH4hgrHkdT8whBKfKcypICGS4U/WgXFW5M3pN4OynSzeqJ9gXn0Fbq50J/t6Cpnr6wqlzRzocAMXnlgrchYZWZJgTL3W8zrg1Fx7RBy3fAbEyWoyrkB9cFIPSkmiUZG9xUhirI4MbdgHVNlkp7xU0V6KfCRlTNE+xzWlbPSga7kjlqiizjDoR7xExKNLbNthB6nlNIEwX+FljtgrTqMV2w6k8H3xfrhdG0993EnMMwdPVmltEjJeZ+l3BETUcibKGFFc5iyR99W7NKhriH5d6OvbXev7JmbqsXrwn8rnu3auDGJs7YaIwzmk= varunmanikoutlo@ip-172-31-17-206 diff --git a/6-ansible-terraform/6.5-ansible-role/host_vars.yml b/6-ansible-terraform/6.5-ansible-role/host_vars.yml new file mode 100644 index 0000000..22f9a46 --- /dev/null +++ b/6-ansible-terraform/6.5-ansible-role/host_vars.yml @@ -0,0 +1,3 @@ +--- +ansible_user: ubuntu +ansible_ssh_private_key_file: ./deployer diff --git a/6-ansible-terraform/6.5-ansible-role/inventory.ini b/6-ansible-terraform/6.5-ansible-role/inventory.ini new file mode 100644 index 0000000..4dbc68f --- /dev/null +++ b/6-ansible-terraform/6.5-ansible-role/inventory.ini @@ -0,0 +1,3 @@ +[my_servers] +my_server ansible_host=localhost +# my_server ansible_host=54.224.173.170 diff --git a/6-ansible-terraform/6.6-setup-terraform/README.md b/6-ansible-terraform/6.6-setup-terraform/README.md new file mode 100644 index 0000000..f90c90b --- /dev/null +++ b/6-ansible-terraform/6.6-setup-terraform/README.md @@ -0,0 +1,41 @@ + +# Lesson 06 Demo 6 +## Set up Terraform + +Steps to be performed: + +## Install Terraform from SH Script + +``` +sudo chmod 755 tf-installation.sh +sudo sh tf-installation.sh + +``` + + +## Create an AWS Account + +1. Go to the AWS website and click on the "Create an AWS Account" button. +2. Follow the on-screen instructions to create your account. +3. Once your account is created, log in to the AWS Management Console. + +### Create Access Keys in IAM + +1. In the AWS Management Console, navigate to the IAM service. +2. Click on "Users" in the left sidebar, and then click on the "Add User" button. +3. Enter a user name and select "Programmatic Access" as the access type. +4. Click on the "Next: Permissions" button. +5. Choose the appropriate permissions for your user, or attach an existing policy. +6. Click on the "Next: Tags" button. +7. Add any tags (optional) and click on the "Next: Review" button. +8. Review your settings and click on the "Create User" button. +9. Once the user is created, take note of the access key ID and secret access key. You will need these later to configure the AWS CLI. + +### Install AWS CLI and Configure it + +1. Install AWS CLI using the following command: +``` +sudo apt-get install awscli +``` +2. Run the command `aws configure` to configure your access key ID, secret access key, default region, and output format. + diff --git a/6-ansible-terraform/6.6-setup-terraform/tf-installation.sh b/6-ansible-terraform/6.6-setup-terraform/tf-installation.sh new file mode 100755 index 0000000..835ee3b --- /dev/null +++ b/6-ansible-terraform/6.6-setup-terraform/tf-installation.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Set the desired Terraform version +TERRAFORM_VERSION="1.4.5" + +# Download Terraform +wget "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" + +# Install unzip if not installed +sudo apt-get update +sudo apt-get install -y unzip + +# Unzip the Terraform package +unzip "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" + +# Move the Terraform binary to the /usr/local/bin folder +sudo cp terraform /usr/local/bin/ +sudo mv terraform /usr/bin/ + +# Clean up the downloaded zip file +rm "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" + +# Verify the installation +terraform --version \ No newline at end of file diff --git a/6-ansible-terraform/6.6.1-tf-local-file/.terraform.lock.hcl b/6-ansible-terraform/6.6.1-tf-local-file/.terraform.lock.hcl new file mode 100644 index 0000000..62da99d --- /dev/null +++ b/6-ansible-terraform/6.6.1-tf-local-file/.terraform.lock.hcl @@ -0,0 +1,21 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/local" { + version = "2.4.1" + hashes = [ + "h1:FzraUapGrJoH3ZOWiUT2m6QpZAD+HmU+JmqZgM4/o2Y=", + "zh:244b445bf34ddbd167731cc6c6b95bbed231dc4493f8cc34bd6850cfe1f78528", + "zh:3c330bdb626123228a0d1b1daa6c741b4d5d484ab1c7ae5d2f48d4c9885cc5e9", + "zh:5ff5f9b791ddd7557e815449173f2db38d338e674d2d91800ac6e6d808de1d1d", + "zh:70206147104f4bf26ae67d730c995772f85bf23e28c2c2e7612c74f4dae3c46f", + "zh:75029676993accd6bef933c196b2fad51a9ec8a69a847dbbe96ec8ebf7926cdc", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:7d48d5999fe1fcdae9295a7c3448ac1541f5a24c474bd82df6d4fa3732483f2b", + "zh:b766b38b027f0f84028244d1c2f990431a37d4fc3ac645962924554016507e77", + "zh:bfc7ad301dada204cf51c59d8bd6a9a87de5fddb42190b4d6ba157d6e08a1f10", + "zh:c902b527702a8c5e2c25a6637d07bbb1690cb6c1e63917a5f6dc460efd18d43f", + "zh:d68ae0e1070cf429c46586bc87580c3ed113f76241da2b6e4f1a8348126b3c46", + "zh:f4903fd89f7c92a346ae9e666c2d0b6884c4474ae109e9b4bd15e7efaa4bfc29", + ] +} diff --git a/6-ansible-terraform/6.6.1-tf-local-file/index.html b/6-ansible-terraform/6.6.1-tf-local-file/index.html new file mode 100755 index 0000000..f077469 --- /dev/null +++ b/6-ansible-terraform/6.6.1-tf-local-file/index.html @@ -0,0 +1 @@ +Hi How are you ? \ No newline at end of file diff --git a/6-ansible-terraform/6.6.1-tf-local-file/main.tf b/6-ansible-terraform/6.6.1-tf-local-file/main.tf new file mode 100644 index 0000000..5c53112 --- /dev/null +++ b/6-ansible-terraform/6.6.1-tf-local-file/main.tf @@ -0,0 +1,7 @@ +resource "local_file" "index_file" { + + content = "Hi How are you ?" + + filename = "index.html" + +} diff --git a/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/.gitignore b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/.gitignore new file mode 100644 index 0000000..7a3e2fd --- /dev/null +++ b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/.gitignore @@ -0,0 +1,29 @@ +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log + +# Ignore any .tfvars files that are generated automatically for each Terraform run. Most +# .tfvars files are managed as part of configuration and so should be included in +# version control. +# +# example.tfvars + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Include override files you do wish to add to version control using negated pattern +# +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* diff --git a/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/.terraform.lock.hcl b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/.terraform.lock.hcl new file mode 100644 index 0000000..e747866 --- /dev/null +++ b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/.terraform.lock.hcl @@ -0,0 +1,24 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "4.66.1" + hashes = [ + "h1:D/qzK7fE3pgdg25W1u5GqI+VILy8UmhzXruz6c8rJ7g=", + "zh:001c707174b7d6bf89a96cf806f925bb852d1a285fb80b81222cbeb4743bcb79", + "zh:19bc6ac0a7fd1c564fd56c536f1743f71a5e7ca724e21ea51a6a79218939733d", + "zh:3dac5c27f40b511239e9fe6f97dc0b6c95f630ba328001820ddc764e766a5ca2", + "zh:49092c92e2565db4cd4c98ec6878386e6957525d3392b63f0d5df4c48a7c1913", + "zh:4f9e2e1d0c5365a4e6689096cc91ba88ca9c0dc7c633377ba674c1dd856b6a9f", + "zh:57e32bb454f2dc17d5631a9559e36188761d8ae95a452478f81f41bb568a3a42", + "zh:678b78ba629dd833f0705ac90630969f514a54013ab9713ce7ceda55fc5ea138", + "zh:8aab1d76348cf2a685f72382cb838a910b77353179e81ab5794b9c45c8fb36a3", + "zh:8b6791bf0948aa8b49258863992a8ad7e7332dcae1a889e86da0e5ab778dc3b6", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:a36f2777452c2cebdaa8a27378416d512ead367acc078a671bb12276dd4bc9dd", + "zh:c492e6f685882fad6481f4793e696d9e1b01aaae419225c2db0a484b632d1cac", + "zh:d4418e0d1d18e321db364a91d7a768e274bb0fb46df9f3cb5b9debb2bb6917b9", + "zh:d5b4310ef2b2ec22ae14cf909deb1231b56bdd79dc2b51e5db4e46a05e0110c4", + "zh:dedfb01e26b34fb61a52b7e953b8bf5d7a69971187e91697b67221298bbed377", + ] +} diff --git a/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/README.md b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/README.md new file mode 100644 index 0000000..17a0124 --- /dev/null +++ b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/README.md @@ -0,0 +1,167 @@ +# Lesson 06 Demo 7 - Create an S3 Bucket Using Terraform + +This document provides the steps to create an S3 bucket using Terraform. + +## Steps to be performed + +1. Set up Terraform components +2. Create Terraform execution plan + +## Step 1: Set up Terraform components + +1.1 Run the following commands in the given sequence to set up the Terraform component: + +``` +pip install awscli +sudo apt-get update +``` + +1.2 Create a new file to execute this project. + + + +``` + +mkdir s3back +cd s3back +``` + +## Step 2: Create a Terraform execution plan +2.1 Create creds.tf under s3back and add the following code: + + + +``` + +nano creds.tf +``` + +2.2 Paste the following code: + + +``` + + +provider "aws" { + access_key = "" + secret_key = "" + token = "" + region = "us-east-1" +} +``` + +Note: Use the AWS access credentials provided in the AWS API Access tab in your LMS in your PRACTICE LAB tab as shown in the screenshot. + +2.3 Create main.tf under s3back and run the following code: + + + +``` + +nano main.tf +``` + +2.4 Paste the following code: + + + +``` + +resource "aws_s3_bucket" "b" { + bucket = "my-tf-test-bucket" + acl = "private" + + tags = { + Name = "My bucket" + Environment = "Dev" + } +} + +``` + +Note: Bucket name (here my-tf-test-bucket) entered here should be unique globally otherwise it may throw an error while executing the script. + +2.5 Run the following commands in the given sequence to add the AWS providers: + + + +``` + +terraform init +``` + +2.6 Run the following command to commit TF state: + + + +``` + +terraform plan +``` + +2.7 Run the following command to create the S3 bucket: + + + +``` + +terraform apply +``` + +**Enter a value: Yes** + +2.8 Verify the creation of S3 bucket in the AWS Management console. + + +--- + +# Creating and Using Secret Access Keys and Access IDs in AWS IAM for Linux VMs + +## Steps + +1. **Create an IAM User:** + - Access the AWS Management Console and navigate to IAM. + - Click "Users" -> "Add user." + - Assign a meaningful username and select "Programmatic access." + - Click "Next: Permissions." + +2. **Attach Permissions:** + - Choose an existing policy or create a custom one, granting only necessary permissions. + - Click "Next: Tags." + - Optionally add tags. + - Click "Next: Review." + - Verify details and click "Create user." + +3. **Securely Store Access Key and ID:** + - Immediately download and securely store the secret access key (not retrievable later). + - Note the access key ID. + +4. **Add Credentials to Linux VM:** + - Choose a secure storage method: + + - **Environment variables (temporary):** + ```bash + export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY_ID + export AWS_SECRET_ACCESS_KEY=YOUR_SECRET_ACCESS_KEY + ``` + + - **AWS CLI configuration file:** + Create `~/.aws/credentials`: + ``` + [default] + aws_access_key_id = YOUR_ACCESS_KEY_ID + aws_secret_access_key = YOUR_SECRET_ACCESS_KEY + + + - **AWS SDK environment variables:** + Set `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` for applications using the SDK. + +## Security Best Practices + +- **Avoid hardcoding access keys:** Use AWS Secrets Manager or similar for secure storage and rotation. +- **Regularly rotate access keys:** Enhance security. +- **Use strong passwords for IAM users:** Strengthen protection. +- **Enable MFA:** Add a layer of security. +- **Implement AWS CloudTrail:** Log API activity for auditing and analysis. +- **Regularly review and update permissions:** Maintain least privilege. + diff --git a/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/creds.tf b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/creds.tf new file mode 100644 index 0000000..9b3bfe6 --- /dev/null +++ b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/creds.tf @@ -0,0 +1,6 @@ +provider "aws" { + access_key = "" + secret_key = "" + token = "" + region = "us-east-1" +} \ No newline at end of file diff --git a/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/main.tf b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/main.tf new file mode 100644 index 0000000..74a335d --- /dev/null +++ b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/main.tf @@ -0,0 +1,10 @@ + +resource "aws_s3_bucket" "bucket" { + bucket = "varun-tf-test-bucket-0acb9876" + acl = "private" + + tags = { + Name = "My bucket" + Environment = "Dev" + } +} diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/.gitignore b/6-ansible-terraform/6.8-tf-ec2-provisioning/.gitignore new file mode 100644 index 0000000..7a3e2fd --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/.gitignore @@ -0,0 +1,29 @@ +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log + +# Ignore any .tfvars files that are generated automatically for each Terraform run. Most +# .tfvars files are managed as part of configuration and so should be included in +# version control. +# +# example.tfvars + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Include override files you do wish to add to version control using negated pattern +# +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/.terraform.lock.hcl b/6-ansible-terraform/6.8-tf-ec2-provisioning/.terraform.lock.hcl new file mode 100644 index 0000000..7864285 --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/.terraform.lock.hcl @@ -0,0 +1,25 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "3.76.1" + constraints = "~> 3.27" + hashes = [ + "h1:5WSHHV9CgBvZ0rDDDxLnNHsjDfm4knb7ihJ2AIGB58A=", + "zh:1cf933104a641ffdb64d71a76806f4df35d19101b47e0eb02c9c36bd64bfdd2d", + "zh:273afaf908775ade6c9d32462938e7739ee8b00a0de2ef3cdddc5bc115bb1d4f", + "zh:2bc24ae989e38f575de034083082c69b41c54b8df69d35728853257c400ce0f4", + "zh:53ba88dbdaf9f818d35001c3d519a787f457283d9341f562dc3d0af51fd9606e", + "zh:5cdac7afea68bbd89d3bdb345d99470226482eff41f375f220fe338d2e5808da", + "zh:63127808890ac4be6cff6554985510b15ac715df698d550a3e722722dc56523c", + "zh:97a1237791f15373743189b078a0e0f2fa4dd7d7474077423376cd186312dc55", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:a4f625e97e5f25073c08080e4a619f959bc0149fc853a6b1b49ab41d58b59665", + "zh:b56cca54019237941f7614e8d2712586a6ab3092e8e9492c70f06563259171e9", + "zh:d4bc33bfd6ac78fb61e6d48a61c179907dfdbdf149b89fb97272c663989a7fcd", + "zh:e0089d73fa56d128c574601305634a774eebacf4a84babba71da10040cecf99a", + "zh:e957531f1d92a6474c9b02bd9200da91b99ba07a0ab761c8e3176400dd41721c", + "zh:eceb85818d57d8270db4df7564cf4ed51b5c650a361aaa017c42227158e1946b", + "zh:f565e5caa1b349ec404c6d03d01c68b02233f5485ed038d0aab810dd4023a880", + ] +} diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/README.md b/6-ansible-terraform/6.8-tf-ec2-provisioning/README.md new file mode 100644 index 0000000..49f69a6 --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/README.md @@ -0,0 +1,310 @@ +# Create EC2 instances with Terraform + +This branch contains Terraform code to create EC2 instances in AWS. + +## Related Blog Posts By Author: + +- [DevSecOps CI/CD Java Tomcat Project](https://varunmanik1.medium.com/devsecops-cicd-java-tomcat-project-141d6b73e436) +- [DevOps Jenkins AWS Series Part 1: How to Install Jenkins on AWS Ubuntu 22.04](https://varunmanik1.medium.com/devops-jenkins-aws-series-part-1-how-to-install-jenkins-on-aws-ubuntu-22-04-cb0c3cdb055) +- [DevOps Jenkins AWS Series Part 2: Setup AWS CloudShell, Install Terraform in Persistent](https://varunmanik1.medium.com/devops-jenkins-aws-series-part-2-setup-aws-cloudshell-install-terraform-in-persistent-425dc0537cf5) + + +## Prerequisites + +Before you start, make sure you have the following: + +- An AWS account, with ec2 full access permission +- And Linux Terminal, wher you can run all these commands + +## Files + +- `README.md`: This file, providing an overview of the branch. +- `deployer` and `deployer.pub`: SSH keys for accessing the EC2 instances. +- `history.txt`: A text file with a record of changes to this project. +- `jenkins-installation-ubuntu.sh`: A shell script to install Jenkins on the EC2 instance. +- `main.tf`: The main Terraform configuration file that creates the AWS resources. +- `slave-vm.tf`: A Terraform configuration file that creates a Jenkins slave instance. +- `tf-cli-installation.sh`: A shell script to install the Terraform CLI on the EC2 instance. +- `ubuntu-vm.tf`: A Terraform configuration file that creates an Ubuntu EC2 instance. + +## Usage + +To create EC2 instances with Terraform, follow these steps: + +1. Clone this repository to your local machine by running the command: `git clone https://github.com/manikcloud/Jenkins-cicd.git`. +2. Switch to the `0.1_create_ec2_tf` branch by running the command: `git checkout 0.1_create_ec2_tf`. +3. Navigate to the `terraform` directory by running the command: `cd terraform`. +4. Initialize Terraform by running the command: `terraform init`. +5. Create an execution plan by running the command: `terraform plan`. +6. Apply the execution plan by running the command: `terraform apply`. + +You will be prompted to enter values for the variables defined in the `variables.tf` file. + + +Create an AWS Account + +1. Go to the AWS website and click on the "Create an AWS Account" button. +2. Follow the on-screen instructions to create your account. +3. Once your account is created, log in to the AWS Management Console. + +### Create Access Keys in IAM + +1. In the AWS Management Console, navigate to the IAM service. +2. Click on "Users" in the left sidebar, and then click on the "Add User" button. +3. Enter a user name and select "Programmatic Access" as the access type. +4. Click on the "Next: Permissions" button. +5. Choose the appropriate permissions for your user, or attach an existing policy. +6. Click on the "Next: Tags" button. +7. Add any tags (optional) and click on the "Next: Review" button. +8. Review your settings and click on the "Create User" button. +9. Once the user is created, take note of the access key ID and secret access key. You will need these later to configure the AWS CLI. + +### Install AWS CLI and Configure it + +1. Install AWS CLI using the following command: +``` +sudo apt-get install awscli +``` +2. Run the command `aws configure` to configure your access key ID, secret access key, default region, and output format. + +## Install Terraform from SH Script + +``` +sudo chmod 755 chmod 755 tf-cli-installation.sh +sudo sh chmod 755 tf-cli-installation.sh + +``` +# OR + +## Install Terraform Manual +1. Set the desired Terraform version: `TERRAFORM_VERSION="1.4.5"` +2. Download Terraform: +``` +wget "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" +``` +3. Install unzip if not installed: +``` +sudo apt-get update && sudo apt-get install -y unzip +``` +4. Unzip the Terraform package: +``` +unzip "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" +``` +5. Move the Terraform binary to the /usr/local/bin folder: +``` +sudo cp terraform /usr/local/bin/ && sudo mv terraform /usr/bin/ +``` +6. Clean up the downloaded zip file: +``` +rm "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" +``` +7. Verify the installation: +``` +terraform --version +``` +That's it! With an AWS account, access keys, AWS CLI, and Terraform installed and configured, you're ready to use Terraform to create AWS resources. + + +After the Terraform code has finished executing, you can choose one of the following options to install Jenkins: + +### Option 1.1 : Install Jenkins by SH Script + +``` +chmod 755 jenkins-installation-ubuntu.sh +sudo sh jenkins-installation-ubuntu.sh +``` + +### Option 1.2 : Manually Install Jenkins + +To manually install Jenkins, follow these steps: + +1. SSH into the Ubuntu EC2 instance created by Terraform by running the command: + `ssh -i deployer ubuntu@`. + +2. Install Java by running the command: + `sudo apt-get update && sudo apt-get install default-jdk`. + +3. Add the Jenkins repository key by running the command: + +4. Add the Jenkins repository by running the command: + +``` + +sudo mkdir -p /usr/share/keyrings + +sudo curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null + +sudo echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null + +``` +5. Update the package list by running the command, + +6. Install Jenkins by running the command: + +``` +sudo apt-get update +sudo apt-get install jenkins + ``` +### Option 2: Use Terraform to Install Jenkins + +To use Terraform to install Jenkins, follow these steps: + +1. SSH into the Ubuntu EC2 instance created by Terraform by running the command: +`ssh -i deployer ubuntu@`. + +2. Run the Jenkins installation script by running the command: +`sudo sh /home/ubuntu/jenkins-installation-ubuntu.sh`. + +3. The script will install Jenkins and its dependencies. Once the installation is complete, Jenkins will be running on the EC2 instance. + +## Clean Up + +To destroy the EC2 instances and associated resources, run the command: `terraform destroy` + +Note: This will delete all resources created by Terraform in this branch. + + +## For More info on lab machine plz expend below: + +
+# Jenkins-cicd +PG DO - CI/CD Pipeline with Jenkins Simplilearn + +# AWS Ubuntu VM Provisioning steps +- Step 1: Click on Launch Instance +- Step 2 : Click on Software Image (AMI) +- Select Ubuntu +- Step 4: Key pair name – required +- Click on Create new key pair +- Put key pair name Jenkins-sl +- & Download it +- Step 5 : Click on Launch Instance +- Step 6 : Select your VM and Click connect +- Step 7 : You can see the terminal +- Step: Showing Github example + +# Git Status +``` +git --version +``` +## cretae Dir +``` +mkdir demo +cd demo +``` +## GIT & Ubuntu SSH connection +``` +ssh-keygen + +"Hit enter button 3 time" + +cat ~/.ssh/id_rsa.pub +git clone git@github.com:manikcloud/Jenkins-cicd.git +history +history | cut -c 8- +``` + +# Jenkins installation on UBUNTU 18.04 & Ubuntu 22.04 + +### Step 1 +``` +sudo apt-get update -y && sudo apt install openjdk-8-jdk -y +``` +### Step 2: Downloading Key +``` +sudo wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add +``` + +### Step 3: Adding Key +``` +sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' +``` + +### Step 4: Jenkins Package installation +``` +sudo apt-get update -y && sudo apt install jenkins -y +sudo /etc/init.d/jenkins start +sudo service jenkins status +``` +### Step 5: Jenkins default password +``` +sudo cat /home/labsuser/jenkins/secrets/initialAdminPassword +``` +### Step 6: History command + +``` +history | cut -c 8- + +``` +# Jenkins URL with port 8080 +- http://x.x.x.x:8080/ + +Replace x with your ip + +# Change Security group rule for Jenkins +``` +- Select your instance +- Down below select your security tab +- Click on the Security groups sg-0c51908b5fa4abf75 (launch-wizard-2) +- Click on the action +- Click on EDIT INBOUND RULE +- Select custom TCP and put port 8080 +- Custom ip should be 0.0.0.0/0 +- Click on Save the rule +``` + +# Common error + +``` +getting "E: Unable to locate package openjdk-8-jdk" message on java update +``` + +# Resolution +Run this command + +``` +sudo apt update -y +``` +# Plugin Installation +dashboard>manage>jenkins>manage plugins>maven integration + + + +# Jenkins Setting + +``` +Java_Home +/usr/lib/jvm/java-8-openjdk-amd64/ +``` + +# Post Build Step + +``` +java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App + +``` + +# This project is parameterized +``` +echo "User First name is : $First_Name" +echo "User Last name is : $Last_Name" +echo "User Gender is : $Sex" + +``` +
+ +# References: +1. https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html +2. https://maven.apache.org/download.cgi + +## Connect & Follow + +For more info, please connect and follow me: + +- Github: [https://github.com/manikcloud](https://github.com/manikcloud) +- LinkedIn: [https://www.linkedin.com/in/vkmanik/](https://www.linkedin.com/in/vkmanik/) +- Email: [varunmanik1@gmail.com](mailto:varunmanik1@gmail.com) +- Facebook: [https://www.facebook.com/cloudvirtualization/](https://www.facebook.com/cloudvirtualization/) +- YouTube: [https://bit.ly/32fknRN](https://bit.ly/32fknRN) +- Twitter: [https://twitter.com/varunkmanik](https://twitter.com/varunkmanik) + diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/amazon-linux-vm.tf b/6-ansible-terraform/6.8-tf-ec2-provisioning/amazon-linux-vm.tf new file mode 100644 index 0000000..7f3d4cc --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/amazon-linux-vm.tf @@ -0,0 +1,55 @@ + +resource "aws_security_group" "allow_ssh_slave" { + name = "allow_SSH_Slave_aws_linux" + description = "Allow SSH inbound traffic" + # vpc_id = aws_vpc.main.id + + + ingress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + ipv6_cidr_blocks = ["::/0"] + # description = "SSH from VPC" + # from_port = 22 + # to_port = 22 + # protocol = "tcp" + # cidr_blocks = ["0.0.0.0/0"] + # # ipv6_cidr_blocks = [aws_vpc.main.ipv6_cidr_block] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + ipv6_cidr_blocks = ["::/0"] + } +} + +resource "aws_key_pair" "deployer3" { + key_name = "deployer-key3" + public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDD8gTEP0wdqJnHkVDc7IMzFygpsibTemZylZvk4gcGiaa+YX8/VpUEyOrqYOg/8OrOAsdQCpPcc8J3AhUBSvgjeKc7sJZ0N8v+AOKnVQDni/y+9mWD6oGOszzH6DVfoHOy1HRZAbF6n+xFkk0DeisSJ3FsGVQK/J5rYgXVCBJii34mL0+DOBogxLva8tDcLgWLz+qxs8QcH4hgrHkdT8whBKfKcypICGS4U/WgXFW5M3pN4OynSzeqJ9gXn0Fbq50J/t6Cpnr6wqlzRzocAMXnlgrchYZWZJgTL3W8zrg1Fx7RBy3fAbEyWoyrkB9cFIPSkmiUZG9xUhirI4MbdgHVNlkp7xU0V6KfCRlTNE+xzWlbPSga7kjlqiizjDoR7xExKNLbNthB6nlNIEwX+FljtgrTqMV2w6k8H3xfrhdG0993EnMMwdPVmltEjJeZ+l3BETUcibKGFFc5iyR99W7NKhriH5d6OvbXev7JmbqsXrwn8rnu3auDGJs7YaIwzmk= varunmanikoutlo@ip-172-31-17-206" +} + +resource "aws_instance" "linux" { + ami = "ami-0c02fb55956c7d316" + instance_type = "t3.micro" + key_name = aws_key_pair.deployer3.key_name + count = 3 + vpc_security_group_ids = ["${aws_security_group.allow_ssh_slave.id}"] + tags = { + "Name" = "WP-Node-${count.index}" + "ENV" = "Dev" + } + + depends_on = [aws_key_pair.deployer3] + +} + +####### Amazon Linux VM OutPut##### +output "linux" { + value = aws_instance.linux.*.public_ip + description = "description" +} diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/README.md b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/README.md new file mode 100644 index 0000000..035e329 --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/README.md @@ -0,0 +1,111 @@ +# Course Content + +This repository contains various resources and scripts used for the course, focusing on Ansible and Terraform. + +## Directory Structure + + - **6.8-tf-ec2-provisioning**: Terraform scripts for provisioning EC2 instances and additional Ansible files. + - README.md + - deployer + - deployer.pub + - main.tf + - slave-vm.tf + - ubuntu-vm.tf + - ansible.cfg: Ansible configuration file. + - apache.yaml: Ansible playbook for installing Apache. + - host_vars.yml: Host variables file for Ansible configuration. + - inventory.ini: Ansible inventory file with server details. + - jenkins.yaml: Ansible playbook for installing Jenkins. + - node.yml: Ansible playbook for installing Node.js. + - **host_vars.yaml**: Host variables file for Ansible configuration. + +## Prerequisites + +Before using the resources in this repository, make sure you have the following prerequisites installed: + +- Ansible +- Terraform +- Git + +## How to Clone and Change Directory + +To clone the repository and change the directory, follow these steps: + +1. Open your terminal or command prompt. +2. Run the following command to clone the repository: + +``` +git clone https://github.com/manikcloud/DevOps-Tutorial.git +``` + +# Ansible Setup on Ubuntu + +This guide will help you set up Ansible on an Ubuntu system. + +## Prerequisites + +- An Ubuntu system +- SSH access to a remote server + +## Steps + +1. Install Ansible on the Ubuntu system: + +``` +sudo apt update +sudo apt install -y ansible +``` + +2. Create an inventory file, for example, `inventory.ini`, and add your server details: + +```ini +[my_servers] +my_server ansible_host=18.209.59.137 +``` + +3. Create an Ansible configuration file, `ansible.cfg`, and add the following content: + +```ini +[defaults] +inventory = inventory.ini +remote_user = ubuntu +private_key_file = ../deployer +host_key_checking = False +retry_files_enabled = False +``` + +4. Test the Ansible connection to the remote server with the following command: + +``` +ansible my_servers -m ping +``` + +Replace 'my_servers' with the appropriate group name + + +from your inventory file. + +# Additional Ansible Files in 6.8 Directory + +Below is a brief explanation of the additional Ansible files found in the `6.8` directory: + +- **ansible.cfg**: This is the Ansible configuration file that contains settings such as the inventory file path, remote user, private key file, host key checking, and retry file settings. +- **apache.yaml**: This Ansible playbook installs the Apache web server on the target machines. To run the playbook, use the following command: + +``` +ansible-playbook apache.yaml +``` + +- **host_vars.yml**: This file contains host-specific variables for Ansible configuration. It allows you to define variables for each host in your inventory. +- **inventory.ini**: This is the Ansible inventory file that contains the server details, such as the server's hostname and IP address. +- **jenkins.yaml**: This Ansible playbook installs Jenkins on the target machines. To run the playbook, use the following command: + +``` +ansible-playbook jenkins.yaml +``` + +- **node.yml**: This Ansible playbook installs Node.js on the target machines. To run the playbook, use the following command: + +``` +ansible-playbook node.yml +``` diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ansible.cfg b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ansible.cfg new file mode 100644 index 0000000..3f2db16 --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ansible.cfg @@ -0,0 +1,6 @@ +[defaults] +inventory = inventory.ini +remote_user = ubuntu +private_key_file = ../deployer +host_key_checking = False +retry_files_enabled = False diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/apache.yaml b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/apache.yaml new file mode 100644 index 0000000..445f6de --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/apache.yaml @@ -0,0 +1,12 @@ +--- +- hosts: my_servers + become: true + + tasks: + - name: Install apache2 + apt: name=apache2 update_cache=no state=latest + + + handlers: + - name: restart apache2 + service: name=apache2 state=restarted diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/host_vars.yaml b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/host_vars.yaml new file mode 100644 index 0000000..a2e3a6f --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/host_vars.yaml @@ -0,0 +1,4 @@ +--- +# ansible_user: ec2-user +ansible_user: ubuntu +ansible_ssh_private_key_file: ../deployer diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory copy.ini-backup b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory copy.ini-backup new file mode 100644 index 0000000..88cc143 --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory copy.ini-backup @@ -0,0 +1,15 @@ +[aws_linux_vm] +; wp-server ansible_host=54.158.174.154 +; wp-server1 ansible_host=34.230.43.235 + +[ubuntu-vm] +my_server_1 ansible_host=3.88.212.253 + + +; my_server_2 ansible_host=3.94.145.119 +; my_server_3 ansible_host=54.196.214.244 +; ubuntu = [ +; "", +; "54.166.96.63", +; "35.172.211.176", +; ] diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory.ini b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory.ini new file mode 100644 index 0000000..2f2a14f --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory.ini @@ -0,0 +1,29 @@ + +[ubuntu_vm] +my_server_1 ansible_host=54.224.173.170 +my_server_2 ansible_host=54.166.216.181 +my_server_3 ansible_host=50.16.161.255 + + +[ubuntu:children] +ubuntu_vm + +[ubuntu:vars] +ansible_user=ubuntu +ansible_ssh_private_key_file=../deployer + + + +[aws_linux_vm] +# aws_linux ansible_host=54.210.170.163 +aws_linux ansible_host=54.161.95.81 +# aws_linux ansible_host=34.207.226.250 + + + +[aws:children] +aws_linux_vm + +[aws:vars] +ansible_user=ec2-user +ansible_ssh_private_key_file=../deployer diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory.ini.org b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory.ini.org new file mode 100644 index 0000000..0489eaf --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory.ini.org @@ -0,0 +1,19 @@ +[aws:children] +aws_linux_vm + +[aws:vars] +ansible_user=ec2-user +ansible_ssh_private_key_file=../deployer + +[aws_linux_vm] +wp-server ansible_host=3.81.25.108 + +[ubuntu:children] +ubuntu_vm + +[ubuntu:vars] +ansible_user=ubuntu +ansible_ssh_private_key_file=../deployer + +[ubuntu_vm] +my_server_1 ansible_host=44.210.103.164 diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/jenkins.yaml b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/jenkins.yaml new file mode 100644 index 0000000..a3e7136 --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/jenkins.yaml @@ -0,0 +1,66 @@ +--- +- name: Install Jenkins on Ubuntu + hosts: all + become: yes + gather_facts: yes + + tasks: + - name: Update and upgrade apt packages + apt: + update_cache: yes + upgrade: yes + + - name: Install default JDK + apt: + name: default-jdk + state: present + + - name: Check Java version + command: java -version + register: java_version + changed_when: False + + - name: Create keyrings directory + file: + path: /usr/share/keyrings + state: directory + + - name: Add Jenkins key + ansible.builtin.get_url: + url: https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key + dest: /usr/share/keyrings/jenkins-keyring.asc + + - name: Add Jenkins repository + ansible.builtin.apt_repository: + repo: deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/ + state: present + + - name: Update apt cache + apt: + update_cache: yes + + - name: Install Jenkins + apt: + name: jenkins + state: present + + - name: Check Jenkins status + command: systemctl status jenkins --no-pager -l + register: jenkins_status + changed_when: False + + - name: Enable and start Jenkins service + ansible.builtin.systemd: + name: jenkins + enabled: yes + state: started + + - name: Get Jenkins initial admin password + slurp: + src: /var/lib/jenkins/secrets/initialAdminPassword + register: jenkins_initial_admin_password + changed_when: False + + - name: Display Jenkins initial admin password + debug: + msg: "Initial Jenkins admin password: {{ jenkins_initial_admin_password['content'] | b64decode }}" diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/node.yaml b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/node.yaml new file mode 100644 index 0000000..079e9bc --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/node.yaml @@ -0,0 +1,19 @@ +--- +- hosts: all + become: true + tasks: + - name: add apt key for nodesource + become: true + apt_key: + url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key + + - name: add repo for nodesource + become: true + apt_repository: + repo: 'deb https://deb.nodesource.com/node_0.10 {{ ansible_distribution_release }} main' + update_cache: no + + - name: install nodejs + become: true + apt: + name: nodejs diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_1 b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_1 new file mode 100644 index 0000000..f2c413c --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_1 @@ -0,0 +1 @@ +{"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": true, "cmd": "apt update -y", "delta": "0:00:02.166809", "end": "2024-01-20 07:28:54.068907", "msg": "", "rc": 0, "start": "2024-01-20 07:28:51.902098", "stderr": "\nWARNING: apt does not have a stable CLI interface. Use with caution in scripts.", "stderr_lines": ["", "WARNING: apt does not have a stable CLI interface. Use with caution in scripts."], "stdout": "Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy InRelease\nHit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease\nHit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease\nHit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease\nReading package lists...\nBuilding dependency tree...\nReading state information...\n168 packages can be upgraded. Run 'apt list --upgradable' to see them.", "stdout_lines": ["Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy InRelease", "Hit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease", "Hit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease", "Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease", "Reading package lists...", "Building dependency tree...", "Reading state information...", "168 packages can be upgraded. Run 'apt list --upgradable' to see them."]} \ No newline at end of file diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_2 b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_2 new file mode 100644 index 0000000..46b4678 --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_2 @@ -0,0 +1 @@ +{"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": true, "cmd": "apt update -y", "delta": "0:00:02.238591", "end": "2024-01-20 07:28:54.160319", "msg": "", "rc": 0, "start": "2024-01-20 07:28:51.921728", "stderr": "\nWARNING: apt does not have a stable CLI interface. Use with caution in scripts.", "stderr_lines": ["", "WARNING: apt does not have a stable CLI interface. Use with caution in scripts."], "stdout": "Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy InRelease\nHit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease\nHit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease\nHit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease\nReading package lists...\nBuilding dependency tree...\nReading state information...\n168 packages can be upgraded. Run 'apt list --upgradable' to see them.", "stdout_lines": ["Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy InRelease", "Hit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease", "Hit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease", "Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease", "Reading package lists...", "Building dependency tree...", "Reading state information...", "168 packages can be upgraded. Run 'apt list --upgradable' to see them."]} \ No newline at end of file diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_3 b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_3 new file mode 100644 index 0000000..fbf4eae --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_3 @@ -0,0 +1 @@ +{"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": true, "cmd": "apt update -y", "delta": "0:00:02.234414", "end": "2024-01-20 07:28:54.111227", "msg": "", "rc": 0, "start": "2024-01-20 07:28:51.876813", "stderr": "\nWARNING: apt does not have a stable CLI interface. Use with caution in scripts.", "stderr_lines": ["", "WARNING: apt does not have a stable CLI interface. Use with caution in scripts."], "stdout": "Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy InRelease\nHit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease\nHit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease\nHit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease\nReading package lists...\nBuilding dependency tree...\nReading state information...\n168 packages can be upgraded. Run 'apt list --upgradable' to see them.", "stdout_lines": ["Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy InRelease", "Hit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease", "Hit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease", "Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease", "Reading package lists...", "Building dependency tree...", "Reading state information...", "168 packages can be upgraded. Run 'apt list --upgradable' to see them."]} \ No newline at end of file diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-1.yaml b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-1.yaml new file mode 100644 index 0000000..4526380 --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-1.yaml @@ -0,0 +1,83 @@ +--- +- hosts: ubuntu_vm + become: yes + vars: + wp_db_name: wordpress1 + wp_db_user: wordpress + wp_db_password: secure-123 + db_host: 44.210.103.164 # Added db_host + table_prefix: wp_ + + tasks: + - name: Update APT package cache + apt: + update_cache: yes + + - name: Install LAMP stack + apt: + name: + - apache2 + - mysql-server + - php + - libapache2-mod-php + - php-mysql + - python3-pymysql + state: present + + - name: Start Apache and MySQL services + systemd: + name: "{{ item }}" + state: started + enabled: yes + loop: + - apache2 + - mysql + + - name: Remove MySQL root password + shell: | + mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';" + mysql -u root -e "FLUSH PRIVILEGES;" + + - name: Create a new database for WordPress + mysql_db: + name: "{{ wp_db_name }}" + state: present + login_user: root + login_password: "" + + - name: Create a new user for WordPress + mysql_user: + name: "{{ wp_db_user }}" + password: "{{ wp_db_password }}" + priv: "*.*:ALL" + host: "%" + state: present + notify: restart mysql + + - name: Download WordPress + get_url: + url: https://wordpress.org/latest.tar.gz + dest: /tmp/wordpress.tar.gz + mode: '0644' + + - name: Extract WordPress + unarchive: + src: /tmp/wordpress.tar.gz + dest: /var/www/html/ + remote_src: yes + + - name: Update WordPress config file + template: + src: ./ubuntu-wp-config.php.j2 + dest: /var/www/html/wordpress/wp-config.php + + - name: Restart Apache service + systemd: + name: apache2 + state: restarted + + handlers: + - name: restart mysql + systemd: + name: mysql + state: restarted diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-config.php.j2 b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-config.php.j2 new file mode 100644 index 0000000..bb1bbde --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-config.php.j2 @@ -0,0 +1,13 @@ + 3.27" + } + } + + required_version = ">= 0.14.9" +} + diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ubuntu-vm.tf b/6-ansible-terraform/6.8-tf-ec2-provisioning/ubuntu-vm.tf new file mode 100644 index 0000000..d070f9c --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ubuntu-vm.tf @@ -0,0 +1,50 @@ +resource "aws_security_group" "allow_SSH_ubuntu" { + name = "allow_SSH_ubuntu" + description = "Allow SSH inbound traffic" + + + ingress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + ipv6_cidr_blocks = ["::/0"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + ipv6_cidr_blocks = ["::/0"] + } +} + +resource "aws_key_pair" "deployer" { + key_name = "deployer-key" + public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDD8gTEP0wdqJnHkVDc7IMzFygpsibTemZylZvk4gcGiaa+YX8/VpUEyOrqYOg/8OrOAsdQCpPcc8J3AhUBSvgjeKc7sJZ0N8v+AOKnVQDni/y+9mWD6oGOszzH6DVfoHOy1HRZAbF6n+xFkk0DeisSJ3FsGVQK/J5rYgXVCBJii34mL0+DOBogxLva8tDcLgWLz+qxs8QcH4hgrHkdT8whBKfKcypICGS4U/WgXFW5M3pN4OynSzeqJ9gXn0Fbq50J/t6Cpnr6wqlzRzocAMXnlgrchYZWZJgTL3W8zrg1Fx7RBy3fAbEyWoyrkB9cFIPSkmiUZG9xUhirI4MbdgHVNlkp7xU0V6KfCRlTNE+xzWlbPSga7kjlqiizjDoR7xExKNLbNthB6nlNIEwX+FljtgrTqMV2w6k8H3xfrhdG0993EnMMwdPVmltEjJeZ+l3BETUcibKGFFc5iyR99W7NKhriH5d6OvbXev7JmbqsXrwn8rnu3auDGJs7YaIwzmk= varunmanikoutlo@ip-172-31-17-206" +} + +####### Ubuntu VM ##### + + +resource "aws_instance" "ubuntu" { + ami = "ami-007855ac798b5175e" + instance_type = "t3.micro" + key_name = aws_key_pair.deployer.key_name + count = 3 + vpc_security_group_ids = ["${aws_security_group.allow_SSH_ubuntu.id}"] + tags = { + "Name" = "UBUNTU-${count.index}" + "ENV" = "Dev" + } + + + depends_on = [aws_key_pair.deployer] + +} + +output "ubuntu" { + value = aws_instance.ubuntu.*.public_ip + description = "Ubuntu vm public IP" +} diff --git a/6-ansible-terraform/README.md b/6-ansible-terraform/README.md new file mode 100644 index 0000000..9b4cf6f --- /dev/null +++ b/6-ansible-terraform/README.md @@ -0,0 +1,131 @@ +# Course Content + +This repository contains various resources and scripts used for the course, focusing on Ansible and Terraform. + +## Directory Structure + +- **6-ansible** + - **6.2-node-ansible-playbook**: Ansible playbook for installing Node.js. + - node.yml + - **6.3-apache-ansible-playbook**: Ansible playbook for installing Apache. + - apache.yaml + - **6.4-ansible-module**: Documentation on how to use Ansible modules. + - README.md + - **6.5-ansible-role**: Documentation on how to create and use Ansible roles. + - README.md + - **6.6-setup-terraform**: Scripts and instructions for setting up Terraform. + - README.md + - tf-installation.sh + - **6.7-S3-Bucket-Using-Terraform**: Instructions on how to create an S3 bucket using Terraform. + - README.md + - **6.8-tf-ec2-provisioning**: Terraform scripts for provisioning EC2 instances and additional Ansible files. + - README.md + - deployer + - deployer.pub + - main.tf + - slave-vm.tf + - ubuntu-vm.tf + - ansible.cfg: Ansible configuration file. + - apache.yaml: Ansible playbook for installing Apache. + - host_vars.yml: Host variables file for Ansible configuration. + - inventory.ini: Ansible inventory file with server details. + - jenkins.yaml: Ansible playbook for installing Jenkins. + - node.yml: Ansible playbook for installing Node.js. + - **host_vars.yaml**: Host variables file for Ansible configuration. + +## Prerequisites + +Before using the resources in this repository, make sure you have the following prerequisites installed: + +- Ansible +- Terraform +- Git + +## How to Clone and Change Directory + +To clone the repository and change the directory, follow these steps: + +1. Open your terminal or command prompt. +2. Run the following command to clone the repository: + +``` +git clone https://github.com/manikcloud/DevOps-Tutorial.git +``` + +## Features + +This repository provides resources and scripts to help you learn and practice Ansible and Terraform. It includes Ansible playbooks for installing Node.js, Apache, and Jenkins, documentation on how to use Ansible modules and roles, and Terraform scripts for setting up infrastructure and provisioning EC2 instances. + +Feel free to explore the repository and use the provided resources to enhance your learning experience. + +# Ansible Setup on Ubuntu + +This guide will help you set up Ansible on an Ubuntu system. + +## Prerequisites + +- An Ubuntu system +- SSH access to a remote server + +## Steps + +1. Install Ansible on the Ubuntu system: + +``` +sudo apt update +sudo apt install -y ansible +``` + +2. Create an inventory file, for example, `inventory.ini`, and add your server details: + +```ini +[my_servers] +my_server ansible_host=18.209.59.137 +``` + +3. Create an Ansible configuration file, `ansible.cfg`, and add the following content: + +```ini +[defaults] +inventory = inventory.ini +remote_user = ubuntu +private_key_file = ../deployer +host_key_checking = False +retry_files_enabled = False +``` + +4. Test the Ansible connection to the remote server with the following command: + +``` +ansible my_servers -m ping +``` + +Replace 'my_servers' with the appropriate group name + + +from your inventory file. + +# Additional Ansible Files in 6.8 Directory + +Below is a brief explanation of the additional Ansible files found in the `6.8` directory: + +- **ansible.cfg**: This is the Ansible configuration file that contains settings such as the inventory file path, remote user, private key file, host key checking, and retry file settings. +- **apache.yaml**: This Ansible playbook installs the Apache web server on the target machines. To run the playbook, use the following command: + +``` +ansible-playbook apache.yaml +``` + +- **host_vars.yml**: This file contains host-specific variables for Ansible configuration. It allows you to define variables for each host in your inventory. +- **inventory.ini**: This is the Ansible inventory file that contains the server details, such as the server's hostname and IP address. +- **jenkins.yaml**: This Ansible playbook installs Jenkins on the target machines. To run the playbook, use the following command: + +``` +ansible-playbook jenkins.yaml +``` + +- **node.yml**: This Ansible playbook installs Node.js on the target machines. To run the playbook, use the following command: + +``` +ansible-playbook node.yml +``` diff --git a/6-ansible-terraform/wordpress/README.md b/6-ansible-terraform/wordpress/README.md new file mode 100644 index 0000000..0803bd6 --- /dev/null +++ b/6-ansible-terraform/wordpress/README.md @@ -0,0 +1,123 @@ +# DevOps-Tutorial + +## Goal +The goal of this project is to provide an example of how to use Ansible to setup a WordPress site on an AWS EC2 instance running Amazon Linux 2. + +## Features +- This Ansible playbook will install all necessary dependencies including Python, PHP, Apache, and MariaDB. +- It sets up a WordPress database and user. +- It downloads the latest version of WordPress and configures it to use the database. +- It updates the WordPress config file using an Ansible template. + +## Prerequisites +- An AWS account with the necessary permissions to create EC2 instances. +- Ansible installed on your local machine or control node. +- Basic knowledge of Ansible playbooks. + +## Usage +1. Clone this repository to your local machine or control node: `git clone https://github.com/manikcloud/DevOps-Tutorial.git` +2. Change into the project directory: `cd DevOps-Tutorial` +3. Update the `aws_linux_vm` variable in the playbook with the IP address or hostname of your EC2 instance. +4. Run the playbook: `ansible-playbook playbook.yml` + +--- + + +# Setting up WordPress on an Amazon Linux Instance + +This guide provides a simplified overview of setting up WordPress on an Amazon Linux instance. **It assumes familiarity with the command line and AWS services.** + +**## Steps:** + +1. **Launch an Amazon Linux EC2 Instance:** + - Log into your AWS account. + - Launch an Amazon Linux EC2 instance. + - Ensure security groups allow HTTP (port 80) and SSH (port 22) access. + +2. **Connect to Your Instance:** + - Use SSH to connect to your instance: + ```bash + ssh -i /path/to/your-key.pem ec2-user@your-instance-public-dns + ``` + +3. **Update Your Instance:** + - Once connected, update your instance: + ```bash + sudo yum update -y + ``` + +4. **Install Apache Web Server:** + - Install and start Apache: + ```bash + sudo yum install httpd -y + sudo systemctl start httpd.service + sudo systemctl enable httpd.service + ``` + +5. **Install MySQL (MariaDB):** + - Install the MariaDB server: + ```bash + sudo yum install mariadb-server mariadb -y + sudo systemctl start mariadb + sudo mysql_secure_installation + sudo systemctl enable mariadb.service + ``` + +6. **Create a WordPress Database and User:** + - Log into the MariaDB shell and create a database and user: + ```sql + mysql -u root -p + CREATE DATABASE wordpress; + GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password'; + FLUSH PRIVILEGES; + EXIT; + ``` + +7. **Install PHP:** + - Install PHP and necessary extensions: + ```bash + sudo yum install php php-mysql php-gd php-pear -y + sudo systemctl restart httpd.service + ``` + +8. **Download and Install WordPress:** + - Download and configure WordPress: + ```bash + wget [https://wordpress.org/latest.tar.gz](https://wordpress.org/latest.tar.gz) + tar -xzf latest.tar.gz + sudo rsync -avP ~/wordpress/ /var/www/html/ + mkdir /var/www/html/wp-content/uploads + sudo chown -R apache:apache /var/www/html/* + ``` + +9. **Configure WordPress:** + - Navigate to the `/var/www/html` directory. + - Rename and edit the WordPress configuration file: + ```bash + cd /var/www/html + mv wp-config-sample.php wp-config.php + sudo nano wp-config.php + ``` + - Update the database settings. + +10. **Complete Installation Through the Web Interface:** + - Access your server's domain or IP address in a web browser. + - Complete the WordPress installation through the web interface. + +**## Additional Considerations:** + +- **HTTPS:** Set up HTTPS for secure communication. +- **Virtual Hosts:** Configure virtual hosts to manage multiple websites. +- **Server Optimization:** Optimize server performance for WordPress. +- **WordPress Security:** Secure your WordPress installation. + + + +## Conclusion +This project provides a starting point for automating the setup of WordPress sites using Ansible and AWS. It can be extended or modified to suit your specific needs. This project is for demonstration purposes and should not be used as-is for production environments. + +## Contributing +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. + +## License +[MIT](https://choosealicense.com/licenses/mit/) diff --git a/6-ansible-terraform/wordpress/wp-config.php.j2 b/6-ansible-terraform/wordpress/wp-config.php.j2 new file mode 100644 index 0000000..9aaf05c --- /dev/null +++ b/6-ansible-terraform/wordpress/wp-config.php.j2 @@ -0,0 +1,51 @@ + + +Please **Note** that the entire repository is owned and maintained by [Varun Kumar Manik](https://www.linkedin.com/in/vkmanik/). While every effort has been made to ensure the accuracy and reliability of the information and resources provided in this repository, Varun Kumar Manik takes full responsibility for any errors or inaccuracies that may be present. + +Simplilearn is not responsible for the content or materials provided in this repository and disclaims all liability for any issues, misunderstandings, or claims that may arise from the use of the information or materials provided. By using this repository, you acknowledge that Varun Kumar Manik is solely accountable for its content, and you agree to hold Simplilearn harmless from any claims or liabilities that may arise as a result of your use or reliance on the information provided herein. + +It is important to understand that this repository contains educational materials for a training course, and users are expected to apply their own judgment and discretion when utilizing the provided resources. Neither Varun Kumar Manik nor Simplilearn can guarantee specific results or outcomes from following the materials in this repository. + + + +## Connect & Follow + +For more info, please connect and follow me: + +- Github: [https://github.com/manikcloud](https://github.com/manikcloud) +- LinkedIn: [https://www.linkedin.com/in/vkmanik/](https://www.linkedin.com/in/vkmanik/) +- Email: [varunmanik1@gmail.com](mailto:varunmanik1@gmail.com) +- Facebook: [https://www.facebook.com/cloudvirtualization/](https://www.facebook.com/cloudvirtualization/) +- YouTube: [https://bit.ly/32fknRN](https://bit.ly/32fknRN) +- Twitter: [https://twitter.com/varunkmanik](https://twitter.com/varunkmanik) diff --git a/7-docker/7.4-docker-compose/python-flask-app/Dockerfile b/7-docker/7.4-docker-compose/python-flask-app/Dockerfile new file mode 100644 index 0000000..6463319 --- /dev/null +++ b/7-docker/7.4-docker-compose/python-flask-app/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.7 + +WORKDIR /app + +COPY . /app + +RUN pip install --no-cache-dir -r requirements.txt + +CMD ["flask", "run", "--host=0.0.0.0", "--port=5000"] diff --git a/7-docker/7.4-docker-compose/python-flask-app/app.py b/7-docker/7.4-docker-compose/python-flask-app/app.py new file mode 100644 index 0000000..1465857 --- /dev/null +++ b/7-docker/7.4-docker-compose/python-flask-app/app.py @@ -0,0 +1,13 @@ +from flask import Flask +from redis import Redis + +app = Flask(__name__) +redis = Redis(host='redis', port=6379) + +@app.route('/') +def hello(): + count = redis.incr('hits') + return 'Hello World! I have been seen {} times.\n'.format(count) + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=8000, debug=True) diff --git a/7-docker/7.4-docker-compose/python-flask-app/requirements.txt b/7-docker/7.4-docker-compose/python-flask-app/requirements.txt new file mode 100644 index 0000000..1a5dc97 --- /dev/null +++ b/7-docker/7.4-docker-compose/python-flask-app/requirements.txt @@ -0,0 +1,2 @@ +flask +redis diff --git a/7-docker/7.4-docker-compose/wordpress/docker-compose-wp.yml b/7-docker/7.4-docker-compose/wordpress/docker-compose-wp.yml new file mode 100644 index 0000000..99b8a12 --- /dev/null +++ b/7-docker/7.4-docker-compose/wordpress/docker-compose-wp.yml @@ -0,0 +1,36 @@ +version: '3' + +services: + db: + image: mariadb + volumes: + - db_data:/var/lib/mysql + environment: + MYSQL_ROOT_PASSWORD: wordpress + MYSQL_DATABASE: wordpress + MYSQL_USER: wordpress + MYSQL_PASSWORD: wordpress + + wordpress: + depends_on: + - db + image: wordpress:latest + ports: + - "8000:80" + environment: + WORDPRESS_DB_HOST: db:3306 + WORDPRESS_DB_USER: wordpress + WORDPRESS_DB_PASSWORD: wordpress + WORDPRESS_DB_NAME: wordpress + volumes: + - wordpress_data:/var/www/html + + redis: + image: redis:latest + volumes: + - redis_data:/data + +volumes: + db_data: {} + wordpress_data: {} + redis_data: {} diff --git a/7-docker/Dockerfile b/7-docker/Dockerfile new file mode 100644 index 0000000..b4723a1 --- /dev/null +++ b/7-docker/Dockerfile @@ -0,0 +1,15 @@ +# Use Ubuntu as a base image +FROM ubuntu:22.04 + +# Update and install nginx +RUN apt-get update + +RUN apt-get install -y nginx + +# Copy the custom index file to the nginx directory +COPY index.html /var/www/html + +EXPOSE 80 + +# Start nginx in the foreground to keep the container running +CMD ["nginx", "-g", "daemon off;"] diff --git a/7-docker/Final-project-docker/5.11-docker-compose/Dockerfile b/7-docker/Final-project-docker/5.11-docker-compose/Dockerfile new file mode 100644 index 0000000..9ec6968 --- /dev/null +++ b/7-docker/Final-project-docker/5.11-docker-compose/Dockerfile @@ -0,0 +1,5 @@ +FROM python:3.4-alpine +ADD . /code +WORKDIR /code +RUN pip install -r requirements.txt +CMD ["python", "app.py"] diff --git a/7-docker/Final-project-docker/5.11-docker-compose/README.md b/7-docker/Final-project-docker/5.11-docker-compose/README.md new file mode 100644 index 0000000..ae09000 --- /dev/null +++ b/7-docker/Final-project-docker/5.11-docker-compose/README.md @@ -0,0 +1,348 @@ +# Lesson 5 Demo 11: Convert an Application Deployment into a Stack + +This section will guide you to: +- Convert an application deployment into a stack using a file named docker-compose.yml + +| Feature | Docker Service | Docker Stack | +|---------|----------------|--------------| +| Definition | A Docker Service is the definition of the tasks to execute on the manager or worker nodes. It is a part of Docker Swarm, Docker's built-in orchestration solution. | A Docker Stack is a group of interrelated services that share dependencies, and can be orchestrated and scaled together. A stack effectively encapsulates a multi-service application. | +| Use Case | Docker Services are ideal for deploying the same image across multiple environments. You can adjust the number of replicas for each service based on the environment's requirements. | Docker Stacks are perfect for defining and managing multi-service applications. Stacks allow you to manage all the services of an application with just one file. | +| Scale | Services can be scaled up or down individually. | All services within a stack are scaled together, maintaining the application's functionality. | +| Command | `docker service create` | `docker stack deploy` | + +### Step 1: Drain the worker nodes in the swarm cluster to make sure the registry service runs on the manager node +- List all the nodes present in the swarm cluster and ensure that all nodes are in Active state + +``` +sudo docker node ls + +``` + + +**Note**: Copy the HOSTNAME of worker nodes +- Use the following command to drain the worker nodes: + +``` +sudo docker node update --availability drain hostname_Worker_Node + +``` + + +**Note**: Replace hostname_Worker_Node with the HOSTNAME copied in previous ### Step + + +### Step 2: Start the registry as a service on your swarm + +``` +sudo docker service create --name registry --publish published=5000,target=5000 registry:2 + + +``` + + +### Step 3: List the running services to check the status of registry service + +``` +sudo docker service ls + +``` + + + +### Step 4: Check if registry service is working with curl + +``` + +curl http://localhost:5000/v2/ + +``` + + + +### Step 5: Create a directory for the project + +``` + +mkdir stackdemo +cd stackdemo + +``` + + + +### Step 6: Create a file called app.py in the stackdemo directory +- Use the following command to create a project file: + +``` + +nano app.py + +``` + + +- Add the following code in the app.py file: + +``` + +from flask import Flask +from redis import Redis + +app = Flask(__name__) +redis = Redis(host='redis', port=6379) + +@app.route('/') +def hello(): + count = redis.incr('hits') + return 'Hello World! I have been seen {} times.\n'.format(count) + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=8000, debug=True) + +``` + + +**Note**: Press Ctrl+X to exit the editor. Then type Y and press Enter to save the file. + +### Step 7: Create a file called requirements.txt +- Use the following command to create and open requirements.txt: + +``` + +nano requirements.txt + +``` + + +- Add the following text in the requirements.txt file: + +``` + +flask +redis + +``` + + +**Note**: Press Ctrl+X to exit the editor. Then type Y and press Enter to save the file. + +### Step 8: Create a file called Dockerfile +- Use the following command to create a Dockerfile: + +``` + +nano Dockerfile + +``` + + +- Add the following code in the Dockerfile: + +``` + +FROM python:3.4-alpine +ADD . /code +WORKDIR /code +RUN pip install -r requirements.txt +CMD ["python", "app.py"] + +``` + + +**Note**: Press Ctrl+X to exit the editor. Then type Y and press Enter to save the file. + +### Step 9: Create a file named docker-compose.yml +- Use the following command to create the docker-compose.yml file: + +``` + +nano docker-compose.yml + +``` + + +- Add the following code in the docker-compose.yml file: + +``` + +version: "3.3" +services: + web: + image: 127.0.0.1:5000/stackdemo + build: . + ports: + - "8000:8000" + redis: + image: redis:alpine + +``` + + +**Note**: Press Ctrl+X to exit the editor. Then type Y and press Enter to save the file. + +### Step 10: Start the application +- Use the following commands to install docker-compose: + +``` +sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + + +sudo chmod +x /usr/local/bin/docker-compose + docker-compose --version + +``` + + + + +- Start docker-compose using the following command: + +``` +sudo docker-compose up -d + +``` + + + + +### Step 11: Use the following commands to check whether the app is running + +``` +sudo docker-compose ps + +curl http://localhost:8000 + +``` + + + +### Step 12: Bring the application down + +``` +sudo docker-compose down --volumes + + +``` + + +### Step 13: Push the application to the registry + +``` +sudo docker-compose push + +``` + + + +### Step 14: Use the following command to create the stack docker stack deploy: + +``` +sudo docker stack deploy --compose-file docker-compose.yml stackdemo + +``` + + + +### Step 15: Check if the stack is running + +``` +sudo docker stack services stackdemo + +``` + + + +### Step 16: Test the app again with curl command + +``` + +curl http://localhost:8000 +curl http://ip-172-31-26-147:8000 + +``` + +**Note**: In ### Step 10 while starting docker-compose if you get an error showing the port is already assigned, run the command + +``` +sudo docker ps and kill the container with the same port and then proceed. + +``` + + + +### Step 17: Use the following command to bring the stack down: + +``` +sudo docker stack rm stackdemo + +``` + +----------------------------------------------------------------- + +# Lesson 5 Demo 12: Increase Number of Replicas + +This section will guide you to: +- Increase the number of replicas of a task for any given service + +### Step 1: List the Docker services + +``` +sudo docker service ls +``` + +### Step 2: Scale up the redis service to five tasks + +``` +sudo docker service scale redis=5 + ``` + +### Step 3: Scale the registry service to four tasks using update flag + +``` +sudo docker service update --replicas=4 registry + ``` + +### Step 4: Use the scale flag to scale both redis and registry services at the same time + +``` +sudo docker service scale redis=4 registry=3 + ``` + +### Step 5: Check the actual number of replicas created + +``` +sudo docker service ls + ``` + +### Step 6: Create a global service and scale it up to ten tasks + +``` +sudo docker service create --mode global --name nginx nginx:latest + + +sudo docker service scale nginx=10 +``` + +**Note**: Notice that the scaling cannot be used with global services. It can only be done with replicated service. + + +# Disclaimer +
+ +Please **Note** that the entire repository is owned and maintained by [Varun Kumar Manik](https://www.linkedin.com/in/vkmanik/). While every effort has been made to ensure the accuracy and reliability of the information and resources provided in this repository, Varun Kumar Manik takes full responsibility for any errors or inaccuracies that may be present. + +Simplilearn is not responsible for the content or materials provided in this repository and disclaims all liability for any issues, misunderstandings, or claims that may arise from the use of the information or materials provided. By using this repository, you acknowledge that Varun Kumar Manik is solely accountable for its content, and you agree to hold Simplilearn harmless from any claims or liabilities that may arise as a result of your use or reliance on the information provided herein. + +It is important to understand that this repository contains educational materials for a training course, and users are expected to apply their own judgment and discretion when utilizing the provided resources. Neither Varun Kumar Manik nor Simplilearn can guarantee specific results or outcomes from following the materials in this repository. + +
+ +## Connect & Follow + +For more info, please connect and follow me: + +- Github: [https://github.com/manikcloud](https://github.com/manikcloud) +- LinkedIn: [https://www.linkedin.com/in/vkmanik/](https://www.linkedin.com/in/vkmanik/) +- Email: [varunmanik1@gmail.com](mailto:varunmanik1@gmail.com) +- Facebook: [https://www.facebook.com/cloudvirtualization/](https://www.facebook.com/cloudvirtualization/) +- YouTube: [https://bit.ly/32fknRN](https://bit.ly/32fknRN) +- Twitter: [https://twitter.com/varunkmanik](https://twitter.com/varunkmanik) diff --git a/7-docker/Final-project-docker/5.11-docker-compose/app.py b/7-docker/Final-project-docker/5.11-docker-compose/app.py new file mode 100644 index 0000000..c3bfb04 --- /dev/null +++ b/7-docker/Final-project-docker/5.11-docker-compose/app.py @@ -0,0 +1,13 @@ +from flask import Flask +from redis import Redis + +app = Flask(__name__) +redis = Redis(host='redis', port=6379) + +@app.route('/') +def hello(): + count = redis.incr('hits') + return 'Hello World! I have been seen {} times.\n'.format(count) + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=8000, debug=True) diff --git a/7-docker/Final-project-docker/5.11-docker-compose/requirements.txt b/7-docker/Final-project-docker/5.11-docker-compose/requirements.txt new file mode 100644 index 0000000..02c585a --- /dev/null +++ b/7-docker/Final-project-docker/5.11-docker-compose/requirements.txt @@ -0,0 +1,2 @@ +flask +redis diff --git a/7-docker/README.md b/7-docker/README.md new file mode 100644 index 0000000..13d7062 --- /dev/null +++ b/7-docker/README.md @@ -0,0 +1,597 @@ +# Docker +- [# Docekr basic commands & their flags](#Docekr-basic-commands-their-flags) +- [Lesson 7 Demo 2: Performing CRUD Operation on Containers](#lesson-7-demo-2) + - [Step 1: Pulling a Docker image](#step-1-pulling-a-docker-image) + - [Step 2: Creating a new container](#step-2-creating-a-new-container) + - [Step 3: Stopping the container](#step-3-stopping-the-container) + - [Step 4: Listing all the containers](#step-4-listing-all-the-containers) + - [Step 5: Deleting the container](#step-5-deleting-the-container) + - [Step 6: Removing the image](#step-6-removing-the-image) +- [Lesson 7 Demo 3: Creating a Docker Image](#lesson-7-demo-3) + - [Step 1: Creating the Dockerfile](#step-1-creating-the-dockerfile) + - [Step 2: Executing the Dockerfile](#step-2-executing-the-dockerfile) +- [Lesson 7 Demo 4: Docker Compose Setup](#lesson-7-demo-4) + - [Step 1: Setting up docker-compose](#step-1-setting-up-docker-compose) + - [Step 2: Creating a docker-compose file](#step-2-creating-a-docker-compose-file) +- [Lesson 7 Demo 5: Docker Registry](#lesson-7-demo-5) + - [Step 1: Pulling a Linux container](#step-1-pulling-a-linux-container) + - [Step 2: Pushing the image to the local repository](#step-2-pushing-the-image-to-the-local-repository) + - [Step 3: Running the new image](#step-3-running-the-new-image) +- [Lesson 7 Demo 6: Docker Networking with SSHs](#lesson-7-demo-6) + - [Step 1: Creating a container, and committing it](#step-1-creating-a-container-and-committing-it) + - [Step 2: Creating a bridge network, and finding its IP address](#step-2-creating-a-bridge-network-and-finding-its-ip-address) + - [Step 3: Connecting the network from another SSH server](#step-3-connecting-the-network-from-another-ssh-server) + + + +# Docekr basic commands their flags + +| Command | Description | Flags/Options | +|---------|-------------|---------------| +| `docker run` | Run a new container | `-d` (detached), `-p` (port mapping), `--name` (name of the container), `-e` (environment variables) | +| `docker ps` | List running containers | `-a` (all containers), `--format` (format output) | +| `docker stop` | Stop a running container | `` (ID or name of the container) | +| `docker rm` | Remove a container | `-f` (force), `` | +| `docker images` | List Docker images | `-a` (all images), `--format` (format output) | +| `docker rmi` | Remove a Docker image | `` (ID or name of the image), `-f` (force) | +| `docker build` | Build an image from a Dockerfile | `-t` (tag/name of the image), `` | +| `docker pull` | Pull an image from a registry | `` (name of the image) | +| `docker push` | Push an image to a registry | `` (name of the image) | +| `docker exec` | Execute a command in a running container | `-it` (interactive terminal), `` (ID or name of the container), `` (command to execute) | +| `docker logs` | Fetch the logs of a container | `` (ID or name of the container), `--tail` (number of lines to show) | +| `docker network` | Manage Docker networks | `create`, `inspect`, `ls`, `rm` (subcommands for network management) | +| `docker volume` | Manage Docker volumes | `create`, `inspect`, `ls`, `rm` (subcommands for volume management) | + + +# Lesson 7 Demo 2 +Performing CRUD Operation on Containers + +### Steps to be followed: +1. Pulling a Docker image +2. Creating a new container +3. Stopping the container +4. Listing all the containers +5. Deleting the container +6. Removing the image + +### Step 1: Pulling a Docker image +1.1 Open the terminal and pull an image using the command: + +``` +sudo docker pull nginx + + +``` + + +1.2 List all the docker images to check the newly pulled nginx image: + +``` +sudo docker images + +``` + + +### Step 2: Creating a new container + 2.1 Create a new container from the nginx image: + +``` +sudo docker run -dt -p 81:81 nginx + +``` + + +2.2 List all the running containers to check the newly created container. You can find various details like port of container, it’s time of creation and ID. + +``` +sudo docker ps + +``` + +### Step 3: Stopping the container +3.1 Use the following command to stop the running container. (You can also us the container ID to stop the container: +``` +sudo docker stop CONTAINER_ID) + + +sudo docker stop CONTAINER_NAME + +``` + + +3.2 Use the following command to list all the running containers and verify if the container has stopped running: + +``` +sudo docker ps + +``` + +3.3 You can start the container again and check the running containers. (You can also us the container ID to start the container: + +``` +sudo docker start CONTAINER_ID) + + +sudo docker start CONTAINER_NAME + +sudo docker ps + +``` + + + +3.4 To start the container in interactive mode, use the –i and –t options. + +``` +sudo docker run -it --name=Test_1 ubuntu + +``` + +### Step 4: Listing all the containers +4.1 Use the below command to list all the containers started and the once which are stopped: + +``` +sudo docker ps -a + +``` + + +4.2 To list the containers by their ID, use the below command + +``` +sudo docker ps -aq + +``` + + +You can see the containers with ID are listed. + +4.3 To list the total file size of each container, use the below command: + + +``` +sudo docker ps -s + +``` + + +4.4 To list the latest created containers, use the following command: + + +``` +sudo docker ps -l + + +``` + +### Step 5: Deleting the container +5.1 Stop the running container and remove it using the following commands: + + +``` +sudo docker stop CONTAINER_NAME +sudo docker container rm CONTAINER_NAME + + +``` + + + + +### Step 6: Removing the image +6.1 Remove the image using the command: + +``` +sudo docker image rm nginx + +``` + + + +---------------------------- + + + +# Lesson 7 Demo 3 +Creating a Docker Image + + +### Steps to be followed: +1. Creating the Dockerfile +2. Executing the Dockerfile + +### Step 1: Creating the Dockerfile + 1.1 Create a directory + + +``` +mkdir demo +cd demo + +``` + +1.2 Create the Dockerfile + +``` +vi Dockerfile + +``` + + +1.3 Add the following code snippet to the Dockerfile + +``` +# Use Ubuntu as a base image +FROM ubuntu + +# Update and install nginx +RUN apt-get update && apt-get install -y nginx + +# Copy the custom index file to the nginx directory +COPY index.html /var/www/html + +# Start nginx in the foreground to keep the container running +CMD ["nginx", "-g", "daemon off;"] + + +``` + + + +1.4 Create another file in the same directory + +``` +vi index.html + +``` + +1.5 Add the following welcome message to the index file + +``` +WELCOME TO NGINX. + +``` + + + +### Step 2: Executing the file + +- 2.1 Execute the Dockerfile (note that there is space between build and “.”) + +``` +sudo docker build . + +``` + + +2.2 Navigate to the root folder, and list the images to check the newly created Docker image + + +``` +cd +sudo docker images + +``` + + + +------------------------------ + + +# Lesson 7 Demo 4 + +``` +Docker Compose Setup + + +``` + + +### Steps to be followed: +1. Setting up docker-compose +2. Creating a docker-compose file + +### Step 1: Setting up docker-compose +1.1 Install docker-compose using the command given below: + +``` +mkdir compose-test +cd compose-test +pip --version + + +``` + + +1.2 Then type the command given below, to install docker-compose + +``` +sudo pip install docker-compose + +``` + + + +### Step 2: Creating docker-compose file +2.1 Inside compose-test folder, create docker-compose.yml file, and add the following code in it: + +``` +vi docker-compose.yml + +``` + +2.2 Add the following code snippet in the file: +``` +version: '3' +services: + compose-test: + image: centos + command: /bin/bash -c "while true; do sleep 30; done" + depends_on: + - compose-db + compose-db: + image: redis + ports: + - "6379:6379" + +``` + +- In this updated version, I've added version: '3' at the top. This is the version of the Docker Compose file format, and it's generally a good idea to specify it. + +- I also replaced links with depends_on, which makes sure the compose-db service is started before the compose-test service. + +- I've replaced the command for the compose-test service to keep the container running indefinitely. Your previous command would execute curl once and then the container would exit. If you need to run curl, you can do it manually by exec-ing into the running container. + +- Finally, expose only exposes the port to linked services; it doesn't map the port to the host. If you want to access the Redis service from outside of the Docker network (from your host machine, for example), you should use ports instead. If not, you can stick with expose. + + + +2.3 Run the following command to execute the yaml file: + +``` +sudo docker-compose up + + +``` + + + + +------------------------------ +# Lesson 7 Demo 5 + +## Docker Registry + + +### Steps to be followed: +1. Pulling a Linux container +2. Pushing the image to the local repository +3. Running the new image + +### Step 1: Pulling a Linux container +1.1 Pull a recent version of the Centos Linux container. + +``` +sudo docker pull registry:2 + +``` + +1.2 Run the registry in a new Docker container with port 5000 exposed + +``` +sudo docker run -d -p 5000:5000 \ +--restart=always --name registry registry:2 + +``` + + +1.3 Pull another image from Docker Hub and store it in the local registry + +``` +sudo docker pull ubuntu + + +``` +1.4 Tag the image for the local registry + +``` +sudo docker tag ubuntu localhost:5000/ubuntu + +``` + + +### Step 2: Pushing the image to the local registry +2.1 Use the following command to push the image to a local registry: + +``` +sudo docker push localhost:5000/ubuntu + +``` +2.2 Remove the image from the local cache + +``` +sudo docker rmi ubuntu + +``` +2.3 Confirm that it has been removed + +``` +sudo docker images + +``` + + +### Step 3: Running the new image +3.1 Pull the image from the local registry + +``` +sudo docker pull localhost:5000/ubuntu + +``` +3.2 Confirm it is in the local cache + +``` +sudo docker images + +``` +3.3 Run the new image + +``` +sudo docker run -it --rm localhost:5000/ubuntu /bin/bash + +``` +3.4 Exit the container + +``` + +exit + +``` + +3.5 Clean up the images and containers + +``` +sudo docker rm -f $(docker ps -aq) + +``` + +**Note:** In case you get a permission denied error as shown below, run the following + +``` +sudo chmod 666 /var/run/docker.sock + +``` +After running this, run the +``` +sudo docker rm -f $(docker ps -aq) command. + + +sudo docker rmi $(docker images -q) + +``` + + + +------------------------------- +# Lesson 7 Demo 6 +## Docker Networking with SSHs + + +### Steps to be followed: +1. Creating a container and committing it +2. Creating a bridge network and finding its IP address +3. Connecting the network from another SSH server + +### Step 1: Creating a container, and commit it +1.1 Create a Centos Docker container. and install net-tools + +``` +sudo docker run -it --name centos centos /bin/bash +yum install -y net-tools + +``` + + +1.2 Check the IP address and hostname + + +``` +ifconfig +cat /etc/hosts +hostname + + +``` +1.3 Exit the container using CTRL+D + 1.3.1 Commit the container to an image (Please refer to the screenshot) + +``` + docker commit centos centos-net + docker images + docker rm centos + +``` + +### Step 2: Creating a bridge network, and find its IP address +2.1 Create a bridge network, and find its IP range + +``` +docker network create exnet +docker network ls +docker network inspect exnet + +``` + + + +2.2 Run the centos container using the new network + +``` +docker run -it --rm --network exnet centos-net /bin/bash + +``` + +2.3 Check the IP address and hostname + +``` +ifconfig +cat /etc/hosts +hostname + +``` + + +2.4 Exit the container using CTRL+D + 2.4.1 Start a new container using the default network + +``` + docker run -it --rm --name centos centos-net /bin/bash + +``` +2.5 Check the IP address and hostname + +``` +ifconfig +cat /etc/hosts +hostname + +``` + +### Step 3: Connecting the network from another SSH server +3.1 Click on + to open another Terminal window. Type the below given command to from the second SSH terminal to connect the network to the container + +``` +docker network connect exnet centos + +``` + + +3.2 Go back to the running container. You will see that it now has two IP addresses (Please refer to the screenshot) + +``` +ifconfig +cat /etc/hosts +hostname + + +``` + +3.3 Go to the second SSH window, and disconnect the network + +``` +docker network disconnect exnet centos + +``` + +3.4 Go back to the running container, and see that it now has one IP address + +``` +ifconfig +cat /etc/hosts +hostname + +``` + +3.5 Exit the container using CTRL+D + +______________ \ No newline at end of file diff --git a/7-docker/index.html b/7-docker/index.html new file mode 100644 index 0000000..e0cf6b2 --- /dev/null +++ b/7-docker/index.html @@ -0,0 +1,10 @@ + + + + +

My First Heading

+

Lorem ipsum...

+

This is DevOps class.

+ + + diff --git a/8-k8s/FAQ/Readme.md b/8-k8s/FAQ/Readme.md new file mode 100644 index 0000000..1df76d4 --- /dev/null +++ b/8-k8s/FAQ/Readme.md @@ -0,0 +1,181 @@ + + +# PodDisruptionBudget (PDB) in Kubernetes + +A `PodDisruptionBudget` (PDB) in Kubernetes is a policy that sets limits on the number of Pods of a replicated application that can be simultaneously down among a set of Pods. It helps ensure that a specified minimum number of Pods are always available during voluntary disruptions, such as when performing cluster maintenance (e.g., node upgrades, resizes). + +## Key Concepts + +- **MinAvailable**: Specifies the minimum number of Pods that should remain available during the disruption. +- **MaxUnavailable**: Defines the maximum number of Pods that can be unavailable during the disruption. + +## Usage + +PDBs are particularly useful in production environments to maintain application availability during operations that require Pod eviction, like node maintenance. + +## Example + +A simple PDB might look like this: + +```yaml +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: myapp-pdb +spec: + minAvailable: 2 + selector: + matchLabels: + app: myapp +``` + +--- + +# Finding Configuration Files in Kubernetes + +Kubernetes configuration files are YAML or JSON files that define how resources should be created and managed within the Kubernetes cluster. These files can specify configurations for pods, services, volumes, and more. Here's how you can find and manage these configuration files. + +## Locations of Configuration Files + +### System-Wide Configuration + +- **Kubernetes Master Node**: + - `/etc/kubernetes/manifests`: Contains static pod manifests for the Kubernetes control plane components (apiserver, controller-manager, scheduler, etc.). + - `/etc/kubernetes/admin.conf`, `/etc/kubernetes/kubelet.conf`, and `/etc/kubernetes/controller-manager.conf`: Configuration files for accessing the Kubernetes API. + +- **Kubelet**: + - `/var/lib/kubelet/config.yaml`: The primary configuration file for the kubelet. + +- **Kubeadm**: + - `/etc/kubernetes/kubeadm-config.yaml`: The configuration file used by `kubeadm init` and `kubeadm join`. + +### User-Defined Resource Configurations + +- **Application Specific**: Typically, the configuration files for your applications (pods, deployments, services, etc.) are not stored on the cluster nodes. Instead, they are managed by users and stored wherever is convenient for version control, such as in a Git repository. + +--- + +# Kubernetes Storage and Stateful Workloads Explained + +Understanding Persistent Volumes (PV), Persistent Volume Claims (PVC), and StatefulSets is crucial for managing stateful applications in Kubernetes. Here's a surface-level overview of these concepts without diving into specific commands. + +## Persistent Volumes (PV) + +**Persistent Volumes** are a way for users to manage durable storage in Kubernetes. PVs are resources in the cluster that provision storage, such as disks, that persist beyond the lifecycle of individual pods. Administrators typically create PVs to represent available storage in the cluster. + +### Key Points: + +- **Cluster Resource**: PVs are a cluster-level resource, meaning they are not tied to a specific namespace. +- **Storage Abstraction**: Provides an abstraction over underlying storage systems, supporting various storage backends like NFS, iSCSI, cloud storage services, and more. +- **Lifecycle Independent**: PVs exist independently of pods, ensuring data persists even when pods are deleted or moved. + +## Persistent Volume Claims (PVC) + +**Persistent Volume Claims** are requests for storage by users. PVCs specify size, access modes (e.g., read/write), and sometimes specific storage class requirements. Kubernetes matches a PVC to an available PV and binds them together. + +### Key Points: + +- **User Request**: PVCs allow users to request specific sizes and types of storage. +- **Dynamic Provisioning**: If no suitable PV exists, a new one can be dynamically provisioned according to the requested storage class. +- **Binding**: A PVC is bound to a single PV, creating a one-to-one relationship that reserves the PV for the PVC's use. + +## StatefulSets + +**StatefulSets** are used to manage stateful applications, providing stable, unique network identifiers, stable persistent storage, and ordered, graceful deployment and scaling. + +### Key Points: + +- **Stable Identity**: Each pod in a StatefulSet has a unique ordinal index and stable network identity. +- **Ordered Operations**: Pods are created, scaled, and deleted in a predictable order, important for stateful applications like databases that require careful management of replicas. +- **Persistent Storage**: StatefulSets can use PVCs to provide each pod with its persistent storage, ensuring data persists across pod rescheduling and restarts. + +### Conclusion + +While PVs and PVCs provide the mechanisms for handling persistent storage in Kubernetes, StatefulSets allow for the management of stateful applications, leveraging PVs and PVCs to ensure data persistence. Together, these components enable the deployment and management of complex, stateful applications within a Kubernetes cluster. + +## Script Explanation + +This guide explains the components of the script that creates Kubernetes resources, including Persistent Volumes (PVs), Persistent Volume Claims (PVCs), and a StatefulSet. + +## Components + +### Persistent Volume (PV) + +- **What it Does**: Creates a PV named `example-pv` with a capacity of 1Gi and a storage class of `standard`. +- **Storage Method**: Utilizes `hostPath` for storage, which mounts a directory from the host. This approach is primarily for testing purposes on a single-node cluster. + +### Persistent Volume Claim (PVC) + +- **What it Does**: Generates a PVC named `example-pvc` that requests 1Gi of storage with the same storage class, `standard`. +- **Binding**: This PVC is designed to bind to the previously created PV, `example-pv`. + +### StatefulSet + +- **What it Does**: Constructs a StatefulSet named `example-statefulset` with 2 replicas. +- **Configuration**: Each pod within the StatefulSet mounts the PVC created by the `volumeClaimTemplates`. +- **Use Case**: Provides a simple example that employs an Nginx container to deliver content stored on the persistent volume. + +## How to Run + +1. **Save the Script**: Store the script in a file, for instance, `create-pv-pvc-statefulset.sh`. +2. **Make Executable**: + + ``` + + chmod +x create-pv-pvc-statefulset.sh + create-pv-pvc-statefulset.sh + + ``` +--- + +# Using Vault in Jenkins + +HashiCorp Vault is a tool for secrets management, allowing you to securely store and access sensitive data like passwords, tokens, and keys. Integrating Vault with Jenkins can significantly enhance the security of your CI/CD pipelines by providing a secure way to handle credentials and other sensitive information. + +## Benefits of Integrating Vault with Jenkins + +- **Security**: Keeps sensitive data out of your build logs and source code. +- **Centralization**: Manages all your secrets in one place, making them easier to rotate, revoke, and keep track of. +- **Auditing**: Vault offers detailed audit logs, allowing you to track access to secrets, which is invaluable for compliance and security. + +## How to Use Vault with Jenkins + +### Step 1: Install Vault Plugin in Jenkins + +First, you need to install the [HashiCorp Vault Plugin](https://plugins.jenkins.io/hashicorp-vault-plugin/) for Jenkins. This can be done through the "Manage Jenkins" > "Manage Plugins" menu in the Jenkins UI. + +### Step 2: Configure Vault in Jenkins + +After installing the plugin, configure Jenkins to communicate with your Vault server: + +1. Go to "Manage Jenkins" > "Configure System". +2. Find the Vault section and add a new Vault configuration. +3. Enter your Vault Server URL and the Vault Credential. + +### Step 3: Set Up Vault Credentials + +Vault credentials in Jenkins can be set up as follows: + +1. Navigate to "Credentials" in Jenkins. +2. Choose the appropriate scope and click "Add Credentials". +3. Select "Vault Token" or the appropriate credential type. +4. Enter your Vault Token and other details as necessary. + +### Step 4: Accessing Secrets in Jenkins Jobs + +To access Vault secrets in your Jenkins jobs: + +1. In your job configuration, add a "Build Environment" step. +2. Select "Vault Secrets" and configure the Vault Key/Values you wish to inject into the build environment. +3. Use the injected environment variables in your build steps. + +## Best Practices + +- **Least Privilege**: Grant Jenkins access only to the secrets it needs, nothing more. +- **Audit**: Regularly review access logs and rotate secrets. +- **Secure Communication**: Ensure communication between Jenkins and Vault is over HTTPS to prevent eavesdropping. + +## Conclusion + +Integrating Vault with Jenkins allows you to manage and inject secrets into your CI/CD pipelines securely. By centralizing secret management, you not only improve the security posture of your development environment but also make managing and rotating secrets much more manageable. + diff --git a/8-k8s/FAQ/vol-k8s.ymal b/8-k8s/FAQ/vol-k8s.ymal new file mode 100644 index 0000000..e60747d --- /dev/null +++ b/8-k8s/FAQ/vol-k8s.ymal @@ -0,0 +1,73 @@ +#!/bin/bash + +# Create a Persistent Volume +cat < /etc/apt/sources.list.d/kubernetes.list + +``` + + +1.2 Update the apt-get package by executing the command mentioned below: + + +``` + +sudo apt-get update + + +``` + +1.3 Install the kubernetes and the tools required to manage it. Run the command mentioned below in the terminal: + + +``` + +sudo apt install docker.io kubectl=1.20.5-00 kubeadm=1.20.5-00 kubelet=1.20.5-00 + +``` + + +### Step 2: Setting up a Kubernetes cluster +2.1 Update the apt-get package by executing the command mentioned below: + +``` + +sudo apt-get update + +``` + + +2.2 To initialize the cluster run the following command on the master node + +``` + +sudo kubeadm init + +``` + + +2.3 To start using your cluster, you need to run the following on master node: + +``` + +mkdir -p $HOME/.kube + sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config + sudo chown $(id -u):$(id -g) $HOME/.kube/config + +``` + + +2.4 You should see a single master node deployed on running the command: + +``` + +sudo kubectl get nodes + + +``` + + +2.5 Copy the kubeadm join command that you can see on the screen of your master node + + + + + +2.6 Run the copied kubeadm join command as a root user on the worker node. You can use the terminal only lab as a worker node. Make sure you have Kubernetes installed on the worker node and then run the below command. + + +``` + +kubeadm join 172.31.64.38:6443 --token 425qb8.51rbrxc5h862g202 \ + --discovery-token-ca-cert-hash sha256:a502867d97b05820f186e3ee748afddd9142aae4104aee804d30662148138bae + +``` + + + +2.7 On the master node, run the following command to install the weavenet plugin in order to create a network: + +``` + +kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 |tr -d '\n')" + +``` + + +2.8 List all the nodes again to check the status of nodes using the command: + +``` + +kubectl get nodes + + +``` + + + +--------------------------------------------- +# Lesson 08 Demo 2 +Pod Creation in Kubernetes + + +### Steps to be followed: +1. Creating multi-container pods +2. Creating a single container pod + +### Step 1: Creating multi-container pods +1.1 On the master node, create a new file named sample.yaml: + +sudo su +vi sample.yaml +1.2 Add the following code in the sample.yaml file: + +``` +apiVersion: v1 +kind: Pod +metadata: + name: multi-container +spec: + terminationGracePeriodSeconds: 0 + containers: + - name: nginx + image: nginx:1.10-alpine + ports: + - containerPort: 80 + - name: alpine + image: alpine:3.5 + command: ["watch", "wget", "-qO-", "localhost"] + ``` + + +1.3 Use the following command to create the multi-container pod: + +``` + +kubectl create -f sample.yaml + +``` + + + +### Step 2: Creating a single container pod +2.1 On the master node, create a single container pod with a tomcat image using the following command: + +``` + +kubectl run tomcat --image=tomcat:8.0 + +``` + + + +2.2 Check all the running pods + +``` + +kubectl get pods + +``` + + +2.3 To check why exactly a pod is in the pending state, run the command + +``` + +kubectl describe pods + +``` + +To check why multi-container pod is pending,use the command + +``` + +kubectl describe pods multi-container + +``` + + + +2.4 To remove the taint from the node run the following commands: + +``` + +kubectl get nodes +Copy the node name and use it in the below command + +``` + +kubectl taint nodes node-role.kubernetes.io/master- + +``` + +Here for example we use the command given below + +``` + +kubectl taint nodes ip-172-31-18-183 node-role.kubernetes.io/master- + +``` + + +2.5 Now check the pod status. The pods should be in the running state. + +``` + +sudo kubectl get pods +``` +``` +# kubectl commands + +``` +kubectl get namespace + +kubeadm token list +kubectl get namespaces + +kubectl get replicationcontroller,services +kubectl get pods -n kube-public +kubectl get pods -n kube-system +kubectl get pods --all-namespaces + +kubectl run nginx --image=nginx +kubectl get pods --all-namespaces + +kubectl get pods +kubectl get pods -o wide +kubectl describe pod nginx +kubectl get pods +kubectl run nginx --image=httpd +kubectl run httpd --image=httpd +kubectl get pods + +service docker status +sudo kubectl get nodes + +``` +# Pod Creation in Kubernetes + +- Steps to be followed: +1. Creating multi-container pods +2. Creating a single container pod + +## Step 1: Creating multi-container pods +- 1.1 On the master node, create a new file named sample.yaml: +``` +sudo su +vi sample.yaml +1.2 Add the following code in the multi-container.yaml file: +https://github.com/manikcloud/k8s/blob/main/pods/multi-container.yaml +``` + +- 1.3 Use the following command to create the multi-container pod: +``` +kubectl create -f sample.yaml + ``` + +## Step 2: Creating a single container pod +- 2.1 On the master node, create a single container pod with a tomcat image using the following command: +``` +kubectl run tomcat --image=tomcat:8.0 + ``` + +- 2.2 Check all the running pods +``` +kubectl get pods +``` +- 2.3 To check why exactly a pod is in the pending state, run the command +-- kubectl describe pods +- To check why multi-container pod is pending,use the command +``` +kubectl describe pods multi-container +``` + + +## 2.4 To remove the taint from the node run the following commands: +``` +kubectl get nodes +``` +- Copy the node name and use it in the below command +- kubectl taint nodes node-role.kubernetes.io/master- + +### Here for example we use the command given below +``` +kubectl taint nodes ip-172-31-17-206 node-role.kubernetes.io/master- + ``` +-- 2.5 Now check the pod status. The pods should be in the running state. +``` +sudo kubectl get pods + +``` + +# Dashboard Creation in Kubernetes + +``` +kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.1/aio/deploy/recommended.yaml + +kubectl proxy + +http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ + +kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | awk '/^deployment-controller-token-/{print $1}') | awk '$1=="token:"{print $2}' + +kubectl -n kube-system describe secret $( + kubectl -n kube-system get secret | \ + awk '/^deployment-controller-token-/{print $1}' +) | \ +awk '$1=="token:"{print $2}' + +``` +## After executing the above commands, there are 4 distinct commands and they get called in this order: + +- Line 1 - This is the second command from @silverfox's Token section. +- Line 2 - This is the first command from @silverfox's Token section. +- Line 3 - Print only the first field of the line beginning with deployment-controller-token- (which is the pod name) +- Line 5 - Print only the second field of the line whose first field is "token:" + +# ReplicaSet commands in K8S + +``` + +kubectl apply -f ReplicaSet/ReplicaSet.yaml +kubectl get pods +kubectl get replicaset +kubectl delete pod sl-replicaset-hnd76 +kubectl descr +kubectl apply -f pods/pod-def.yaml +kubectl get pods +kubectl apply -f pods/pod-def.yaml +kubectl get pods +kubectl get replicaset sl-replicaset +kubectl edit replicaset sl-replicaset +kubectl get replicaset sl-replicaset +kubectl scale replicaset sl-replicaset --replicas=2 +kubectl get replicaset sl-replicaset + +kubectl get replicaset sl-replicaset +``` +# Deployment commands in K8S +``` +kubectl create -f deployment/deployment.yaml +kubectl get pods -o wide + +kubectl get deployment +kubectl get deployment -o wide +kubectl describe deployment +kubectl create -f deployment/deployment.yaml +kubectl get pods -o wide +kubectl rollout history deployment/web-app-deployment +kubectl delete deployment web-app-deployment +kubectl get pods -o wide +kubectl create -f deployment/deployment.yaml --record +kubectl rollout history deployment/web-app-deployment +kubectl edit deployment web-app-deployment --record +kubectl rollout history deployment/web-app-deployment +kubectl rollout status deployment/web-app-deployment +kubectl get pods -o wide +kubectl describe deployment web-app-deployment +kubectl rollout status deployment/web-app-deployment +kubectl set image deployment web-app-deployment blue=varunmanik/httpd:v1-blue --record +kubectl get pods -o wide +kubectl rollout history deployment web-app-deployment +``` +# scaling commands in K8S +``` +kubectl scale deployment web-app-deployment --replicas=6 +``` + +# Roll Out +``` +kubectl rollout undo deployment/web-app-deployment --to-revision=3 +kubectl rollout history deployment web-app-deployment +``` + +# Docker testing in you K8S setup +``` +docker build -t varunmanik/httpd:green . +docker run -itd -p 9000:80 varunmanik/httpd:green +docker build -t varunmanik/httpd:blue . +docker run -itd -p 9001:80 varunmanik/httpd:blue +kubectl describe pod green-app | grep -i "IP:" +``` + +# Services commands in K8S + +``` +kubectl create -f services/service-def.yaml +kubectl describe svc web-app-service +kubectl get svc,pods -o wide +kubectl delete service web-app-service +kubectl get svc,pods -o wide +kubectl scale deployment/blue-green-deployment --replicas=1 +kubectl get svc,pods -o wide +kubectl get svc,pods,deployment -o wide + +``` + + +# Cleanup the entire setup + +- Run this command to cleanup +``` +sh installation/cleanup.sh +``` +- OR copy and paste below commands one by one. + +``` +docker ps +kubeadm reset -f +rm -rf /etc/cni /etc/kubernetes /var/lib/dockershim /var/lib/etcd /var/lib/kubelet /var/run/kubernetes ~/.kube/* +v +apt remove -y kubeadm kubectl kubelet kubernetes-cni +sudo apt-get purge kubeadm kubectl kubelet kubernetes-cni kube* +sudo apt-get autoremove +sudo rm -rf ~/.kube +docker ps +system restart docker +systemctl restart docker +``` + +# Check your history from below command + +``` +history | cut -c 8- > history.txt +``` + +# References +1. https://kubernetes.io/ +2. https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/ +3. https://kubernetes.io/docs/concepts/workloads/pods/ +4. https://etcd.io/ +5. https://kubernetes.io/docs/reference/kubectl/ +6. https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/ + + + diff --git a/8-k8s/ReplicaSet/ReplicaSet-sl-ex.yaml b/8-k8s/ReplicaSet/ReplicaSet-sl-ex.yaml new file mode 100644 index 0000000..8cfcc36 --- /dev/null +++ b/8-k8s/ReplicaSet/ReplicaSet-sl-ex.yaml @@ -0,0 +1,27 @@ +apiVersion: v1 + + + +kind: Pod + + + + + +metadata: + + name: web-pod + + labels: + + application: web-app3 + +spec: + + containers: + + - name: google-ex + + image: gcr.io/google_samples/gb-frontend:v3 + + diff --git a/8-k8s/ReplicaSet/ReplicaSet.yaml b/8-k8s/ReplicaSet/ReplicaSet.yaml new file mode 100644 index 0000000..73ae3cc --- /dev/null +++ b/8-k8s/ReplicaSet/ReplicaSet.yaml @@ -0,0 +1,25 @@ +apiVersion: apps/v1 + +kind: ReplicaSet + +metadata: + name: sl-replicaset + labels: + application: web-app + +spec: + selector: + matchLabels: + application: web-app + replicas: 20 + template: + metadata: + name: web2 + labels: + application: web-app + env: dev + + spec: + containers: + - name: httpd + image: varunmanik/httpd:alpine diff --git a/8-k8s/ReplicaSet/blue-replicaset.yaml b/8-k8s/ReplicaSet/blue-replicaset.yaml new file mode 100644 index 0000000..d4cbe1e --- /dev/null +++ b/8-k8s/ReplicaSet/blue-replicaset.yaml @@ -0,0 +1,25 @@ +apiVersion: apps/v1 + +kind: ReplicaSet + +metadata: + name: blue-replicaset + labels: + application: web-app + +spec: + template: + metadata: + name: blue-app + labels: + env: dev + application: web-app + color: blue + spec: + containers: + - name: httpd + image: varunmanik/httpd:blue + selector: + matchLabels: + color: blue + replicas: 5 \ No newline at end of file diff --git a/8-k8s/ReplicaSet/green-replicaset.yaml b/8-k8s/ReplicaSet/green-replicaset.yaml new file mode 100644 index 0000000..a358d39 --- /dev/null +++ b/8-k8s/ReplicaSet/green-replicaset.yaml @@ -0,0 +1,25 @@ +apiVersion: apps/v1 + +kind: ReplicaSet + +metadata: + name: green-replicaset + labels: + application: web-app + +spec: + template: + metadata: + name: green-app + labels: + env: dev + application: web-app + color: green + spec: + containers: + - name: httpd + image: varunmanik/httpd:green + selector: + matchLabels: + color: green + replicas: 5 \ No newline at end of file diff --git a/8-k8s/deployment/bg-deployment.yaml b/8-k8s/deployment/bg-deployment.yaml new file mode 100644 index 0000000..af8b2e6 --- /dev/null +++ b/8-k8s/deployment/bg-deployment.yaml @@ -0,0 +1,25 @@ +apiVersion: apps/v1 + +kind: Deployment + +metadata: + name: blue-green-deployment + labels: + application: web-app + +spec: + template: + metadata: + name: blue-app + labels: + application: web-app + env: dev + color: blue + spec: + containers: + - name: httpd + image: varunmanik/httpd:green + selector: + matchLabels: + application: web-app + replicas: 3 \ No newline at end of file diff --git a/8-k8s/deployment/deployment.yaml b/8-k8s/deployment/deployment.yaml new file mode 100644 index 0000000..92609e5 --- /dev/null +++ b/8-k8s/deployment/deployment.yaml @@ -0,0 +1,26 @@ +apiVersion: apps/v1 + +kind: Deployment + +metadata: + name: web-app-deployment + labels: + application: web-app + +spec: + selector: + matchLabels: + application: web-app + replicas: 3 + template: + metadata: + name: web2 + labels: + application: web-app + env: dev + color: blue + + spec: + containers: + - name: blue + image: varunmanik/httpd:v1-blue diff --git a/8-k8s/lesson-end-project/calc.yml b/8-k8s/lesson-end-project/calc.yml new file mode 100644 index 0000000..a1daaae --- /dev/null +++ b/8-k8s/lesson-end-project/calc.yml @@ -0,0 +1,26 @@ +apiVersion: apps/v1 + +kind: Deployment + +metadata: + name: web-calc + labels: + application: web-app-calc + +spec: + selector: + matchLabels: + application: web-app-calc + replicas: 3 + template: + metadata: + name: calculator + labels: + application: web-app-calc + env: dev + product: calculator-py + + spec: + containers: + - name: calc-image + image: varunmanik/python-calc-app \ No newline at end of file diff --git a/8-k8s/pods/blue-pod.yaml b/8-k8s/pods/blue-pod.yaml new file mode 100644 index 0000000..1334765 --- /dev/null +++ b/8-k8s/pods/blue-pod.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 + +kind: Pod +metadata: + name: blue-app + labels: + env: dev + application: web-app + color: blue + +spec: + containers: + - name: httpd + image: varunmanik/httpd:blue \ No newline at end of file diff --git a/8-k8s/pods/database.yaml b/8-k8s/pods/database.yaml new file mode 100644 index 0000000..693382f --- /dev/null +++ b/8-k8s/pods/database.yaml @@ -0,0 +1,17 @@ +apiVersion:vi + +kind: Pod + +metadata: + name : postgress-database + labels: + tier: db-tier + +spec: + containers: + - name: postgres + image: postgres + env: + - name: db_pass + value: 123456 + diff --git a/8-k8s/pods/green-pod.yaml b/8-k8s/pods/green-pod.yaml new file mode 100644 index 0000000..dec9cac --- /dev/null +++ b/8-k8s/pods/green-pod.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 + +kind: Pod +metadata: + name: green-app + labels: + env: dev + application: web-app + color: green + +spec: + containers: + - name: httpd + image: varunmanik/httpd:green \ No newline at end of file diff --git a/8-k8s/pods/multi-container.yaml b/8-k8s/pods/multi-container.yaml new file mode 100644 index 0000000..99265e9 --- /dev/null +++ b/8-k8s/pods/multi-container.yaml @@ -0,0 +1,28 @@ +apiVersion: v1 + +kind: Pod + +metadata: + name: mulit-container + labels: + env: dev + tier: frontend + costcenter: devops + +spec: + containers: + - name: nginx + image: nginx:1.10-alpine + ports: + - containerPort: 80 + - name: alpine + image: alpine:3.5 + command: + - "watch" + - "wget" + - "-qO-" + - "localhost" + + + + diff --git a/8-k8s/pods/my-pod.yml b/8-k8s/pods/my-pod.yml new file mode 100644 index 0000000..b98ba13 --- /dev/null +++ b/8-k8s/pods/my-pod.yml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Pod +metadata: + name: myapp + labels: + name: myapp +spec: + containers: + - name: myapp + image: varunmanik/httpd:green + + ports: + - containerPort: 80 \ No newline at end of file diff --git a/8-k8s/pods/new_pod.yaml b/8-k8s/pods/new_pod.yaml new file mode 100644 index 0000000..f841749 --- /dev/null +++ b/8-k8s/pods/new_pod.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 + +kind: Pod +metadata: + name: varunapp + labels: + name: webapp +spec: + containers: + - name: httpdBlueApp + image: varunmanik/httpd:blue + + ports: + - containerPort: 80 diff --git a/8-k8s/pods/pod-def.yaml b/8-k8s/pods/pod-def.yaml new file mode 100644 index 0000000..c96cefc --- /dev/null +++ b/8-k8s/pods/pod-def.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 + + +kind: Pod + +metadata: + name: pod-def + +spec: + containers: + - name: web-blue + image: varunmanik/httpd:blue \ No newline at end of file diff --git a/8-k8s/pods/web-container.yaml b/8-k8s/pods/web-container.yaml new file mode 100644 index 0000000..889e233 --- /dev/null +++ b/8-k8s/pods/web-container.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 + +kind: Pod + +metadata: + + name: web-server + +spec: + + containers: + + - name: web-container + + image: httpd + + diff --git a/8-k8s/resources/pods.yaml b/8-k8s/resources/pods.yaml new file mode 100644 index 0000000..3debaa1 --- /dev/null +++ b/8-k8s/resources/pods.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Pod +metadata: + name: web-server + labels: + env: dev + acconut: non-prod + +spec: + containers: + - name: nginx-server + image: nginx:alpine + + diff --git a/9.1-NagiOS/README.md b/9.1-NagiOS/README.md new file mode 100644 index 0000000..cedd631 --- /dev/null +++ b/9.1-NagiOS/README.md @@ -0,0 +1,274 @@ +# ELK +## https://github.com/manikcloud/elk-stack +# NagiOS (https://github.com/manikcloud/DevOps-Tutorial/tree/main/9.1-NagiOS) +--- + +# Lesson 9 Demo 1 +How to Install Nagios Monitoring Tool + + +### Steps to be followed: +1. Updating the packages +- 2. Installing the latest version of Nagios XI + + + +**Note**: You need a blank ubuntu lab before you proceed with installations. Any pre-installed tool/package might interfere with the installation process giving errors. So kindly, terminate the lab access and launch a fresh lab instance before you proceed with this demo. + + +### Step 1: Updating the packages +1.1 Update the packages using the following command: + + +``` + sudo apt update -y + +``` + +### Step 2: Installing the latest version of Nagios Xi +- 2.1 Login as the root user using the command given below + +``` + sudo -i + +``` + +- 2.2 Execute the below command to install Nagios XI + +``` +curl https://assets.nagios.com/downloads/nagiosxi/install.sh | sh +``` + +**Note**: The installation takes around 20 mins. Please wait patiently till you get the Installation Complete message as shown below + + +- 2.3 Navigate to the user interface by using the URL provided in your terminal session. You can refer to the screenshot given above. +- 2.4 You will be presented with the Nagios XI Installation screen as shown below + + + + +- 2.5 You will be first prompted to define the General System Settings + +- 2.6 Once you've made your desired selections choose your License Settings. Here for demonstration purposes we have chosen a trial version. + +- 2.7 You will have to enter a key for the trial version. To get the key, click on the click to get a trial key link. You will be asked to enter details like the first name, last name and email id. Once you enter all those you will get the key mailed to the email-id you just mentioned. Enter the key as shown below + +- 2.8 Click Next to proceed. + +- 2.9 The next page provides you with options for the Admin Account. You can use the default password or change it if you want. After this click on Finish Install + +- 2.10 The page will display a spinning logo while it applies your settings to Nagios XI. + +- 2.11 The Installation Complete screen will be shown with the username and password required to login to Nagios XI. + +- 2.12 Click the Login to Nagios XI button to begin. + + + +- 2.13 The Login Screen will appear, provide your credentials and then click the Login button. + + + +- 2.14 You will need to accept the License Agreement to proceed. + + +- 2.15 You will be logged into Nagios XI and be placed at the home screen. + + + + +---------------------------------------------------------------------------------------- + +# Lesson 9 Demo 2 +Adding Hosts to the Nagios Monitoring Tool + + +### Steps to be followed: +1. Logging into the Nagios XI Dashboard +- 2. Adding a host using the core config manager + + +### Step 1: Logging into the Nagios Dashboard +1.1 Login to the nagios dashboard using the url as mentioned in the previous demo. + + +### Step 2: Adding a host using the core config manager +- 2.1 Navigate to Configure > Core config manager from the nagios dashboard + + +- 2.2 To manually add a new host, select the Hosts link located under Monitoring on the left menu of CCM + +- 2.3 This will bring up the Host Management page, which displays a list of the current hosts being monitored by Nagios XI. + +- 2.4 Click the Add New button to manually add a new host. + +- 2.5 The Host Management page will open on the Common Settings tab. + +- 2.6 Define the primary host parameters such as Host Name, Description, Address, and Display name. + +- 2.7 Use the Manage Parents button to associate parent host(s) for the host. +- 2.8 Use the Manage Templates button to associate template(s) to the host. + +- 2.9 Use the Manage Host Groups button to associate existing host group(s) to the host + + +- 2.10 On the previous screenshot of the Common Settings tab you'll notice that the Active checkbox is checked. If this box is unchecked the host configuration won't be put into production when Apply Configuration is performed. However the settings will remain in CCM until you activate the host object. + +- 2.11 To define the check command for this host, you select the appropriate command from the Check command drop down list . Every command in the Check command drop down list is associated with a set of Nagios Core commands and arguments, which are shown in the Command view field. + + +- 2.12 The Check Settings tab allows you to specify the settings for frequency of checks and also the host state + + +- 2.13 Configure settings as shown in the screenshot below + +- 2.14 The Alert Settings tab allows you to specify your notification settings. + + +- 2.15 Enter the value as shown below: + +- 2.16 Click on manage contacts to add any contact that needs to be notified about the host status. + +- 2.17 The Misc Settings tab is for defining additional host information + +- 2.18 Once you've finished entering information for your new host, click the Save button to return to the Host Management page + +- 2.19 Click the Apply Configuration button to restart Nagios XI and put the new settings info effect. Nagios XI will verify the settings and display a success message that the host was set up correctly + +- 2.20 You can see the apply configuration successful message as shown below: + +- 2.21 You can verify that the host is added to the monitoring tool. + + + + + +---------------------------------------------------------------------------------------- + +# Lesson 9 Demo 3 +Continuous Monitoring on Docker with ELK Stack + + +### Steps to be followed: +1. Set up ELK stack on Docker +2. Configure Jenkins pipeline for Docker build and deployment +3. Run the Spring Boot application and check the logs in Kibana + +### Step 1: Set up ELK stack on Docker + + + + + +1.1 Download Docker compose file in one of the git repositories and follow the set of commands given below to initialize the ELK stack. + + +``` + su +git clone https://github.com/Siraj-ul-muneera/ELKExample.git +cd ELKExample +ls -alrt + +``` + +1.2 Start the ELK stack using the docker-compose command. Usually, this binary is not installed on a server. So, follow the set of commands given below to install Docker Compose. + + +``` + apt install docker-compose +docker-compose version + +``` + +1.3 Before starting the ELK stack, run the command given below so that elastic search is configured properly. + +``` + +sysctl -w vm.max_map_count=262144 + +``` + +1.4 Run the docker-compose command to initialize the ELK stack. + + + +``` + docker-compose up -d +docker ps + +``` + + + + +1.5 Open the Kibana URL using the public IP of the host and 5601 port to access the Kibana dashboard. + +http://localhost:5601/app/kibana + + + +### Step 2: Configure Jenkins pipeline for Docker build and deployment +- 2.1 From the browser, navigate to http://localhost:8080 and login to Jenkins. +- 2.2 Configure your Docker hub credentials in Jenkins. Go to Manage Jenkins -> Manage Credentials -> click on Jenkins link -> click on Global credentials (unrestricted) -> click on Add Credentials from the left pane. + +- 2.3 Add the details as shown below + + +``` + Username: +Password: + +``` + +- 2.4 You should now see the credentials saved as shown below + +- 2.5 Create a Jenkins pipeline job to fetch Jenkinsfile from the URL mentioned below. + +- 2.6 You can either use the below git repository or Fork it in your Github account and use it +https://github.com/Siraj-ul-muneera/ELKExample.git + +- 2.7 Configure the job as shown in the screenshot below and then run the build. + + +- 2.8 Give 777 permission to the Docker sock file since we are running Docker command from a Jenkins user. + + +``` + chmod 777 /var/run/docker.sock + +``` + + +- 2.9 Build the Jenkins job to deploy the Docker container on the Docker host. + +- 2.10 Jenkins pipeline will complete the build and the deployment process for the Spring Boot application + + +- 2.11 We can see the Docker container deployed on the Docker host using the command: + + +``` + docker ps | grep springbootapp + +``` + + + +### Step 3: Run the Spring Boot application and check the logs in Kibana + +3.1 Access the Spring Boot web application and perform some random activity so that the logs will be pushed to ELK stack. + +http://localhost:81 + +3.2 Check the logs pushed to ELK stack in Kibana. + +3.3 Navigate to the Kibana dashboard. Select Management > Index Management from the navigation bar on the left. You can see the logs created. + + + + + +---------------------------------------------------------------------------------------- + +---------------------------------------------------------------------------------------- diff --git a/README.md b/README.md index d75f935..396c78a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,47 @@ -# DevOps-Tutorial -DevOps-Tutorial +# DevOps Tutorial + +Welcome to the [DevOps Tutorial Repository](https://github.com/manikcloud/DevOps-Tutorial/tree/main), a key resource for AWS-focused DevOps learning! This repository is an extensive collection of tutorials and guides, specifically curated for those leveraging AWS in their DevOps practices. Whether you're just starting your journey in DevOps, or you're an experienced practitioner seeking to deepen your expertise with AWS tools and methodologies, this repository is tailored for you. + +## Emphasis on AWS and DevOps + +Our tutorials and resources provide in-depth coverage of various DevOps tools and practices, with a special focus on integrating them within the AWS ecosystem. AWS offers a broad set of services and tools that are crucial in the DevOps landscape, and our repository aims to help you harness these capabilities to their fullest potential. + +## Ideal for All Skill Levels + +Whether you're a beginner who's curious about AWS and DevOps, or a seasoned DevOps professional looking to integrate more AWS services into your workflow, this repository has something for everyone. It's designed to guide you through the nuances of AWS services and how they can optimize your DevOps processes. + +## Repository Contents + +1. **[Linux Tutorial](https://github.com/manikcloud/DevOps-Tutorial/tree/main/Linux_Tutorial):** Dive into the world of Linux with our tutorials, starting with the `history-of-jan-06-2024.txt`, a comprehensive guide to Linux basics and advanced concepts. + +2. **[Git](https://github.com/manikcloud/DevOps-Tutorial/tree/main/2-Git):** Master version control with Git. Our tutorials provide insights from basic usage to advanced Git strategies and workflows. + +3. **[Jenkins](https://github.com/manikcloud/DevOps-Tutorial/tree/main/5-jenkins):** Learn about Jenkins, a cornerstone tool for continuous integration and continuous deployment (CI/CD). + +4. **[Ansible and Terraform](https://github.com/manikcloud/DevOps-Tutorial/tree/main/6-ansible-terraform):** Explore the world of infrastructure as code (IaC) with Ansible and Terraform tutorials, perfect for automating your infrastructure setup. + +5. **[Docker](https://github.com/manikcloud/DevOps-Tutorial/tree/main/7-docker):** Delve into containerization with Docker. Understand how to containerize applications and manage them effectively. + +6. **[Kubernetes (k8s)](https://github.com/manikcloud/DevOps-Tutorial/tree/main/8-k8s):** Get hands-on with Kubernetes, a powerful system for automating deployment, scaling, and management of containerized applications. + +7. **[Nagios](https://github.com/manikcloud/DevOps-Tutorial/tree/main/9.1-NagiOS):** Learn about Nagios for monitoring systems, networks, and infrastructure. + +## Additional Resources + +- **[Ansible Command History](https://github.com/manikcloud/DevOps-Tutorial/blob/main/ansible-cmd-history.txt):** A log of practical Ansible commands for reference. +- **[VS Code Installation Script](https://github.com/manikcloud/DevOps-Tutorial/blob/main/vs-code-installation.sh):** A handy script for installing VS Code, a popular editor among DevOps professionals. + +## Contribution + +Your contributions to enhance or extend the tutorials and resources in this repository are most welcome! Feel free to fork the repository, make your changes, and submit a pull request. + +Happy learning, and let's make DevOps easy and accessible for everyone! + +--- + +*Disclaimer: The contents of this repository are intended for educational purposes. Please ensure to test and validate in a controlled environment before applying in production.* +---- + # Caltech-DevOps Simplilearn PG Program This repository contains course materials for the Caltech-DevOps Simplilearn Postgraduate Program. @@ -119,3 +161,25 @@ When you are ready to merge your changes with the master branch, create a pull r Remember to always keep your local repository up to date by fetching and merging changes from the remote repository. Happy coding! + +# Disclaimer +
+ +Please note that the entire repository is owned and maintained by [Varun Kumar Manik](https://www.linkedin.com/in/vkmanik/). While every effort has been made to ensure the accuracy and reliability of the information and resources provided in this repository, Varun Kumar Manik takes full responsibility for any errors or inaccuracies that may be present. + +Simplilearn is not responsible for the content or materials provided in this repository and disclaims all liability for any issues, misunderstandings, or claims that may arise from the use of the information or materials provided. By using this repository, you acknowledge that Varun Kumar Manik is solely accountable for its content, and you agree to hold Simplilearn harmless from any claims or liabilities that may arise as a result of your use or reliance on the information provided herein. + +It is important to understand that this repository contains educational materials for a training course, and users are expected to apply their own judgment and discretion when utilizing the provided resources. Neither Varun Kumar Manik nor Simplilearn can guarantee specific results or outcomes from following the materials in this repository. + +
+ +## Connect & Follow + +For more info, please connect and follow me: + +- Github: [https://github.com/manikcloud](https://github.com/manikcloud) +- LinkedIn: [https://www.linkedin.com/in/vkmanik/](https://www.linkedin.com/in/vkmanik/) +- Email: [varunmanik1@gmail.com](mailto:varunmanik1@gmail.com) +- Facebook: [https://www.facebook.com/cloudvirtualization/](https://www.facebook.com/cloudvirtualization/) +- YouTube: [https://bit.ly/32fknRN](https://bit.ly/32fknRN) +- Twitter: [https://twitter.com/varunkmanik](https://twitter.com/varunkmanik) diff --git a/ansible-cmd-history.txt b/ansible-cmd-history.txt new file mode 100644 index 0000000..074a595 --- /dev/null +++ b/ansible-cmd-history.txt @@ -0,0 +1,147 @@ +ll +git clone +git clone git@github.com:manikcloud/DevOps-Tutorial.git +ssh-keygen +cat ~/.ssh/id_rsa.pub +git clone git@github.com:manikcloud/DevOps-Tutorial.git +ll +cd DevOps-Tutorial/ +code . +cd DevOps-Tutorial/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ +ansible-playbook ping.yaml +ansible all -m shell -a "apt upda +ansible all -m shell -a "apt update -y" become true +ansible all -m shell -a "apt update -y" +ansible all -m shell -a "apt update -y" -b=yes +ansible all -m shell -a "apt update -y" -b true +ansible all -m shell -a "apt update -y" -b=true +ansible-playbook ping.yaml +code +ll +cd DevOps-Tutorial/ +ls +mv 6-ansible 6-ansible-terraform +ll +cd 6-ansible-terraform/ +ls +mkdir 6.6.1-tf-local-file +cd 6.6.1-tf-local-file/ +terraform +terraform -version +vim main.tf +terraform init +cleaf +terraform plan +terraform apply +ll +cat index.html +git add . && git commit-am"adding tf local" +git add . && git commit -am"adding tf local" +git push +resource "local_file" "foo" { +git push +cd .. +git add . && git commit -am"adding tf local" && git push +git config --global user.name "varun" +git add . && git commit -am"adding tf local" && git push +ll +ansible +ansible --version +ansible -m ping localhost +ansible -m ping localhost -v +ansible -m ping localhost -vv +ansible -m ping localhost -vvv +ansible -m ping localhost -vvvv +cd 6-ansible-terraform/6.8-tf-ec2-provisioning/ +ll +cd .. +ll +ls +cd 6.8-tf-ec2-provisioning/ +ls +ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key ../deployer +ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer +chmod 400 deployer +ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer +ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer -v +ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer -vv +ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer -vvvv +ansible all -i '3.87.250.203, 54.198.128.135, 107.22.117.179' -m ping -u ubuntu --private-key deployer +ansible all -i ' 54.198.128.135' -m ping -u ubuntu --private-key deployer +ls +ansible all -i '54.198.128.135' -m ping -u ubuntu --private-key deployer +vim ~/.ssh/known_hosts +ansible all -i '54.198.128.135' -m ping -u ubuntu --private-key deployer +ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer +ansible all -i '54.198.128.135,' -m ping -u ubuntu --private-key deployer +ansible all -i '107.22.117.179,' -m ping -u ubuntu --private-key deployer +ll +cd ansible/ +ll +cd .. +ansible all -i ansible/inventory.ini -m ping +cd - +ll +ansible all -i inventory.ini -m ping +ansible all -i inventory.ini -m shell -a "la -l" +ansible all -i inventory.ini -m shell -a "ls -l" +ansible all -i inventory.ini -m shell -a "pwd" +ansible all -i inventory.ini -m shell -a "touch index.txt" +ansible all -i inventory.ini -m shell -a "ls -l" +ansible -m ping localhost -v +ansible -m ping localhost -vv +cd ../../.. +ansible -m ping localhost -vv +vim /etc/ansible/ansible.cfg +cd - +ansible all -m shell -a "ls -l" +ansible all -m shell -a "rm -rf index.txt" +ansible all -m shell -a "ls -l" +ansible all -m setup +ll +ansible-playbook ping.yaml +ansible all -m shell -a "ls -l" +ansible-playbook ping.yaml +ansible-doc -l +ansible-doc apt +q q +ansible-doc aptans +cd 6-ansible-terraform/6.8-tf-ec2-provisioning/ +terraform plan +terraform apply +terraform output +cd 6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/ +ll +terraform ini +terraform init +terraform plan +terraform apply +terraform plan +terraform apply +terraform plan +terraform apply +cd .. +git add . +git commit -am "adding creds" +git push +ll +cd 6-ansible-terraform/ +ll +cd 6.8-tf-ec2-provisioning/ +ll +cd .. +cd - +terraform init +terraform plan +terraform apply +terraform plan +terraform apply +terraform destroy +git push +cd .. +git add . +git commit -am"adding cred.tf" +git push +cd DevOps-Tutorial/ +code . +history | cut -c 8- > ansible-cmd-history.txt diff --git a/hi.txt b/hi.txt new file mode 100644 index 0000000..45b983b --- /dev/null +++ b/hi.txt @@ -0,0 +1 @@ +hi diff --git a/history-apr-29-2023.txt b/history-apr-29-2023.txt new file mode 100644 index 0000000..a3825ec --- /dev/null +++ b/history-apr-29-2023.txt @@ -0,0 +1,19 @@ +git clone git@github.com:manikcloud/DevOps-Tutorial.git +ll +git branch +git branch -a +git checkout -b dev1 +git branch -a +git checkout -b dev-4567 +git branch -a +git switch -c uat-123 +git branch -a +git switch dev +git switch dev1 +git switch - +git branch -a +git switch main +git switch dev-4567 +history +history | cut -c 8- +history | cut -c 8- > history-apr-29-2023.txt diff --git a/index.html b/index.html new file mode 100644 index 0000000..4ba7365 --- /dev/null +++ b/index.html @@ -0,0 +1,26 @@ + + + + + + +XYZ-company/title> + +</head> + +<body> + + + +<h1>This is GitOps Class going on. </h1> + +<p>This is a paragraph in Dev Branch. </p> + +<p>we are learning about git Merge </p> + + + +</body> + +</html> +hi diff --git a/vs-code-installation.sh b/vs-code-installation.sh new file mode 100755 index 0000000..c67920f --- /dev/null +++ b/vs-code-installation.sh @@ -0,0 +1,6 @@ +#!/bin/bash +sudo apt update -y +sudo apt install software-properties-common apt-transport-https wget -y +wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add - +sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" +sudo apt install code -y