├── .gitignore ├── 1-Linux_Tutorial ├── History.txt ├── README.md └── history-of-jan-06-2024.txt ├── 2-Git ├── README.md ├── history.txt └── ssh-command-details ├── 5-jenkins ├── 5.2-simple-java-program │ ├── HelloWorld.java │ └── README.md ├── 5.3-maven-project │ ├── README.md │ └── my-app │ │ ├── pom.xml │ │ ├── src │ │ ├── main │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── mycompany │ │ │ │ └── app │ │ │ │ └── App.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── mycompany │ │ │ └── app │ │ │ └── AppTest.java │ │ └── target │ │ ├── maven-archiver │ │ └── pom.properties │ │ ├── maven-status │ │ └── maven-compiler-plugin │ │ │ ├── compile │ │ │ └── default-compile │ │ │ │ ├── createdFiles.lst │ │ │ │ └── inputFiles.lst │ │ │ └── testCompile │ │ │ └── default-testCompile │ │ │ ├── createdFiles.lst │ │ │ └── inputFiles.lst │ │ └── surefire-reports │ │ ├── TEST-com.mycompany.app.AppTest.xml │ │ └── com.mycompany.app.AppTest.txt ├── 5.4-ant-java │ ├── HelloWorldAnt │ │ ├── build.xml │ │ └── src │ │ │ └── HelloWorld.java │ └── README.md ├── README.md └── terraform-jenkins-pipeline │ ├── Jenkinsfile │ ├── main.tf │ ├── output.tf │ ├── provider.tf │ └── variables.tf ├── 6-ansible-terraform ├── 6.2-node-ansible-playbook │ ├── README.md │ └── node.yml ├── 6.3-apache-ansible-playbook │ └── apache.yaml ├── 6.4-ansible-module │ └── README.md ├── 6.5-ansible-role │ ├── README.md │ ├── ansible.cfg │ ├── demor-role.yml │ ├── demor │ │ ├── .travis.yml │ │ ├── README.md │ │ ├── defaults │ │ │ └── main.yml │ │ ├── meta │ │ │ └── main.yml │ │ ├── tasks │ │ │ └── main.yml │ │ └── templates │ │ │ └── demor.j2 │ ├── deployer │ ├── deployer.pub │ ├── host_vars.yml │ └── inventory.ini ├── 6.6-setup-terraform │ ├── README.md │ └── tf-installation.sh ├── 6.6.1-tf-local-file │ ├── .terraform.lock.hcl │ ├── index.html │ └── main.tf ├── 6.7-S3-Bucket-Using-Terraform │ ├── .gitignore │ ├── .terraform.lock.hcl │ ├── README.md │ ├── creds.tf │ └── main.tf ├── 6.8-tf-ec2-provisioning │ ├── .gitignore │ ├── .terraform.lock.hcl │ ├── README.md │ ├── amazon-linux-vm.tf │ ├── ansible │ │ ├── README.md │ │ ├── ansible.cfg │ │ ├── apache.yaml │ │ ├── host_vars.yaml │ │ ├── inventory copy.ini-backup │ │ ├── inventory.ini │ │ ├── inventory.ini.org │ │ ├── jenkins.yaml │ │ ├── node.yaml │ │ ├── rue │ │ │ ├── my_server_1 │ │ │ ├── my_server_2 │ │ │ └── my_server_3 │ │ ├── ubuntu-wp-1.yaml │ │ ├── ubuntu-wp-config.php.j2 │ │ ├── wp-config.php.j2 │ │ └── wp.yaml │ ├── creds.tf │ ├── deployer │ ├── deployer.ppk │ ├── deployer.pub │ ├── main.tf │ └── ubuntu-vm.tf ├── README.md └── wordpress │ ├── README.md │ ├── wp-config.php.j2 │ └── wp.yaml ├── 7-docker ├── 7.4-docker-compose │ ├── README.md │ ├── python-flask-app │ │ ├── Dockerfile │ │ ├── app.py │ │ └── requirements.txt │ └── wordpress │ │ └── docker-compose-wp.yml ├── Dockerfile ├── Final-project-docker │ └── 5.11-docker-compose │ │ ├── Dockerfile │ │ ├── README.md │ │ ├── app.py │ │ └── requirements.txt ├── README.md └── index.html ├── 8-k8s ├── FAQ │ ├── Readme.md │ └── vol-k8s.ymal ├── Installation │ ├── cleanup-k8s-docker.sh │ └── setup-k8s.sh ├── README.md ├── ReplicaSet │ ├── ReplicaSet-sl-ex.yaml │ ├── ReplicaSet.yaml │ ├── blue-replicaset.yaml │ └── green-replicaset.yaml ├── deployment │ ├── bg-deployment.yaml │ └── deployment.yaml ├── lesson-end-project │ └── calc.yml ├── pods │ ├── blue-pod.yaml │ ├── database.yaml │ ├── green-pod.yaml │ ├── multi-container.yaml │ ├── my-pod.yml │ ├── new_pod.yaml │ ├── pod-def.yaml │ └── web-container.yaml └── resources │ └── pods.yaml ├── 9.1-NagiOS └── README.md ├── README.md ├── ansible-cmd-history.txt ├── hi.txt ├── history-apr-29-2023.txt ├── index.html └── vs-code-installation.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | replay_pid* 25 | # Local .terraform directories 26 | **/.terraform/* 27 | 28 | # .tfstate files 29 | *.tfstate 30 | *.tfstate.* 31 | 32 | # Crash log files 33 | crash.log 34 | 35 | # Ignore any .tfvars files that are generated automatically for each Terraform run. Most 36 | # .tfvars files are managed as part of configuration and so should be included in 37 | # version control. 38 | # 39 | # example.tfvars 40 | 41 | # Ignore override files as they are usually used to override resources locally and so 42 | # are not checked in 43 | override.tf 44 | override.tf.json 45 | *_override.tf 46 | *_override.tf.json 47 | 48 | # Include override files you do wish to add to version control using negated pattern 49 | # 50 | # !example_override.tf 51 | 52 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 53 | # example: *tfplan* 54 | # Ansible 55 | *.retry 56 | *.log 57 | 58 | # Terraform 59 | .terraform 60 | *.tfstate 61 | *.tfstate.backup 62 | *.tfplan 63 | 64 | # Java 65 | target/ 66 | *.class 67 | *.jar 68 | 69 | # Python 70 | __pycache__/ 71 | *.pyc 72 | *.pyo 73 | *.egg-info/ 74 | dist/ 75 | build/ 76 | *.egg 77 | *.log 78 | *.retry 79 | 80 | # Docker 81 | *.dockerignore 82 | .docker/ 83 | docker-compose.yml 84 | docker-compose.yaml 85 | docker-compose.override.yml 86 | docker-compose.override.yaml 87 | *.env 88 | 89 | # PHP 90 | vendor/ 91 | composer.lock 92 | -------------------------------------------------------------------------------- /1-Linux_Tutorial/History.txt: -------------------------------------------------------------------------------- 1 | # Linux tutorial 2 | 3 | ## Basic Commands: 4 | 5 | ``` 6 | 7 | s 8 | ls -l 9 | clear 10 | pwd 11 | ls 12 | cd Desktop/ 13 | ls 14 | ll 15 | pwd 16 | cd /home/varunmanikoutlo/ 17 | pwd 18 | ll 19 | ls -l 20 | ll 21 | ls -la 22 | ls -lar 23 | ls -lart 24 | ls -larth 25 | cd /home/varunmanikoutlo/ 26 | pwd 27 | cd Desktop/ 28 | cd ../ 29 | history 30 | history | cut -c 8- 31 | 32 | ``` 33 | -------------------------------------------------------------------------------- /1-Linux_Tutorial/README.md: -------------------------------------------------------------------------------- 1 | # Linux Basic Commands 2 | 3 | This README file provides a brief introduction to some essential Linux commands for beginners. 4 | 5 | ## Table of Contents 6 | 1. [Navigating the File System](#navigating-the-file-system) 7 | 2. [File Management](#file-management) 8 | 3. [Directory Management](#directory-management) 9 | 4. [Permissions](#permissions) 10 | 5. [Viewing File Contents](#viewing-file-contents) 11 | 6. [System Information](#system-information) 12 | 13 | ### Navigating the File System 14 | 15 | - To print the current working directory: 16 | 17 | ``` 18 | pwd 19 | ``` 20 | 21 | - To change the current working directory: 22 | 23 | ``` 24 | cd [directory] 25 | ``` 26 | 27 | - To list the contents of a directory: 28 | 29 | ``` 30 | ls [options] [directory] 31 | ``` 32 | 33 | ### File Management 34 | 35 | - To create a new file: 36 | 37 | ``` 38 | touch [file] 39 | ``` 40 | 41 | - To copy a file: 42 | 43 | ``` 44 | cp [source] [destination] 45 | ``` 46 | 47 | - To move a file: 48 | 49 | ``` 50 | mv [source] [destination] 51 | ``` 52 | 53 | - To remove a file: 54 | 55 | ``` 56 | rm [file] 57 | ``` 58 | 59 | ### Directory Management 60 | 61 | - To create a new directory: 62 | 63 | ``` 64 | mkdir [directory] 65 | ``` 66 | 67 | - To remove an empty directory: 68 | 69 | ``` 70 | rmdir [directory] 71 | ``` 72 | 73 | - To remove a non-empty directory: 74 | 75 | ``` 76 | rm -r [directory] 77 | ``` 78 | 79 | ### Permissions 80 | 81 | - To change file or directory permissions: 82 | 83 | ``` 84 | chmod [permissions] [file or directory] 85 | ``` 86 | 87 | - To change file or directory ownership: 88 | 89 | ``` 90 | chown [owner] [file or directory] 91 | ``` 92 | 93 | ### Viewing File Contents 94 | 95 | - To display the contents of a file: 96 | 97 | ``` 98 | cat [file] 99 | ``` 100 | 101 | - To display the first few lines of a file: 102 | 103 | ``` 104 | head [file] 105 | ``` 106 | 107 | - To display the last few lines of a file: 108 | 109 | ``` 110 | tail [file] 111 | ``` 112 | 113 | ### System Information 114 | 115 | - To display system information: 116 | 117 | ``` 118 | uname -a 119 | ``` 120 | 121 | - To display disk usage: 122 | 123 | ``` 124 | df -h 125 | ``` 126 | 127 | - To display memory usage: 128 | 129 | ``` 130 | free -h 131 | ``` 132 | 133 | 134 | # Linux Basic Commands - chmod and chown 135 | 136 | This section provides an in-depth explanation of the `chmod` and `chown` commands, including examples. 137 | 138 | ## chmod - Change File and Directory Permissions 139 | 140 | ### Symbolic Mode 141 | 142 | | Operator | Description | 143 | | -------- | ----------- | 144 | | `u` | User | 145 | | `g` | Group | 146 | | `o` | Others | 147 | | `a` | All (User, Group, and Others) | 148 | 149 | | Permission | Description | 150 | | ---------- | ----------- | 151 | | `r` | Read | 152 | | `w` | Write | 153 | | `x` | Execute | 154 | 155 | | Action | Description | 156 | | ------ | ----------- | 157 | | `+` | Add permission | 158 | | `-` | Remove permission | 159 | | `=` | Set permission | 160 | 161 | ### Example 162 | 163 | To add execute permission for the user: 164 | 165 | 166 | ``` 167 | chmod u+x [file or directory] 168 | ``` 169 | 170 | To remove write permission for the group and others: 171 | 172 | ``` 173 | chmod go-w [file or directory] 174 | ``` 175 | 176 | 177 | To set read and execute permissions for the user, and read permission for the group and others: 178 | 179 | 180 | ``` 181 | chmod u=rw,g=r,o=r [file or directory] 182 | ``` 183 | 184 | ## Octal Mode 185 | 186 | | Octal Value | Permission | 187 | | ----------- | ------------------- | 188 | | `0` | No permission | 189 | | `1` | Execute | 190 | | `2` | Write | 191 | | `3` | Write and Execute | 192 | | `4` | Read | 193 | | `5` | Read and Execute | 194 | | `6` | Read and Write | 195 | | `7` | Read, Write, Execute| 196 | 197 | 198 | ## Octal Permissions and Examples 199 | 200 | | Octal Value | Permission | Description | Example | 201 | | ----------- | ------------------- | ---------------------------------------- | ---------------------------- | 202 | | `0` | No permission | No permissions are granted | `chmod 000 file.txt` | 203 | | `1` | Execute | Execute permission only | `chmod 111 script.sh` | 204 | | `2` | Write | Write permission only | `chmod 222 file.txt` | 205 | | `3` | Write and Execute | Write and execute permissions | `chmod 333 script.sh` | 206 | | `4` | Read | Read permission only | `chmod 444 file.txt` | 207 | | `5` | Read and Execute | Read and execute permissions | `chmod 555 script.sh` | 208 | | `6` | Read and Write | Read and write permissions | `chmod 666 file.txt` | 209 | | `7` | Read, Write, Execute| All permissions (read, write, and execute)| `chmod 777 script.sh` | 210 | 211 | To set permissions using octal values, use the `chmod` command followed by the octal value for user, group, and others: 212 | ``` 213 | chmod [user][group][others] [file or directory] 214 | ``` 215 | Example: 216 | 217 | To set read, write, and execute permissions for the user, read and execute permissions for the group, and read permissions for others: 218 | ``` 219 | chmod 754 script.sh 220 | ``` 221 | ## Combining Octal Permissions 222 | 223 | 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. 224 | 225 | ### Examples 226 | 227 | 1. To set read and write permissions for the user, and read permissions for the group and others: 228 | 229 | ``` 230 | chmod 644 file.txt 231 | ``` 232 | 233 | 2. To set read, write, and execute permissions for the user, and read permissions for the group and others: 234 | ``` 235 | chmod 744 script.sh 236 | ``` 237 | 238 | 3. To set read and execute permissions for the user, group, and others: 239 | ``` 240 | chmod 555 script.sh 241 | ``` 242 | 243 | Remember to carefully choose permissions based on the security requirements 244 | ### Example 245 | 246 | To set read, write, and execute permissions for the user, read and write permissions for the group, and read permission for others: 247 | 248 | ``` 249 | chmod 764 [file or directory] 250 | ``` 251 | 252 | 253 | ## chown - Change File and Directory Ownership 254 | 255 | ### Syntax 256 | 257 | ``` 258 | chown [owner]:[group] [file or directory] 259 | ``` 260 | 261 | ### Example 262 | 263 | To change the owner of a file or directory to `newuser` and the group to `newgroup`: 264 | 265 | ``` 266 | chown newuser:newgroup [file or directory] 267 | ``` 268 | 269 | To change only the owner to `newuser`: 270 | 271 | ``` 272 | chown newuser [file or directory] 273 | ``` 274 | 275 | To change only the group to `newgroup`: 276 | 277 | ``` 278 | chown :newgroup [file or directory] 279 | ``` 280 | 281 | ## chmod Examples for Different File Types 282 | 283 | 1. Set read-only permission for a `.pem` file: 284 | 285 | ``` 286 | chmod 400 private_key.pem 287 | ``` 288 | This restricts the `.pem` file to be readable only by the owner, ensuring the private key remains secure. 289 | 290 | 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: 291 | 292 | ``` 293 | chmod 755 script.sh 294 | 295 | ``` 296 | This allows the owner to read, write, and execute the script, while others can only read and execute it. 297 | 298 | 3. Set read, write, and execute permissions for the owner, group, and others on a `script.sh` file: 299 | 300 | ``` 301 | chmod 777 script.sh 302 | ``` 303 | 304 | This allows everyone to read, write, and execute the script, which can be a security risk and is generally not recommended. 305 | 306 | ## Additional Notes 307 | 308 | - The `chmod` and `chown` commands can be used recursively with the `-R` option to change permissions or ownership for a directory and its contents: 309 | 310 | 311 | ``` 312 | chmod -R [permissions] [directory] 313 | chown -R [owner]:[group] [directory] 314 | ``` 315 | 316 | 317 | - You can use the `umask` command to set default file permissions for newly created files: 318 | 319 | ``` 320 | umask [octal value] 321 | ``` 322 | 323 | - You can use the `id` command to display information about the current user and group: 324 | 325 | ``` 326 | id 327 | ``` 328 | For more information and examples, consult the `man` pages for each command: 329 | ``` 330 | man chmod 331 | man chown 332 | ``` -------------------------------------------------------------------------------- /1-Linux_Tutorial/history-of-jan-06-2024.txt: -------------------------------------------------------------------------------- 1 | 2 | 1 cat /etc/issue 3 | 2 clear 4 | 3 ls 5 | 4 pwd 6 | 5 ls -l 7 | 6 date 8 | 7 ls -l 9 | 8 cat hello > a.txt 10 | 9 ll 11 | 10 date 12 | 11 clear 13 | 12 ls -la 14 | 13 ls -lah 15 | 14 ls -lh 16 | 15 ls -lht 17 | 16 ls -lhtr 18 | 17 ls -larth 19 | 18 mkdir devops 20 | 19 ll 21 | 20 mkdir -p mgmt/dev/non-prod/code 22 | 21 ll 23 | 22 cd mgmt/ 24 | 23 ll 25 | 24 ll * 26 | 25 ll ** 27 | 28 | 28 ll * 29 | 29 tree 30 | 30 apt install tree 31 | 31 sudo apt install tree 32 | 32 tree 33 | 33 sudo -i 34 | 34 sudo su 35 | 35 cd dev/non-prod/ 36 | 36 cd /home/varunmanikoutlo/mgmt/dev/ 37 | 37 cd non-prod/ 38 | 38 cd .. 39 | 39 cd mgmt/dev/non-prod/ 40 | 40 cd ../../ 41 | 41 cd - 42 | 42 tree 43 | 43 rmdir -r dev 44 | 44 rm -rf dev 45 | 45 tree 46 | 46 touch calc.java 47 | 47 ls 48 | 48 cat calc.java 49 | 49 cat calc.java index.html calc.py 50 | 50 touch calc.java index.html calc.py 51 | 51 ls 52 | 52 rm calc.java 53 | 53 ls 54 | 54 rm * 55 | 55 ll 56 | 56 cat Hi, we are learning Linux. 57 | 57 cat Hi, we are learning Linux. > index.html 58 | 58 cat "Hi, we are learning Linux." > index.html 59 | 59 echo "Hi, we are learning Linux." > index.html 60 | 60 echo "my name is: XYZ" 61 | 61 ls 62 | 62 cat index.html 63 | 63 ll 64 | 64 vim contacts.html 65 | 65 ls 66 | 66 nano aboutus.html 67 | 67 ll 68 | 68 cat aboutus.html 69 | 69 history 70 | 70 nano sales.html 71 | 71 ls 72 | 72 history 73 | 73 ll 74 | 74 vim install.sh 75 | 75 ll 76 | 76 chmod u+x 77 | 77 chmod u+x install.sh 78 | 78 ls 79 | 79 ll 80 | 80 chmod ug+x install.sh 81 | 81 ll 82 | 82 chmod ug-w install.sh 83 | 83 ll 84 | 84 mkdir test 85 | 85 mv install.sh test/ 86 | 86 cd test/ 87 | 87 ll 88 | 88 user>group>others chmod 777 install.sh 89 | 89 chmod 777 install.sh 90 | 90 ll 91 | 91 chmod 774 install.sh 92 | 92 ll 93 | 93 echo "hi this is php page" > index.php 94 | 94 ll 95 | 97 96 | 101 cat /etc/passwd | grep -i tomcat 97 | 102 ll 98 | 103 99 | 110 sudo chown tomcat:tomcat index.php 100 | 111 ll 101 | 112 sudo chown tomcat: install.sh 102 | 113 ll 103 | 114 history | cut -8 104 | 115 history > jan-06-2024.txt 105 | -------------------------------------------------------------------------------- /2-Git/history.txt: -------------------------------------------------------------------------------- 1 | ls 2 | ls -l 3 | clear 4 | pwd 5 | ls 6 | cd Desktop/ 7 | ls 8 | ll 9 | pwd 10 | cd /home/varunmanikoutlo/ 11 | pwd 12 | ll 13 | ls -l 14 | ll 15 | ls -la 16 | ls -lar 17 | ls -lart 18 | ls -larth 19 | cd /home/varunmanikoutlo/ 20 | pwd 21 | cd Desktop/ 22 | cd ../ 23 | history 24 | history | cut -c 8- 25 | history 26 | history | cut -c 8- 27 | man cut 28 | man 29 | man ls 30 | man cut 31 | ll 32 | mkdir varun 33 | ll 34 | mkdir -p /opt/one/two/tree/four 35 | mkdir -p ./one/two/tree/four 36 | ll 37 | ll one/ 38 | ll one/two/ 39 | ll one/two/tree/ 40 | tree 41 | apt install tree 42 | sudo -i 43 | sudo su 44 | sudo apt install tree 45 | htop 46 | sudo apt install elinks 47 | apt install elinks 48 | sudo apt install elinks 49 | sudo visudo 50 | touch one/one.txt 51 | tree one/ 52 | tree one/two/index.html 53 | touch one/two/index.html 54 | tree one/two/index.html 55 | tree one/ 56 | cd one/ 57 | touch a.txt b.txt c.txt d.log 58 | ll 59 | vim a.txt 60 | ll 61 | echo "hi this is for file b.txt" 62 | echo "hi this is for file b.txt" > b.txt 63 | cat b.txt 64 | cat a.txt 65 | history 66 | history > history.txt 67 | ll 68 | cat history.txt 69 | ll 70 | rm a.txt 71 | ll 72 | rm *.txt 73 | ll 74 | tree 75 | rm two/ 76 | rmdir two/ 77 | rmdir two/ -r 78 | rmdir two/ -f 79 | rmdir two 80 | rmdir -f two 81 | rmdir -rf two 82 | rm -rf two 83 | tree 84 | ls 85 | cd .. 86 | ll 87 | rm -rf one/ 88 | history 89 | history | cut -c 8- 90 | ehoc "hi" > index.html 91 | echo "hi" > index.html 92 | cat index.html 93 | echo "hi i am good " >> index.html 94 | cat index.html 95 | echo "hi i am good. How are you ? " >> index.html 96 | cat index.html 97 | ll 98 | touch varun/a.txt 99 | uname -a 100 | date 101 | cat /etc/issue 102 | apt install git 103 | sudo apt install git 104 | cat /etc/os-release 105 | cd varun/ 106 | git clone https://github.com/manikcloud/java-calculator-delete.git 107 | ll 108 | cd java-calculator-delete/ 109 | ll 110 | vim README.md 111 | git add README.md 112 | git commit -am"first upload" 113 | git push 114 | cd .. 115 | rm -rf java-calculator-delete/ 116 | ll 117 | git clone git@github.com:manikcloud/java-calculator-delete.git 118 | ssh-keygen 119 | cd ~/.ssh/ 120 | ll 121 | cat id_rsa 122 | cat id_rsa.pub 123 | llcd - 124 | cd - 125 | git clone git@github.com:manikcloud/java-calculator-delete.git 126 | ll 127 | cd java-calculator-delete/ 128 | vim README.md 129 | git add . 130 | git push 131 | git config --global user.email varunmanik1@gmail.com 132 | git config --global user.name varun-sl 133 | git push 134 | git status 135 | git commit -am"hi" 136 | gitpush 137 | git push 138 | cd .. 139 | git clone git@github.com:manikcloud/DevOps-Tutorial.git 140 | ll 141 | cd DevOps-Tutorial/ 142 | ll 143 | cd 2-Git/ 144 | history 145 | history | cut -c 8- > history.txt 146 | -------------------------------------------------------------------------------- /2-Git/ssh-command-details: -------------------------------------------------------------------------------- 1 | ssh-keygen 2 | cd ~/.ssh/ 3 | ll 4 | cat id_rsa.pub 5 | cd - 6 | git clone git@github.com:manikcloud/java-calculator-delete.git 7 | ll 8 | cd java-calculator-delete/ 9 | vim README.md 10 | git add . 11 | git push 12 | git config --global user.email varunmanik1@gmail.com 13 | git config --global user.name varun-sl 14 | git push 15 | git status 16 | git commit -am"hi" 17 | gitpush 18 | git push 19 | cd .. 20 | git clone git@github.com:manikcloud/DevOps-Tutorial.git 21 | ll 22 | cd DevOps-Tutorial/ 23 | ll 24 | cd 2-Git/ 25 | history 26 | history | cut -c 8- > history.txt 27 | -------------------------------------------------------------------------------- /5-jenkins/5.2-simple-java-program/HelloWorld.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { 2 | public static void main(String[] args) { 3 | System.out.println("Hello, World From Varun Manik on date MaJan 13 2024"); 4 | } 5 | } -------------------------------------------------------------------------------- /5-jenkins/5.2-simple-java-program/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ## Copy & paste this commands in your Jenkins, build option, execute shell 5 | 6 | ``` 7 | cd 5-jenkins/5.2-simple-java-program 8 | 9 | ls -l 10 | 11 | javac HelloWorld.java 12 | 13 | 14 | java HelloWorld 15 | 16 | ``` -------------------------------------------------------------------------------- /5-jenkins/5.3-maven-project/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ## Copy & paste this commands in your Jenkins, build option, execute shell 5 | 6 | ``` 7 | cd 5-jenkins/5.3-maven-project/my-app 8 | 9 | mvn clean install 10 | 11 | tree 12 | 13 | java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App 14 | 15 | ``` -------------------------------------------------------------------------------- /5-jenkins/5.3-maven-project/my-app/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 4.0.0 6 | 7 | com.mycompany.app 8 | my-app 9 | 1.0-SNAPSHOT 10 | 11 | my-app 12 | 13 | http://www.example.com 14 | 15 | 16 | UTF-8 17 | 1.7 18 | 1.7 19 | 11 20 | 21 | 22 | 23 | 24 | 25 | 26 | junit 27 | junit 28 | 4.11 29 | test 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.apache.maven.plugins 38 | maven-compiler-plugin 39 | 3.8.1 40 | 41 | 42 | 43 | maven-clean-plugin 44 | 3.1.0 45 | 46 | 47 | 48 | maven-resources-plugin 49 | 3.0.2 50 | 51 | 52 | maven-compiler-plugin 53 | 3.8.0 54 | 55 | 56 | maven-surefire-plugin 57 | 2.22.1 58 | 59 | 60 | maven-jar-plugin 61 | 3.0.2 62 | 63 | 64 | maven-install-plugin 65 | 2.5.2 66 | 67 | 68 | maven-deploy-plugin 69 | 2.8.2 70 | 71 | 72 | 73 | maven-site-plugin 74 | 3.7.1 75 | 76 | 77 | maven-project-info-reports-plugin 78 | 3.0.0 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /5-jenkins/5.3-maven-project/my-app/src/main/java/com/mycompany/app/App.java: -------------------------------------------------------------------------------- 1 | package com.mycompany.app; 2 | 3 | /** 4 | * Hello world! 5 | * 6 | */ 7 | public class App 8 | { 9 | public static void main( String[] args ) 10 | { 11 | System.out.println( "Hello World! From Varun Manik in Simplilearn class on date Jan 13 2024" ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /5-jenkins/5.3-maven-project/my-app/src/test/java/com/mycompany/app/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.mycompany.app; 2 | 3 | import static org.junit.Assert.assertTrue; 4 | 5 | import org.junit.Test; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | { 12 | /** 13 | * Rigorous Test :-) 14 | */ 15 | @Test 16 | public void shouldAnswerWithTrue() 17 | { 18 | assertTrue( true ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /5-jenkins/5.3-maven-project/my-app/target/maven-archiver/pom.properties: -------------------------------------------------------------------------------- 1 | #Created by Apache Maven 3.6.3 2 | groupId=com.mycompany.app 3 | artifactId=my-app 4 | version=1.0-SNAPSHOT 5 | -------------------------------------------------------------------------------- /5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | com/mycompany/app/App.class 2 | -------------------------------------------------------------------------------- /5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /home/varunmanikoutlo/varun/DevOps-Tutorial/5-jenkins/5.3-maven-project/my-app/src/main/java/com/mycompany/app/App.java 2 | -------------------------------------------------------------------------------- /5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | com/mycompany/app/AppTest.class 2 | -------------------------------------------------------------------------------- /5-jenkins/5.3-maven-project/my-app/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /home/varunmanikoutlo/varun/DevOps-Tutorial/5-jenkins/5.3-maven-project/my-app/src/test/java/com/mycompany/app/AppTest.java 2 | -------------------------------------------------------------------------------- /5-jenkins/5.3-maven-project/my-app/target/surefire-reports/TEST-com.mycompany.app.AppTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /5-jenkins/5.3-maven-project/my-app/target/surefire-reports/com.mycompany.app.AppTest.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | Test set: com.mycompany.app.AppTest 3 | ------------------------------------------------------------------------------- 4 | Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.042 s - in com.mycompany.app.AppTest 5 | -------------------------------------------------------------------------------- /5-jenkins/5.4-ant-java/HelloWorldAnt/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /5-jenkins/5.4-ant-java/HelloWorldAnt/src/HelloWorld.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { 2 | public static void main(String[] args) { 3 | System.out.println("Hello, World!"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /5-jenkins/5.4-ant-java/README.md: -------------------------------------------------------------------------------- 1 | # Hello World Java Program with Ant on Linux. 2 | 3 | ## Introduction 4 | This tutorial guides you through creating and running a simple "Hello World" Java program using Apache Ant on a Linux system. 5 | 6 | ## Prerequisites 7 | - Java Development Kit (JDK) 8 | - Apache Ant 9 | 10 | Ensure both are installed on your system. You can verify by running `java -version` and `ant -version` in your terminal. 11 | 12 | ## Setup 13 | 14 | ### Step 1: Project Structure 15 | Create a project directory and set up the following structure: 16 | 17 | 18 | 19 | Navigate to your project directory: 20 | ```bash 21 | mkdir HelloWorldAnt 22 | cd HelloWorldAnt 23 | ``` 24 | 25 | - Step 2: Java Source File 26 | Inside the src directory, create a file HelloWorld.java: 27 | 28 | 29 | 30 | ``` 31 | public class HelloWorld { 32 | public static void main(String[] args) { 33 | System.out.println("Hello, World!"); 34 | } 35 | } 36 | ``` 37 | - Step 3: Ant Build File 38 | Create build.xml at the root of your project with the following content: 39 | 40 | ``` 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | ``` 53 | 54 | 55 | - Running the Program 56 | To build and run your program, execute: 57 | 58 | ``` 59 | ant run 60 | ``` 61 | 62 | You should see Hello, World! printed in the console. 63 | -------------------------------------------------------------------------------- /5-jenkins/README.md: -------------------------------------------------------------------------------- 1 | # DevOps-Tutorial for Jenkins 1 2 | DevOps-Tutorial 3 | # Caltech-DevOps Simplilearn PG Program 4 | 5 | This repository contains course materials for the Caltech-DevOps Simplilearn Postgraduate Program. 6 | 7 | ## Course Contents 8 | 9 | 1. **Course Introduction** 10 | - Overview of the program 11 | - Objectives and outcomes 12 | 13 | 2. **Basic Linux** 14 | - Introduction to Linux 15 | - File system and basic commands 16 | - Shell scripting 17 | 18 | 3. **Introduction to DevOps** 19 | - DevOps concepts and principles 20 | - DevOps practices and tools 21 | 22 | 4. **Version Control System** 23 | - Introduction to Git 24 | - Git workflow 25 | - Branching and merging strategies 26 | 27 | 5. **CI/CD Pipeline with Jenkins** 28 | - Introduction to Jenkins 29 | - Configuring and managing Jenkins 30 | - Building and deploying pipelines 31 | 32 | 6. **Configuration Management with Ansible** 33 | - Introduction to Ansible 34 | - Writing Ansible playbooks 35 | - Ansible roles and best practices 36 | 37 | 7. **Infrastructure as Code with Terraform** 38 | - Introduction to Terraform 39 | - Writing Terraform configurations 40 | - Terraform modules and best practices 41 | 42 | 8. **Containerization with Docker** 43 | - Introduction to Docker 44 | - Dockerfile and Docker Compose 45 | - Docker networking and storage 46 | 47 | 9. **Container Orchestration with Kubernetes** 48 | - Introduction to Kubernetes 49 | - Kubernetes objects and resources 50 | - Kubernetes networking and storage 51 | 52 | 10. **Continuous Monitoring** 53 | - Introduction to monitoring 54 | - Monitoring tools and techniques 55 | - Integrating monitoring with CI/CD pipelines 56 | 57 | 11. **Centralized Notification System** 58 | - Introduction to centralized notifications 59 | - Notification tools and techniques 60 | - Integrating notifications with CI/CD pipelines 61 | 62 | 12. **AWS Cloud** 63 | - Introduction to AWS 64 | - AWS services and best practices 65 | - Deploying and managing applications on AWS 66 | 67 | 13. **Real-Time Project** 68 | - Working with Java, Maven, and Tomcat 69 | - Building a complete CI/CD pipeline 70 | - Applying DevOps principles and practices 71 | 72 | --------------------------------------------------------------------------------------------------- 73 | ## How to Use This Repository 74 | 75 | This repository contains course materials, example projects, and code snippets. Use it as a reference while working through the Caltech-DevOps Simplilearn Postgraduate Program. 76 | 77 | 78 | 79 | # Getting Started 80 | 81 | To get started, you will need to clone the repository to your local machine. Follow the instructions below: 82 | 83 | 1. Open a terminal or Git Bash. 84 | 2. Navigate to the directory where you want to clone the repository. 85 | 3. Run the following command to clone the repository: 86 | 87 | ``` 88 | git clone git@github.com:manikcloud/devops-project.git 89 | ``` 90 | 91 | 4. Change into the cloned repository directory: 92 | ``` 93 | cd devops-project 94 | ``` 95 | 96 | 97 | 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. 98 | 99 | ## Contributing to the Project 100 | 101 | 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. 102 | 103 | 1. Ensure you are in the `devops-project` directory. 104 | 2. Run the following command to create a new branch: 105 | 106 | ``` 107 | git checkout -b your_branch_name 108 | ``` 109 | 3. Make your changes, commit them, and push them to the remote repository: 110 | ``` 111 | git add . 112 | git commit -m "Your commit message" 113 | git push origin your_branch_name 114 | ``` 115 | 116 | 117 | 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. 118 | 119 | Remember to always keep your local repository up to date by fetching and merging changes from the remote repository. 120 | 121 | Happy coding! 122 | -------------------------------------------------------------------------------- /5-jenkins/terraform-jenkins-pipeline/Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent any 3 | 4 | environment { 5 | AWS_REGION = 'us-east-1' 6 | AWS_ACCESS_KEY_ID = "" 7 | AWS_SECRET_ACCESS_KEY = "" 8 | } 9 | 10 | stages { 11 | stage('Checkout') { 12 | steps { 13 | checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/vijeshnair89/terraform-jenkins-pipeline.git']]) 14 | } 15 | } 16 | 17 | stage('Terraform Init') { 18 | steps { 19 | sh 'terraform init' 20 | } 21 | } 22 | 23 | stage('Terraform Plan') { 24 | steps { 25 | sh 'terraform plan' 26 | } 27 | } 28 | 29 | stage('Terraform Apply') { 30 | steps { 31 | sh 'terraform apply -auto-approve' 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /5-jenkins/terraform-jenkins-pipeline/main.tf: -------------------------------------------------------------------------------- 1 | resource "aws_instance" "public_instance" { 2 | ami = var.ami 3 | instance_type = var.instance_type 4 | 5 | tags = { 6 | Name = var.name_tag, 7 | } 8 | } -------------------------------------------------------------------------------- /5-jenkins/terraform-jenkins-pipeline/output.tf: -------------------------------------------------------------------------------- 1 | output "public_ip" { 2 | value = aws_instance.public_instance.public_ip 3 | description = "Public IP Address of EC2 instance" 4 | } 5 | 6 | output "instance_id" { 7 | value = aws_instance.public_instance.id 8 | description = "Instance ID" 9 | } -------------------------------------------------------------------------------- /5-jenkins/terraform-jenkins-pipeline/provider.tf: -------------------------------------------------------------------------------- 1 | provider "aws" {} 2 | -------------------------------------------------------------------------------- /5-jenkins/terraform-jenkins-pipeline/variables.tf: -------------------------------------------------------------------------------- 1 | variable "ami" { 2 | type = string 3 | description = "Ubuntu AMI ID" 4 | default = "ami-03f4878755434977f" 5 | } 6 | 7 | variable "instance_type" { 8 | type = string 9 | description = "Instance type" 10 | default = "t2.micro" 11 | } 12 | 13 | variable "name_tag" { 14 | type = string 15 | description = "Name of the EC2 instance" 16 | default = "Terraform" 17 | } 18 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.2-node-ansible-playbook/README.md: -------------------------------------------------------------------------------- 1 | # Create EC2 instances with Terraform 2 | 3 | This branch contains Terraform code to create EC2 instances in AWS. 4 | 5 | ## Related Blog Posts By Author: 6 | 7 | - [DevSecOps CI/CD Java Tomcat Project](https://varunmanik1.medium.com/devsecops-cicd-java-tomcat-project-141d6b73e436) 8 | - [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) 9 | - [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) 10 | 11 | 12 | ## Prerequisites 13 | 14 | Before you start, make sure you have the following: 15 | 16 | - An AWS account, with ec2 full access permission 17 | - And Linux Terminal, wher you can run all these commands 18 | 19 | ## Files 20 | 21 | - `README.md`: This file, providing an overview of the branch. 22 | - `deployer` and `deployer.pub`: SSH keys for accessing the EC2 instances. 23 | - `history.txt`: A text file with a record of changes to this project. 24 | - `jenkins-installation-ubuntu.sh`: A shell script to install Jenkins on the EC2 instance. 25 | - `main.tf`: The main Terraform configuration file that creates the AWS resources. 26 | - `slave-vm.tf`: A Terraform configuration file that creates a Jenkins slave instance. 27 | - `tf-cli-installation.sh`: A shell script to install the Terraform CLI on the EC2 instance. 28 | - `ubuntu-vm.tf`: A Terraform configuration file that creates an Ubuntu EC2 instance. 29 | 30 | ## Usage 31 | 32 | To create EC2 instances with Terraform, follow these steps: 33 | 34 | 1. Clone this repository to your local machine by running the command: `git clone https://github.com/manikcloud/Jenkins-cicd.git`. 35 | 2. Switch to the `0.1_create_ec2_tf` branch by running the command: `git checkout 0.1_create_ec2_tf`. 36 | 3. Navigate to the `terraform` directory by running the command: `cd terraform`. 37 | 4. Initialize Terraform by running the command: `terraform init`. 38 | 5. Create an execution plan by running the command: `terraform plan`. 39 | 6. Apply the execution plan by running the command: `terraform apply`. 40 | 41 | You will be prompted to enter values for the variables defined in the `variables.tf` file. 42 | 43 | 44 | Create an AWS Account 45 | 46 | 1. Go to the AWS website and click on the "Create an AWS Account" button. 47 | 2. Follow the on-screen instructions to create your account. 48 | 3. Once your account is created, log in to the AWS Management Console. 49 | 50 | ### Create Access Keys in IAM 51 | 52 | 1. In the AWS Management Console, navigate to the IAM service. 53 | 2. Click on "Users" in the left sidebar, and then click on the "Add User" button. 54 | 3. Enter a user name and select "Programmatic Access" as the access type. 55 | 4. Click on the "Next: Permissions" button. 56 | 5. Choose the appropriate permissions for your user, or attach an existing policy. 57 | 6. Click on the "Next: Tags" button. 58 | 7. Add any tags (optional) and click on the "Next: Review" button. 59 | 8. Review your settings and click on the "Create User" button. 60 | 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. 61 | 62 | ### Install AWS CLI and Configure it 63 | 64 | 1. Install AWS CLI using the following command: 65 | ``` 66 | sudo apt-get install awscli 67 | ``` 68 | 2. Run the command `aws configure` to configure your access key ID, secret access key, default region, and output format. 69 | 70 | ## Install Terraform from SH Script 71 | 72 | ``` 73 | sudo chmod 755 chmod 755 tf-cli-installation.sh 74 | sudo sh chmod 755 tf-cli-installation.sh 75 | 76 | ``` 77 | # OR 78 | 79 | ## Install Terraform Manual 80 | 1. Set the desired Terraform version: `TERRAFORM_VERSION="1.4.5"` 81 | 2. Download Terraform: 82 | ``` 83 | wget "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" 84 | ``` 85 | 3. Install unzip if not installed: 86 | ``` 87 | sudo apt-get update && sudo apt-get install -y unzip 88 | ``` 89 | 4. Unzip the Terraform package: 90 | ``` 91 | unzip "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" 92 | ``` 93 | 5. Move the Terraform binary to the /usr/local/bin folder: 94 | ``` 95 | sudo cp terraform /usr/local/bin/ && sudo mv terraform /usr/bin/ 96 | ``` 97 | 6. Clean up the downloaded zip file: 98 | ``` 99 | rm "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" 100 | ``` 101 | 7. Verify the installation: 102 | ``` 103 | terraform --version 104 | ``` 105 | 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. 106 | 107 | 108 | After the Terraform code has finished executing, you can choose one of the following options to install Jenkins: 109 | 110 | ### Option 1.1 : Install Jenkins by SH Script 111 | 112 | ``` 113 | chmod 755 jenkins-installation-ubuntu.sh 114 | sudo sh jenkins-installation-ubuntu.sh 115 | ``` 116 | 117 | ### Option 1.2 : Manually Install Jenkins 118 | 119 | To manually install Jenkins, follow these steps: 120 | 121 | 1. SSH into the Ubuntu EC2 instance created by Terraform by running the command: 122 | `ssh -i deployer ubuntu@`. 123 | 124 | 2. Install Java by running the command: 125 | `sudo apt-get update && sudo apt-get install default-jdk`. 126 | 127 | 3. Add the Jenkins repository key by running the command: 128 | 129 | 4. Add the Jenkins repository by running the command: 130 | 131 | ``` 132 | 133 | sudo mkdir -p /usr/share/keyrings 134 | 135 | sudo curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null 136 | 137 | 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 138 | 139 | ``` 140 | 5. Update the package list by running the command, 141 | 142 | 6. Install Jenkins by running the command: 143 | 144 | ``` 145 | sudo apt-get update 146 | sudo apt-get install jenkins 147 | ``` 148 | ### Option 2: Use Terraform to Install Jenkins 149 | 150 | To use Terraform to install Jenkins, follow these steps: 151 | 152 | 1. SSH into the Ubuntu EC2 instance created by Terraform by running the command: 153 | `ssh -i deployer ubuntu@`. 154 | 155 | 2. Run the Jenkins installation script by running the command: 156 | `sudo sh /home/ubuntu/jenkins-installation-ubuntu.sh`. 157 | 158 | 3. The script will install Jenkins and its dependencies. Once the installation is complete, Jenkins will be running on the EC2 instance. 159 | 160 | ## Clean Up 161 | 162 | To destroy the EC2 instances and associated resources, run the command: `terraform destroy` 163 | 164 | Note: This will delete all resources created by Terraform in this branch. 165 | 166 | 167 | ## For More info on lab machine plz expend below: 168 | 169 |
170 | # Jenkins-cicd 171 | PG DO - CI/CD Pipeline with Jenkins Simplilearn 172 | 173 | # AWS Ubuntu VM Provisioning steps 174 | - Step 1: Click on Launch Instance 175 | - Step 2 : Click on Software Image (AMI) 176 | - Select Ubuntu 177 | - Step 4: Key pair name – required 178 | - Click on Create new key pair 179 | - Put key pair name Jenkins-sl 180 | - & Download it 181 | - Step 5 : Click on Launch Instance 182 | - Step 6 : Select your VM and Click connect 183 | - Step 7 : You can see the terminal 184 | - Step: Showing Github example 185 | 186 | # Git Status 187 | ``` 188 | git --version 189 | ``` 190 | ## cretae Dir 191 | ``` 192 | mkdir demo 193 | cd demo 194 | ``` 195 | ## GIT & Ubuntu SSH connection 196 | ``` 197 | ssh-keygen 198 | 199 | "Hit enter button 3 time" 200 | 201 | cat ~/.ssh/id_rsa.pub 202 | git clone git@github.com:manikcloud/Jenkins-cicd.git 203 | history 204 | history | cut -c 8- 205 | ``` 206 | 207 | # Jenkins installation on UBUNTU 18.04 & Ubuntu 22.04 208 | 209 | ### Step 1 210 | ``` 211 | sudo apt-get update -y && sudo apt install openjdk-8-jdk -y 212 | ``` 213 | ### Step 2: Downloading Key 214 | ``` 215 | sudo wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add 216 | ``` 217 | 218 | ### Step 3: Adding Key 219 | ``` 220 | sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' 221 | ``` 222 | 223 | ### Step 4: Jenkins Package installation 224 | ``` 225 | sudo apt-get update -y && sudo apt install jenkins -y 226 | sudo /etc/init.d/jenkins start 227 | sudo service jenkins status 228 | ``` 229 | ### Step 5: Jenkins default password 230 | ``` 231 | sudo cat /home/labsuser/jenkins/secrets/initialAdminPassword 232 | ``` 233 | ### Step 6: History command 234 | 235 | ``` 236 | history | cut -c 8- 237 | 238 | ``` 239 | # Jenkins URL with port 8080 240 | - http://x.x.x.x:8080/ 241 | 242 | Replace x with your ip 243 | 244 | # Change Security group rule for Jenkins 245 | ``` 246 | - Select your instance 247 | - Down below select your security tab 248 | - Click on the Security groups sg-0c51908b5fa4abf75 (launch-wizard-2) 249 | - Click on the action 250 | - Click on EDIT INBOUND RULE 251 | - Select custom TCP and put port 8080 252 | - Custom ip should be 0.0.0.0/0 253 | - Click on Save the rule 254 | ``` 255 | 256 | # Common error 257 | 258 | ``` 259 | getting "E: Unable to locate package openjdk-8-jdk" message on java update 260 | ``` 261 | 262 | # Resolution 263 | Run this command 264 | 265 | ``` 266 | sudo apt update -y 267 | ``` 268 | # Plugin Installation 269 | dashboard>manage>jenkins>manage plugins>maven integration 270 | 271 | 272 | 273 | # Jenkins Setting 274 | 275 | ``` 276 | Java_Home 277 | /usr/lib/jvm/java-8-openjdk-amd64/ 278 | ``` 279 | 280 | # Post Build Step 281 | 282 | ``` 283 | java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App 284 | 285 | ``` 286 | 287 | # This project is parameterized 288 | ``` 289 | echo "User First name is : $First_Name" 290 | echo "User Last name is : $Last_Name" 291 | echo "User Gender is : $Sex" 292 | 293 | ``` 294 |
295 | 296 | # References: 297 | 1. https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html 298 | 2. https://maven.apache.org/download.cgi 299 | 300 | ## Connect & Follow 301 | 302 | For more info, please connect and follow me: 303 | 304 | - Github: [https://github.com/manikcloud](https://github.com/manikcloud) 305 | - LinkedIn: [https://www.linkedin.com/in/vkmanik/](https://www.linkedin.com/in/vkmanik/) 306 | - Email: [varunmanik1@gmail.com](mailto:varunmanik1@gmail.com) 307 | - Facebook: [https://www.facebook.com/cloudvirtualization/](https://www.facebook.com/cloudvirtualization/) 308 | - YouTube: [https://bit.ly/32fknRN](https://bit.ly/32fknRN) 309 | - Twitter: [https://twitter.com/varunkmanik](https://twitter.com/varunkmanik) 310 | 311 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.2-node-ansible-playbook/node.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: webservers 3 | become: true 4 | tasks: 5 | - name: add apt key for nodesource 6 | become: true 7 | apt_key: 8 | url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key 9 | 10 | - name: add repo for nodesource 11 | become: true 12 | apt_repository: 13 | repo: 'deb https://deb.nodesource.com/node_0.10 {{ ansible_distribution_release }} main' 14 | update_cache: no 15 | 16 | - name: install nodejs 17 | become: true 18 | apt: 19 | name: nodejs 20 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.3-apache-ansible-playbook/apache.yaml: -------------------------------------------------------------------------------- 1 | hosts: webservers 2 | become: true 3 | tasks: 4 | - name: install apache2 5 | apt: name=apache2 update_cache=no state=latest 6 | - name: enabled mod_rewrite 7 | apache2_module: name=rewrite state=present 8 | notify: 9 | - restart apache2 10 | 11 | handlers: 12 | - name: restart apache2 13 | service: name=apache2 state=restarted 14 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.4-ansible-module/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | ## Lesson 06 Demo 4 - Ansible Modules 4 | 5 | This document provides the steps to execute Ansible modules on a local server. 6 | 7 | ### Steps to be performed: 8 | 9 | 1. Execute Ansible modules on a local server. 10 | 11 | #### Step 1: Executing Ansible modules with local server 12 | 13 | 1.1 Run the below commands in the given sequence to execute different Ansible modules. 14 | 15 | ``` 16 | ansible -m setup all 17 | ansible all -m shell -a 'hostname' 18 | ansible webservers -m apt -a 'name=git state=present' --become 19 | ansible webservers -m file -a 'dest=/root/sample.txt state=touch mode=600 owner=root group=root' --become 20 | ``` 21 | 22 | ## description of the commands used in the README: 23 | 24 | - 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. 25 | 26 | - 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. 27 | 28 | - 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. 29 | 30 | - 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. 31 | 32 | 33 | # Step 1: Ansible Ad-hoc Command without Configuration Files 34 | ``` 35 | ansible all -i '18.209.59.137,' -m ping -u ubuntu --private-key ../deployer 36 | ``` 37 | 38 | # Step 2: Add Inventory File (inventory.ini) 39 | echo "[my_servers]\nmy_server ansible_host=18.209.59.137" > inventory.ini 40 | ``` 41 | 42 | ansible my_servers -i inventory.ini -m ping -u ubuntu --private-key ../deployer 43 | ``` 44 | 45 | 46 | # Step 3: Add Ansible Configuration File (ansible.cfg) 47 | 48 | echo -e "[defaults]\ninventory = inventory.ini\nremote_user = ubuntu\nprivate_key_file = ../deployer\nhost_key_checking = False\nretry_files_enabled = False" > ansible.cfg 49 | ``` 50 | 51 | ansible my_servers -m ping 52 | ``` 53 | 54 | 55 | # Step 4: Simplified Ansible Command with Configuration Files 56 | ``` 57 | 58 | ansible my_servers -m ping 59 | ``` 60 | 61 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.5-ansible-role/README.md: -------------------------------------------------------------------------------- 1 | ## Lesson 06 Demo 5 - Creating and Working with Ansible Roles 2 | 3 | This document provides the steps to create and work with Ansible roles. 4 | 5 | ### Steps to be performed: 6 | 7 | 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) 8 | 2. Create Ansible Role 9 | 3. Create Ansible tasks 10 | 4. Create Ansible template 11 | 5. Create Ansible variable 12 | 6. Remove unwanted directory 13 | 7. Create Ansible role playbook 14 | 8. Deploy Ansible role playbook 15 | 16 | ## Step 1: Install Ansible on Ubuntu, and establish connectivity between Ansible controller and node machine 17 | 18 | If Ansible is not installed on the Ubuntu system, use the following commands to install Ansible: 19 | 20 | ``` 21 | sudo apt-get install -f 22 | sudo apt-get install software-properties-common 23 | sudo apt-add-repository ppa:ansible/ansible 24 | sudo apt-get update 25 | sudo apt-get install ansible 26 | ``` 27 | 28 | ## Step 2: Create Ansible Role 29 | 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: 30 | 31 | 32 | 33 | ``` 34 | 35 | mkdir base 36 | cd base 37 | ``` 38 | 39 | 2.2 To create an Ansible role, use ansible-galaxy init to create the role directory structure: 40 | 41 | ``` 42 | 43 | cd roles 44 | ansible-galaxy init demor 45 | cd demor 46 | ``` 47 | 48 | 49 | 2.3 You can use the ls command to list the Ansible role directory structure. 50 | 51 | ## Step 3: Create Ansible Tasks 52 | 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. 53 | 54 | 55 | ``` 56 | 57 | 58 | cd tasks 59 | ls 60 | vi main.yml 61 | ``` 62 | 63 | 3.2 Enter the following code: 64 | 65 | 66 | # tasks file for demor 67 | ``` 68 | 69 | - name: copy demor file 70 | template: 71 | src: templates/demor.j2 72 | dest: /etc/demor 73 | owner: root 74 | group: root 75 | mode: 0444 76 | ``` 77 | 78 | ## Step 4: Create Ansible Template 79 | 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. 80 | 81 | 82 | 83 | ``` 84 | 85 | cd .. 86 | cd templates 87 | vi demor.j2 88 | ``` 89 | 90 | 4.2 Enter the following details: 91 | 92 | 93 | ``` 94 | 95 | Welcome to {{ ansible_hostname }} 96 | 97 | This file was created on {{ ansible_date_time.date }} 98 | Go away if you have no business being here 99 | 100 | Contact {{ system_manager }} if anything is wrong 101 | ``` 102 | 103 | ## Step 5: Create Ansible Variable 104 | 5.1 We will use the defaults folder to define custom variables which are used in our template file templates/demor.j2. 105 | 106 | 107 | 108 | ``` 109 | 110 | cd .. 111 | cd defaults 112 | ls 113 | vi main.yml 114 | ``` 115 | 116 | 5.2 Enter the following details in the file: 117 | 118 | ``` 119 | # defaults file for demor 120 | system_manager: admin@golinuxcloud.com 121 | ``` 122 | 123 | ## Step 6: Remove unwanted directories (Optional) 124 | 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. 125 | 126 | 127 | ``` 128 | 129 | 130 | cd .. 131 | rm -rf handlers tests vars 132 | ``` 133 | 134 | 135 | ## Step 7: Create an Ansible Role Playbook 136 | 137 | 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. 138 | 139 | ``` 140 | cd .. 141 | cd .. 142 | sudo vi demor-role.yml 143 | ``` 144 | 145 | 146 | 7.2 Enter the following code in the file: 147 | 148 | ``` 149 | 150 | 151 | --- 152 | - name: use demor role playbook 153 | hosts: webservers 154 | user: ansible 155 | become: true 156 | 157 | roles: 158 | - role: demor 159 | system_manager: admin@golinuxcloud.com 160 | ``` 161 | 162 | ## Step 8: Deploy Ansible Role Playbook 163 | 8.1 Execute the following command: 164 | 165 | 166 | ``` 167 | 168 | 169 | ansible-playbook demor-role.yml 170 | ``` 171 | 172 | 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. 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.5-ansible-role/ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | inventory = inventory.ini 3 | remote_user = ubuntu 4 | private_key_file = ./deployer 5 | host_key_checking = False 6 | retry_files_enabled = False 7 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.5-ansible-role/demor-role.yml: -------------------------------------------------------------------------------- 1 | 2 | 3 | --- 4 | - name: use demor role playbook 5 | hosts: localhost 6 | user: ubuntu 7 | become: true 8 | 9 | roles: 10 | - role: demor 11 | system_manager: admin@golinuxcloud.com 12 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.5-ansible-role/demor/.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: python 3 | python: "2.7" 4 | 5 | # Use the new container infrastructure 6 | sudo: false 7 | 8 | # Install ansible 9 | addons: 10 | apt: 11 | packages: 12 | - python-pip 13 | 14 | install: 15 | # Install ansible 16 | - pip install ansible 17 | 18 | # Check ansible version 19 | - ansible --version 20 | 21 | # Create ansible.cfg with correct roles_path 22 | - printf '[defaults]\nroles_path=../' >ansible.cfg 23 | 24 | script: 25 | # Basic role syntax check 26 | - ansible-playbook tests/test.yml -i tests/inventory --syntax-check 27 | 28 | notifications: 29 | webhooks: https://galaxy.ansible.com/api/v1/notifications/ -------------------------------------------------------------------------------- /6-ansible-terraform/6.5-ansible-role/demor/README.md: -------------------------------------------------------------------------------- 1 | Role Name 2 | ========= 3 | 4 | A brief description of the role goes here. 5 | 6 | Requirements 7 | ------------ 8 | 9 | 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. 10 | 11 | Role Variables 12 | -------------- 13 | 14 | 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. 15 | 16 | Dependencies 17 | ------------ 18 | 19 | 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. 20 | 21 | Example Playbook 22 | ---------------- 23 | 24 | Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: 25 | 26 | - hosts: servers 27 | roles: 28 | - { role: username.rolename, x: 42 } 29 | 30 | License 31 | ------- 32 | 33 | BSD 34 | 35 | Author Information 36 | ------------------ 37 | 38 | An optional section for the role authors to include contact information, or a website (HTML is not allowed). 39 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.5-ansible-role/demor/defaults/main.yml: -------------------------------------------------------------------------------- 1 | # defaults file for demor 2 | system_manager: admin@golinuxcloud.com 3 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.5-ansible-role/demor/meta/main.yml: -------------------------------------------------------------------------------- 1 | galaxy_info: 2 | author: Varun 3 | description: Cloud Engineer 4 | company: your company (optional) 5 | 6 | # If the issue tracker for your role is not on github, uncomment the 7 | # next line and provide a value 8 | # issue_tracker_url: http://example.com/issue/tracker 9 | 10 | # Choose a valid license ID from https://spdx.org - some suggested licenses: 11 | # - BSD-3-Clause (default) 12 | # - MIT 13 | # - GPL-2.0-or-later 14 | # - GPL-3.0-only 15 | # - Apache-2.0 16 | # - CC-BY-4.0 17 | license: license (GPL-2.0-or-later, MIT, etc) 18 | 19 | min_ansible_version: 2.1 20 | 21 | # If this a Container Enabled role, provide the minimum Ansible Container version. 22 | # min_ansible_container_version: 23 | 24 | # 25 | # Provide a list of supported platforms, and for each platform a list of versions. 26 | # If you don't wish to enumerate all versions for a particular platform, use 'all'. 27 | # To view available platforms and versions (or releases), visit: 28 | # https://galaxy.ansible.com/api/v1/platforms/ 29 | # 30 | # platforms: 31 | # - name: Fedora 32 | # versions: 33 | # - all 34 | # - 25 35 | # - name: SomePlatform 36 | # versions: 37 | # - all 38 | # - 1.0 39 | # - 7 40 | # - 99.99 41 | 42 | galaxy_tags: [] 43 | # List tags for your role here, one per line. A tag is a keyword that describes 44 | # and categorizes the role. Users find roles by searching for tags. Be sure to 45 | # remove the '[]' above, if you add tags to this list. 46 | # 47 | # NOTE: A tag is limited to a single word comprised of alphanumeric characters. 48 | # Maximum 20 tags per role. 49 | 50 | dependencies: [] 51 | # List your role dependencies here, one per line. Be sure to remove the '[]' above, 52 | # if you add dependencies to this list. 53 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.5-ansible-role/demor/tasks/main.yml: -------------------------------------------------------------------------------- 1 | 2 | - name: copy demor file 3 | template: 4 | src: templates/demor.j2 5 | dest: /etc/demor 6 | owner: root 7 | group: root 8 | mode: 0444 9 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.5-ansible-role/demor/templates/demor.j2: -------------------------------------------------------------------------------- 1 | 2 | Welcome to {{ ansible_hostname }} 3 | 4 | This file was created on {{ ansible_date_time.date }} 5 | Go away if you have no business being here 6 | 7 | Contact {{ system_manager }} if anything is wrong 8 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.5-ansible-role/deployer: -------------------------------------------------------------------------------- 1 | -----BEGIN OPENSSH PRIVATE KEY----- 2 | b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn 3 | NhAAAAAwEAAQAAAYEAw/IExD9MHaiZx5FQ3OyDMxcoKbIm03pmcpWb5OIHBommvmF/P1aV 4 | BMjq6mDoP/DqzgLHUAqT3HPCdwIVAUr4I3inO7CWdDfL/gDip1UA54v8vvZlg+qBjrM8x+ 5 | g1X6BzstR0WQGxep/sRZJNA3orEidxbBlUCvyea2IF1QgSYot+Ji9PgzgaIMS72vLQ3C4F 6 | i8/qsbPEHB+IYKx5HU/MIQSnynMqSAhkuFP1oFxVuTN6TeDsp0s3qifYF59BW6udCf7egq 7 | Z6+sKpc0c6HADF55YK3IWGVmSYEy91vM64NRce0Qct3wGxMlqMq5AfXBSD0pJolGRvcVIY 8 | qyODG3YB1TZZKe8VNFeinwkZUzRPsc1pWz0oGu5I5aoos4w6Ee8RMSjS2zbYQep5TSBMF/ 9 | hZY7YK06jFdsOpPB98X64XRtPfdxJzDMHT1ZpbRIyXmfpdwRE1HImyhhRXOYskffVuzSoa 10 | 4h+Xejr213r+yZm6rF68J/K57t2rgxibO2GiMM5pAAAFmKv3VXqr91V6AAAAB3NzaC1yc2 11 | EAAAGBAMPyBMQ/TB2omceRUNzsgzMXKCmyJtN6ZnKVm+TiBwaJpr5hfz9WlQTI6upg6D/w 12 | 6s4Cx1AKk9xzwncCFQFK+CN4pzuwlnQ3y/4A4qdVAOeL/L72ZYPqgY6zPMfoNV+gc7LUdF 13 | kBsXqf7EWSTQN6KxIncWwZVAr8nmtiBdUIEmKLfiYvT4M4GiDEu9ry0NwuBYvP6rGzxBwf 14 | iGCseR1PzCEEp8pzKkgIZLhT9aBcVbkzek3g7KdLN6on2BefQVurnQn+3oKmevrCqXNHOh 15 | wAxeeWCtyFhlZkmBMvdbzOuDUXHtEHLd8BsTJajKuQH1wUg9KSaJRkb3FSGKsjgxt2AdU2 16 | WSnvFTRXop8JGVM0T7HNaVs9KBruSOWqKLOMOhHvETEo0ts22EHqeU0gTBf4WWO2CtOoxX 17 | bDqTwffF+uF0bT33cScwzB09WaW0SMl5n6XcERNRyJsoYUVzmLJH31bs0qGuIfl3o69td6 18 | /smZuqxevCfyue7dq4MYmzthojDOaQAAAAMBAAEAAAGBAIVNW7LKwRSYQ+4BzTpO6L7ULS 19 | 2YllNevN2NLF5c6pym/rocB/5l/8EekrparQX69zKpr0CjwY3DbvOZhgK4JvGyvkqcSu7L 20 | msq1fXyLFq9vi8W6SLuiyPr0sw/oyI7C0JNDd9epkD01GP8Hlb8c2Lpj/QSmgodq7rdtGz 21 | yfXiqObYa6vuQtQZEzZf2BHVf9Mya3jxnPi0X6qcPi8g5f4CZCTYgsKwKQOz0vWTX8OxFg 22 | lP7wWu9A+6CVtKv1WvhrWZy0g68CaMsBRZ2weZ1K4ScqbZvJdvWPfJzY0rJgJk7wNPA5Ak 23 | QEG+IaMtmFQ5phGEcxqXkoGcSlLEW7P8XMwLHTWdlFAgVwrWsvmU8dzZ+tOa82ZY8tIF+B 24 | wzzYgFZoO3H4fFXd3sXx7f/ME5a1NTTiEU/8I16omN8xdrDSVHbJd4stljpUGda6iTgF2s 25 | khXmZ7dxCq/ZDlbCQwsumzbmPz+ass13/bP/PG7e92CRhwxrRELQij0DWpRiLPc13c0QAA 26 | AMEAg+5tOG/WZA1P8KfeDmZXImTWOuTnaOZzYRI9ZXFpF9gUa+zYO/0l5br4I0/SKQJs0Y 27 | C+XIamiN7HoOjH4MDkqTHrmkliGsJ0Z5Ag/u6eEEvXqMqkdJ8dbhP9aHVUhPUJ9AuJ7Bsf 28 | Jgy/hgjkntf165K83Gkrgmcql+iPOxA9EjrWFRuWdTrMFRJgqTirtwMPI7ywKXkXKB5tX+ 29 | AqgpPb2s7cj00B4pQku9RA0apE0UOcRzEiAMUpP9egTHBIN1XzAAAAwQDnJbhvuZkZxKjD 30 | KMJsta1nom0+TLNxix7y/oOaX+YRmYY+6vS7WHCY5qg/7wUNd6npTS/QU1FoL0HsQalVwy 31 | YDYoUAbmfdT2xQEUesO6cKpFNfI+ToolsZppp+Nuqi60FEFE+S/pV/4gMxQnt0DcQ/Wumu 32 | R/eBTBdjbFh4ZkedPIulue6XxtBmhfzor8IGNklChWrKib47D0/LN5AJA62uriQmo23yKG 33 | AVDYuhSnEOt4yPZgW5e0tVrajkUti0cpUAAADBANkDXzsfmG1GyF9I68NdLhDfU0huxRWs 34 | 8bVPX92eKI2HKZ/ZzHx9s3gwkz/nj2iCmIKOEI0S7qNkGGjt+vQ+qH7oxWhjW4t8S7b/pe 35 | JBVDvRUGNk2XIYk5Jdcgv+VPJDrfe51IV6cXxxkmOU5asMgvlsMue8pKuiBw/HgdmNOQBp 36 | 9Y/NSXLTUDh0jOwFyryYZKDZPSaP/iWN38Y3v6UHwa9wz0AnL1Iv1sT12sui9dEQ9hdTDd 37 | thvT0LVaxmsBlrhQAAACB2YXJ1bm1hbmlrb3V0bG9AaXAtMTcyLTMxLTE3LTIwNgE= 38 | -----END OPENSSH PRIVATE KEY----- 39 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.5-ansible-role/deployer.pub: -------------------------------------------------------------------------------- 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 2 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.5-ansible-role/host_vars.yml: -------------------------------------------------------------------------------- 1 | --- 2 | ansible_user: ubuntu 3 | ansible_ssh_private_key_file: ./deployer 4 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.5-ansible-role/inventory.ini: -------------------------------------------------------------------------------- 1 | [my_servers] 2 | my_server ansible_host=localhost 3 | # my_server ansible_host=54.224.173.170 4 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.6-setup-terraform/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Lesson 06 Demo 6 3 | ## Set up Terraform 4 | 5 | Steps to be performed: 6 | 7 | ## Install Terraform from SH Script 8 | 9 | ``` 10 | sudo chmod 755 tf-installation.sh 11 | sudo sh tf-installation.sh 12 | 13 | ``` 14 | 15 | 16 | ## Create an AWS Account 17 | 18 | 1. Go to the AWS website and click on the "Create an AWS Account" button. 19 | 2. Follow the on-screen instructions to create your account. 20 | 3. Once your account is created, log in to the AWS Management Console. 21 | 22 | ### Create Access Keys in IAM 23 | 24 | 1. In the AWS Management Console, navigate to the IAM service. 25 | 2. Click on "Users" in the left sidebar, and then click on the "Add User" button. 26 | 3. Enter a user name and select "Programmatic Access" as the access type. 27 | 4. Click on the "Next: Permissions" button. 28 | 5. Choose the appropriate permissions for your user, or attach an existing policy. 29 | 6. Click on the "Next: Tags" button. 30 | 7. Add any tags (optional) and click on the "Next: Review" button. 31 | 8. Review your settings and click on the "Create User" button. 32 | 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. 33 | 34 | ### Install AWS CLI and Configure it 35 | 36 | 1. Install AWS CLI using the following command: 37 | ``` 38 | sudo apt-get install awscli 39 | ``` 40 | 2. Run the command `aws configure` to configure your access key ID, secret access key, default region, and output format. 41 | 42 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.6-setup-terraform/tf-installation.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Set the desired Terraform version 4 | TERRAFORM_VERSION="1.4.5" 5 | 6 | # Download Terraform 7 | wget "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" 8 | 9 | # Install unzip if not installed 10 | sudo apt-get update 11 | sudo apt-get install -y unzip 12 | 13 | # Unzip the Terraform package 14 | unzip "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" 15 | 16 | # Move the Terraform binary to the /usr/local/bin folder 17 | sudo cp terraform /usr/local/bin/ 18 | sudo mv terraform /usr/bin/ 19 | 20 | # Clean up the downloaded zip file 21 | rm "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" 22 | 23 | # Verify the installation 24 | terraform --version -------------------------------------------------------------------------------- /6-ansible-terraform/6.6.1-tf-local-file/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/local" { 5 | version = "2.4.1" 6 | hashes = [ 7 | "h1:FzraUapGrJoH3ZOWiUT2m6QpZAD+HmU+JmqZgM4/o2Y=", 8 | "zh:244b445bf34ddbd167731cc6c6b95bbed231dc4493f8cc34bd6850cfe1f78528", 9 | "zh:3c330bdb626123228a0d1b1daa6c741b4d5d484ab1c7ae5d2f48d4c9885cc5e9", 10 | "zh:5ff5f9b791ddd7557e815449173f2db38d338e674d2d91800ac6e6d808de1d1d", 11 | "zh:70206147104f4bf26ae67d730c995772f85bf23e28c2c2e7612c74f4dae3c46f", 12 | "zh:75029676993accd6bef933c196b2fad51a9ec8a69a847dbbe96ec8ebf7926cdc", 13 | "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", 14 | "zh:7d48d5999fe1fcdae9295a7c3448ac1541f5a24c474bd82df6d4fa3732483f2b", 15 | "zh:b766b38b027f0f84028244d1c2f990431a37d4fc3ac645962924554016507e77", 16 | "zh:bfc7ad301dada204cf51c59d8bd6a9a87de5fddb42190b4d6ba157d6e08a1f10", 17 | "zh:c902b527702a8c5e2c25a6637d07bbb1690cb6c1e63917a5f6dc460efd18d43f", 18 | "zh:d68ae0e1070cf429c46586bc87580c3ed113f76241da2b6e4f1a8348126b3c46", 19 | "zh:f4903fd89f7c92a346ae9e666c2d0b6884c4474ae109e9b4bd15e7efaa4bfc29", 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.6.1-tf-local-file/index.html: -------------------------------------------------------------------------------- 1 | Hi How are you ? -------------------------------------------------------------------------------- /6-ansible-terraform/6.6.1-tf-local-file/main.tf: -------------------------------------------------------------------------------- 1 | resource "local_file" "index_file" { 2 | 3 | content = "Hi How are you ?" 4 | 5 | filename = "index.html" 6 | 7 | } 8 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/.gitignore: -------------------------------------------------------------------------------- 1 | # Local .terraform directories 2 | **/.terraform/* 3 | 4 | # .tfstate files 5 | *.tfstate 6 | *.tfstate.* 7 | 8 | # Crash log files 9 | crash.log 10 | 11 | # Ignore any .tfvars files that are generated automatically for each Terraform run. Most 12 | # .tfvars files are managed as part of configuration and so should be included in 13 | # version control. 14 | # 15 | # example.tfvars 16 | 17 | # Ignore override files as they are usually used to override resources locally and so 18 | # are not checked in 19 | override.tf 20 | override.tf.json 21 | *_override.tf 22 | *_override.tf.json 23 | 24 | # Include override files you do wish to add to version control using negated pattern 25 | # 26 | # !example_override.tf 27 | 28 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 29 | # example: *tfplan* 30 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "4.66.1" 6 | hashes = [ 7 | "h1:D/qzK7fE3pgdg25W1u5GqI+VILy8UmhzXruz6c8rJ7g=", 8 | "zh:001c707174b7d6bf89a96cf806f925bb852d1a285fb80b81222cbeb4743bcb79", 9 | "zh:19bc6ac0a7fd1c564fd56c536f1743f71a5e7ca724e21ea51a6a79218939733d", 10 | "zh:3dac5c27f40b511239e9fe6f97dc0b6c95f630ba328001820ddc764e766a5ca2", 11 | "zh:49092c92e2565db4cd4c98ec6878386e6957525d3392b63f0d5df4c48a7c1913", 12 | "zh:4f9e2e1d0c5365a4e6689096cc91ba88ca9c0dc7c633377ba674c1dd856b6a9f", 13 | "zh:57e32bb454f2dc17d5631a9559e36188761d8ae95a452478f81f41bb568a3a42", 14 | "zh:678b78ba629dd833f0705ac90630969f514a54013ab9713ce7ceda55fc5ea138", 15 | "zh:8aab1d76348cf2a685f72382cb838a910b77353179e81ab5794b9c45c8fb36a3", 16 | "zh:8b6791bf0948aa8b49258863992a8ad7e7332dcae1a889e86da0e5ab778dc3b6", 17 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 18 | "zh:a36f2777452c2cebdaa8a27378416d512ead367acc078a671bb12276dd4bc9dd", 19 | "zh:c492e6f685882fad6481f4793e696d9e1b01aaae419225c2db0a484b632d1cac", 20 | "zh:d4418e0d1d18e321db364a91d7a768e274bb0fb46df9f3cb5b9debb2bb6917b9", 21 | "zh:d5b4310ef2b2ec22ae14cf909deb1231b56bdd79dc2b51e5db4e46a05e0110c4", 22 | "zh:dedfb01e26b34fb61a52b7e953b8bf5d7a69971187e91697b67221298bbed377", 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/README.md: -------------------------------------------------------------------------------- 1 | # Lesson 06 Demo 7 - Create an S3 Bucket Using Terraform 2 | 3 | This document provides the steps to create an S3 bucket using Terraform. 4 | 5 | ## Steps to be performed 6 | 7 | 1. Set up Terraform components 8 | 2. Create Terraform execution plan 9 | 10 | ## Step 1: Set up Terraform components 11 | 12 | 1.1 Run the following commands in the given sequence to set up the Terraform component: 13 | 14 | ``` 15 | pip install awscli 16 | sudo apt-get update 17 | ``` 18 | 19 | 1.2 Create a new file to execute this project. 20 | 21 | 22 | 23 | ``` 24 | 25 | mkdir s3back 26 | cd s3back 27 | ``` 28 | 29 | ## Step 2: Create a Terraform execution plan 30 | 2.1 Create creds.tf under s3back and add the following code: 31 | 32 | 33 | 34 | ``` 35 | 36 | nano creds.tf 37 | ``` 38 | 39 | 2.2 Paste the following code: 40 | 41 | 42 | ``` 43 | 44 | 45 | provider "aws" { 46 | access_key = "" 47 | secret_key = "" 48 | token = "" 49 | region = "us-east-1" 50 | } 51 | ``` 52 | 53 | 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. 54 | 55 | 2.3 Create main.tf under s3back and run the following code: 56 | 57 | 58 | 59 | ``` 60 | 61 | nano main.tf 62 | ``` 63 | 64 | 2.4 Paste the following code: 65 | 66 | 67 | 68 | ``` 69 | 70 | resource "aws_s3_bucket" "b" { 71 | bucket = "my-tf-test-bucket" 72 | acl = "private" 73 | 74 | tags = { 75 | Name = "My bucket" 76 | Environment = "Dev" 77 | } 78 | } 79 | 80 | ``` 81 | 82 | Note: Bucket name (here my-tf-test-bucket) entered here should be unique globally otherwise it may throw an error while executing the script. 83 | 84 | 2.5 Run the following commands in the given sequence to add the AWS providers: 85 | 86 | 87 | 88 | ``` 89 | 90 | terraform init 91 | ``` 92 | 93 | 2.6 Run the following command to commit TF state: 94 | 95 | 96 | 97 | ``` 98 | 99 | terraform plan 100 | ``` 101 | 102 | 2.7 Run the following command to create the S3 bucket: 103 | 104 | 105 | 106 | ``` 107 | 108 | terraform apply 109 | ``` 110 | 111 | **Enter a value: Yes** 112 | 113 | 2.8 Verify the creation of S3 bucket in the AWS Management console. 114 | 115 | 116 | --- 117 | 118 | # Creating and Using Secret Access Keys and Access IDs in AWS IAM for Linux VMs 119 | 120 | ## Steps 121 | 122 | 1. **Create an IAM User:** 123 | - Access the AWS Management Console and navigate to IAM. 124 | - Click "Users" -> "Add user." 125 | - Assign a meaningful username and select "Programmatic access." 126 | - Click "Next: Permissions." 127 | 128 | 2. **Attach Permissions:** 129 | - Choose an existing policy or create a custom one, granting only necessary permissions. 130 | - Click "Next: Tags." 131 | - Optionally add tags. 132 | - Click "Next: Review." 133 | - Verify details and click "Create user." 134 | 135 | 3. **Securely Store Access Key and ID:** 136 | - Immediately download and securely store the secret access key (not retrievable later). 137 | - Note the access key ID. 138 | 139 | 4. **Add Credentials to Linux VM:** 140 | - Choose a secure storage method: 141 | 142 | - **Environment variables (temporary):** 143 | ```bash 144 | export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY_ID 145 | export AWS_SECRET_ACCESS_KEY=YOUR_SECRET_ACCESS_KEY 146 | ``` 147 | 148 | - **AWS CLI configuration file:** 149 | Create `~/.aws/credentials`: 150 | ``` 151 | [default] 152 | aws_access_key_id = YOUR_ACCESS_KEY_ID 153 | aws_secret_access_key = YOUR_SECRET_ACCESS_KEY 154 | 155 | 156 | - **AWS SDK environment variables:** 157 | Set `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` for applications using the SDK. 158 | 159 | ## Security Best Practices 160 | 161 | - **Avoid hardcoding access keys:** Use AWS Secrets Manager or similar for secure storage and rotation. 162 | - **Regularly rotate access keys:** Enhance security. 163 | - **Use strong passwords for IAM users:** Strengthen protection. 164 | - **Enable MFA:** Add a layer of security. 165 | - **Implement AWS CloudTrail:** Log API activity for auditing and analysis. 166 | - **Regularly review and update permissions:** Maintain least privilege. 167 | 168 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/creds.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | access_key = "" 3 | secret_key = "" 4 | token = "" 5 | region = "us-east-1" 6 | } -------------------------------------------------------------------------------- /6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/main.tf: -------------------------------------------------------------------------------- 1 | 2 | resource "aws_s3_bucket" "bucket" { 3 | bucket = "varun-tf-test-bucket-0acb9876" 4 | acl = "private" 5 | 6 | tags = { 7 | Name = "My bucket" 8 | Environment = "Dev" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/.gitignore: -------------------------------------------------------------------------------- 1 | # Local .terraform directories 2 | **/.terraform/* 3 | 4 | # .tfstate files 5 | *.tfstate 6 | *.tfstate.* 7 | 8 | # Crash log files 9 | crash.log 10 | 11 | # Ignore any .tfvars files that are generated automatically for each Terraform run. Most 12 | # .tfvars files are managed as part of configuration and so should be included in 13 | # version control. 14 | # 15 | # example.tfvars 16 | 17 | # Ignore override files as they are usually used to override resources locally and so 18 | # are not checked in 19 | override.tf 20 | override.tf.json 21 | *_override.tf 22 | *_override.tf.json 23 | 24 | # Include override files you do wish to add to version control using negated pattern 25 | # 26 | # !example_override.tf 27 | 28 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 29 | # example: *tfplan* 30 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/aws" { 5 | version = "3.76.1" 6 | constraints = "~> 3.27" 7 | hashes = [ 8 | "h1:5WSHHV9CgBvZ0rDDDxLnNHsjDfm4knb7ihJ2AIGB58A=", 9 | "zh:1cf933104a641ffdb64d71a76806f4df35d19101b47e0eb02c9c36bd64bfdd2d", 10 | "zh:273afaf908775ade6c9d32462938e7739ee8b00a0de2ef3cdddc5bc115bb1d4f", 11 | "zh:2bc24ae989e38f575de034083082c69b41c54b8df69d35728853257c400ce0f4", 12 | "zh:53ba88dbdaf9f818d35001c3d519a787f457283d9341f562dc3d0af51fd9606e", 13 | "zh:5cdac7afea68bbd89d3bdb345d99470226482eff41f375f220fe338d2e5808da", 14 | "zh:63127808890ac4be6cff6554985510b15ac715df698d550a3e722722dc56523c", 15 | "zh:97a1237791f15373743189b078a0e0f2fa4dd7d7474077423376cd186312dc55", 16 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 17 | "zh:a4f625e97e5f25073c08080e4a619f959bc0149fc853a6b1b49ab41d58b59665", 18 | "zh:b56cca54019237941f7614e8d2712586a6ab3092e8e9492c70f06563259171e9", 19 | "zh:d4bc33bfd6ac78fb61e6d48a61c179907dfdbdf149b89fb97272c663989a7fcd", 20 | "zh:e0089d73fa56d128c574601305634a774eebacf4a84babba71da10040cecf99a", 21 | "zh:e957531f1d92a6474c9b02bd9200da91b99ba07a0ab761c8e3176400dd41721c", 22 | "zh:eceb85818d57d8270db4df7564cf4ed51b5c650a361aaa017c42227158e1946b", 23 | "zh:f565e5caa1b349ec404c6d03d01c68b02233f5485ed038d0aab810dd4023a880", 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/README.md: -------------------------------------------------------------------------------- 1 | # Create EC2 instances with Terraform 2 | 3 | This branch contains Terraform code to create EC2 instances in AWS. 4 | 5 | ## Related Blog Posts By Author: 6 | 7 | - [DevSecOps CI/CD Java Tomcat Project](https://varunmanik1.medium.com/devsecops-cicd-java-tomcat-project-141d6b73e436) 8 | - [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) 9 | - [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) 10 | 11 | 12 | ## Prerequisites 13 | 14 | Before you start, make sure you have the following: 15 | 16 | - An AWS account, with ec2 full access permission 17 | - And Linux Terminal, wher you can run all these commands 18 | 19 | ## Files 20 | 21 | - `README.md`: This file, providing an overview of the branch. 22 | - `deployer` and `deployer.pub`: SSH keys for accessing the EC2 instances. 23 | - `history.txt`: A text file with a record of changes to this project. 24 | - `jenkins-installation-ubuntu.sh`: A shell script to install Jenkins on the EC2 instance. 25 | - `main.tf`: The main Terraform configuration file that creates the AWS resources. 26 | - `slave-vm.tf`: A Terraform configuration file that creates a Jenkins slave instance. 27 | - `tf-cli-installation.sh`: A shell script to install the Terraform CLI on the EC2 instance. 28 | - `ubuntu-vm.tf`: A Terraform configuration file that creates an Ubuntu EC2 instance. 29 | 30 | ## Usage 31 | 32 | To create EC2 instances with Terraform, follow these steps: 33 | 34 | 1. Clone this repository to your local machine by running the command: `git clone https://github.com/manikcloud/Jenkins-cicd.git`. 35 | 2. Switch to the `0.1_create_ec2_tf` branch by running the command: `git checkout 0.1_create_ec2_tf`. 36 | 3. Navigate to the `terraform` directory by running the command: `cd terraform`. 37 | 4. Initialize Terraform by running the command: `terraform init`. 38 | 5. Create an execution plan by running the command: `terraform plan`. 39 | 6. Apply the execution plan by running the command: `terraform apply`. 40 | 41 | You will be prompted to enter values for the variables defined in the `variables.tf` file. 42 | 43 | 44 | Create an AWS Account 45 | 46 | 1. Go to the AWS website and click on the "Create an AWS Account" button. 47 | 2. Follow the on-screen instructions to create your account. 48 | 3. Once your account is created, log in to the AWS Management Console. 49 | 50 | ### Create Access Keys in IAM 51 | 52 | 1. In the AWS Management Console, navigate to the IAM service. 53 | 2. Click on "Users" in the left sidebar, and then click on the "Add User" button. 54 | 3. Enter a user name and select "Programmatic Access" as the access type. 55 | 4. Click on the "Next: Permissions" button. 56 | 5. Choose the appropriate permissions for your user, or attach an existing policy. 57 | 6. Click on the "Next: Tags" button. 58 | 7. Add any tags (optional) and click on the "Next: Review" button. 59 | 8. Review your settings and click on the "Create User" button. 60 | 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. 61 | 62 | ### Install AWS CLI and Configure it 63 | 64 | 1. Install AWS CLI using the following command: 65 | ``` 66 | sudo apt-get install awscli 67 | ``` 68 | 2. Run the command `aws configure` to configure your access key ID, secret access key, default region, and output format. 69 | 70 | ## Install Terraform from SH Script 71 | 72 | ``` 73 | sudo chmod 755 chmod 755 tf-cli-installation.sh 74 | sudo sh chmod 755 tf-cli-installation.sh 75 | 76 | ``` 77 | # OR 78 | 79 | ## Install Terraform Manual 80 | 1. Set the desired Terraform version: `TERRAFORM_VERSION="1.4.5"` 81 | 2. Download Terraform: 82 | ``` 83 | wget "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" 84 | ``` 85 | 3. Install unzip if not installed: 86 | ``` 87 | sudo apt-get update && sudo apt-get install -y unzip 88 | ``` 89 | 4. Unzip the Terraform package: 90 | ``` 91 | unzip "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" 92 | ``` 93 | 5. Move the Terraform binary to the /usr/local/bin folder: 94 | ``` 95 | sudo cp terraform /usr/local/bin/ && sudo mv terraform /usr/bin/ 96 | ``` 97 | 6. Clean up the downloaded zip file: 98 | ``` 99 | rm "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" 100 | ``` 101 | 7. Verify the installation: 102 | ``` 103 | terraform --version 104 | ``` 105 | 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. 106 | 107 | 108 | After the Terraform code has finished executing, you can choose one of the following options to install Jenkins: 109 | 110 | ### Option 1.1 : Install Jenkins by SH Script 111 | 112 | ``` 113 | chmod 755 jenkins-installation-ubuntu.sh 114 | sudo sh jenkins-installation-ubuntu.sh 115 | ``` 116 | 117 | ### Option 1.2 : Manually Install Jenkins 118 | 119 | To manually install Jenkins, follow these steps: 120 | 121 | 1. SSH into the Ubuntu EC2 instance created by Terraform by running the command: 122 | `ssh -i deployer ubuntu@`. 123 | 124 | 2. Install Java by running the command: 125 | `sudo apt-get update && sudo apt-get install default-jdk`. 126 | 127 | 3. Add the Jenkins repository key by running the command: 128 | 129 | 4. Add the Jenkins repository by running the command: 130 | 131 | ``` 132 | 133 | sudo mkdir -p /usr/share/keyrings 134 | 135 | sudo curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null 136 | 137 | 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 138 | 139 | ``` 140 | 5. Update the package list by running the command, 141 | 142 | 6. Install Jenkins by running the command: 143 | 144 | ``` 145 | sudo apt-get update 146 | sudo apt-get install jenkins 147 | ``` 148 | ### Option 2: Use Terraform to Install Jenkins 149 | 150 | To use Terraform to install Jenkins, follow these steps: 151 | 152 | 1. SSH into the Ubuntu EC2 instance created by Terraform by running the command: 153 | `ssh -i deployer ubuntu@`. 154 | 155 | 2. Run the Jenkins installation script by running the command: 156 | `sudo sh /home/ubuntu/jenkins-installation-ubuntu.sh`. 157 | 158 | 3. The script will install Jenkins and its dependencies. Once the installation is complete, Jenkins will be running on the EC2 instance. 159 | 160 | ## Clean Up 161 | 162 | To destroy the EC2 instances and associated resources, run the command: `terraform destroy` 163 | 164 | Note: This will delete all resources created by Terraform in this branch. 165 | 166 | 167 | ## For More info on lab machine plz expend below: 168 | 169 |
170 | # Jenkins-cicd 171 | PG DO - CI/CD Pipeline with Jenkins Simplilearn 172 | 173 | # AWS Ubuntu VM Provisioning steps 174 | - Step 1: Click on Launch Instance 175 | - Step 2 : Click on Software Image (AMI) 176 | - Select Ubuntu 177 | - Step 4: Key pair name – required 178 | - Click on Create new key pair 179 | - Put key pair name Jenkins-sl 180 | - & Download it 181 | - Step 5 : Click on Launch Instance 182 | - Step 6 : Select your VM and Click connect 183 | - Step 7 : You can see the terminal 184 | - Step: Showing Github example 185 | 186 | # Git Status 187 | ``` 188 | git --version 189 | ``` 190 | ## cretae Dir 191 | ``` 192 | mkdir demo 193 | cd demo 194 | ``` 195 | ## GIT & Ubuntu SSH connection 196 | ``` 197 | ssh-keygen 198 | 199 | "Hit enter button 3 time" 200 | 201 | cat ~/.ssh/id_rsa.pub 202 | git clone git@github.com:manikcloud/Jenkins-cicd.git 203 | history 204 | history | cut -c 8- 205 | ``` 206 | 207 | # Jenkins installation on UBUNTU 18.04 & Ubuntu 22.04 208 | 209 | ### Step 1 210 | ``` 211 | sudo apt-get update -y && sudo apt install openjdk-8-jdk -y 212 | ``` 213 | ### Step 2: Downloading Key 214 | ``` 215 | sudo wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add 216 | ``` 217 | 218 | ### Step 3: Adding Key 219 | ``` 220 | sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' 221 | ``` 222 | 223 | ### Step 4: Jenkins Package installation 224 | ``` 225 | sudo apt-get update -y && sudo apt install jenkins -y 226 | sudo /etc/init.d/jenkins start 227 | sudo service jenkins status 228 | ``` 229 | ### Step 5: Jenkins default password 230 | ``` 231 | sudo cat /home/labsuser/jenkins/secrets/initialAdminPassword 232 | ``` 233 | ### Step 6: History command 234 | 235 | ``` 236 | history | cut -c 8- 237 | 238 | ``` 239 | # Jenkins URL with port 8080 240 | - http://x.x.x.x:8080/ 241 | 242 | Replace x with your ip 243 | 244 | # Change Security group rule for Jenkins 245 | ``` 246 | - Select your instance 247 | - Down below select your security tab 248 | - Click on the Security groups sg-0c51908b5fa4abf75 (launch-wizard-2) 249 | - Click on the action 250 | - Click on EDIT INBOUND RULE 251 | - Select custom TCP and put port 8080 252 | - Custom ip should be 0.0.0.0/0 253 | - Click on Save the rule 254 | ``` 255 | 256 | # Common error 257 | 258 | ``` 259 | getting "E: Unable to locate package openjdk-8-jdk" message on java update 260 | ``` 261 | 262 | # Resolution 263 | Run this command 264 | 265 | ``` 266 | sudo apt update -y 267 | ``` 268 | # Plugin Installation 269 | dashboard>manage>jenkins>manage plugins>maven integration 270 | 271 | 272 | 273 | # Jenkins Setting 274 | 275 | ``` 276 | Java_Home 277 | /usr/lib/jvm/java-8-openjdk-amd64/ 278 | ``` 279 | 280 | # Post Build Step 281 | 282 | ``` 283 | java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App 284 | 285 | ``` 286 | 287 | # This project is parameterized 288 | ``` 289 | echo "User First name is : $First_Name" 290 | echo "User Last name is : $Last_Name" 291 | echo "User Gender is : $Sex" 292 | 293 | ``` 294 |
295 | 296 | # References: 297 | 1. https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html 298 | 2. https://maven.apache.org/download.cgi 299 | 300 | ## Connect & Follow 301 | 302 | For more info, please connect and follow me: 303 | 304 | - Github: [https://github.com/manikcloud](https://github.com/manikcloud) 305 | - LinkedIn: [https://www.linkedin.com/in/vkmanik/](https://www.linkedin.com/in/vkmanik/) 306 | - Email: [varunmanik1@gmail.com](mailto:varunmanik1@gmail.com) 307 | - Facebook: [https://www.facebook.com/cloudvirtualization/](https://www.facebook.com/cloudvirtualization/) 308 | - YouTube: [https://bit.ly/32fknRN](https://bit.ly/32fknRN) 309 | - Twitter: [https://twitter.com/varunkmanik](https://twitter.com/varunkmanik) 310 | 311 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/amazon-linux-vm.tf: -------------------------------------------------------------------------------- 1 | 2 | resource "aws_security_group" "allow_ssh_slave" { 3 | name = "allow_SSH_Slave_aws_linux" 4 | description = "Allow SSH inbound traffic" 5 | # vpc_id = aws_vpc.main.id 6 | 7 | 8 | ingress { 9 | from_port = 0 10 | to_port = 0 11 | protocol = "-1" 12 | cidr_blocks = ["0.0.0.0/0"] 13 | ipv6_cidr_blocks = ["::/0"] 14 | # description = "SSH from VPC" 15 | # from_port = 22 16 | # to_port = 22 17 | # protocol = "tcp" 18 | # cidr_blocks = ["0.0.0.0/0"] 19 | # # ipv6_cidr_blocks = [aws_vpc.main.ipv6_cidr_block] 20 | } 21 | 22 | egress { 23 | from_port = 0 24 | to_port = 0 25 | protocol = "-1" 26 | cidr_blocks = ["0.0.0.0/0"] 27 | ipv6_cidr_blocks = ["::/0"] 28 | } 29 | } 30 | 31 | resource "aws_key_pair" "deployer3" { 32 | key_name = "deployer-key3" 33 | 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" 34 | } 35 | 36 | resource "aws_instance" "linux" { 37 | ami = "ami-0c02fb55956c7d316" 38 | instance_type = "t3.micro" 39 | key_name = aws_key_pair.deployer3.key_name 40 | count = 3 41 | vpc_security_group_ids = ["${aws_security_group.allow_ssh_slave.id}"] 42 | tags = { 43 | "Name" = "WP-Node-${count.index}" 44 | "ENV" = "Dev" 45 | } 46 | 47 | depends_on = [aws_key_pair.deployer3] 48 | 49 | } 50 | 51 | ####### Amazon Linux VM OutPut##### 52 | output "linux" { 53 | value = aws_instance.linux.*.public_ip 54 | description = "description" 55 | } 56 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/README.md: -------------------------------------------------------------------------------- 1 | # Course Content 2 | 3 | This repository contains various resources and scripts used for the course, focusing on Ansible and Terraform. 4 | 5 | ## Directory Structure 6 | 7 | - **6.8-tf-ec2-provisioning**: Terraform scripts for provisioning EC2 instances and additional Ansible files. 8 | - README.md 9 | - deployer 10 | - deployer.pub 11 | - main.tf 12 | - slave-vm.tf 13 | - ubuntu-vm.tf 14 | - ansible.cfg: Ansible configuration file. 15 | - apache.yaml: Ansible playbook for installing Apache. 16 | - host_vars.yml: Host variables file for Ansible configuration. 17 | - inventory.ini: Ansible inventory file with server details. 18 | - jenkins.yaml: Ansible playbook for installing Jenkins. 19 | - node.yml: Ansible playbook for installing Node.js. 20 | - **host_vars.yaml**: Host variables file for Ansible configuration. 21 | 22 | ## Prerequisites 23 | 24 | Before using the resources in this repository, make sure you have the following prerequisites installed: 25 | 26 | - Ansible 27 | - Terraform 28 | - Git 29 | 30 | ## How to Clone and Change Directory 31 | 32 | To clone the repository and change the directory, follow these steps: 33 | 34 | 1. Open your terminal or command prompt. 35 | 2. Run the following command to clone the repository: 36 | 37 | ``` 38 | git clone https://github.com/manikcloud/DevOps-Tutorial.git 39 | ``` 40 | 41 | # Ansible Setup on Ubuntu 42 | 43 | This guide will help you set up Ansible on an Ubuntu system. 44 | 45 | ## Prerequisites 46 | 47 | - An Ubuntu system 48 | - SSH access to a remote server 49 | 50 | ## Steps 51 | 52 | 1. Install Ansible on the Ubuntu system: 53 | 54 | ``` 55 | sudo apt update 56 | sudo apt install -y ansible 57 | ``` 58 | 59 | 2. Create an inventory file, for example, `inventory.ini`, and add your server details: 60 | 61 | ```ini 62 | [my_servers] 63 | my_server ansible_host=18.209.59.137 64 | ``` 65 | 66 | 3. Create an Ansible configuration file, `ansible.cfg`, and add the following content: 67 | 68 | ```ini 69 | [defaults] 70 | inventory = inventory.ini 71 | remote_user = ubuntu 72 | private_key_file = ../deployer 73 | host_key_checking = False 74 | retry_files_enabled = False 75 | ``` 76 | 77 | 4. Test the Ansible connection to the remote server with the following command: 78 | 79 | ``` 80 | ansible my_servers -m ping 81 | ``` 82 | 83 | Replace 'my_servers' with the appropriate group name 84 | 85 | 86 | from your inventory file. 87 | 88 | # Additional Ansible Files in 6.8 Directory 89 | 90 | Below is a brief explanation of the additional Ansible files found in the `6.8` directory: 91 | 92 | - **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. 93 | - **apache.yaml**: This Ansible playbook installs the Apache web server on the target machines. To run the playbook, use the following command: 94 | 95 | ``` 96 | ansible-playbook apache.yaml 97 | ``` 98 | 99 | - **host_vars.yml**: This file contains host-specific variables for Ansible configuration. It allows you to define variables for each host in your inventory. 100 | - **inventory.ini**: This is the Ansible inventory file that contains the server details, such as the server's hostname and IP address. 101 | - **jenkins.yaml**: This Ansible playbook installs Jenkins on the target machines. To run the playbook, use the following command: 102 | 103 | ``` 104 | ansible-playbook jenkins.yaml 105 | ``` 106 | 107 | - **node.yml**: This Ansible playbook installs Node.js on the target machines. To run the playbook, use the following command: 108 | 109 | ``` 110 | ansible-playbook node.yml 111 | ``` 112 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | inventory = inventory.ini 3 | remote_user = ubuntu 4 | private_key_file = ../deployer 5 | host_key_checking = False 6 | retry_files_enabled = False 7 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/apache.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: my_servers 3 | become: true 4 | 5 | tasks: 6 | - name: Install apache2 7 | apt: name=apache2 update_cache=no state=latest 8 | 9 | 10 | handlers: 11 | - name: restart apache2 12 | service: name=apache2 state=restarted 13 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/host_vars.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # ansible_user: ec2-user 3 | ansible_user: ubuntu 4 | ansible_ssh_private_key_file: ../deployer 5 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory copy.ini-backup: -------------------------------------------------------------------------------- 1 | [aws_linux_vm] 2 | ; wp-server ansible_host=54.158.174.154 3 | ; wp-server1 ansible_host=34.230.43.235 4 | 5 | [ubuntu-vm] 6 | my_server_1 ansible_host=3.88.212.253 7 | 8 | 9 | ; my_server_2 ansible_host=3.94.145.119 10 | ; my_server_3 ansible_host=54.196.214.244 11 | ; ubuntu = [ 12 | ; "", 13 | ; "54.166.96.63", 14 | ; "35.172.211.176", 15 | ; ] 16 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory.ini: -------------------------------------------------------------------------------- 1 | 2 | [ubuntu_vm] 3 | my_server_1 ansible_host=54.224.173.170 4 | my_server_2 ansible_host=54.166.216.181 5 | my_server_3 ansible_host=50.16.161.255 6 | 7 | 8 | [ubuntu:children] 9 | ubuntu_vm 10 | 11 | [ubuntu:vars] 12 | ansible_user=ubuntu 13 | ansible_ssh_private_key_file=../deployer 14 | 15 | 16 | 17 | [aws_linux_vm] 18 | # aws_linux ansible_host=54.210.170.163 19 | aws_linux ansible_host=54.161.95.81 20 | # aws_linux ansible_host=34.207.226.250 21 | 22 | 23 | 24 | [aws:children] 25 | aws_linux_vm 26 | 27 | [aws:vars] 28 | ansible_user=ec2-user 29 | ansible_ssh_private_key_file=../deployer 30 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory.ini.org: -------------------------------------------------------------------------------- 1 | [aws:children] 2 | aws_linux_vm 3 | 4 | [aws:vars] 5 | ansible_user=ec2-user 6 | ansible_ssh_private_key_file=../deployer 7 | 8 | [aws_linux_vm] 9 | wp-server ansible_host=3.81.25.108 10 | 11 | [ubuntu:children] 12 | ubuntu_vm 13 | 14 | [ubuntu:vars] 15 | ansible_user=ubuntu 16 | ansible_ssh_private_key_file=../deployer 17 | 18 | [ubuntu_vm] 19 | my_server_1 ansible_host=44.210.103.164 20 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/jenkins.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install Jenkins on Ubuntu 3 | hosts: all 4 | become: yes 5 | gather_facts: yes 6 | 7 | tasks: 8 | - name: Update and upgrade apt packages 9 | apt: 10 | update_cache: yes 11 | upgrade: yes 12 | 13 | - name: Install default JDK 14 | apt: 15 | name: default-jdk 16 | state: present 17 | 18 | - name: Check Java version 19 | command: java -version 20 | register: java_version 21 | changed_when: False 22 | 23 | - name: Create keyrings directory 24 | file: 25 | path: /usr/share/keyrings 26 | state: directory 27 | 28 | - name: Add Jenkins key 29 | ansible.builtin.get_url: 30 | url: https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key 31 | dest: /usr/share/keyrings/jenkins-keyring.asc 32 | 33 | - name: Add Jenkins repository 34 | ansible.builtin.apt_repository: 35 | repo: deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/ 36 | state: present 37 | 38 | - name: Update apt cache 39 | apt: 40 | update_cache: yes 41 | 42 | - name: Install Jenkins 43 | apt: 44 | name: jenkins 45 | state: present 46 | 47 | - name: Check Jenkins status 48 | command: systemctl status jenkins --no-pager -l 49 | register: jenkins_status 50 | changed_when: False 51 | 52 | - name: Enable and start Jenkins service 53 | ansible.builtin.systemd: 54 | name: jenkins 55 | enabled: yes 56 | state: started 57 | 58 | - name: Get Jenkins initial admin password 59 | slurp: 60 | src: /var/lib/jenkins/secrets/initialAdminPassword 61 | register: jenkins_initial_admin_password 62 | changed_when: False 63 | 64 | - name: Display Jenkins initial admin password 65 | debug: 66 | msg: "Initial Jenkins admin password: {{ jenkins_initial_admin_password['content'] | b64decode }}" 67 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/node.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: all 3 | become: true 4 | tasks: 5 | - name: add apt key for nodesource 6 | become: true 7 | apt_key: 8 | url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key 9 | 10 | - name: add repo for nodesource 11 | become: true 12 | apt_repository: 13 | repo: 'deb https://deb.nodesource.com/node_0.10 {{ ansible_distribution_release }} main' 14 | update_cache: no 15 | 16 | - name: install nodejs 17 | become: true 18 | apt: 19 | name: nodejs 20 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_1: -------------------------------------------------------------------------------- 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."]} -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_2: -------------------------------------------------------------------------------- 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."]} -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_3: -------------------------------------------------------------------------------- 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."]} -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-1.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: ubuntu_vm 3 | become: yes 4 | vars: 5 | wp_db_name: wordpress1 6 | wp_db_user: wordpress 7 | wp_db_password: secure-123 8 | db_host: 44.210.103.164 # Added db_host 9 | table_prefix: wp_ 10 | 11 | tasks: 12 | - name: Update APT package cache 13 | apt: 14 | update_cache: yes 15 | 16 | - name: Install LAMP stack 17 | apt: 18 | name: 19 | - apache2 20 | - mysql-server 21 | - php 22 | - libapache2-mod-php 23 | - php-mysql 24 | - python3-pymysql 25 | state: present 26 | 27 | - name: Start Apache and MySQL services 28 | systemd: 29 | name: "{{ item }}" 30 | state: started 31 | enabled: yes 32 | loop: 33 | - apache2 34 | - mysql 35 | 36 | - name: Remove MySQL root password 37 | shell: | 38 | mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';" 39 | mysql -u root -e "FLUSH PRIVILEGES;" 40 | 41 | - name: Create a new database for WordPress 42 | mysql_db: 43 | name: "{{ wp_db_name }}" 44 | state: present 45 | login_user: root 46 | login_password: "" 47 | 48 | - name: Create a new user for WordPress 49 | mysql_user: 50 | name: "{{ wp_db_user }}" 51 | password: "{{ wp_db_password }}" 52 | priv: "*.*:ALL" 53 | host: "%" 54 | state: present 55 | notify: restart mysql 56 | 57 | - name: Download WordPress 58 | get_url: 59 | url: https://wordpress.org/latest.tar.gz 60 | dest: /tmp/wordpress.tar.gz 61 | mode: '0644' 62 | 63 | - name: Extract WordPress 64 | unarchive: 65 | src: /tmp/wordpress.tar.gz 66 | dest: /var/www/html/ 67 | remote_src: yes 68 | 69 | - name: Update WordPress config file 70 | template: 71 | src: ./ubuntu-wp-config.php.j2 72 | dest: /var/www/html/wordpress/wp-config.php 73 | 74 | - name: Restart Apache service 75 | systemd: 76 | name: apache2 77 | state: restarted 78 | 79 | handlers: 80 | - name: restart mysql 81 | systemd: 82 | name: mysql 83 | state: restarted 84 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-config.php.j2: -------------------------------------------------------------------------------- 1 | 3.27" 6 | } 7 | } 8 | 9 | required_version = ">= 0.14.9" 10 | } 11 | 12 | -------------------------------------------------------------------------------- /6-ansible-terraform/6.8-tf-ec2-provisioning/ubuntu-vm.tf: -------------------------------------------------------------------------------- 1 | resource "aws_security_group" "allow_SSH_ubuntu" { 2 | name = "allow_SSH_ubuntu" 3 | description = "Allow SSH inbound traffic" 4 | 5 | 6 | ingress { 7 | from_port = 0 8 | to_port = 0 9 | protocol = "-1" 10 | cidr_blocks = ["0.0.0.0/0"] 11 | ipv6_cidr_blocks = ["::/0"] 12 | } 13 | 14 | egress { 15 | from_port = 0 16 | to_port = 0 17 | protocol = "-1" 18 | cidr_blocks = ["0.0.0.0/0"] 19 | ipv6_cidr_blocks = ["::/0"] 20 | } 21 | } 22 | 23 | resource "aws_key_pair" "deployer" { 24 | key_name = "deployer-key" 25 | 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" 26 | } 27 | 28 | ####### Ubuntu VM ##### 29 | 30 | 31 | resource "aws_instance" "ubuntu" { 32 | ami = "ami-007855ac798b5175e" 33 | instance_type = "t3.micro" 34 | key_name = aws_key_pair.deployer.key_name 35 | count = 3 36 | vpc_security_group_ids = ["${aws_security_group.allow_SSH_ubuntu.id}"] 37 | tags = { 38 | "Name" = "UBUNTU-${count.index}" 39 | "ENV" = "Dev" 40 | } 41 | 42 | 43 | depends_on = [aws_key_pair.deployer] 44 | 45 | } 46 | 47 | output "ubuntu" { 48 | value = aws_instance.ubuntu.*.public_ip 49 | description = "Ubuntu vm public IP" 50 | } 51 | -------------------------------------------------------------------------------- /6-ansible-terraform/README.md: -------------------------------------------------------------------------------- 1 | # Course Content 2 | 3 | This repository contains various resources and scripts used for the course, focusing on Ansible and Terraform. 4 | 5 | ## Directory Structure 6 | 7 | - **6-ansible** 8 | - **6.2-node-ansible-playbook**: Ansible playbook for installing Node.js. 9 | - node.yml 10 | - **6.3-apache-ansible-playbook**: Ansible playbook for installing Apache. 11 | - apache.yaml 12 | - **6.4-ansible-module**: Documentation on how to use Ansible modules. 13 | - README.md 14 | - **6.5-ansible-role**: Documentation on how to create and use Ansible roles. 15 | - README.md 16 | - **6.6-setup-terraform**: Scripts and instructions for setting up Terraform. 17 | - README.md 18 | - tf-installation.sh 19 | - **6.7-S3-Bucket-Using-Terraform**: Instructions on how to create an S3 bucket using Terraform. 20 | - README.md 21 | - **6.8-tf-ec2-provisioning**: Terraform scripts for provisioning EC2 instances and additional Ansible files. 22 | - README.md 23 | - deployer 24 | - deployer.pub 25 | - main.tf 26 | - slave-vm.tf 27 | - ubuntu-vm.tf 28 | - ansible.cfg: Ansible configuration file. 29 | - apache.yaml: Ansible playbook for installing Apache. 30 | - host_vars.yml: Host variables file for Ansible configuration. 31 | - inventory.ini: Ansible inventory file with server details. 32 | - jenkins.yaml: Ansible playbook for installing Jenkins. 33 | - node.yml: Ansible playbook for installing Node.js. 34 | - **host_vars.yaml**: Host variables file for Ansible configuration. 35 | 36 | ## Prerequisites 37 | 38 | Before using the resources in this repository, make sure you have the following prerequisites installed: 39 | 40 | - Ansible 41 | - Terraform 42 | - Git 43 | 44 | ## How to Clone and Change Directory 45 | 46 | To clone the repository and change the directory, follow these steps: 47 | 48 | 1. Open your terminal or command prompt. 49 | 2. Run the following command to clone the repository: 50 | 51 | ``` 52 | git clone https://github.com/manikcloud/DevOps-Tutorial.git 53 | ``` 54 | 55 | ## Features 56 | 57 | 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. 58 | 59 | Feel free to explore the repository and use the provided resources to enhance your learning experience. 60 | 61 | # Ansible Setup on Ubuntu 62 | 63 | This guide will help you set up Ansible on an Ubuntu system. 64 | 65 | ## Prerequisites 66 | 67 | - An Ubuntu system 68 | - SSH access to a remote server 69 | 70 | ## Steps 71 | 72 | 1. Install Ansible on the Ubuntu system: 73 | 74 | ``` 75 | sudo apt update 76 | sudo apt install -y ansible 77 | ``` 78 | 79 | 2. Create an inventory file, for example, `inventory.ini`, and add your server details: 80 | 81 | ```ini 82 | [my_servers] 83 | my_server ansible_host=18.209.59.137 84 | ``` 85 | 86 | 3. Create an Ansible configuration file, `ansible.cfg`, and add the following content: 87 | 88 | ```ini 89 | [defaults] 90 | inventory = inventory.ini 91 | remote_user = ubuntu 92 | private_key_file = ../deployer 93 | host_key_checking = False 94 | retry_files_enabled = False 95 | ``` 96 | 97 | 4. Test the Ansible connection to the remote server with the following command: 98 | 99 | ``` 100 | ansible my_servers -m ping 101 | ``` 102 | 103 | Replace 'my_servers' with the appropriate group name 104 | 105 | 106 | from your inventory file. 107 | 108 | # Additional Ansible Files in 6.8 Directory 109 | 110 | Below is a brief explanation of the additional Ansible files found in the `6.8` directory: 111 | 112 | - **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. 113 | - **apache.yaml**: This Ansible playbook installs the Apache web server on the target machines. To run the playbook, use the following command: 114 | 115 | ``` 116 | ansible-playbook apache.yaml 117 | ``` 118 | 119 | - **host_vars.yml**: This file contains host-specific variables for Ansible configuration. It allows you to define variables for each host in your inventory. 120 | - **inventory.ini**: This is the Ansible inventory file that contains the server details, such as the server's hostname and IP address. 121 | - **jenkins.yaml**: This Ansible playbook installs Jenkins on the target machines. To run the playbook, use the following command: 122 | 123 | ``` 124 | ansible-playbook jenkins.yaml 125 | ``` 126 | 127 | - **node.yml**: This Ansible playbook installs Node.js on the target machines. To run the playbook, use the following command: 128 | 129 | ``` 130 | ansible-playbook node.yml 131 | ``` 132 | -------------------------------------------------------------------------------- /6-ansible-terraform/wordpress/README.md: -------------------------------------------------------------------------------- 1 | # DevOps-Tutorial 2 | 3 | ## Goal 4 | 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. 5 | 6 | ## Features 7 | - This Ansible playbook will install all necessary dependencies including Python, PHP, Apache, and MariaDB. 8 | - It sets up a WordPress database and user. 9 | - It downloads the latest version of WordPress and configures it to use the database. 10 | - It updates the WordPress config file using an Ansible template. 11 | 12 | ## Prerequisites 13 | - An AWS account with the necessary permissions to create EC2 instances. 14 | - Ansible installed on your local machine or control node. 15 | - Basic knowledge of Ansible playbooks. 16 | 17 | ## Usage 18 | 1. Clone this repository to your local machine or control node: `git clone https://github.com/manikcloud/DevOps-Tutorial.git` 19 | 2. Change into the project directory: `cd DevOps-Tutorial` 20 | 3. Update the `aws_linux_vm` variable in the playbook with the IP address or hostname of your EC2 instance. 21 | 4. Run the playbook: `ansible-playbook playbook.yml` 22 | 23 | --- 24 | 25 | 26 | # Setting up WordPress on an Amazon Linux Instance 27 | 28 | 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.** 29 | 30 | **## Steps:** 31 | 32 | 1. **Launch an Amazon Linux EC2 Instance:** 33 | - Log into your AWS account. 34 | - Launch an Amazon Linux EC2 instance. 35 | - Ensure security groups allow HTTP (port 80) and SSH (port 22) access. 36 | 37 | 2. **Connect to Your Instance:** 38 | - Use SSH to connect to your instance: 39 | ```bash 40 | ssh -i /path/to/your-key.pem ec2-user@your-instance-public-dns 41 | ``` 42 | 43 | 3. **Update Your Instance:** 44 | - Once connected, update your instance: 45 | ```bash 46 | sudo yum update -y 47 | ``` 48 | 49 | 4. **Install Apache Web Server:** 50 | - Install and start Apache: 51 | ```bash 52 | sudo yum install httpd -y 53 | sudo systemctl start httpd.service 54 | sudo systemctl enable httpd.service 55 | ``` 56 | 57 | 5. **Install MySQL (MariaDB):** 58 | - Install the MariaDB server: 59 | ```bash 60 | sudo yum install mariadb-server mariadb -y 61 | sudo systemctl start mariadb 62 | sudo mysql_secure_installation 63 | sudo systemctl enable mariadb.service 64 | ``` 65 | 66 | 6. **Create a WordPress Database and User:** 67 | - Log into the MariaDB shell and create a database and user: 68 | ```sql 69 | mysql -u root -p 70 | CREATE DATABASE wordpress; 71 | GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password'; 72 | FLUSH PRIVILEGES; 73 | EXIT; 74 | ``` 75 | 76 | 7. **Install PHP:** 77 | - Install PHP and necessary extensions: 78 | ```bash 79 | sudo yum install php php-mysql php-gd php-pear -y 80 | sudo systemctl restart httpd.service 81 | ``` 82 | 83 | 8. **Download and Install WordPress:** 84 | - Download and configure WordPress: 85 | ```bash 86 | wget [https://wordpress.org/latest.tar.gz](https://wordpress.org/latest.tar.gz) 87 | tar -xzf latest.tar.gz 88 | sudo rsync -avP ~/wordpress/ /var/www/html/ 89 | mkdir /var/www/html/wp-content/uploads 90 | sudo chown -R apache:apache /var/www/html/* 91 | ``` 92 | 93 | 9. **Configure WordPress:** 94 | - Navigate to the `/var/www/html` directory. 95 | - Rename and edit the WordPress configuration file: 96 | ```bash 97 | cd /var/www/html 98 | mv wp-config-sample.php wp-config.php 99 | sudo nano wp-config.php 100 | ``` 101 | - Update the database settings. 102 | 103 | 10. **Complete Installation Through the Web Interface:** 104 | - Access your server's domain or IP address in a web browser. 105 | - Complete the WordPress installation through the web interface. 106 | 107 | **## Additional Considerations:** 108 | 109 | - **HTTPS:** Set up HTTPS for secure communication. 110 | - **Virtual Hosts:** Configure virtual hosts to manage multiple websites. 111 | - **Server Optimization:** Optimize server performance for WordPress. 112 | - **WordPress Security:** Secure your WordPress installation. 113 | 114 | 115 | 116 | ## Conclusion 117 | 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. 118 | 119 | ## Contributing 120 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 121 | 122 | ## License 123 | [MIT](https://choosealicense.com/licenses/mit/) 124 | -------------------------------------------------------------------------------- /6-ansible-terraform/wordpress/wp-config.php.j2: -------------------------------------------------------------------------------- 1 | 330 | 331 | 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. 332 | 333 | 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. 334 | 335 | 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. 336 | 337 | 338 | 339 | ## Connect & Follow 340 | 341 | For more info, please connect and follow me: 342 | 343 | - Github: [https://github.com/manikcloud](https://github.com/manikcloud) 344 | - LinkedIn: [https://www.linkedin.com/in/vkmanik/](https://www.linkedin.com/in/vkmanik/) 345 | - Email: [varunmanik1@gmail.com](mailto:varunmanik1@gmail.com) 346 | - Facebook: [https://www.facebook.com/cloudvirtualization/](https://www.facebook.com/cloudvirtualization/) 347 | - YouTube: [https://bit.ly/32fknRN](https://bit.ly/32fknRN) 348 | - Twitter: [https://twitter.com/varunkmanik](https://twitter.com/varunkmanik) 349 | -------------------------------------------------------------------------------- /7-docker/7.4-docker-compose/python-flask-app/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.7 2 | 3 | WORKDIR /app 4 | 5 | COPY . /app 6 | 7 | RUN pip install --no-cache-dir -r requirements.txt 8 | 9 | CMD ["flask", "run", "--host=0.0.0.0", "--port=5000"] 10 | -------------------------------------------------------------------------------- /7-docker/7.4-docker-compose/python-flask-app/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | from redis import Redis 3 | 4 | app = Flask(__name__) 5 | redis = Redis(host='redis', port=6379) 6 | 7 | @app.route('/') 8 | def hello(): 9 | count = redis.incr('hits') 10 | return 'Hello World! I have been seen {} times.\n'.format(count) 11 | 12 | if __name__ == "__main__": 13 | app.run(host="0.0.0.0", port=8000, debug=True) 14 | -------------------------------------------------------------------------------- /7-docker/7.4-docker-compose/python-flask-app/requirements.txt: -------------------------------------------------------------------------------- 1 | flask 2 | redis 3 | -------------------------------------------------------------------------------- /7-docker/7.4-docker-compose/wordpress/docker-compose-wp.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | db: 5 | image: mariadb 6 | volumes: 7 | - db_data:/var/lib/mysql 8 | environment: 9 | MYSQL_ROOT_PASSWORD: wordpress 10 | MYSQL_DATABASE: wordpress 11 | MYSQL_USER: wordpress 12 | MYSQL_PASSWORD: wordpress 13 | 14 | wordpress: 15 | depends_on: 16 | - db 17 | image: wordpress:latest 18 | ports: 19 | - "8000:80" 20 | environment: 21 | WORDPRESS_DB_HOST: db:3306 22 | WORDPRESS_DB_USER: wordpress 23 | WORDPRESS_DB_PASSWORD: wordpress 24 | WORDPRESS_DB_NAME: wordpress 25 | volumes: 26 | - wordpress_data:/var/www/html 27 | 28 | redis: 29 | image: redis:latest 30 | volumes: 31 | - redis_data:/data 32 | 33 | volumes: 34 | db_data: {} 35 | wordpress_data: {} 36 | redis_data: {} 37 | -------------------------------------------------------------------------------- /7-docker/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use Ubuntu as a base image 2 | FROM ubuntu:22.04 3 | 4 | # Update and install nginx 5 | RUN apt-get update 6 | 7 | RUN apt-get install -y nginx 8 | 9 | # Copy the custom index file to the nginx directory 10 | COPY index.html /var/www/html 11 | 12 | EXPOSE 80 13 | 14 | # Start nginx in the foreground to keep the container running 15 | CMD ["nginx", "-g", "daemon off;"] 16 | -------------------------------------------------------------------------------- /7-docker/Final-project-docker/5.11-docker-compose/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.4-alpine 2 | ADD . /code 3 | WORKDIR /code 4 | RUN pip install -r requirements.txt 5 | CMD ["python", "app.py"] 6 | -------------------------------------------------------------------------------- /7-docker/Final-project-docker/5.11-docker-compose/README.md: -------------------------------------------------------------------------------- 1 | # Lesson 5 Demo 11: Convert an Application Deployment into a Stack 2 | 3 | This section will guide you to: 4 | - Convert an application deployment into a stack using a file named docker-compose.yml 5 | 6 | | Feature | Docker Service | Docker Stack | 7 | |---------|----------------|--------------| 8 | | 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. | 9 | | 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. | 10 | | Scale | Services can be scaled up or down individually. | All services within a stack are scaled together, maintaining the application's functionality. | 11 | | Command | `docker service create` | `docker stack deploy` | 12 | 13 | ### Step 1: Drain the worker nodes in the swarm cluster to make sure the registry service runs on the manager node 14 | - List all the nodes present in the swarm cluster and ensure that all nodes are in Active state 15 | 16 | ``` 17 | sudo docker node ls 18 | 19 | ``` 20 | 21 | 22 | **Note**: Copy the HOSTNAME of worker nodes 23 | - Use the following command to drain the worker nodes: 24 | 25 | ``` 26 | sudo docker node update --availability drain hostname_Worker_Node 27 | 28 | ``` 29 | 30 | 31 | **Note**: Replace hostname_Worker_Node with the HOSTNAME copied in previous ### Step 32 | 33 | 34 | ### Step 2: Start the registry as a service on your swarm 35 | 36 | ``` 37 | sudo docker service create --name registry --publish published=5000,target=5000 registry:2 38 | 39 | 40 | ``` 41 | 42 | 43 | ### Step 3: List the running services to check the status of registry service 44 | 45 | ``` 46 | sudo docker service ls 47 | 48 | ``` 49 | 50 | 51 | 52 | ### Step 4: Check if registry service is working with curl 53 | 54 | ``` 55 | 56 | curl http://localhost:5000/v2/ 57 | 58 | ``` 59 | 60 | 61 | 62 | ### Step 5: Create a directory for the project 63 | 64 | ``` 65 | 66 | mkdir stackdemo 67 | cd stackdemo 68 | 69 | ``` 70 | 71 | 72 | 73 | ### Step 6: Create a file called app.py in the stackdemo directory 74 | - Use the following command to create a project file: 75 | 76 | ``` 77 | 78 | nano app.py 79 | 80 | ``` 81 | 82 | 83 | - Add the following code in the app.py file: 84 | 85 | ``` 86 | 87 | from flask import Flask 88 | from redis import Redis 89 | 90 | app = Flask(__name__) 91 | redis = Redis(host='redis', port=6379) 92 | 93 | @app.route('/') 94 | def hello(): 95 | count = redis.incr('hits') 96 | return 'Hello World! I have been seen {} times.\n'.format(count) 97 | 98 | if __name__ == "__main__": 99 | app.run(host="0.0.0.0", port=8000, debug=True) 100 | 101 | ``` 102 | 103 | 104 | **Note**: Press Ctrl+X to exit the editor. Then type Y and press Enter to save the file. 105 | 106 | ### Step 7: Create a file called requirements.txt 107 | - Use the following command to create and open requirements.txt: 108 | 109 | ``` 110 | 111 | nano requirements.txt 112 | 113 | ``` 114 | 115 | 116 | - Add the following text in the requirements.txt file: 117 | 118 | ``` 119 | 120 | flask 121 | redis 122 | 123 | ``` 124 | 125 | 126 | **Note**: Press Ctrl+X to exit the editor. Then type Y and press Enter to save the file. 127 | 128 | ### Step 8: Create a file called Dockerfile 129 | - Use the following command to create a Dockerfile: 130 | 131 | ``` 132 | 133 | nano Dockerfile 134 | 135 | ``` 136 | 137 | 138 | - Add the following code in the Dockerfile: 139 | 140 | ``` 141 | 142 | FROM python:3.4-alpine 143 | ADD . /code 144 | WORKDIR /code 145 | RUN pip install -r requirements.txt 146 | CMD ["python", "app.py"] 147 | 148 | ``` 149 | 150 | 151 | **Note**: Press Ctrl+X to exit the editor. Then type Y and press Enter to save the file. 152 | 153 | ### Step 9: Create a file named docker-compose.yml 154 | - Use the following command to create the docker-compose.yml file: 155 | 156 | ``` 157 | 158 | nano docker-compose.yml 159 | 160 | ``` 161 | 162 | 163 | - Add the following code in the docker-compose.yml file: 164 | 165 | ``` 166 | 167 | version: "3.3" 168 | services: 169 | web: 170 | image: 127.0.0.1:5000/stackdemo 171 | build: . 172 | ports: 173 | - "8000:8000" 174 | redis: 175 | image: redis:alpine 176 | 177 | ``` 178 | 179 | 180 | **Note**: Press Ctrl+X to exit the editor. Then type Y and press Enter to save the file. 181 | 182 | ### Step 10: Start the application 183 | - Use the following commands to install docker-compose: 184 | 185 | ``` 186 | 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 187 | 188 | 189 | sudo chmod +x /usr/local/bin/docker-compose 190 | docker-compose --version 191 | 192 | ``` 193 | 194 | 195 | 196 | 197 | - Start docker-compose using the following command: 198 | 199 | ``` 200 | sudo docker-compose up -d 201 | 202 | ``` 203 | 204 | 205 | 206 | 207 | ### Step 11: Use the following commands to check whether the app is running 208 | 209 | ``` 210 | sudo docker-compose ps 211 | 212 | curl http://localhost:8000 213 | 214 | ``` 215 | 216 | 217 | 218 | ### Step 12: Bring the application down 219 | 220 | ``` 221 | sudo docker-compose down --volumes 222 | 223 | 224 | ``` 225 | 226 | 227 | ### Step 13: Push the application to the registry 228 | 229 | ``` 230 | sudo docker-compose push 231 | 232 | ``` 233 | 234 | 235 | 236 | ### Step 14: Use the following command to create the stack docker stack deploy: 237 | 238 | ``` 239 | sudo docker stack deploy --compose-file docker-compose.yml stackdemo 240 | 241 | ``` 242 | 243 | 244 | 245 | ### Step 15: Check if the stack is running 246 | 247 | ``` 248 | sudo docker stack services stackdemo 249 | 250 | ``` 251 | 252 | 253 | 254 | ### Step 16: Test the app again with curl command 255 | 256 | ``` 257 | 258 | curl http://localhost:8000 259 | curl http://ip-172-31-26-147:8000 260 | 261 | ``` 262 | 263 | **Note**: In ### Step 10 while starting docker-compose if you get an error showing the port is already assigned, run the command 264 | 265 | ``` 266 | sudo docker ps and kill the container with the same port and then proceed. 267 | 268 | ``` 269 | 270 | 271 | 272 | ### Step 17: Use the following command to bring the stack down: 273 | 274 | ``` 275 | sudo docker stack rm stackdemo 276 | 277 | ``` 278 | 279 | ----------------------------------------------------------------- 280 | 281 | # Lesson 5 Demo 12: Increase Number of Replicas 282 | 283 | This section will guide you to: 284 | - Increase the number of replicas of a task for any given service 285 | 286 | ### Step 1: List the Docker services 287 | 288 | ``` 289 | sudo docker service ls 290 | ``` 291 | 292 | ### Step 2: Scale up the redis service to five tasks 293 | 294 | ``` 295 | sudo docker service scale redis=5 296 | ``` 297 | 298 | ### Step 3: Scale the registry service to four tasks using update flag 299 | 300 | ``` 301 | sudo docker service update --replicas=4 registry 302 | ``` 303 | 304 | ### Step 4: Use the scale flag to scale both redis and registry services at the same time 305 | 306 | ``` 307 | sudo docker service scale redis=4 registry=3 308 | ``` 309 | 310 | ### Step 5: Check the actual number of replicas created 311 | 312 | ``` 313 | sudo docker service ls 314 | ``` 315 | 316 | ### Step 6: Create a global service and scale it up to ten tasks 317 | 318 | ``` 319 | sudo docker service create --mode global --name nginx nginx:latest 320 | 321 | 322 | sudo docker service scale nginx=10 323 | ``` 324 | 325 | **Note**: Notice that the scaling cannot be used with global services. It can only be done with replicated service. 326 | 327 | 328 | # Disclaimer 329 |
330 | 331 | 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. 332 | 333 | 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. 334 | 335 | 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. 336 | 337 |
338 | 339 | ## Connect & Follow 340 | 341 | For more info, please connect and follow me: 342 | 343 | - Github: [https://github.com/manikcloud](https://github.com/manikcloud) 344 | - LinkedIn: [https://www.linkedin.com/in/vkmanik/](https://www.linkedin.com/in/vkmanik/) 345 | - Email: [varunmanik1@gmail.com](mailto:varunmanik1@gmail.com) 346 | - Facebook: [https://www.facebook.com/cloudvirtualization/](https://www.facebook.com/cloudvirtualization/) 347 | - YouTube: [https://bit.ly/32fknRN](https://bit.ly/32fknRN) 348 | - Twitter: [https://twitter.com/varunkmanik](https://twitter.com/varunkmanik) 349 | -------------------------------------------------------------------------------- /7-docker/Final-project-docker/5.11-docker-compose/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | from redis import Redis 3 | 4 | app = Flask(__name__) 5 | redis = Redis(host='redis', port=6379) 6 | 7 | @app.route('/') 8 | def hello(): 9 | count = redis.incr('hits') 10 | return 'Hello World! I have been seen {} times.\n'.format(count) 11 | 12 | if __name__ == "__main__": 13 | app.run(host="0.0.0.0", port=8000, debug=True) 14 | -------------------------------------------------------------------------------- /7-docker/Final-project-docker/5.11-docker-compose/requirements.txt: -------------------------------------------------------------------------------- 1 | flask 2 | redis 3 | -------------------------------------------------------------------------------- /7-docker/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

My First Heading

6 |

Lorem ipsum...

7 |

This is DevOps class.

8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /8-k8s/FAQ/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # PodDisruptionBudget (PDB) in Kubernetes 4 | 5 | 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). 6 | 7 | ## Key Concepts 8 | 9 | - **MinAvailable**: Specifies the minimum number of Pods that should remain available during the disruption. 10 | - **MaxUnavailable**: Defines the maximum number of Pods that can be unavailable during the disruption. 11 | 12 | ## Usage 13 | 14 | PDBs are particularly useful in production environments to maintain application availability during operations that require Pod eviction, like node maintenance. 15 | 16 | ## Example 17 | 18 | A simple PDB might look like this: 19 | 20 | ```yaml 21 | apiVersion: policy/v1 22 | kind: PodDisruptionBudget 23 | metadata: 24 | name: myapp-pdb 25 | spec: 26 | minAvailable: 2 27 | selector: 28 | matchLabels: 29 | app: myapp 30 | ``` 31 | 32 | --- 33 | 34 | # Finding Configuration Files in Kubernetes 35 | 36 | 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. 37 | 38 | ## Locations of Configuration Files 39 | 40 | ### System-Wide Configuration 41 | 42 | - **Kubernetes Master Node**: 43 | - `/etc/kubernetes/manifests`: Contains static pod manifests for the Kubernetes control plane components (apiserver, controller-manager, scheduler, etc.). 44 | - `/etc/kubernetes/admin.conf`, `/etc/kubernetes/kubelet.conf`, and `/etc/kubernetes/controller-manager.conf`: Configuration files for accessing the Kubernetes API. 45 | 46 | - **Kubelet**: 47 | - `/var/lib/kubelet/config.yaml`: The primary configuration file for the kubelet. 48 | 49 | - **Kubeadm**: 50 | - `/etc/kubernetes/kubeadm-config.yaml`: The configuration file used by `kubeadm init` and `kubeadm join`. 51 | 52 | ### User-Defined Resource Configurations 53 | 54 | - **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. 55 | 56 | --- 57 | 58 | # Kubernetes Storage and Stateful Workloads Explained 59 | 60 | 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. 61 | 62 | ## Persistent Volumes (PV) 63 | 64 | **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. 65 | 66 | ### Key Points: 67 | 68 | - **Cluster Resource**: PVs are a cluster-level resource, meaning they are not tied to a specific namespace. 69 | - **Storage Abstraction**: Provides an abstraction over underlying storage systems, supporting various storage backends like NFS, iSCSI, cloud storage services, and more. 70 | - **Lifecycle Independent**: PVs exist independently of pods, ensuring data persists even when pods are deleted or moved. 71 | 72 | ## Persistent Volume Claims (PVC) 73 | 74 | **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. 75 | 76 | ### Key Points: 77 | 78 | - **User Request**: PVCs allow users to request specific sizes and types of storage. 79 | - **Dynamic Provisioning**: If no suitable PV exists, a new one can be dynamically provisioned according to the requested storage class. 80 | - **Binding**: A PVC is bound to a single PV, creating a one-to-one relationship that reserves the PV for the PVC's use. 81 | 82 | ## StatefulSets 83 | 84 | **StatefulSets** are used to manage stateful applications, providing stable, unique network identifiers, stable persistent storage, and ordered, graceful deployment and scaling. 85 | 86 | ### Key Points: 87 | 88 | - **Stable Identity**: Each pod in a StatefulSet has a unique ordinal index and stable network identity. 89 | - **Ordered Operations**: Pods are created, scaled, and deleted in a predictable order, important for stateful applications like databases that require careful management of replicas. 90 | - **Persistent Storage**: StatefulSets can use PVCs to provide each pod with its persistent storage, ensuring data persists across pod rescheduling and restarts. 91 | 92 | ### Conclusion 93 | 94 | 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. 95 | 96 | ## Script Explanation 97 | 98 | This guide explains the components of the script that creates Kubernetes resources, including Persistent Volumes (PVs), Persistent Volume Claims (PVCs), and a StatefulSet. 99 | 100 | ## Components 101 | 102 | ### Persistent Volume (PV) 103 | 104 | - **What it Does**: Creates a PV named `example-pv` with a capacity of 1Gi and a storage class of `standard`. 105 | - **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. 106 | 107 | ### Persistent Volume Claim (PVC) 108 | 109 | - **What it Does**: Generates a PVC named `example-pvc` that requests 1Gi of storage with the same storage class, `standard`. 110 | - **Binding**: This PVC is designed to bind to the previously created PV, `example-pv`. 111 | 112 | ### StatefulSet 113 | 114 | - **What it Does**: Constructs a StatefulSet named `example-statefulset` with 2 replicas. 115 | - **Configuration**: Each pod within the StatefulSet mounts the PVC created by the `volumeClaimTemplates`. 116 | - **Use Case**: Provides a simple example that employs an Nginx container to deliver content stored on the persistent volume. 117 | 118 | ## How to Run 119 | 120 | 1. **Save the Script**: Store the script in a file, for instance, `create-pv-pvc-statefulset.sh`. 121 | 2. **Make Executable**: 122 | 123 | ``` 124 | 125 | chmod +x create-pv-pvc-statefulset.sh 126 | create-pv-pvc-statefulset.sh 127 | 128 | ``` 129 | --- 130 | 131 | # Using Vault in Jenkins 132 | 133 | 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. 134 | 135 | ## Benefits of Integrating Vault with Jenkins 136 | 137 | - **Security**: Keeps sensitive data out of your build logs and source code. 138 | - **Centralization**: Manages all your secrets in one place, making them easier to rotate, revoke, and keep track of. 139 | - **Auditing**: Vault offers detailed audit logs, allowing you to track access to secrets, which is invaluable for compliance and security. 140 | 141 | ## How to Use Vault with Jenkins 142 | 143 | ### Step 1: Install Vault Plugin in Jenkins 144 | 145 | 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. 146 | 147 | ### Step 2: Configure Vault in Jenkins 148 | 149 | After installing the plugin, configure Jenkins to communicate with your Vault server: 150 | 151 | 1. Go to "Manage Jenkins" > "Configure System". 152 | 2. Find the Vault section and add a new Vault configuration. 153 | 3. Enter your Vault Server URL and the Vault Credential. 154 | 155 | ### Step 3: Set Up Vault Credentials 156 | 157 | Vault credentials in Jenkins can be set up as follows: 158 | 159 | 1. Navigate to "Credentials" in Jenkins. 160 | 2. Choose the appropriate scope and click "Add Credentials". 161 | 3. Select "Vault Token" or the appropriate credential type. 162 | 4. Enter your Vault Token and other details as necessary. 163 | 164 | ### Step 4: Accessing Secrets in Jenkins Jobs 165 | 166 | To access Vault secrets in your Jenkins jobs: 167 | 168 | 1. In your job configuration, add a "Build Environment" step. 169 | 2. Select "Vault Secrets" and configure the Vault Key/Values you wish to inject into the build environment. 170 | 3. Use the injected environment variables in your build steps. 171 | 172 | ## Best Practices 173 | 174 | - **Least Privilege**: Grant Jenkins access only to the secrets it needs, nothing more. 175 | - **Audit**: Regularly review access logs and rotate secrets. 176 | - **Secure Communication**: Ensure communication between Jenkins and Vault is over HTTPS to prevent eavesdropping. 177 | 178 | ## Conclusion 179 | 180 | 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. 181 | 182 | -------------------------------------------------------------------------------- /8-k8s/FAQ/vol-k8s.ymal: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Create a Persistent Volume 4 | cat < /etc/apt/sources.list.d/kubernetes.list 19 | 20 | ``` 21 | 22 | 23 | 1.2 Update the apt-get package by executing the command mentioned below: 24 | 25 | 26 | ``` 27 | 28 | sudo apt-get update 29 | 30 | 31 | ``` 32 | 33 | 1.3 Install the kubernetes and the tools required to manage it. Run the command mentioned below in the terminal: 34 | 35 | 36 | ``` 37 | 38 | sudo apt install docker.io kubectl=1.20.5-00 kubeadm=1.20.5-00 kubelet=1.20.5-00 39 | 40 | ``` 41 | 42 | 43 | ### Step 2: Setting up a Kubernetes cluster 44 | 2.1 Update the apt-get package by executing the command mentioned below: 45 | 46 | ``` 47 | 48 | sudo apt-get update 49 | 50 | ``` 51 | 52 | 53 | 2.2 To initialize the cluster run the following command on the master node 54 | 55 | ``` 56 | 57 | sudo kubeadm init 58 | 59 | ``` 60 | 61 | 62 | 2.3 To start using your cluster, you need to run the following on master node: 63 | 64 | ``` 65 | 66 | mkdir -p $HOME/.kube 67 | sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config 68 | sudo chown $(id -u):$(id -g) $HOME/.kube/config 69 | 70 | ``` 71 | 72 | 73 | 2.4 You should see a single master node deployed on running the command: 74 | 75 | ``` 76 | 77 | sudo kubectl get nodes 78 | 79 | 80 | ``` 81 | 82 | 83 | 2.5 Copy the kubeadm join command that you can see on the screen of your master node 84 | 85 | 86 | 87 | 88 | 89 | 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. 90 | 91 | 92 | ``` 93 | 94 | kubeadm join 172.31.64.38:6443 --token 425qb8.51rbrxc5h862g202 \ 95 | --discovery-token-ca-cert-hash sha256:a502867d97b05820f186e3ee748afddd9142aae4104aee804d30662148138bae 96 | 97 | ``` 98 | 99 | 100 | 101 | 2.7 On the master node, run the following command to install the weavenet plugin in order to create a network: 102 | 103 | ``` 104 | 105 | kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 |tr -d '\n')" 106 | 107 | ``` 108 | 109 | 110 | 2.8 List all the nodes again to check the status of nodes using the command: 111 | 112 | ``` 113 | 114 | kubectl get nodes 115 | 116 | 117 | ``` 118 | 119 | 120 | 121 | --------------------------------------------- 122 | # Lesson 08 Demo 2 123 | Pod Creation in Kubernetes 124 | 125 | 126 | ### Steps to be followed: 127 | 1. Creating multi-container pods 128 | 2. Creating a single container pod 129 | 130 | ### Step 1: Creating multi-container pods 131 | 1.1 On the master node, create a new file named sample.yaml: 132 | 133 | sudo su 134 | vi sample.yaml 135 | 1.2 Add the following code in the sample.yaml file: 136 | 137 | ``` 138 | apiVersion: v1 139 | kind: Pod 140 | metadata: 141 | name: multi-container 142 | spec: 143 | terminationGracePeriodSeconds: 0 144 | containers: 145 | - name: nginx 146 | image: nginx:1.10-alpine 147 | ports: 148 | - containerPort: 80 149 | - name: alpine 150 | image: alpine:3.5 151 | command: ["watch", "wget", "-qO-", "localhost"] 152 | ``` 153 | 154 | 155 | 1.3 Use the following command to create the multi-container pod: 156 | 157 | ``` 158 | 159 | kubectl create -f sample.yaml 160 | 161 | ``` 162 | 163 | 164 | 165 | ### Step 2: Creating a single container pod 166 | 2.1 On the master node, create a single container pod with a tomcat image using the following command: 167 | 168 | ``` 169 | 170 | kubectl run tomcat --image=tomcat:8.0 171 | 172 | ``` 173 | 174 | 175 | 176 | 2.2 Check all the running pods 177 | 178 | ``` 179 | 180 | kubectl get pods 181 | 182 | ``` 183 | 184 | 185 | 2.3 To check why exactly a pod is in the pending state, run the command 186 | 187 | ``` 188 | 189 | kubectl describe pods 190 | 191 | ``` 192 | 193 | To check why multi-container pod is pending,use the command 194 | 195 | ``` 196 | 197 | kubectl describe pods multi-container 198 | 199 | ``` 200 | 201 | 202 | 203 | 2.4 To remove the taint from the node run the following commands: 204 | 205 | ``` 206 | 207 | kubectl get nodes 208 | Copy the node name and use it in the below command 209 | 210 | ``` 211 | 212 | kubectl taint nodes node-role.kubernetes.io/master- 213 | 214 | ``` 215 | 216 | Here for example we use the command given below 217 | 218 | ``` 219 | 220 | kubectl taint nodes ip-172-31-18-183 node-role.kubernetes.io/master- 221 | 222 | ``` 223 | 224 | 225 | 2.5 Now check the pod status. The pods should be in the running state. 226 | 227 | ``` 228 | 229 | sudo kubectl get pods 230 | ``` 231 | ``` 232 | # kubectl commands 233 | 234 | ``` 235 | kubectl get namespace 236 | 237 | kubeadm token list 238 | kubectl get namespaces 239 | 240 | kubectl get replicationcontroller,services 241 | kubectl get pods -n kube-public 242 | kubectl get pods -n kube-system 243 | kubectl get pods --all-namespaces 244 | 245 | kubectl run nginx --image=nginx 246 | kubectl get pods --all-namespaces 247 | 248 | kubectl get pods 249 | kubectl get pods -o wide 250 | kubectl describe pod nginx 251 | kubectl get pods 252 | kubectl run nginx --image=httpd 253 | kubectl run httpd --image=httpd 254 | kubectl get pods 255 | 256 | service docker status 257 | sudo kubectl get nodes 258 | 259 | ``` 260 | # Pod Creation in Kubernetes 261 | 262 | - Steps to be followed: 263 | 1. Creating multi-container pods 264 | 2. Creating a single container pod 265 | 266 | ## Step 1: Creating multi-container pods 267 | - 1.1 On the master node, create a new file named sample.yaml: 268 | ``` 269 | sudo su 270 | vi sample.yaml 271 | 1.2 Add the following code in the multi-container.yaml file: 272 | https://github.com/manikcloud/k8s/blob/main/pods/multi-container.yaml 273 | ``` 274 | 275 | - 1.3 Use the following command to create the multi-container pod: 276 | ``` 277 | kubectl create -f sample.yaml 278 | ``` 279 | 280 | ## Step 2: Creating a single container pod 281 | - 2.1 On the master node, create a single container pod with a tomcat image using the following command: 282 | ``` 283 | kubectl run tomcat --image=tomcat:8.0 284 | ``` 285 | 286 | - 2.2 Check all the running pods 287 | ``` 288 | kubectl get pods 289 | ``` 290 | - 2.3 To check why exactly a pod is in the pending state, run the command 291 | -- kubectl describe pods 292 | - To check why multi-container pod is pending,use the command 293 | ``` 294 | kubectl describe pods multi-container 295 | ``` 296 | 297 | 298 | ## 2.4 To remove the taint from the node run the following commands: 299 | ``` 300 | kubectl get nodes 301 | ``` 302 | - Copy the node name and use it in the below command 303 | - kubectl taint nodes node-role.kubernetes.io/master- 304 | 305 | ### Here for example we use the command given below 306 | ``` 307 | kubectl taint nodes ip-172-31-17-206 node-role.kubernetes.io/master- 308 | ``` 309 | -- 2.5 Now check the pod status. The pods should be in the running state. 310 | ``` 311 | sudo kubectl get pods 312 | 313 | ``` 314 | 315 | # Dashboard Creation in Kubernetes 316 | 317 | ``` 318 | kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.1/aio/deploy/recommended.yaml 319 | 320 | kubectl proxy 321 | 322 | http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ 323 | 324 | kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | awk '/^deployment-controller-token-/{print $1}') | awk '$1=="token:"{print $2}' 325 | 326 | kubectl -n kube-system describe secret $( 327 | kubectl -n kube-system get secret | \ 328 | awk '/^deployment-controller-token-/{print $1}' 329 | ) | \ 330 | awk '$1=="token:"{print $2}' 331 | 332 | ``` 333 | ## After executing the above commands, there are 4 distinct commands and they get called in this order: 334 | 335 | - Line 1 - This is the second command from @silverfox's Token section. 336 | - Line 2 - This is the first command from @silverfox's Token section. 337 | - Line 3 - Print only the first field of the line beginning with deployment-controller-token- (which is the pod name) 338 | - Line 5 - Print only the second field of the line whose first field is "token:" 339 | 340 | # ReplicaSet commands in K8S 341 | 342 | ``` 343 | 344 | kubectl apply -f ReplicaSet/ReplicaSet.yaml 345 | kubectl get pods 346 | kubectl get replicaset 347 | kubectl delete pod sl-replicaset-hnd76 348 | kubectl descr 349 | kubectl apply -f pods/pod-def.yaml 350 | kubectl get pods 351 | kubectl apply -f pods/pod-def.yaml 352 | kubectl get pods 353 | kubectl get replicaset sl-replicaset 354 | kubectl edit replicaset sl-replicaset 355 | kubectl get replicaset sl-replicaset 356 | kubectl scale replicaset sl-replicaset --replicas=2 357 | kubectl get replicaset sl-replicaset 358 | 359 | kubectl get replicaset sl-replicaset 360 | ``` 361 | # Deployment commands in K8S 362 | ``` 363 | kubectl create -f deployment/deployment.yaml 364 | kubectl get pods -o wide 365 | 366 | kubectl get deployment 367 | kubectl get deployment -o wide 368 | kubectl describe deployment 369 | kubectl create -f deployment/deployment.yaml 370 | kubectl get pods -o wide 371 | kubectl rollout history deployment/web-app-deployment 372 | kubectl delete deployment web-app-deployment 373 | kubectl get pods -o wide 374 | kubectl create -f deployment/deployment.yaml --record 375 | kubectl rollout history deployment/web-app-deployment 376 | kubectl edit deployment web-app-deployment --record 377 | kubectl rollout history deployment/web-app-deployment 378 | kubectl rollout status deployment/web-app-deployment 379 | kubectl get pods -o wide 380 | kubectl describe deployment web-app-deployment 381 | kubectl rollout status deployment/web-app-deployment 382 | kubectl set image deployment web-app-deployment blue=varunmanik/httpd:v1-blue --record 383 | kubectl get pods -o wide 384 | kubectl rollout history deployment web-app-deployment 385 | ``` 386 | # scaling commands in K8S 387 | ``` 388 | kubectl scale deployment web-app-deployment --replicas=6 389 | ``` 390 | 391 | # Roll Out 392 | ``` 393 | kubectl rollout undo deployment/web-app-deployment --to-revision=3 394 | kubectl rollout history deployment web-app-deployment 395 | ``` 396 | 397 | # Docker testing in you K8S setup 398 | ``` 399 | docker build -t varunmanik/httpd:green . 400 | docker run -itd -p 9000:80 varunmanik/httpd:green 401 | docker build -t varunmanik/httpd:blue . 402 | docker run -itd -p 9001:80 varunmanik/httpd:blue 403 | kubectl describe pod green-app | grep -i "IP:" 404 | ``` 405 | 406 | # Services commands in K8S 407 | 408 | ``` 409 | kubectl create -f services/service-def.yaml 410 | kubectl describe svc web-app-service 411 | kubectl get svc,pods -o wide 412 | kubectl delete service web-app-service 413 | kubectl get svc,pods -o wide 414 | kubectl scale deployment/blue-green-deployment --replicas=1 415 | kubectl get svc,pods -o wide 416 | kubectl get svc,pods,deployment -o wide 417 | 418 | ``` 419 | 420 | 421 | # Cleanup the entire setup 422 | 423 | - Run this command to cleanup 424 | ``` 425 | sh installation/cleanup.sh 426 | ``` 427 | - OR copy and paste below commands one by one. 428 | 429 | ``` 430 | docker ps 431 | kubeadm reset -f 432 | rm -rf /etc/cni /etc/kubernetes /var/lib/dockershim /var/lib/etcd /var/lib/kubelet /var/run/kubernetes ~/.kube/* 433 | v 434 | apt remove -y kubeadm kubectl kubelet kubernetes-cni 435 | sudo apt-get purge kubeadm kubectl kubelet kubernetes-cni kube* 436 | sudo apt-get autoremove 437 | sudo rm -rf ~/.kube 438 | docker ps 439 | system restart docker 440 | systemctl restart docker 441 | ``` 442 | 443 | # Check your history from below command 444 | 445 | ``` 446 | history | cut -c 8- > history.txt 447 | ``` 448 | 449 | # References 450 | 1. https://kubernetes.io/ 451 | 2. https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/ 452 | 3. https://kubernetes.io/docs/concepts/workloads/pods/ 453 | 4. https://etcd.io/ 454 | 5. https://kubernetes.io/docs/reference/kubectl/ 455 | 6. https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/ 456 | 457 | 458 | 459 | -------------------------------------------------------------------------------- /8-k8s/ReplicaSet/ReplicaSet-sl-ex.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | 3 | 4 | 5 | kind: Pod 6 | 7 | 8 | 9 | 10 | 11 | metadata: 12 | 13 | name: web-pod 14 | 15 | labels: 16 | 17 | application: web-app3 18 | 19 | spec: 20 | 21 | containers: 22 | 23 | - name: google-ex 24 | 25 | image: gcr.io/google_samples/gb-frontend:v3 26 | 27 | 28 | -------------------------------------------------------------------------------- /8-k8s/ReplicaSet/ReplicaSet.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | 3 | kind: ReplicaSet 4 | 5 | metadata: 6 | name: sl-replicaset 7 | labels: 8 | application: web-app 9 | 10 | spec: 11 | selector: 12 | matchLabels: 13 | application: web-app 14 | replicas: 20 15 | template: 16 | metadata: 17 | name: web2 18 | labels: 19 | application: web-app 20 | env: dev 21 | 22 | spec: 23 | containers: 24 | - name: httpd 25 | image: varunmanik/httpd:alpine 26 | -------------------------------------------------------------------------------- /8-k8s/ReplicaSet/blue-replicaset.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | 3 | kind: ReplicaSet 4 | 5 | metadata: 6 | name: blue-replicaset 7 | labels: 8 | application: web-app 9 | 10 | spec: 11 | template: 12 | metadata: 13 | name: blue-app 14 | labels: 15 | env: dev 16 | application: web-app 17 | color: blue 18 | spec: 19 | containers: 20 | - name: httpd 21 | image: varunmanik/httpd:blue 22 | selector: 23 | matchLabels: 24 | color: blue 25 | replicas: 5 -------------------------------------------------------------------------------- /8-k8s/ReplicaSet/green-replicaset.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | 3 | kind: ReplicaSet 4 | 5 | metadata: 6 | name: green-replicaset 7 | labels: 8 | application: web-app 9 | 10 | spec: 11 | template: 12 | metadata: 13 | name: green-app 14 | labels: 15 | env: dev 16 | application: web-app 17 | color: green 18 | spec: 19 | containers: 20 | - name: httpd 21 | image: varunmanik/httpd:green 22 | selector: 23 | matchLabels: 24 | color: green 25 | replicas: 5 -------------------------------------------------------------------------------- /8-k8s/deployment/bg-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | 3 | kind: Deployment 4 | 5 | metadata: 6 | name: blue-green-deployment 7 | labels: 8 | application: web-app 9 | 10 | spec: 11 | template: 12 | metadata: 13 | name: blue-app 14 | labels: 15 | application: web-app 16 | env: dev 17 | color: blue 18 | spec: 19 | containers: 20 | - name: httpd 21 | image: varunmanik/httpd:green 22 | selector: 23 | matchLabels: 24 | application: web-app 25 | replicas: 3 -------------------------------------------------------------------------------- /8-k8s/deployment/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | 3 | kind: Deployment 4 | 5 | metadata: 6 | name: web-app-deployment 7 | labels: 8 | application: web-app 9 | 10 | spec: 11 | selector: 12 | matchLabels: 13 | application: web-app 14 | replicas: 3 15 | template: 16 | metadata: 17 | name: web2 18 | labels: 19 | application: web-app 20 | env: dev 21 | color: blue 22 | 23 | spec: 24 | containers: 25 | - name: blue 26 | image: varunmanik/httpd:v1-blue 27 | -------------------------------------------------------------------------------- /8-k8s/lesson-end-project/calc.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | 3 | kind: Deployment 4 | 5 | metadata: 6 | name: web-calc 7 | labels: 8 | application: web-app-calc 9 | 10 | spec: 11 | selector: 12 | matchLabels: 13 | application: web-app-calc 14 | replicas: 3 15 | template: 16 | metadata: 17 | name: calculator 18 | labels: 19 | application: web-app-calc 20 | env: dev 21 | product: calculator-py 22 | 23 | spec: 24 | containers: 25 | - name: calc-image 26 | image: varunmanik/python-calc-app -------------------------------------------------------------------------------- /8-k8s/pods/blue-pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | 3 | kind: Pod 4 | metadata: 5 | name: blue-app 6 | labels: 7 | env: dev 8 | application: web-app 9 | color: blue 10 | 11 | spec: 12 | containers: 13 | - name: httpd 14 | image: varunmanik/httpd:blue -------------------------------------------------------------------------------- /8-k8s/pods/database.yaml: -------------------------------------------------------------------------------- 1 | apiVersion:vi 2 | 3 | kind: Pod 4 | 5 | metadata: 6 | name : postgress-database 7 | labels: 8 | tier: db-tier 9 | 10 | spec: 11 | containers: 12 | - name: postgres 13 | image: postgres 14 | env: 15 | - name: db_pass 16 | value: 123456 17 | 18 | -------------------------------------------------------------------------------- /8-k8s/pods/green-pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | 3 | kind: Pod 4 | metadata: 5 | name: green-app 6 | labels: 7 | env: dev 8 | application: web-app 9 | color: green 10 | 11 | spec: 12 | containers: 13 | - name: httpd 14 | image: varunmanik/httpd:green -------------------------------------------------------------------------------- /8-k8s/pods/multi-container.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | 3 | kind: Pod 4 | 5 | metadata: 6 | name: mulit-container 7 | labels: 8 | env: dev 9 | tier: frontend 10 | costcenter: devops 11 | 12 | spec: 13 | containers: 14 | - name: nginx 15 | image: nginx:1.10-alpine 16 | ports: 17 | - containerPort: 80 18 | - name: alpine 19 | image: alpine:3.5 20 | command: 21 | - "watch" 22 | - "wget" 23 | - "-qO-" 24 | - "localhost" 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /8-k8s/pods/my-pod.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: myapp 5 | labels: 6 | name: myapp 7 | spec: 8 | containers: 9 | - name: myapp 10 | image: varunmanik/httpd:green 11 | 12 | ports: 13 | - containerPort: 80 -------------------------------------------------------------------------------- /8-k8s/pods/new_pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | 3 | kind: Pod 4 | metadata: 5 | name: varunapp 6 | labels: 7 | name: webapp 8 | spec: 9 | containers: 10 | - name: httpdBlueApp 11 | image: varunmanik/httpd:blue 12 | 13 | ports: 14 | - containerPort: 80 15 | -------------------------------------------------------------------------------- /8-k8s/pods/pod-def.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | 3 | 4 | kind: Pod 5 | 6 | metadata: 7 | name: pod-def 8 | 9 | spec: 10 | containers: 11 | - name: web-blue 12 | image: varunmanik/httpd:blue -------------------------------------------------------------------------------- /8-k8s/pods/web-container.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | 3 | kind: Pod 4 | 5 | metadata: 6 | 7 | name: web-server 8 | 9 | spec: 10 | 11 | containers: 12 | 13 | - name: web-container 14 | 15 | image: httpd 16 | 17 | 18 | -------------------------------------------------------------------------------- /8-k8s/resources/pods.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: web-server 5 | labels: 6 | env: dev 7 | acconut: non-prod 8 | 9 | spec: 10 | containers: 11 | - name: nginx-server 12 | image: nginx:alpine 13 | 14 | 15 | -------------------------------------------------------------------------------- /9.1-NagiOS/README.md: -------------------------------------------------------------------------------- 1 | # ELK 2 | ## https://github.com/manikcloud/elk-stack 3 | # NagiOS (https://github.com/manikcloud/DevOps-Tutorial/tree/main/9.1-NagiOS) 4 | --- 5 | 6 | # Lesson 9 Demo 1 7 | How to Install Nagios Monitoring Tool 8 | 9 | 10 | ### Steps to be followed: 11 | 1. Updating the packages 12 | - 2. Installing the latest version of Nagios XI 13 | 14 | 15 | 16 | **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. 17 | 18 | 19 | ### Step 1: Updating the packages 20 | 1.1 Update the packages using the following command: 21 | 22 | 23 | ``` 24 | sudo apt update -y 25 | 26 | ``` 27 | 28 | ### Step 2: Installing the latest version of Nagios Xi 29 | - 2.1 Login as the root user using the command given below 30 | 31 | ``` 32 | sudo -i 33 | 34 | ``` 35 | 36 | - 2.2 Execute the below command to install Nagios XI 37 | 38 | ``` 39 | curl https://assets.nagios.com/downloads/nagiosxi/install.sh | sh 40 | ``` 41 | 42 | **Note**: The installation takes around 20 mins. Please wait patiently till you get the Installation Complete message as shown below 43 | 44 | 45 | - 2.3 Navigate to the user interface by using the URL provided in your terminal session. You can refer to the screenshot given above. 46 | - 2.4 You will be presented with the Nagios XI Installation screen as shown below 47 | 48 | 49 | 50 | 51 | - 2.5 You will be first prompted to define the General System Settings 52 | 53 | - 2.6 Once you've made your desired selections choose your License Settings. Here for demonstration purposes we have chosen a trial version. 54 | 55 | - 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 56 | 57 | - 2.8 Click Next to proceed. 58 | 59 | - 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 60 | 61 | - 2.10 The page will display a spinning logo while it applies your settings to Nagios XI. 62 | 63 | - 2.11 The Installation Complete screen will be shown with the username and password required to login to Nagios XI. 64 | 65 | - 2.12 Click the Login to Nagios XI button to begin. 66 | 67 | 68 | 69 | - 2.13 The Login Screen will appear, provide your credentials and then click the Login button. 70 | 71 | 72 | 73 | - 2.14 You will need to accept the License Agreement to proceed. 74 | 75 | 76 | - 2.15 You will be logged into Nagios XI and be placed at the home screen. 77 | 78 | 79 | 80 | 81 | ---------------------------------------------------------------------------------------- 82 | 83 | # Lesson 9 Demo 2 84 | Adding Hosts to the Nagios Monitoring Tool 85 | 86 | 87 | ### Steps to be followed: 88 | 1. Logging into the Nagios XI Dashboard 89 | - 2. Adding a host using the core config manager 90 | 91 | 92 | ### Step 1: Logging into the Nagios Dashboard 93 | 1.1 Login to the nagios dashboard using the url as mentioned in the previous demo. 94 | 95 | 96 | ### Step 2: Adding a host using the core config manager 97 | - 2.1 Navigate to Configure > Core config manager from the nagios dashboard 98 | 99 | 100 | - 2.2 To manually add a new host, select the Hosts link located under Monitoring on the left menu of CCM 101 | 102 | - 2.3 This will bring up the Host Management page, which displays a list of the current hosts being monitored by Nagios XI. 103 | 104 | - 2.4 Click the Add New button to manually add a new host. 105 | 106 | - 2.5 The Host Management page will open on the Common Settings tab. 107 | 108 | - 2.6 Define the primary host parameters such as Host Name, Description, Address, and Display name. 109 | 110 | - 2.7 Use the Manage Parents button to associate parent host(s) for the host. 111 | - 2.8 Use the Manage Templates button to associate template(s) to the host. 112 | 113 | - 2.9 Use the Manage Host Groups button to associate existing host group(s) to the host 114 | 115 | 116 | - 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. 117 | 118 | - 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. 119 | 120 | 121 | - 2.12 The Check Settings tab allows you to specify the settings for frequency of checks and also the host state 122 | 123 | 124 | - 2.13 Configure settings as shown in the screenshot below 125 | 126 | - 2.14 The Alert Settings tab allows you to specify your notification settings. 127 | 128 | 129 | - 2.15 Enter the value as shown below: 130 | 131 | - 2.16 Click on manage contacts to add any contact that needs to be notified about the host status. 132 | 133 | - 2.17 The Misc Settings tab is for defining additional host information 134 | 135 | - 2.18 Once you've finished entering information for your new host, click the Save button to return to the Host Management page 136 | 137 | - 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 138 | 139 | - 2.20 You can see the apply configuration successful message as shown below: 140 | 141 | - 2.21 You can verify that the host is added to the monitoring tool. 142 | 143 | 144 | 145 | 146 | 147 | ---------------------------------------------------------------------------------------- 148 | 149 | # Lesson 9 Demo 3 150 | Continuous Monitoring on Docker with ELK Stack 151 | 152 | 153 | ### Steps to be followed: 154 | 1. Set up ELK stack on Docker 155 | 2. Configure Jenkins pipeline for Docker build and deployment 156 | 3. Run the Spring Boot application and check the logs in Kibana 157 | 158 | ### Step 1: Set up ELK stack on Docker 159 | 160 | 161 | 162 | 163 | 164 | 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. 165 | 166 | 167 | ``` 168 | su 169 | git clone https://github.com/Siraj-ul-muneera/ELKExample.git 170 | cd ELKExample 171 | ls -alrt 172 | 173 | ``` 174 | 175 | 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. 176 | 177 | 178 | ``` 179 | apt install docker-compose 180 | docker-compose version 181 | 182 | ``` 183 | 184 | 1.3 Before starting the ELK stack, run the command given below so that elastic search is configured properly. 185 | 186 | ``` 187 | 188 | sysctl -w vm.max_map_count=262144 189 | 190 | ``` 191 | 192 | 1.4 Run the docker-compose command to initialize the ELK stack. 193 | 194 | 195 | 196 | ``` 197 | docker-compose up -d 198 | docker ps 199 | 200 | ``` 201 | 202 | 203 | 204 | 205 | 1.5 Open the Kibana URL using the public IP of the host and 5601 port to access the Kibana dashboard. 206 | 207 | http://localhost:5601/app/kibana 208 | 209 | 210 | 211 | ### Step 2: Configure Jenkins pipeline for Docker build and deployment 212 | - 2.1 From the browser, navigate to http://localhost:8080 and login to Jenkins. 213 | - 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. 214 | 215 | - 2.3 Add the details as shown below 216 | 217 | 218 | ``` 219 | Username: 220 | Password: 221 | 222 | ``` 223 | 224 | - 2.4 You should now see the credentials saved as shown below 225 | 226 | - 2.5 Create a Jenkins pipeline job to fetch Jenkinsfile from the URL mentioned below. 227 | 228 | - 2.6 You can either use the below git repository or Fork it in your Github account and use it 229 | https://github.com/Siraj-ul-muneera/ELKExample.git 230 | 231 | - 2.7 Configure the job as shown in the screenshot below and then run the build. 232 | 233 | 234 | - 2.8 Give 777 permission to the Docker sock file since we are running Docker command from a Jenkins user. 235 | 236 | 237 | ``` 238 | chmod 777 /var/run/docker.sock 239 | 240 | ``` 241 | 242 | 243 | - 2.9 Build the Jenkins job to deploy the Docker container on the Docker host. 244 | 245 | - 2.10 Jenkins pipeline will complete the build and the deployment process for the Spring Boot application 246 | 247 | 248 | - 2.11 We can see the Docker container deployed on the Docker host using the command: 249 | 250 | 251 | ``` 252 | docker ps | grep springbootapp 253 | 254 | ``` 255 | 256 | 257 | 258 | ### Step 3: Run the Spring Boot application and check the logs in Kibana 259 | 260 | 3.1 Access the Spring Boot web application and perform some random activity so that the logs will be pushed to ELK stack. 261 | 262 | http://localhost:81 263 | 264 | 3.2 Check the logs pushed to ELK stack in Kibana. 265 | 266 | 3.3 Navigate to the Kibana dashboard. Select Management > Index Management from the navigation bar on the left. You can see the logs created. 267 | 268 | 269 | 270 | 271 | 272 | ---------------------------------------------------------------------------------------- 273 | 274 | ---------------------------------------------------------------------------------------- 275 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DevOps Tutorial 2 | 3 | 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. 4 | 5 | ## Emphasis on AWS and DevOps 6 | 7 | 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. 8 | 9 | ## Ideal for All Skill Levels 10 | 11 | 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. 12 | 13 | ## Repository Contents 14 | 15 | 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. 16 | 17 | 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. 18 | 19 | 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). 20 | 21 | 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. 22 | 23 | 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. 24 | 25 | 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. 26 | 27 | 7. **[Nagios](https://github.com/manikcloud/DevOps-Tutorial/tree/main/9.1-NagiOS):** Learn about Nagios for monitoring systems, networks, and infrastructure. 28 | 29 | ## Additional Resources 30 | 31 | - **[Ansible Command History](https://github.com/manikcloud/DevOps-Tutorial/blob/main/ansible-cmd-history.txt):** A log of practical Ansible commands for reference. 32 | - **[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. 33 | 34 | ## Contribution 35 | 36 | 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. 37 | 38 | Happy learning, and let's make DevOps easy and accessible for everyone! 39 | 40 | --- 41 | 42 | *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.* 43 | ---- 44 | 45 | # Caltech-DevOps Simplilearn PG Program 46 | 47 | This repository contains course materials for the Caltech-DevOps Simplilearn Postgraduate Program. 48 | 49 | ## Course Contents 50 | 51 | 1. **Course Introduction** 52 | - Overview of the program 53 | - Objectives and outcomes 54 | 55 | 2. **Basic Linux** 56 | - Introduction to Linux 57 | - File system and basic commands 58 | - Shell scripting 59 | 60 | 3. **Introduction to DevOps** 61 | - DevOps concepts and principles 62 | - DevOps practices and tools 63 | 64 | 4. **Version Control System** 65 | - Introduction to Git 66 | - Git workflow 67 | - Branching and merging strategies 68 | 69 | 5. **CI/CD Pipeline with Jenkins** 70 | - Introduction to Jenkins 71 | - Configuring and managing Jenkins 72 | - Building and deploying pipelines 73 | 74 | 6. **Configuration Management with Ansible** 75 | - Introduction to Ansible 76 | - Writing Ansible playbooks 77 | - Ansible roles and best practices 78 | 79 | 7. **Infrastructure as Code with Terraform** 80 | - Introduction to Terraform 81 | - Writing Terraform configurations 82 | - Terraform modules and best practices 83 | 84 | 8. **Containerization with Docker** 85 | - Introduction to Docker 86 | - Dockerfile and Docker Compose 87 | - Docker networking and storage 88 | 89 | 9. **Container Orchestration with Kubernetes** 90 | - Introduction to Kubernetes 91 | - Kubernetes objects and resources 92 | - Kubernetes networking and storage 93 | 94 | 10. **Continuous Monitoring** 95 | - Introduction to monitoring 96 | - Monitoring tools and techniques 97 | - Integrating monitoring with CI/CD pipelines 98 | 99 | 11. **Centralized Notification System** 100 | - Introduction to centralized notifications 101 | - Notification tools and techniques 102 | - Integrating notifications with CI/CD pipelines 103 | 104 | 12. **AWS Cloud** 105 | - Introduction to AWS 106 | - AWS services and best practices 107 | - Deploying and managing applications on AWS 108 | 109 | 13. **Real-Time Project** 110 | - Working with Java, Maven, and Tomcat 111 | - Building a complete CI/CD pipeline 112 | - Applying DevOps principles and practices 113 | 114 | --------------------------------------------------------------------------------------------------- 115 | ## How to Use This Repository 116 | 117 | This repository contains course materials, example projects, and code snippets. Use it as a reference while working through the Caltech-DevOps Simplilearn Postgraduate Program. 118 | 119 | 120 | 121 | # Getting Started 122 | 123 | To get started, you will need to clone the repository to your local machine. Follow the instructions below: 124 | 125 | 1. Open a terminal or Git Bash. 126 | 2. Navigate to the directory where you want to clone the repository. 127 | 3. Run the following command to clone the repository: 128 | 129 | ``` 130 | git clone git@github.com:manikcloud/devops-project.git 131 | ``` 132 | 133 | 4. Change into the cloned repository directory: 134 | ``` 135 | cd devops-project 136 | ``` 137 | 138 | 139 | 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. 140 | 141 | ## Contributing to the Project 142 | 143 | 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. 144 | 145 | 1. Ensure you are in the `devops-project` directory. 146 | 2. Run the following command to create a new branch: 147 | 148 | ``` 149 | git checkout -b your_branch_name 150 | ``` 151 | 3. Make your changes, commit them, and push them to the remote repository: 152 | ``` 153 | git add . 154 | git commit -m "Your commit message" 155 | git push origin your_branch_name 156 | ``` 157 | 158 | 159 | 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. 160 | 161 | Remember to always keep your local repository up to date by fetching and merging changes from the remote repository. 162 | 163 | Happy coding! 164 | 165 | # Disclaimer 166 |
167 | 168 | 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. 169 | 170 | 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. 171 | 172 | 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. 173 | 174 |
175 | 176 | ## Connect & Follow 177 | 178 | For more info, please connect and follow me: 179 | 180 | - Github: [https://github.com/manikcloud](https://github.com/manikcloud) 181 | - LinkedIn: [https://www.linkedin.com/in/vkmanik/](https://www.linkedin.com/in/vkmanik/) 182 | - Email: [varunmanik1@gmail.com](mailto:varunmanik1@gmail.com) 183 | - Facebook: [https://www.facebook.com/cloudvirtualization/](https://www.facebook.com/cloudvirtualization/) 184 | - YouTube: [https://bit.ly/32fknRN](https://bit.ly/32fknRN) 185 | - Twitter: [https://twitter.com/varunkmanik](https://twitter.com/varunkmanik) 186 | -------------------------------------------------------------------------------- /ansible-cmd-history.txt: -------------------------------------------------------------------------------- 1 | ll 2 | git clone 3 | git clone git@github.com:manikcloud/DevOps-Tutorial.git 4 | ssh-keygen 5 | cat ~/.ssh/id_rsa.pub 6 | git clone git@github.com:manikcloud/DevOps-Tutorial.git 7 | ll 8 | cd DevOps-Tutorial/ 9 | code . 10 | cd DevOps-Tutorial/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ 11 | ansible-playbook ping.yaml 12 | ansible all -m shell -a "apt upda 13 | ansible all -m shell -a "apt update -y" become true 14 | ansible all -m shell -a "apt update -y" 15 | ansible all -m shell -a "apt update -y" -b=yes 16 | ansible all -m shell -a "apt update -y" -b true 17 | ansible all -m shell -a "apt update -y" -b=true 18 | ansible-playbook ping.yaml 19 | code 20 | ll 21 | cd DevOps-Tutorial/ 22 | ls 23 | mv 6-ansible 6-ansible-terraform 24 | ll 25 | cd 6-ansible-terraform/ 26 | ls 27 | mkdir 6.6.1-tf-local-file 28 | cd 6.6.1-tf-local-file/ 29 | terraform 30 | terraform -version 31 | vim main.tf 32 | terraform init 33 | cleaf 34 | terraform plan 35 | terraform apply 36 | ll 37 | cat index.html 38 | git add . && git commit-am"adding tf local" 39 | git add . && git commit -am"adding tf local" 40 | git push 41 | resource "local_file" "foo" { 42 | git push 43 | cd .. 44 | git add . && git commit -am"adding tf local" && git push 45 | git config --global user.name "varun" 46 | git add . && git commit -am"adding tf local" && git push 47 | ll 48 | ansible 49 | ansible --version 50 | ansible -m ping localhost 51 | ansible -m ping localhost -v 52 | ansible -m ping localhost -vv 53 | ansible -m ping localhost -vvv 54 | ansible -m ping localhost -vvvv 55 | cd 6-ansible-terraform/6.8-tf-ec2-provisioning/ 56 | ll 57 | cd .. 58 | ll 59 | ls 60 | cd 6.8-tf-ec2-provisioning/ 61 | ls 62 | ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key ../deployer 63 | ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer 64 | chmod 400 deployer 65 | ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer 66 | ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer -v 67 | ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer -vv 68 | ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer -vvvv 69 | ansible all -i '3.87.250.203, 54.198.128.135, 107.22.117.179' -m ping -u ubuntu --private-key deployer 70 | ansible all -i ' 54.198.128.135' -m ping -u ubuntu --private-key deployer 71 | ls 72 | ansible all -i '54.198.128.135' -m ping -u ubuntu --private-key deployer 73 | vim ~/.ssh/known_hosts 74 | ansible all -i '54.198.128.135' -m ping -u ubuntu --private-key deployer 75 | ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer 76 | ansible all -i '54.198.128.135,' -m ping -u ubuntu --private-key deployer 77 | ansible all -i '107.22.117.179,' -m ping -u ubuntu --private-key deployer 78 | ll 79 | cd ansible/ 80 | ll 81 | cd .. 82 | ansible all -i ansible/inventory.ini -m ping 83 | cd - 84 | ll 85 | ansible all -i inventory.ini -m ping 86 | ansible all -i inventory.ini -m shell -a "la -l" 87 | ansible all -i inventory.ini -m shell -a "ls -l" 88 | ansible all -i inventory.ini -m shell -a "pwd" 89 | ansible all -i inventory.ini -m shell -a "touch index.txt" 90 | ansible all -i inventory.ini -m shell -a "ls -l" 91 | ansible -m ping localhost -v 92 | ansible -m ping localhost -vv 93 | cd ../../.. 94 | ansible -m ping localhost -vv 95 | vim /etc/ansible/ansible.cfg 96 | cd - 97 | ansible all -m shell -a "ls -l" 98 | ansible all -m shell -a "rm -rf index.txt" 99 | ansible all -m shell -a "ls -l" 100 | ansible all -m setup 101 | ll 102 | ansible-playbook ping.yaml 103 | ansible all -m shell -a "ls -l" 104 | ansible-playbook ping.yaml 105 | ansible-doc -l 106 | ansible-doc apt 107 | q q 108 | ansible-doc aptans 109 | cd 6-ansible-terraform/6.8-tf-ec2-provisioning/ 110 | terraform plan 111 | terraform apply 112 | terraform output 113 | cd 6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/ 114 | ll 115 | terraform ini 116 | terraform init 117 | terraform plan 118 | terraform apply 119 | terraform plan 120 | terraform apply 121 | terraform plan 122 | terraform apply 123 | cd .. 124 | git add . 125 | git commit -am "adding creds" 126 | git push 127 | ll 128 | cd 6-ansible-terraform/ 129 | ll 130 | cd 6.8-tf-ec2-provisioning/ 131 | ll 132 | cd .. 133 | cd - 134 | terraform init 135 | terraform plan 136 | terraform apply 137 | terraform plan 138 | terraform apply 139 | terraform destroy 140 | git push 141 | cd .. 142 | git add . 143 | git commit -am"adding cred.tf" 144 | git push 145 | cd DevOps-Tutorial/ 146 | code . 147 | history | cut -c 8- > ansible-cmd-history.txt 148 | -------------------------------------------------------------------------------- /hi.txt: -------------------------------------------------------------------------------- 1 | hi 2 | -------------------------------------------------------------------------------- /history-apr-29-2023.txt: -------------------------------------------------------------------------------- 1 | git clone git@github.com:manikcloud/DevOps-Tutorial.git 2 | ll 3 | git branch 4 | git branch -a 5 | git checkout -b dev1 6 | git branch -a 7 | git checkout -b dev-4567 8 | git branch -a 9 | git switch -c uat-123 10 | git branch -a 11 | git switch dev 12 | git switch dev1 13 | git switch - 14 | git branch -a 15 | git switch main 16 | git switch dev-4567 17 | history 18 | history | cut -c 8- 19 | history | cut -c 8- > history-apr-29-2023.txt 20 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | XYZ-company/title> 8 | 9 | </head> 10 | 11 | <body> 12 | 13 | 14 | 15 | <h1>This is GitOps Class going on. </h1> 16 | 17 | <p>This is a paragraph in Dev Branch. </p> 18 | 19 | <p>we are learning about git Merge </p> 20 | 21 | 22 | 23 | </body> 24 | 25 | </html> 26 | hi 27 | -------------------------------------------------------------------------------- /vs-code-installation.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo apt update -y 3 | sudo apt install software-properties-common apt-transport-https wget -y 4 | wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add - 5 | sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" 6 | sudo apt install code -y 7 | --------------------------------------------------------------------------------