diff --git a/5-jenkins/5.2-simple-java-program/HelloWorld.java b/5-jenkins/5.2-simple-java-program/HelloWorld.java index bbff415..3d090dc 100644 --- a/5-jenkins/5.2-simple-java-program/HelloWorld.java +++ b/5-jenkins/5.2-simple-java-program/HelloWorld.java @@ -1,5 +1,5 @@ public class HelloWorld { public static void main(String[] args) { - System.out.println("Hello, World From Varun Manik on date May 6 2023"); + System.out.println("Hello, World From Varun Manik on date MaJan 13 2024"); } } \ No newline at end of file diff --git a/5-jenkins/5.3-maven-project/my-app/src/main/java/com/mycompany/app/App.java b/5-jenkins/5.3-maven-project/my-app/src/main/java/com/mycompany/app/App.java index 32e3060..cff2a1a 100644 --- a/5-jenkins/5.3-maven-project/my-app/src/main/java/com/mycompany/app/App.java +++ b/5-jenkins/5.3-maven-project/my-app/src/main/java/com/mycompany/app/App.java @@ -8,6 +8,6 @@ public class App { public static void main( String[] args ) { - System.out.println( "Hello World! From Varun Manik in Simplilearn class" ); + System.out.println( "Hello World! From Varun Manik in Simplilearn class on date Jan 13 2024" ); } } diff --git a/5-jenkins/5.4-ant-java/HelloWorldAnt/build.xml b/5-jenkins/5.4-ant-java/HelloWorldAnt/build.xml new file mode 100644 index 0000000..cce072a --- /dev/null +++ b/5-jenkins/5.4-ant-java/HelloWorldAnt/build.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/5-jenkins/5.4-ant-java/HelloWorldAnt/src/HelloWorld.java b/5-jenkins/5.4-ant-java/HelloWorldAnt/src/HelloWorld.java new file mode 100644 index 0000000..70fd330 --- /dev/null +++ b/5-jenkins/5.4-ant-java/HelloWorldAnt/src/HelloWorld.java @@ -0,0 +1,5 @@ +public class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +} diff --git a/5-jenkins/5.4-ant-java/README.md b/5-jenkins/5.4-ant-java/README.md new file mode 100644 index 0000000..e081579 --- /dev/null +++ b/5-jenkins/5.4-ant-java/README.md @@ -0,0 +1,62 @@ +# Hello World Java Program with Ant on Linux. + +## Introduction +This tutorial guides you through creating and running a simple "Hello World" Java program using Apache Ant on a Linux system. + +## Prerequisites +- Java Development Kit (JDK) +- Apache Ant + +Ensure both are installed on your system. You can verify by running `java -version` and `ant -version` in your terminal. + +## Setup + +### Step 1: Project Structure +Create a project directory and set up the following structure: + + + +Navigate to your project directory: +```bash +mkdir HelloWorldAnt +cd HelloWorldAnt +``` + +- Step 2: Java Source File +Inside the src directory, create a file HelloWorld.java: + + + +``` +public class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +} +``` +- Step 3: Ant Build File +Create build.xml at the root of your project with the following content: + +``` + + + + + + + + + + + +``` + + +- Running the Program +To build and run your program, execute: + +``` +ant run +``` + +You should see Hello, World! printed in the console. diff --git a/5-jenkins/terraform-jenkins-pipeline/Jenkinsfile b/5-jenkins/terraform-jenkins-pipeline/Jenkinsfile new file mode 100644 index 0000000..0a9d382 --- /dev/null +++ b/5-jenkins/terraform-jenkins-pipeline/Jenkinsfile @@ -0,0 +1,35 @@ +pipeline { + agent any + + environment { + AWS_REGION = 'us-east-1' + AWS_ACCESS_KEY_ID = "" + AWS_SECRET_ACCESS_KEY = "" + } + + stages { + stage('Checkout') { + steps { + checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/vijeshnair89/terraform-jenkins-pipeline.git']]) + } + } + + stage('Terraform Init') { + steps { + sh 'terraform init' + } + } + + stage('Terraform Plan') { + steps { + sh 'terraform plan' + } + } + + stage('Terraform Apply') { + steps { + sh 'terraform apply -auto-approve' + } + } + } +} diff --git a/5-jenkins/terraform-jenkins-pipeline/main.tf b/5-jenkins/terraform-jenkins-pipeline/main.tf new file mode 100644 index 0000000..553af60 --- /dev/null +++ b/5-jenkins/terraform-jenkins-pipeline/main.tf @@ -0,0 +1,8 @@ +resource "aws_instance" "public_instance" { + ami = var.ami + instance_type = var.instance_type + + tags = { + Name = var.name_tag, + } +} \ No newline at end of file diff --git a/5-jenkins/terraform-jenkins-pipeline/output.tf b/5-jenkins/terraform-jenkins-pipeline/output.tf new file mode 100644 index 0000000..5d746db --- /dev/null +++ b/5-jenkins/terraform-jenkins-pipeline/output.tf @@ -0,0 +1,9 @@ +output "public_ip" { + value = aws_instance.public_instance.public_ip + description = "Public IP Address of EC2 instance" +} + +output "instance_id" { + value = aws_instance.public_instance.id + description = "Instance ID" +} \ No newline at end of file diff --git a/5-jenkins/terraform-jenkins-pipeline/provider.tf b/5-jenkins/terraform-jenkins-pipeline/provider.tf new file mode 100644 index 0000000..b21d3b6 --- /dev/null +++ b/5-jenkins/terraform-jenkins-pipeline/provider.tf @@ -0,0 +1 @@ +provider "aws" {} diff --git a/5-jenkins/terraform-jenkins-pipeline/variables.tf b/5-jenkins/terraform-jenkins-pipeline/variables.tf new file mode 100644 index 0000000..84d2520 --- /dev/null +++ b/5-jenkins/terraform-jenkins-pipeline/variables.tf @@ -0,0 +1,17 @@ +variable "ami" { + type = string + description = "Ubuntu AMI ID" + default = "ami-03f4878755434977f" +} + +variable "instance_type" { + type = string + description = "Instance type" + default = "t2.micro" +} + +variable "name_tag" { + type = string + description = "Name of the EC2 instance" + default = "Terraform" +} diff --git a/6-ansible/6.2-node-ansible-playbook/README.md b/6-ansible-terraform/6.2-node-ansible-playbook/README.md similarity index 100% rename from 6-ansible/6.2-node-ansible-playbook/README.md rename to 6-ansible-terraform/6.2-node-ansible-playbook/README.md diff --git a/6-ansible/6.2-node-ansible-playbook/node.yml b/6-ansible-terraform/6.2-node-ansible-playbook/node.yml similarity index 100% rename from 6-ansible/6.2-node-ansible-playbook/node.yml rename to 6-ansible-terraform/6.2-node-ansible-playbook/node.yml diff --git a/6-ansible/6.3-apache-ansible-playbook/apache.yaml b/6-ansible-terraform/6.3-apache-ansible-playbook/apache.yaml similarity index 100% rename from 6-ansible/6.3-apache-ansible-playbook/apache.yaml rename to 6-ansible-terraform/6.3-apache-ansible-playbook/apache.yaml diff --git a/6-ansible/6.4-ansible-module/README.md b/6-ansible-terraform/6.4-ansible-module/README.md similarity index 100% rename from 6-ansible/6.4-ansible-module/README.md rename to 6-ansible-terraform/6.4-ansible-module/README.md diff --git a/6-ansible/6.5-ansible-role/README.md b/6-ansible-terraform/6.5-ansible-role/README.md similarity index 100% rename from 6-ansible/6.5-ansible-role/README.md rename to 6-ansible-terraform/6.5-ansible-role/README.md diff --git a/6-ansible/6.5-ansible-role/ansible.cfg b/6-ansible-terraform/6.5-ansible-role/ansible.cfg similarity index 100% rename from 6-ansible/6.5-ansible-role/ansible.cfg rename to 6-ansible-terraform/6.5-ansible-role/ansible.cfg diff --git a/6-ansible/6.5-ansible-role/demor-role.yml b/6-ansible-terraform/6.5-ansible-role/demor-role.yml similarity index 78% rename from 6-ansible/6.5-ansible-role/demor-role.yml rename to 6-ansible-terraform/6.5-ansible-role/demor-role.yml index 78bb297..b42b276 100644 --- a/6-ansible/6.5-ansible-role/demor-role.yml +++ b/6-ansible-terraform/6.5-ansible-role/demor-role.yml @@ -2,8 +2,8 @@ --- - name: use demor role playbook - hosts: my_server - user: ansible + hosts: localhost + user: ubuntu become: true roles: diff --git a/6-ansible/6.5-ansible-role/demor/.travis.yml b/6-ansible-terraform/6.5-ansible-role/demor/.travis.yml similarity index 100% rename from 6-ansible/6.5-ansible-role/demor/.travis.yml rename to 6-ansible-terraform/6.5-ansible-role/demor/.travis.yml diff --git a/6-ansible/6.5-ansible-role/demor/README.md b/6-ansible-terraform/6.5-ansible-role/demor/README.md similarity index 100% rename from 6-ansible/6.5-ansible-role/demor/README.md rename to 6-ansible-terraform/6.5-ansible-role/demor/README.md diff --git a/6-ansible/6.5-ansible-role/demor/defaults/main.yml b/6-ansible-terraform/6.5-ansible-role/demor/defaults/main.yml similarity index 100% rename from 6-ansible/6.5-ansible-role/demor/defaults/main.yml rename to 6-ansible-terraform/6.5-ansible-role/demor/defaults/main.yml diff --git a/6-ansible/6.5-ansible-role/demor/meta/main.yml b/6-ansible-terraform/6.5-ansible-role/demor/meta/main.yml similarity index 96% rename from 6-ansible/6.5-ansible-role/demor/meta/main.yml rename to 6-ansible-terraform/6.5-ansible-role/demor/meta/main.yml index c572acc..0dbdfb9 100644 --- a/6-ansible/6.5-ansible-role/demor/meta/main.yml +++ b/6-ansible-terraform/6.5-ansible-role/demor/meta/main.yml @@ -1,6 +1,6 @@ galaxy_info: - author: your name - description: your role description + author: Varun + description: Cloud Engineer company: your company (optional) # If the issue tracker for your role is not on github, uncomment the diff --git a/6-ansible/6.5-ansible-role/demor/tasks/main.yml b/6-ansible-terraform/6.5-ansible-role/demor/tasks/main.yml similarity index 100% rename from 6-ansible/6.5-ansible-role/demor/tasks/main.yml rename to 6-ansible-terraform/6.5-ansible-role/demor/tasks/main.yml diff --git a/6-ansible/6.5-ansible-role/demor/templates/demor.j2 b/6-ansible-terraform/6.5-ansible-role/demor/templates/demor.j2 similarity index 100% rename from 6-ansible/6.5-ansible-role/demor/templates/demor.j2 rename to 6-ansible-terraform/6.5-ansible-role/demor/templates/demor.j2 diff --git a/6-ansible/6.5-ansible-role/deployer b/6-ansible-terraform/6.5-ansible-role/deployer similarity index 100% rename from 6-ansible/6.5-ansible-role/deployer rename to 6-ansible-terraform/6.5-ansible-role/deployer diff --git a/6-ansible/6.5-ansible-role/deployer.pub b/6-ansible-terraform/6.5-ansible-role/deployer.pub similarity index 100% rename from 6-ansible/6.5-ansible-role/deployer.pub rename to 6-ansible-terraform/6.5-ansible-role/deployer.pub diff --git a/6-ansible/6.5-ansible-role/host_vars.yml b/6-ansible-terraform/6.5-ansible-role/host_vars.yml similarity index 100% rename from 6-ansible/6.5-ansible-role/host_vars.yml rename to 6-ansible-terraform/6.5-ansible-role/host_vars.yml diff --git a/6-ansible-terraform/6.5-ansible-role/inventory.ini b/6-ansible-terraform/6.5-ansible-role/inventory.ini new file mode 100644 index 0000000..4dbc68f --- /dev/null +++ b/6-ansible-terraform/6.5-ansible-role/inventory.ini @@ -0,0 +1,3 @@ +[my_servers] +my_server ansible_host=localhost +# my_server ansible_host=54.224.173.170 diff --git a/6-ansible/6.6-setup-terraform/README.md b/6-ansible-terraform/6.6-setup-terraform/README.md similarity index 100% rename from 6-ansible/6.6-setup-terraform/README.md rename to 6-ansible-terraform/6.6-setup-terraform/README.md diff --git a/6-ansible/6.6-setup-terraform/tf-installation.sh b/6-ansible-terraform/6.6-setup-terraform/tf-installation.sh similarity index 100% rename from 6-ansible/6.6-setup-terraform/tf-installation.sh rename to 6-ansible-terraform/6.6-setup-terraform/tf-installation.sh diff --git a/6-ansible-terraform/6.6.1-tf-local-file/.terraform.lock.hcl b/6-ansible-terraform/6.6.1-tf-local-file/.terraform.lock.hcl new file mode 100644 index 0000000..62da99d --- /dev/null +++ b/6-ansible-terraform/6.6.1-tf-local-file/.terraform.lock.hcl @@ -0,0 +1,21 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/local" { + version = "2.4.1" + hashes = [ + "h1:FzraUapGrJoH3ZOWiUT2m6QpZAD+HmU+JmqZgM4/o2Y=", + "zh:244b445bf34ddbd167731cc6c6b95bbed231dc4493f8cc34bd6850cfe1f78528", + "zh:3c330bdb626123228a0d1b1daa6c741b4d5d484ab1c7ae5d2f48d4c9885cc5e9", + "zh:5ff5f9b791ddd7557e815449173f2db38d338e674d2d91800ac6e6d808de1d1d", + "zh:70206147104f4bf26ae67d730c995772f85bf23e28c2c2e7612c74f4dae3c46f", + "zh:75029676993accd6bef933c196b2fad51a9ec8a69a847dbbe96ec8ebf7926cdc", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:7d48d5999fe1fcdae9295a7c3448ac1541f5a24c474bd82df6d4fa3732483f2b", + "zh:b766b38b027f0f84028244d1c2f990431a37d4fc3ac645962924554016507e77", + "zh:bfc7ad301dada204cf51c59d8bd6a9a87de5fddb42190b4d6ba157d6e08a1f10", + "zh:c902b527702a8c5e2c25a6637d07bbb1690cb6c1e63917a5f6dc460efd18d43f", + "zh:d68ae0e1070cf429c46586bc87580c3ed113f76241da2b6e4f1a8348126b3c46", + "zh:f4903fd89f7c92a346ae9e666c2d0b6884c4474ae109e9b4bd15e7efaa4bfc29", + ] +} diff --git a/6-ansible-terraform/6.6.1-tf-local-file/index.html b/6-ansible-terraform/6.6.1-tf-local-file/index.html new file mode 100755 index 0000000..f077469 --- /dev/null +++ b/6-ansible-terraform/6.6.1-tf-local-file/index.html @@ -0,0 +1 @@ +Hi How are you ? \ No newline at end of file diff --git a/6-ansible-terraform/6.6.1-tf-local-file/main.tf b/6-ansible-terraform/6.6.1-tf-local-file/main.tf new file mode 100644 index 0000000..5c53112 --- /dev/null +++ b/6-ansible-terraform/6.6.1-tf-local-file/main.tf @@ -0,0 +1,7 @@ +resource "local_file" "index_file" { + + content = "Hi How are you ?" + + filename = "index.html" + +} diff --git a/6-ansible/6.7-S3-Bucket-Using-Terraform/.gitignore b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/.gitignore similarity index 100% rename from 6-ansible/6.7-S3-Bucket-Using-Terraform/.gitignore rename to 6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/.gitignore diff --git a/6-ansible/6.7-S3-Bucket-Using-Terraform/.terraform.lock.hcl b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/.terraform.lock.hcl similarity index 100% rename from 6-ansible/6.7-S3-Bucket-Using-Terraform/.terraform.lock.hcl rename to 6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/.terraform.lock.hcl diff --git a/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/README.md b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/README.md new file mode 100644 index 0000000..17a0124 --- /dev/null +++ b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/README.md @@ -0,0 +1,167 @@ +# Lesson 06 Demo 7 - Create an S3 Bucket Using Terraform + +This document provides the steps to create an S3 bucket using Terraform. + +## Steps to be performed + +1. Set up Terraform components +2. Create Terraform execution plan + +## Step 1: Set up Terraform components + +1.1 Run the following commands in the given sequence to set up the Terraform component: + +``` +pip install awscli +sudo apt-get update +``` + +1.2 Create a new file to execute this project. + + + +``` + +mkdir s3back +cd s3back +``` + +## Step 2: Create a Terraform execution plan +2.1 Create creds.tf under s3back and add the following code: + + + +``` + +nano creds.tf +``` + +2.2 Paste the following code: + + +``` + + +provider "aws" { + access_key = "" + secret_key = "" + token = "" + region = "us-east-1" +} +``` + +Note: Use the AWS access credentials provided in the AWS API Access tab in your LMS in your PRACTICE LAB tab as shown in the screenshot. + +2.3 Create main.tf under s3back and run the following code: + + + +``` + +nano main.tf +``` + +2.4 Paste the following code: + + + +``` + +resource "aws_s3_bucket" "b" { + bucket = "my-tf-test-bucket" + acl = "private" + + tags = { + Name = "My bucket" + Environment = "Dev" + } +} + +``` + +Note: Bucket name (here my-tf-test-bucket) entered here should be unique globally otherwise it may throw an error while executing the script. + +2.5 Run the following commands in the given sequence to add the AWS providers: + + + +``` + +terraform init +``` + +2.6 Run the following command to commit TF state: + + + +``` + +terraform plan +``` + +2.7 Run the following command to create the S3 bucket: + + + +``` + +terraform apply +``` + +**Enter a value: Yes** + +2.8 Verify the creation of S3 bucket in the AWS Management console. + + +--- + +# Creating and Using Secret Access Keys and Access IDs in AWS IAM for Linux VMs + +## Steps + +1. **Create an IAM User:** + - Access the AWS Management Console and navigate to IAM. + - Click "Users" -> "Add user." + - Assign a meaningful username and select "Programmatic access." + - Click "Next: Permissions." + +2. **Attach Permissions:** + - Choose an existing policy or create a custom one, granting only necessary permissions. + - Click "Next: Tags." + - Optionally add tags. + - Click "Next: Review." + - Verify details and click "Create user." + +3. **Securely Store Access Key and ID:** + - Immediately download and securely store the secret access key (not retrievable later). + - Note the access key ID. + +4. **Add Credentials to Linux VM:** + - Choose a secure storage method: + + - **Environment variables (temporary):** + ```bash + export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY_ID + export AWS_SECRET_ACCESS_KEY=YOUR_SECRET_ACCESS_KEY + ``` + + - **AWS CLI configuration file:** + Create `~/.aws/credentials`: + ``` + [default] + aws_access_key_id = YOUR_ACCESS_KEY_ID + aws_secret_access_key = YOUR_SECRET_ACCESS_KEY + + + - **AWS SDK environment variables:** + Set `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` for applications using the SDK. + +## Security Best Practices + +- **Avoid hardcoding access keys:** Use AWS Secrets Manager or similar for secure storage and rotation. +- **Regularly rotate access keys:** Enhance security. +- **Use strong passwords for IAM users:** Strengthen protection. +- **Enable MFA:** Add a layer of security. +- **Implement AWS CloudTrail:** Log API activity for auditing and analysis. +- **Regularly review and update permissions:** Maintain least privilege. + diff --git a/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/creds.tf b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/creds.tf new file mode 100644 index 0000000..9b3bfe6 --- /dev/null +++ b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/creds.tf @@ -0,0 +1,6 @@ +provider "aws" { + access_key = "" + secret_key = "" + token = "" + region = "us-east-1" +} \ No newline at end of file diff --git a/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/main.tf b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/main.tf new file mode 100644 index 0000000..74a335d --- /dev/null +++ b/6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/main.tf @@ -0,0 +1,10 @@ + +resource "aws_s3_bucket" "bucket" { + bucket = "varun-tf-test-bucket-0acb9876" + acl = "private" + + tags = { + Name = "My bucket" + Environment = "Dev" + } +} diff --git a/6-ansible/6.8-tf-ec2-provisioning/.gitignore b/6-ansible-terraform/6.8-tf-ec2-provisioning/.gitignore similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/.gitignore rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/.gitignore diff --git a/6-ansible/6.8-tf-ec2-provisioning/.terraform.lock.hcl b/6-ansible-terraform/6.8-tf-ec2-provisioning/.terraform.lock.hcl similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/.terraform.lock.hcl rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/.terraform.lock.hcl diff --git a/6-ansible/6.8-tf-ec2-provisioning/README.md b/6-ansible-terraform/6.8-tf-ec2-provisioning/README.md similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/README.md rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/README.md diff --git a/6-ansible/6.8-tf-ec2-provisioning/amazon-linux-vm.tf b/6-ansible-terraform/6.8-tf-ec2-provisioning/amazon-linux-vm.tf similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/amazon-linux-vm.tf rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/amazon-linux-vm.tf diff --git a/6-ansible/6.8-tf-ec2-provisioning/ansible/README.md b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/README.md similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/ansible/README.md rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/README.md diff --git a/6-ansible/6.8-tf-ec2-provisioning/ansible/ansible.cfg b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ansible.cfg similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/ansible/ansible.cfg rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ansible.cfg diff --git a/6-ansible/6.8-tf-ec2-provisioning/ansible/apache.yaml b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/apache.yaml similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/ansible/apache.yaml rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/apache.yaml diff --git a/6-ansible/6.8-tf-ec2-provisioning/ansible/host_vars.yaml b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/host_vars.yaml similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/ansible/host_vars.yaml rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/host_vars.yaml diff --git a/6-ansible/6.8-tf-ec2-provisioning/ansible/inventory copy.ini-backup b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory copy.ini-backup similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/ansible/inventory copy.ini-backup rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory copy.ini-backup diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory.ini b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory.ini new file mode 100644 index 0000000..2f2a14f --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory.ini @@ -0,0 +1,29 @@ + +[ubuntu_vm] +my_server_1 ansible_host=54.224.173.170 +my_server_2 ansible_host=54.166.216.181 +my_server_3 ansible_host=50.16.161.255 + + +[ubuntu:children] +ubuntu_vm + +[ubuntu:vars] +ansible_user=ubuntu +ansible_ssh_private_key_file=../deployer + + + +[aws_linux_vm] +# aws_linux ansible_host=54.210.170.163 +aws_linux ansible_host=54.161.95.81 +# aws_linux ansible_host=34.207.226.250 + + + +[aws:children] +aws_linux_vm + +[aws:vars] +ansible_user=ec2-user +ansible_ssh_private_key_file=../deployer diff --git a/6-ansible/6.8-tf-ec2-provisioning/ansible/inventory.ini b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory.ini.org similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/ansible/inventory.ini rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/inventory.ini.org diff --git a/6-ansible/6.8-tf-ec2-provisioning/ansible/jenkins.yaml b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/jenkins.yaml similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/ansible/jenkins.yaml rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/jenkins.yaml diff --git a/6-ansible/6.8-tf-ec2-provisioning/ansible/node.yaml b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/node.yaml similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/ansible/node.yaml rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/node.yaml diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_1 b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_1 new file mode 100644 index 0000000..f2c413c --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_1 @@ -0,0 +1 @@ +{"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": true, "cmd": "apt update -y", "delta": "0:00:02.166809", "end": "2024-01-20 07:28:54.068907", "msg": "", "rc": 0, "start": "2024-01-20 07:28:51.902098", "stderr": "\nWARNING: apt does not have a stable CLI interface. Use with caution in scripts.", "stderr_lines": ["", "WARNING: apt does not have a stable CLI interface. Use with caution in scripts."], "stdout": "Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy InRelease\nHit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease\nHit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease\nHit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease\nReading package lists...\nBuilding dependency tree...\nReading state information...\n168 packages can be upgraded. Run 'apt list --upgradable' to see them.", "stdout_lines": ["Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy InRelease", "Hit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease", "Hit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease", "Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease", "Reading package lists...", "Building dependency tree...", "Reading state information...", "168 packages can be upgraded. Run 'apt list --upgradable' to see them."]} \ No newline at end of file diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_2 b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_2 new file mode 100644 index 0000000..46b4678 --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_2 @@ -0,0 +1 @@ +{"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": true, "cmd": "apt update -y", "delta": "0:00:02.238591", "end": "2024-01-20 07:28:54.160319", "msg": "", "rc": 0, "start": "2024-01-20 07:28:51.921728", "stderr": "\nWARNING: apt does not have a stable CLI interface. Use with caution in scripts.", "stderr_lines": ["", "WARNING: apt does not have a stable CLI interface. Use with caution in scripts."], "stdout": "Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy InRelease\nHit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease\nHit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease\nHit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease\nReading package lists...\nBuilding dependency tree...\nReading state information...\n168 packages can be upgraded. Run 'apt list --upgradable' to see them.", "stdout_lines": ["Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy InRelease", "Hit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease", "Hit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease", "Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease", "Reading package lists...", "Building dependency tree...", "Reading state information...", "168 packages can be upgraded. Run 'apt list --upgradable' to see them."]} \ No newline at end of file diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_3 b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_3 new file mode 100644 index 0000000..fbf4eae --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/rue/my_server_3 @@ -0,0 +1 @@ +{"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": true, "cmd": "apt update -y", "delta": "0:00:02.234414", "end": "2024-01-20 07:28:54.111227", "msg": "", "rc": 0, "start": "2024-01-20 07:28:51.876813", "stderr": "\nWARNING: apt does not have a stable CLI interface. Use with caution in scripts.", "stderr_lines": ["", "WARNING: apt does not have a stable CLI interface. Use with caution in scripts."], "stdout": "Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy InRelease\nHit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease\nHit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease\nHit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease\nReading package lists...\nBuilding dependency tree...\nReading state information...\n168 packages can be upgraded. Run 'apt list --upgradable' to see them.", "stdout_lines": ["Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy InRelease", "Hit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease", "Hit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease", "Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease", "Reading package lists...", "Building dependency tree...", "Reading state information...", "168 packages can be upgraded. Run 'apt list --upgradable' to see them."]} \ No newline at end of file diff --git a/6-ansible/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-1.yaml b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-1.yaml similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-1.yaml rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-1.yaml diff --git a/6-ansible/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-config.php.j2 b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-config.php.j2 similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-config.php.j2 rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ubuntu-wp-config.php.j2 diff --git a/6-ansible/6.8-tf-ec2-provisioning/ansible/wp-config.php.j2 b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/wp-config.php.j2 similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/ansible/wp-config.php.j2 rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/wp-config.php.j2 diff --git a/6-ansible/6.8-tf-ec2-provisioning/ansible/wp.yaml b/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/wp.yaml similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/ansible/wp.yaml rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/wp.yaml diff --git a/6-ansible-terraform/6.8-tf-ec2-provisioning/creds.tf b/6-ansible-terraform/6.8-tf-ec2-provisioning/creds.tf new file mode 100644 index 0000000..9d4d164 --- /dev/null +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/creds.tf @@ -0,0 +1,6 @@ +provider "aws" { + access_key = "AKIAQ7ZCMYMXTD7Q2FOK" + secret_key = "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" + token = "" + region = "us-east-1" +} \ No newline at end of file diff --git a/6-ansible/6.8-tf-ec2-provisioning/deployer b/6-ansible-terraform/6.8-tf-ec2-provisioning/deployer similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/deployer rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/deployer diff --git a/6-ansible/6.8-tf-ec2-provisioning/deployer.ppk b/6-ansible-terraform/6.8-tf-ec2-provisioning/deployer.ppk similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/deployer.ppk rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/deployer.ppk diff --git a/6-ansible/6.8-tf-ec2-provisioning/deployer.pub b/6-ansible-terraform/6.8-tf-ec2-provisioning/deployer.pub similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/deployer.pub rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/deployer.pub diff --git a/6-ansible/6.8-tf-ec2-provisioning/main.tf b/6-ansible-terraform/6.8-tf-ec2-provisioning/main.tf similarity index 70% rename from 6-ansible/6.8-tf-ec2-provisioning/main.tf rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/main.tf index a97b619..aa62dda 100644 --- a/6-ansible/6.8-tf-ec2-provisioning/main.tf +++ b/6-ansible-terraform/6.8-tf-ec2-provisioning/main.tf @@ -9,7 +9,3 @@ terraform { required_version = ">= 0.14.9" } -provider "aws" { - profile = "default" - region = "us-east-1" -} diff --git a/6-ansible/6.8-tf-ec2-provisioning/ubuntu-vm.tf b/6-ansible-terraform/6.8-tf-ec2-provisioning/ubuntu-vm.tf similarity index 100% rename from 6-ansible/6.8-tf-ec2-provisioning/ubuntu-vm.tf rename to 6-ansible-terraform/6.8-tf-ec2-provisioning/ubuntu-vm.tf diff --git a/6-ansible/README.md b/6-ansible-terraform/README.md similarity index 100% rename from 6-ansible/README.md rename to 6-ansible-terraform/README.md diff --git a/6-ansible-terraform/wordpress/README.md b/6-ansible-terraform/wordpress/README.md new file mode 100644 index 0000000..0803bd6 --- /dev/null +++ b/6-ansible-terraform/wordpress/README.md @@ -0,0 +1,123 @@ +# DevOps-Tutorial + +## Goal +The goal of this project is to provide an example of how to use Ansible to setup a WordPress site on an AWS EC2 instance running Amazon Linux 2. + +## Features +- This Ansible playbook will install all necessary dependencies including Python, PHP, Apache, and MariaDB. +- It sets up a WordPress database and user. +- It downloads the latest version of WordPress and configures it to use the database. +- It updates the WordPress config file using an Ansible template. + +## Prerequisites +- An AWS account with the necessary permissions to create EC2 instances. +- Ansible installed on your local machine or control node. +- Basic knowledge of Ansible playbooks. + +## Usage +1. Clone this repository to your local machine or control node: `git clone https://github.com/manikcloud/DevOps-Tutorial.git` +2. Change into the project directory: `cd DevOps-Tutorial` +3. Update the `aws_linux_vm` variable in the playbook with the IP address or hostname of your EC2 instance. +4. Run the playbook: `ansible-playbook playbook.yml` + +--- + + +# Setting up WordPress on an Amazon Linux Instance + +This guide provides a simplified overview of setting up WordPress on an Amazon Linux instance. **It assumes familiarity with the command line and AWS services.** + +**## Steps:** + +1. **Launch an Amazon Linux EC2 Instance:** + - Log into your AWS account. + - Launch an Amazon Linux EC2 instance. + - Ensure security groups allow HTTP (port 80) and SSH (port 22) access. + +2. **Connect to Your Instance:** + - Use SSH to connect to your instance: + ```bash + ssh -i /path/to/your-key.pem ec2-user@your-instance-public-dns + ``` + +3. **Update Your Instance:** + - Once connected, update your instance: + ```bash + sudo yum update -y + ``` + +4. **Install Apache Web Server:** + - Install and start Apache: + ```bash + sudo yum install httpd -y + sudo systemctl start httpd.service + sudo systemctl enable httpd.service + ``` + +5. **Install MySQL (MariaDB):** + - Install the MariaDB server: + ```bash + sudo yum install mariadb-server mariadb -y + sudo systemctl start mariadb + sudo mysql_secure_installation + sudo systemctl enable mariadb.service + ``` + +6. **Create a WordPress Database and User:** + - Log into the MariaDB shell and create a database and user: + ```sql + mysql -u root -p + CREATE DATABASE wordpress; + GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password'; + FLUSH PRIVILEGES; + EXIT; + ``` + +7. **Install PHP:** + - Install PHP and necessary extensions: + ```bash + sudo yum install php php-mysql php-gd php-pear -y + sudo systemctl restart httpd.service + ``` + +8. **Download and Install WordPress:** + - Download and configure WordPress: + ```bash + wget [https://wordpress.org/latest.tar.gz](https://wordpress.org/latest.tar.gz) + tar -xzf latest.tar.gz + sudo rsync -avP ~/wordpress/ /var/www/html/ + mkdir /var/www/html/wp-content/uploads + sudo chown -R apache:apache /var/www/html/* + ``` + +9. **Configure WordPress:** + - Navigate to the `/var/www/html` directory. + - Rename and edit the WordPress configuration file: + ```bash + cd /var/www/html + mv wp-config-sample.php wp-config.php + sudo nano wp-config.php + ``` + - Update the database settings. + +10. **Complete Installation Through the Web Interface:** + - Access your server's domain or IP address in a web browser. + - Complete the WordPress installation through the web interface. + +**## Additional Considerations:** + +- **HTTPS:** Set up HTTPS for secure communication. +- **Virtual Hosts:** Configure virtual hosts to manage multiple websites. +- **Server Optimization:** Optimize server performance for WordPress. +- **WordPress Security:** Secure your WordPress installation. + + + +## Conclusion +This project provides a starting point for automating the setup of WordPress sites using Ansible and AWS. It can be extended or modified to suit your specific needs. This project is for demonstration purposes and should not be used as-is for production environments. + +## Contributing +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. + +## License +[MIT](https://choosealicense.com/licenses/mit/) diff --git a/6-ansible/wordpress/wp-config.php.j2 b/6-ansible-terraform/wordpress/wp-config.php.j2 similarity index 100% rename from 6-ansible/wordpress/wp-config.php.j2 rename to 6-ansible-terraform/wordpress/wp-config.php.j2 diff --git a/6-ansible/wordpress/wp.yaml b/6-ansible-terraform/wordpress/wp.yaml similarity index 100% rename from 6-ansible/wordpress/wp.yaml rename to 6-ansible-terraform/wordpress/wp.yaml diff --git a/6-ansible/6.5-ansible-role/inventory.ini b/6-ansible/6.5-ansible-role/inventory.ini deleted file mode 100644 index 83727e2..0000000 --- a/6-ansible/6.5-ansible-role/inventory.ini +++ /dev/null @@ -1,4 +0,0 @@ -[my_servers] -my_server ansible_host=18.209.59.137 - -#ansible all -i '18.209.59.137,' --private-key=path/to/deployer -m ping \ No newline at end of file diff --git a/6-ansible/6.7-S3-Bucket-Using-Terraform/README.md b/6-ansible/6.7-S3-Bucket-Using-Terraform/README.md deleted file mode 100644 index bfbace2..0000000 --- a/6-ansible/6.7-S3-Bucket-Using-Terraform/README.md +++ /dev/null @@ -1,115 +0,0 @@ -# Lesson 06 Demo 7 - Create an S3 Bucket Using Terraform - -This document provides the steps to create an S3 bucket using Terraform. - -## Steps to be performed - -1. Set up Terraform components -2. Create Terraform execution plan - -## Step 1: Set up Terraform components - -1.1 Run the following commands in the given sequence to set up the Terraform component: - -``` -pip install awscli -sudo apt-get update -``` - -1.2 Create a new file to execute this project. - - - -``` - -mkdir s3back -cd s3back -``` - -## Step 2: Create a Terraform execution plan -2.1 Create creds.tf under s3back and add the following code: - - - -``` - -nano creds.tf -``` - -2.2 Paste the following code: - - -``` - - -provider "aws" { - access_key = "" - secret_key = "" - token = "" - region = "us-east-1" -} -``` - -Note: Use the AWS access credentials provided in the AWS API Access tab in your LMS in your PRACTICE LAB tab as shown in the screenshot. - -2.3 Create main.tf under s3back and run the following code: - - - -``` - -nano main.tf -``` - -2.4 Paste the following code: - - - -``` - -resource "aws_s3_bucket" "b" { - bucket = "my-tf-test-bucket" - acl = "private" - - tags = { - Name = "My bucket" - Environment = "Dev" - } -} - -``` - -Note: Bucket name (here my-tf-test-bucket) entered here should be unique globally otherwise it may throw an error while executing the script. - -2.5 Run the following commands in the given sequence to add the AWS providers: - - - -``` - -terraform init -``` - -2.6 Run the following command to commit TF state: - - - -``` - -terraform plan -``` - -2.7 Run the following command to create the S3 bucket: - - - -``` - -terraform apply -``` - -**Enter a value: Yes** - -2.8 Verify the creation of S3 bucket in the AWS Management console. - - diff --git a/6-ansible/6.7-S3-Bucket-Using-Terraform/main.tf b/6-ansible/6.7-S3-Bucket-Using-Terraform/main.tf deleted file mode 100644 index 84b4269..0000000 --- a/6-ansible/6.7-S3-Bucket-Using-Terraform/main.tf +++ /dev/null @@ -1,13 +0,0 @@ -provider "aws" { - - region = "us-east-1" -} -resource "aws_s3_bucket" "b" { - bucket = "my-tf-test-bucket-345611" - acl = "private" - - tags = { - Name = "My bucket" - Environment = "Dev" - } -} diff --git a/6-ansible/6.8-tf-ec2-provisioning/ansible/ping.yaml b/6-ansible/6.8-tf-ec2-provisioning/ansible/ping.yaml deleted file mode 100644 index 52c7a72..0000000 --- a/6-ansible/6.8-tf-ec2-provisioning/ansible/ping.yaml +++ /dev/null @@ -1,33 +0,0 @@ ---- - -- name: This is a simple Playbook. - hosts: my_servers - become: yes - gather_facts: yes - - tasks: - - name: 1. Ping the remote server - ping: - - name: 2. Create index file - file: - path: /home/ubuntu/index.html - state: touch - - - name: 3. Apache2 - apt: - name: apache2 - state: present - - - - name: 4. Apache2-service - service: - name: apache2 - state: restarted - - # # - name: 2. Un-Install git - # # apt: - # # name: git - # # state: present - - - \ No newline at end of file diff --git a/6-ansible/wordpress/README.md b/6-ansible/wordpress/README.md deleted file mode 100644 index ce902c9..0000000 --- a/6-ansible/wordpress/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# DevOps-Tutorial - -## Goal -The goal of this project is to provide an example of how to use Ansible to setup a WordPress site on an AWS EC2 instance running Amazon Linux 2. - -## Features -- This Ansible playbook will install all necessary dependencies including Python, PHP, Apache, and MariaDB. -- It sets up a WordPress database and user. -- It downloads the latest version of WordPress and configures it to use the database. -- It updates the WordPress config file using an Ansible template. - -## Prerequisites -- An AWS account with the necessary permissions to create EC2 instances. -- Ansible installed on your local machine or control node. -- Basic knowledge of Ansible playbooks. - -## Usage -1. Clone this repository to your local machine or control node: `git clone https://github.com/manikcloud/DevOps-Tutorial.git` -2. Change into the project directory: `cd DevOps-Tutorial` -3. Update the `aws_linux_vm` variable in the playbook with the IP address or hostname of your EC2 instance. -4. Run the playbook: `ansible-playbook playbook.yml` - -## Conclusion -This project provides a starting point for automating the setup of WordPress sites using Ansible and AWS. It can be extended or modified to suit your specific needs. This project is for demonstration purposes and should not be used as-is for production environments. - -## Contributing -Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. - -## License -[MIT](https://choosealicense.com/licenses/mit/) diff --git a/7-docker/Dockerfile b/7-docker/Dockerfile index 3331d7b..b4723a1 100644 --- a/7-docker/Dockerfile +++ b/7-docker/Dockerfile @@ -1,11 +1,15 @@ # Use Ubuntu as a base image -FROM ubuntu +FROM ubuntu:22.04 # Update and install nginx -RUN apt-get update && apt-get install -y nginx +RUN apt-get update + +RUN apt-get install -y nginx # Copy the custom index file to the nginx directory -COPY index.nginx-debian.html /var/www/html +COPY index.html /var/www/html + +EXPOSE 80 # Start nginx in the foreground to keep the container running CMD ["nginx", "-g", "daemon off;"] diff --git a/7-docker/Final-project-docker/5.11-docker-compose/Dockerfile b/7-docker/Final-project-docker/5.11-docker-compose/Dockerfile new file mode 100644 index 0000000..9ec6968 --- /dev/null +++ b/7-docker/Final-project-docker/5.11-docker-compose/Dockerfile @@ -0,0 +1,5 @@ +FROM python:3.4-alpine +ADD . /code +WORKDIR /code +RUN pip install -r requirements.txt +CMD ["python", "app.py"] diff --git a/7-docker/Final-project-docker/5.11-docker-compose/README.md b/7-docker/Final-project-docker/5.11-docker-compose/README.md new file mode 100644 index 0000000..ae09000 --- /dev/null +++ b/7-docker/Final-project-docker/5.11-docker-compose/README.md @@ -0,0 +1,348 @@ +# Lesson 5 Demo 11: Convert an Application Deployment into a Stack + +This section will guide you to: +- Convert an application deployment into a stack using a file named docker-compose.yml + +| Feature | Docker Service | Docker Stack | +|---------|----------------|--------------| +| Definition | A Docker Service is the definition of the tasks to execute on the manager or worker nodes. It is a part of Docker Swarm, Docker's built-in orchestration solution. | A Docker Stack is a group of interrelated services that share dependencies, and can be orchestrated and scaled together. A stack effectively encapsulates a multi-service application. | +| Use Case | Docker Services are ideal for deploying the same image across multiple environments. You can adjust the number of replicas for each service based on the environment's requirements. | Docker Stacks are perfect for defining and managing multi-service applications. Stacks allow you to manage all the services of an application with just one file. | +| Scale | Services can be scaled up or down individually. | All services within a stack are scaled together, maintaining the application's functionality. | +| Command | `docker service create` | `docker stack deploy` | + +### Step 1: Drain the worker nodes in the swarm cluster to make sure the registry service runs on the manager node +- List all the nodes present in the swarm cluster and ensure that all nodes are in Active state + +``` +sudo docker node ls + +``` + + +**Note**: Copy the HOSTNAME of worker nodes +- Use the following command to drain the worker nodes: + +``` +sudo docker node update --availability drain hostname_Worker_Node + +``` + + +**Note**: Replace hostname_Worker_Node with the HOSTNAME copied in previous ### Step + + +### Step 2: Start the registry as a service on your swarm + +``` +sudo docker service create --name registry --publish published=5000,target=5000 registry:2 + + +``` + + +### Step 3: List the running services to check the status of registry service + +``` +sudo docker service ls + +``` + + + +### Step 4: Check if registry service is working with curl + +``` + +curl http://localhost:5000/v2/ + +``` + + + +### Step 5: Create a directory for the project + +``` + +mkdir stackdemo +cd stackdemo + +``` + + + +### Step 6: Create a file called app.py in the stackdemo directory +- Use the following command to create a project file: + +``` + +nano app.py + +``` + + +- Add the following code in the app.py file: + +``` + +from flask import Flask +from redis import Redis + +app = Flask(__name__) +redis = Redis(host='redis', port=6379) + +@app.route('/') +def hello(): + count = redis.incr('hits') + return 'Hello World! I have been seen {} times.\n'.format(count) + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=8000, debug=True) + +``` + + +**Note**: Press Ctrl+X to exit the editor. Then type Y and press Enter to save the file. + +### Step 7: Create a file called requirements.txt +- Use the following command to create and open requirements.txt: + +``` + +nano requirements.txt + +``` + + +- Add the following text in the requirements.txt file: + +``` + +flask +redis + +``` + + +**Note**: Press Ctrl+X to exit the editor. Then type Y and press Enter to save the file. + +### Step 8: Create a file called Dockerfile +- Use the following command to create a Dockerfile: + +``` + +nano Dockerfile + +``` + + +- Add the following code in the Dockerfile: + +``` + +FROM python:3.4-alpine +ADD . /code +WORKDIR /code +RUN pip install -r requirements.txt +CMD ["python", "app.py"] + +``` + + +**Note**: Press Ctrl+X to exit the editor. Then type Y and press Enter to save the file. + +### Step 9: Create a file named docker-compose.yml +- Use the following command to create the docker-compose.yml file: + +``` + +nano docker-compose.yml + +``` + + +- Add the following code in the docker-compose.yml file: + +``` + +version: "3.3" +services: + web: + image: 127.0.0.1:5000/stackdemo + build: . + ports: + - "8000:8000" + redis: + image: redis:alpine + +``` + + +**Note**: Press Ctrl+X to exit the editor. Then type Y and press Enter to save the file. + +### Step 10: Start the application +- Use the following commands to install docker-compose: + +``` +sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + + +sudo chmod +x /usr/local/bin/docker-compose + docker-compose --version + +``` + + + + +- Start docker-compose using the following command: + +``` +sudo docker-compose up -d + +``` + + + + +### Step 11: Use the following commands to check whether the app is running + +``` +sudo docker-compose ps + +curl http://localhost:8000 + +``` + + + +### Step 12: Bring the application down + +``` +sudo docker-compose down --volumes + + +``` + + +### Step 13: Push the application to the registry + +``` +sudo docker-compose push + +``` + + + +### Step 14: Use the following command to create the stack docker stack deploy: + +``` +sudo docker stack deploy --compose-file docker-compose.yml stackdemo + +``` + + + +### Step 15: Check if the stack is running + +``` +sudo docker stack services stackdemo + +``` + + + +### Step 16: Test the app again with curl command + +``` + +curl http://localhost:8000 +curl http://ip-172-31-26-147:8000 + +``` + +**Note**: In ### Step 10 while starting docker-compose if you get an error showing the port is already assigned, run the command + +``` +sudo docker ps and kill the container with the same port and then proceed. + +``` + + + +### Step 17: Use the following command to bring the stack down: + +``` +sudo docker stack rm stackdemo + +``` + +----------------------------------------------------------------- + +# Lesson 5 Demo 12: Increase Number of Replicas + +This section will guide you to: +- Increase the number of replicas of a task for any given service + +### Step 1: List the Docker services + +``` +sudo docker service ls +``` + +### Step 2: Scale up the redis service to five tasks + +``` +sudo docker service scale redis=5 + ``` + +### Step 3: Scale the registry service to four tasks using update flag + +``` +sudo docker service update --replicas=4 registry + ``` + +### Step 4: Use the scale flag to scale both redis and registry services at the same time + +``` +sudo docker service scale redis=4 registry=3 + ``` + +### Step 5: Check the actual number of replicas created + +``` +sudo docker service ls + ``` + +### Step 6: Create a global service and scale it up to ten tasks + +``` +sudo docker service create --mode global --name nginx nginx:latest + + +sudo docker service scale nginx=10 +``` + +**Note**: Notice that the scaling cannot be used with global services. It can only be done with replicated service. + + +# Disclaimer +
+ +Please **Note** that the entire repository is owned and maintained by [Varun Kumar Manik](https://www.linkedin.com/in/vkmanik/). While every effort has been made to ensure the accuracy and reliability of the information and resources provided in this repository, Varun Kumar Manik takes full responsibility for any errors or inaccuracies that may be present. + +Simplilearn is not responsible for the content or materials provided in this repository and disclaims all liability for any issues, misunderstandings, or claims that may arise from the use of the information or materials provided. By using this repository, you acknowledge that Varun Kumar Manik is solely accountable for its content, and you agree to hold Simplilearn harmless from any claims or liabilities that may arise as a result of your use or reliance on the information provided herein. + +It is important to understand that this repository contains educational materials for a training course, and users are expected to apply their own judgment and discretion when utilizing the provided resources. Neither Varun Kumar Manik nor Simplilearn can guarantee specific results or outcomes from following the materials in this repository. + +
+ +## Connect & Follow + +For more info, please connect and follow me: + +- Github: [https://github.com/manikcloud](https://github.com/manikcloud) +- LinkedIn: [https://www.linkedin.com/in/vkmanik/](https://www.linkedin.com/in/vkmanik/) +- Email: [varunmanik1@gmail.com](mailto:varunmanik1@gmail.com) +- Facebook: [https://www.facebook.com/cloudvirtualization/](https://www.facebook.com/cloudvirtualization/) +- YouTube: [https://bit.ly/32fknRN](https://bit.ly/32fknRN) +- Twitter: [https://twitter.com/varunkmanik](https://twitter.com/varunkmanik) diff --git a/7-docker/Final-project-docker/5.11-docker-compose/app.py b/7-docker/Final-project-docker/5.11-docker-compose/app.py new file mode 100644 index 0000000..c3bfb04 --- /dev/null +++ b/7-docker/Final-project-docker/5.11-docker-compose/app.py @@ -0,0 +1,13 @@ +from flask import Flask +from redis import Redis + +app = Flask(__name__) +redis = Redis(host='redis', port=6379) + +@app.route('/') +def hello(): + count = redis.incr('hits') + return 'Hello World! I have been seen {} times.\n'.format(count) + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=8000, debug=True) diff --git a/7-docker/Final-project-docker/5.11-docker-compose/requirements.txt b/7-docker/Final-project-docker/5.11-docker-compose/requirements.txt new file mode 100644 index 0000000..02c585a --- /dev/null +++ b/7-docker/Final-project-docker/5.11-docker-compose/requirements.txt @@ -0,0 +1,2 @@ +flask +redis diff --git a/7-docker/README.md b/7-docker/README.md index 0acced9..13d7062 100644 --- a/7-docker/README.md +++ b/7-docker/README.md @@ -1,5 +1,5 @@ # Docker - +- [# Docekr basic commands & their flags](#Docekr-basic-commands-their-flags) - [Lesson 7 Demo 2: Performing CRUD Operation on Containers](#lesson-7-demo-2) - [Step 1: Pulling a Docker image](#step-1-pulling-a-docker-image) - [Step 2: Creating a new container](#step-2-creating-a-new-container) @@ -23,6 +23,26 @@ - [Step 3: Connecting the network from another SSH server](#step-3-connecting-the-network-from-another-ssh-server) + +# Docekr basic commands their flags + +| Command | Description | Flags/Options | +|---------|-------------|---------------| +| `docker run` | Run a new container | `-d` (detached), `-p` (port mapping), `--name` (name of the container), `-e` (environment variables) | +| `docker ps` | List running containers | `-a` (all containers), `--format` (format output) | +| `docker stop` | Stop a running container | `` (ID or name of the container) | +| `docker rm` | Remove a container | `-f` (force), `` | +| `docker images` | List Docker images | `-a` (all images), `--format` (format output) | +| `docker rmi` | Remove a Docker image | `` (ID or name of the image), `-f` (force) | +| `docker build` | Build an image from a Dockerfile | `-t` (tag/name of the image), `` | +| `docker pull` | Pull an image from a registry | `` (name of the image) | +| `docker push` | Push an image to a registry | `` (name of the image) | +| `docker exec` | Execute a command in a running container | `-it` (interactive terminal), `` (ID or name of the container), `` (command to execute) | +| `docker logs` | Fetch the logs of a container | `` (ID or name of the container), `--tail` (number of lines to show) | +| `docker network` | Manage Docker networks | `create`, `inspect`, `ls`, `rm` (subcommands for network management) | +| `docker volume` | Manage Docker volumes | `create`, `inspect`, `ls`, `rm` (subcommands for volume management) | + + # Lesson 7 Demo 2 Performing CRUD Operation on Containers diff --git a/7-docker/index.html b/7-docker/index.html index 6d580ec..e0cf6b2 100644 --- a/7-docker/index.html +++ b/7-docker/index.html @@ -3,7 +3,8 @@

My First Heading

-

My first paragraph.

+

Lorem ipsum...

+

This is DevOps class.

- \ No newline at end of file + diff --git a/8-k8s/FAQ/Readme.md b/8-k8s/FAQ/Readme.md new file mode 100644 index 0000000..1df76d4 --- /dev/null +++ b/8-k8s/FAQ/Readme.md @@ -0,0 +1,181 @@ + + +# PodDisruptionBudget (PDB) in Kubernetes + +A `PodDisruptionBudget` (PDB) in Kubernetes is a policy that sets limits on the number of Pods of a replicated application that can be simultaneously down among a set of Pods. It helps ensure that a specified minimum number of Pods are always available during voluntary disruptions, such as when performing cluster maintenance (e.g., node upgrades, resizes). + +## Key Concepts + +- **MinAvailable**: Specifies the minimum number of Pods that should remain available during the disruption. +- **MaxUnavailable**: Defines the maximum number of Pods that can be unavailable during the disruption. + +## Usage + +PDBs are particularly useful in production environments to maintain application availability during operations that require Pod eviction, like node maintenance. + +## Example + +A simple PDB might look like this: + +```yaml +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: myapp-pdb +spec: + minAvailable: 2 + selector: + matchLabels: + app: myapp +``` + +--- + +# Finding Configuration Files in Kubernetes + +Kubernetes configuration files are YAML or JSON files that define how resources should be created and managed within the Kubernetes cluster. These files can specify configurations for pods, services, volumes, and more. Here's how you can find and manage these configuration files. + +## Locations of Configuration Files + +### System-Wide Configuration + +- **Kubernetes Master Node**: + - `/etc/kubernetes/manifests`: Contains static pod manifests for the Kubernetes control plane components (apiserver, controller-manager, scheduler, etc.). + - `/etc/kubernetes/admin.conf`, `/etc/kubernetes/kubelet.conf`, and `/etc/kubernetes/controller-manager.conf`: Configuration files for accessing the Kubernetes API. + +- **Kubelet**: + - `/var/lib/kubelet/config.yaml`: The primary configuration file for the kubelet. + +- **Kubeadm**: + - `/etc/kubernetes/kubeadm-config.yaml`: The configuration file used by `kubeadm init` and `kubeadm join`. + +### User-Defined Resource Configurations + +- **Application Specific**: Typically, the configuration files for your applications (pods, deployments, services, etc.) are not stored on the cluster nodes. Instead, they are managed by users and stored wherever is convenient for version control, such as in a Git repository. + +--- + +# Kubernetes Storage and Stateful Workloads Explained + +Understanding Persistent Volumes (PV), Persistent Volume Claims (PVC), and StatefulSets is crucial for managing stateful applications in Kubernetes. Here's a surface-level overview of these concepts without diving into specific commands. + +## Persistent Volumes (PV) + +**Persistent Volumes** are a way for users to manage durable storage in Kubernetes. PVs are resources in the cluster that provision storage, such as disks, that persist beyond the lifecycle of individual pods. Administrators typically create PVs to represent available storage in the cluster. + +### Key Points: + +- **Cluster Resource**: PVs are a cluster-level resource, meaning they are not tied to a specific namespace. +- **Storage Abstraction**: Provides an abstraction over underlying storage systems, supporting various storage backends like NFS, iSCSI, cloud storage services, and more. +- **Lifecycle Independent**: PVs exist independently of pods, ensuring data persists even when pods are deleted or moved. + +## Persistent Volume Claims (PVC) + +**Persistent Volume Claims** are requests for storage by users. PVCs specify size, access modes (e.g., read/write), and sometimes specific storage class requirements. Kubernetes matches a PVC to an available PV and binds them together. + +### Key Points: + +- **User Request**: PVCs allow users to request specific sizes and types of storage. +- **Dynamic Provisioning**: If no suitable PV exists, a new one can be dynamically provisioned according to the requested storage class. +- **Binding**: A PVC is bound to a single PV, creating a one-to-one relationship that reserves the PV for the PVC's use. + +## StatefulSets + +**StatefulSets** are used to manage stateful applications, providing stable, unique network identifiers, stable persistent storage, and ordered, graceful deployment and scaling. + +### Key Points: + +- **Stable Identity**: Each pod in a StatefulSet has a unique ordinal index and stable network identity. +- **Ordered Operations**: Pods are created, scaled, and deleted in a predictable order, important for stateful applications like databases that require careful management of replicas. +- **Persistent Storage**: StatefulSets can use PVCs to provide each pod with its persistent storage, ensuring data persists across pod rescheduling and restarts. + +### Conclusion + +While PVs and PVCs provide the mechanisms for handling persistent storage in Kubernetes, StatefulSets allow for the management of stateful applications, leveraging PVs and PVCs to ensure data persistence. Together, these components enable the deployment and management of complex, stateful applications within a Kubernetes cluster. + +## Script Explanation + +This guide explains the components of the script that creates Kubernetes resources, including Persistent Volumes (PVs), Persistent Volume Claims (PVCs), and a StatefulSet. + +## Components + +### Persistent Volume (PV) + +- **What it Does**: Creates a PV named `example-pv` with a capacity of 1Gi and a storage class of `standard`. +- **Storage Method**: Utilizes `hostPath` for storage, which mounts a directory from the host. This approach is primarily for testing purposes on a single-node cluster. + +### Persistent Volume Claim (PVC) + +- **What it Does**: Generates a PVC named `example-pvc` that requests 1Gi of storage with the same storage class, `standard`. +- **Binding**: This PVC is designed to bind to the previously created PV, `example-pv`. + +### StatefulSet + +- **What it Does**: Constructs a StatefulSet named `example-statefulset` with 2 replicas. +- **Configuration**: Each pod within the StatefulSet mounts the PVC created by the `volumeClaimTemplates`. +- **Use Case**: Provides a simple example that employs an Nginx container to deliver content stored on the persistent volume. + +## How to Run + +1. **Save the Script**: Store the script in a file, for instance, `create-pv-pvc-statefulset.sh`. +2. **Make Executable**: + + ``` + + chmod +x create-pv-pvc-statefulset.sh + create-pv-pvc-statefulset.sh + + ``` +--- + +# Using Vault in Jenkins + +HashiCorp Vault is a tool for secrets management, allowing you to securely store and access sensitive data like passwords, tokens, and keys. Integrating Vault with Jenkins can significantly enhance the security of your CI/CD pipelines by providing a secure way to handle credentials and other sensitive information. + +## Benefits of Integrating Vault with Jenkins + +- **Security**: Keeps sensitive data out of your build logs and source code. +- **Centralization**: Manages all your secrets in one place, making them easier to rotate, revoke, and keep track of. +- **Auditing**: Vault offers detailed audit logs, allowing you to track access to secrets, which is invaluable for compliance and security. + +## How to Use Vault with Jenkins + +### Step 1: Install Vault Plugin in Jenkins + +First, you need to install the [HashiCorp Vault Plugin](https://plugins.jenkins.io/hashicorp-vault-plugin/) for Jenkins. This can be done through the "Manage Jenkins" > "Manage Plugins" menu in the Jenkins UI. + +### Step 2: Configure Vault in Jenkins + +After installing the plugin, configure Jenkins to communicate with your Vault server: + +1. Go to "Manage Jenkins" > "Configure System". +2. Find the Vault section and add a new Vault configuration. +3. Enter your Vault Server URL and the Vault Credential. + +### Step 3: Set Up Vault Credentials + +Vault credentials in Jenkins can be set up as follows: + +1. Navigate to "Credentials" in Jenkins. +2. Choose the appropriate scope and click "Add Credentials". +3. Select "Vault Token" or the appropriate credential type. +4. Enter your Vault Token and other details as necessary. + +### Step 4: Accessing Secrets in Jenkins Jobs + +To access Vault secrets in your Jenkins jobs: + +1. In your job configuration, add a "Build Environment" step. +2. Select "Vault Secrets" and configure the Vault Key/Values you wish to inject into the build environment. +3. Use the injected environment variables in your build steps. + +## Best Practices + +- **Least Privilege**: Grant Jenkins access only to the secrets it needs, nothing more. +- **Audit**: Regularly review access logs and rotate secrets. +- **Secure Communication**: Ensure communication between Jenkins and Vault is over HTTPS to prevent eavesdropping. + +## Conclusion + +Integrating Vault with Jenkins allows you to manage and inject secrets into your CI/CD pipelines securely. By centralizing secret management, you not only improve the security posture of your development environment but also make managing and rotating secrets much more manageable. + diff --git a/8-k8s/FAQ/vol-k8s.ymal b/8-k8s/FAQ/vol-k8s.ymal new file mode 100644 index 0000000..e60747d --- /dev/null +++ b/8-k8s/FAQ/vol-k8s.ymal @@ -0,0 +1,73 @@ +#!/bin/bash + +# Create a Persistent Volume +cat < +- To check why multi-container pod is pending,use the command +``` +kubectl describe pods multi-container +``` + +## 2.4 To remove the taint from the node run the following commands: +``` +kubectl get nodes +``` +- Copy the node name and use it in the below command +- kubectl taint nodes node-role.kubernetes.io/master- + +### Here for example we use the command given below +``` +kubectl taint nodes ip-172-31-17-206 node-role.kubernetes.io/master- + ``` +-- 2.5 Now check the pod status. The pods should be in the running state. +``` +sudo kubectl get pods + +``` + +# Dashboard Creation in Kubernetes + +``` +kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.1/aio/deploy/recommended.yaml + +kubectl proxy + +http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ + +kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | awk '/^deployment-controller-token-/{print $1}') | awk '$1=="token:"{print $2}' + +kubectl -n kube-system describe secret $( + kubectl -n kube-system get secret | \ + awk '/^deployment-controller-token-/{print $1}' +) | \ +awk '$1=="token:"{print $2}' + +``` +## After executing the above commands, there are 4 distinct commands and they get called in this order: + +- Line 1 - This is the second command from @silverfox's Token section. +- Line 2 - This is the first command from @silverfox's Token section. +- Line 3 - Print only the first field of the line beginning with deployment-controller-token- (which is the pod name) +- Line 5 - Print only the second field of the line whose first field is "token:" + +# ReplicaSet commands in K8S + +``` + +kubectl apply -f ReplicaSet/ReplicaSet.yaml +kubectl get pods +kubectl get replicaset +kubectl delete pod sl-replicaset-hnd76 +kubectl descr +kubectl apply -f pods/pod-def.yaml +kubectl get pods +kubectl apply -f pods/pod-def.yaml +kubectl get pods +kubectl get replicaset sl-replicaset +kubectl edit replicaset sl-replicaset +kubectl get replicaset sl-replicaset +kubectl scale replicaset sl-replicaset --replicas=2 +kubectl get replicaset sl-replicaset + +kubectl get replicaset sl-replicaset +``` +# Deployment commands in K8S +``` +kubectl create -f deployment/deployment.yaml +kubectl get pods -o wide + +kubectl get deployment +kubectl get deployment -o wide +kubectl describe deployment +kubectl create -f deployment/deployment.yaml +kubectl get pods -o wide +kubectl rollout history deployment/web-app-deployment +kubectl delete deployment web-app-deployment +kubectl get pods -o wide +kubectl create -f deployment/deployment.yaml --record +kubectl rollout history deployment/web-app-deployment +kubectl edit deployment web-app-deployment --record +kubectl rollout history deployment/web-app-deployment +kubectl rollout status deployment/web-app-deployment +kubectl get pods -o wide +kubectl describe deployment web-app-deployment +kubectl rollout status deployment/web-app-deployment +kubectl set image deployment web-app-deployment blue=varunmanik/httpd:v1-blue --record +kubectl get pods -o wide +kubectl rollout history deployment web-app-deployment +``` +# scaling commands in K8S +``` +kubectl scale deployment web-app-deployment --replicas=6 +``` + +# Roll Out +``` +kubectl rollout undo deployment/web-app-deployment --to-revision=3 +kubectl rollout history deployment web-app-deployment +``` + +# Docker testing in you K8S setup +``` +docker build -t varunmanik/httpd:green . +docker run -itd -p 9000:80 varunmanik/httpd:green +docker build -t varunmanik/httpd:blue . +docker run -itd -p 9001:80 varunmanik/httpd:blue +kubectl describe pod green-app | grep -i "IP:" +``` + +# Services commands in K8S + +``` +kubectl create -f services/service-def.yaml +kubectl describe svc web-app-service +kubectl get svc,pods -o wide +kubectl delete service web-app-service +kubectl get svc,pods -o wide +kubectl scale deployment/blue-green-deployment --replicas=1 +kubectl get svc,pods -o wide +kubectl get svc,pods,deployment -o wide + +``` + + +# Cleanup the entire setup + +- Run this command to cleanup +``` +sh installation/cleanup.sh +``` +- OR copy and paste below commands one by one. + +``` +docker ps +kubeadm reset -f +rm -rf /etc/cni /etc/kubernetes /var/lib/dockershim /var/lib/etcd /var/lib/kubelet /var/run/kubernetes ~/.kube/* +v +apt remove -y kubeadm kubectl kubelet kubernetes-cni +sudo apt-get purge kubeadm kubectl kubelet kubernetes-cni kube* +sudo apt-get autoremove +sudo rm -rf ~/.kube +docker ps +system restart docker +systemctl restart docker +``` + +# Check your history from below command + +``` +history | cut -c 8- > history.txt ``` +# References +1. https://kubernetes.io/ +2. https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/ +3. https://kubernetes.io/docs/concepts/workloads/pods/ +4. https://etcd.io/ +5. https://kubernetes.io/docs/reference/kubectl/ +6. https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/ diff --git a/8-k8s/ReplicaSet/ReplicaSet-sl-ex.yaml b/8-k8s/ReplicaSet/ReplicaSet-sl-ex.yaml new file mode 100644 index 0000000..8cfcc36 --- /dev/null +++ b/8-k8s/ReplicaSet/ReplicaSet-sl-ex.yaml @@ -0,0 +1,27 @@ +apiVersion: v1 + + + +kind: Pod + + + + + +metadata: + + name: web-pod + + labels: + + application: web-app3 + +spec: + + containers: + + - name: google-ex + + image: gcr.io/google_samples/gb-frontend:v3 + + diff --git a/8-k8s/ReplicaSet/ReplicaSet.yaml b/8-k8s/ReplicaSet/ReplicaSet.yaml new file mode 100644 index 0000000..73ae3cc --- /dev/null +++ b/8-k8s/ReplicaSet/ReplicaSet.yaml @@ -0,0 +1,25 @@ +apiVersion: apps/v1 + +kind: ReplicaSet + +metadata: + name: sl-replicaset + labels: + application: web-app + +spec: + selector: + matchLabels: + application: web-app + replicas: 20 + template: + metadata: + name: web2 + labels: + application: web-app + env: dev + + spec: + containers: + - name: httpd + image: varunmanik/httpd:alpine diff --git a/8-k8s/ReplicaSet/blue-replicaset.yaml b/8-k8s/ReplicaSet/blue-replicaset.yaml new file mode 100644 index 0000000..d4cbe1e --- /dev/null +++ b/8-k8s/ReplicaSet/blue-replicaset.yaml @@ -0,0 +1,25 @@ +apiVersion: apps/v1 + +kind: ReplicaSet + +metadata: + name: blue-replicaset + labels: + application: web-app + +spec: + template: + metadata: + name: blue-app + labels: + env: dev + application: web-app + color: blue + spec: + containers: + - name: httpd + image: varunmanik/httpd:blue + selector: + matchLabels: + color: blue + replicas: 5 \ No newline at end of file diff --git a/8-k8s/ReplicaSet/green-replicaset.yaml b/8-k8s/ReplicaSet/green-replicaset.yaml new file mode 100644 index 0000000..a358d39 --- /dev/null +++ b/8-k8s/ReplicaSet/green-replicaset.yaml @@ -0,0 +1,25 @@ +apiVersion: apps/v1 + +kind: ReplicaSet + +metadata: + name: green-replicaset + labels: + application: web-app + +spec: + template: + metadata: + name: green-app + labels: + env: dev + application: web-app + color: green + spec: + containers: + - name: httpd + image: varunmanik/httpd:green + selector: + matchLabels: + color: green + replicas: 5 \ No newline at end of file diff --git a/8-k8s/deployment/bg-deployment.yaml b/8-k8s/deployment/bg-deployment.yaml new file mode 100644 index 0000000..af8b2e6 --- /dev/null +++ b/8-k8s/deployment/bg-deployment.yaml @@ -0,0 +1,25 @@ +apiVersion: apps/v1 + +kind: Deployment + +metadata: + name: blue-green-deployment + labels: + application: web-app + +spec: + template: + metadata: + name: blue-app + labels: + application: web-app + env: dev + color: blue + spec: + containers: + - name: httpd + image: varunmanik/httpd:green + selector: + matchLabels: + application: web-app + replicas: 3 \ No newline at end of file diff --git a/8-k8s/deployment/deployment.yaml b/8-k8s/deployment/deployment.yaml new file mode 100644 index 0000000..92609e5 --- /dev/null +++ b/8-k8s/deployment/deployment.yaml @@ -0,0 +1,26 @@ +apiVersion: apps/v1 + +kind: Deployment + +metadata: + name: web-app-deployment + labels: + application: web-app + +spec: + selector: + matchLabels: + application: web-app + replicas: 3 + template: + metadata: + name: web2 + labels: + application: web-app + env: dev + color: blue + + spec: + containers: + - name: blue + image: varunmanik/httpd:v1-blue diff --git a/8-k8s/lesson-end-project/calc.yml b/8-k8s/lesson-end-project/calc.yml new file mode 100644 index 0000000..a1daaae --- /dev/null +++ b/8-k8s/lesson-end-project/calc.yml @@ -0,0 +1,26 @@ +apiVersion: apps/v1 + +kind: Deployment + +metadata: + name: web-calc + labels: + application: web-app-calc + +spec: + selector: + matchLabels: + application: web-app-calc + replicas: 3 + template: + metadata: + name: calculator + labels: + application: web-app-calc + env: dev + product: calculator-py + + spec: + containers: + - name: calc-image + image: varunmanik/python-calc-app \ No newline at end of file diff --git a/8-k8s/pods/blue-pod.yaml b/8-k8s/pods/blue-pod.yaml new file mode 100644 index 0000000..1334765 --- /dev/null +++ b/8-k8s/pods/blue-pod.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 + +kind: Pod +metadata: + name: blue-app + labels: + env: dev + application: web-app + color: blue + +spec: + containers: + - name: httpd + image: varunmanik/httpd:blue \ No newline at end of file diff --git a/8-k8s/pods/database.yaml b/8-k8s/pods/database.yaml new file mode 100644 index 0000000..693382f --- /dev/null +++ b/8-k8s/pods/database.yaml @@ -0,0 +1,17 @@ +apiVersion:vi + +kind: Pod + +metadata: + name : postgress-database + labels: + tier: db-tier + +spec: + containers: + - name: postgres + image: postgres + env: + - name: db_pass + value: 123456 + diff --git a/8-k8s/pods/green-pod.yaml b/8-k8s/pods/green-pod.yaml new file mode 100644 index 0000000..dec9cac --- /dev/null +++ b/8-k8s/pods/green-pod.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 + +kind: Pod +metadata: + name: green-app + labels: + env: dev + application: web-app + color: green + +spec: + containers: + - name: httpd + image: varunmanik/httpd:green \ No newline at end of file diff --git a/8-k8s/pods/multi-container.yaml b/8-k8s/pods/multi-container.yaml new file mode 100644 index 0000000..99265e9 --- /dev/null +++ b/8-k8s/pods/multi-container.yaml @@ -0,0 +1,28 @@ +apiVersion: v1 + +kind: Pod + +metadata: + name: mulit-container + labels: + env: dev + tier: frontend + costcenter: devops + +spec: + containers: + - name: nginx + image: nginx:1.10-alpine + ports: + - containerPort: 80 + - name: alpine + image: alpine:3.5 + command: + - "watch" + - "wget" + - "-qO-" + - "localhost" + + + + diff --git a/8-k8s/pods/my-pod.yml b/8-k8s/pods/my-pod.yml new file mode 100644 index 0000000..b98ba13 --- /dev/null +++ b/8-k8s/pods/my-pod.yml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Pod +metadata: + name: myapp + labels: + name: myapp +spec: + containers: + - name: myapp + image: varunmanik/httpd:green + + ports: + - containerPort: 80 \ No newline at end of file diff --git a/8-k8s/pods/new_pod.yaml b/8-k8s/pods/new_pod.yaml new file mode 100644 index 0000000..f841749 --- /dev/null +++ b/8-k8s/pods/new_pod.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 + +kind: Pod +metadata: + name: varunapp + labels: + name: webapp +spec: + containers: + - name: httpdBlueApp + image: varunmanik/httpd:blue + + ports: + - containerPort: 80 diff --git a/8-k8s/pods/pod-def.yaml b/8-k8s/pods/pod-def.yaml new file mode 100644 index 0000000..c96cefc --- /dev/null +++ b/8-k8s/pods/pod-def.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 + + +kind: Pod + +metadata: + name: pod-def + +spec: + containers: + - name: web-blue + image: varunmanik/httpd:blue \ No newline at end of file diff --git a/8-k8s/pods/web-container.yaml b/8-k8s/pods/web-container.yaml new file mode 100644 index 0000000..889e233 --- /dev/null +++ b/8-k8s/pods/web-container.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 + +kind: Pod + +metadata: + + name: web-server + +spec: + + containers: + + - name: web-container + + image: httpd + + diff --git a/8-k8s/resources/pods.yaml b/8-k8s/resources/pods.yaml new file mode 100644 index 0000000..3debaa1 --- /dev/null +++ b/8-k8s/resources/pods.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Pod +metadata: + name: web-server + labels: + env: dev + acconut: non-prod + +spec: + containers: + - name: nginx-server + image: nginx:alpine + + diff --git a/9.1-NagiOS/README.md b/9.1-NagiOS/README.md index 226ab73..cedd631 100644 --- a/9.1-NagiOS/README.md +++ b/9.1-NagiOS/README.md @@ -1,3 +1,7 @@ +# ELK +## https://github.com/manikcloud/elk-stack +# NagiOS (https://github.com/manikcloud/DevOps-Tutorial/tree/main/9.1-NagiOS) +--- # Lesson 9 Demo 1 How to Install Nagios Monitoring Tool diff --git a/README.md b/README.md index ecbef35..396c78a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,47 @@ -# DevOps-Tutorial +# DevOps Tutorial + +Welcome to the [DevOps Tutorial Repository](https://github.com/manikcloud/DevOps-Tutorial/tree/main), a key resource for AWS-focused DevOps learning! This repository is an extensive collection of tutorials and guides, specifically curated for those leveraging AWS in their DevOps practices. Whether you're just starting your journey in DevOps, or you're an experienced practitioner seeking to deepen your expertise with AWS tools and methodologies, this repository is tailored for you. + +## Emphasis on AWS and DevOps + +Our tutorials and resources provide in-depth coverage of various DevOps tools and practices, with a special focus on integrating them within the AWS ecosystem. AWS offers a broad set of services and tools that are crucial in the DevOps landscape, and our repository aims to help you harness these capabilities to their fullest potential. + +## Ideal for All Skill Levels + +Whether you're a beginner who's curious about AWS and DevOps, or a seasoned DevOps professional looking to integrate more AWS services into your workflow, this repository has something for everyone. It's designed to guide you through the nuances of AWS services and how they can optimize your DevOps processes. + +## Repository Contents + +1. **[Linux Tutorial](https://github.com/manikcloud/DevOps-Tutorial/tree/main/Linux_Tutorial):** Dive into the world of Linux with our tutorials, starting with the `history-of-jan-06-2024.txt`, a comprehensive guide to Linux basics and advanced concepts. + +2. **[Git](https://github.com/manikcloud/DevOps-Tutorial/tree/main/2-Git):** Master version control with Git. Our tutorials provide insights from basic usage to advanced Git strategies and workflows. + +3. **[Jenkins](https://github.com/manikcloud/DevOps-Tutorial/tree/main/5-jenkins):** Learn about Jenkins, a cornerstone tool for continuous integration and continuous deployment (CI/CD). + +4. **[Ansible and Terraform](https://github.com/manikcloud/DevOps-Tutorial/tree/main/6-ansible-terraform):** Explore the world of infrastructure as code (IaC) with Ansible and Terraform tutorials, perfect for automating your infrastructure setup. + +5. **[Docker](https://github.com/manikcloud/DevOps-Tutorial/tree/main/7-docker):** Delve into containerization with Docker. Understand how to containerize applications and manage them effectively. + +6. **[Kubernetes (k8s)](https://github.com/manikcloud/DevOps-Tutorial/tree/main/8-k8s):** Get hands-on with Kubernetes, a powerful system for automating deployment, scaling, and management of containerized applications. + +7. **[Nagios](https://github.com/manikcloud/DevOps-Tutorial/tree/main/9.1-NagiOS):** Learn about Nagios for monitoring systems, networks, and infrastructure. + +## Additional Resources + +- **[Ansible Command History](https://github.com/manikcloud/DevOps-Tutorial/blob/main/ansible-cmd-history.txt):** A log of practical Ansible commands for reference. +- **[VS Code Installation Script](https://github.com/manikcloud/DevOps-Tutorial/blob/main/vs-code-installation.sh):** A handy script for installing VS Code, a popular editor among DevOps professionals. + +## Contribution + +Your contributions to enhance or extend the tutorials and resources in this repository are most welcome! Feel free to fork the repository, make your changes, and submit a pull request. + +Happy learning, and let's make DevOps easy and accessible for everyone! + +--- + +*Disclaimer: The contents of this repository are intended for educational purposes. Please ensure to test and validate in a controlled environment before applying in production.* +---- -- DevOps-Tutorial By Varun Kumar Manik. -- Sending from User. # Caltech-DevOps Simplilearn PG Program This repository contains course materials for the Caltech-DevOps Simplilearn Postgraduate Program. @@ -142,4 +182,4 @@ For more info, please connect and follow me: - Email: [varunmanik1@gmail.com](mailto:varunmanik1@gmail.com) - Facebook: [https://www.facebook.com/cloudvirtualization/](https://www.facebook.com/cloudvirtualization/) - YouTube: [https://bit.ly/32fknRN](https://bit.ly/32fknRN) -- Twitter: [https://twitter.com/varunkmanik](https://twitter.com/varunkmanik) \ No newline at end of file +- Twitter: [https://twitter.com/varunkmanik](https://twitter.com/varunkmanik) diff --git a/ansible-cmd-history.txt b/ansible-cmd-history.txt new file mode 100644 index 0000000..074a595 --- /dev/null +++ b/ansible-cmd-history.txt @@ -0,0 +1,147 @@ +ll +git clone +git clone git@github.com:manikcloud/DevOps-Tutorial.git +ssh-keygen +cat ~/.ssh/id_rsa.pub +git clone git@github.com:manikcloud/DevOps-Tutorial.git +ll +cd DevOps-Tutorial/ +code . +cd DevOps-Tutorial/6-ansible-terraform/6.8-tf-ec2-provisioning/ansible/ +ansible-playbook ping.yaml +ansible all -m shell -a "apt upda +ansible all -m shell -a "apt update -y" become true +ansible all -m shell -a "apt update -y" +ansible all -m shell -a "apt update -y" -b=yes +ansible all -m shell -a "apt update -y" -b true +ansible all -m shell -a "apt update -y" -b=true +ansible-playbook ping.yaml +code +ll +cd DevOps-Tutorial/ +ls +mv 6-ansible 6-ansible-terraform +ll +cd 6-ansible-terraform/ +ls +mkdir 6.6.1-tf-local-file +cd 6.6.1-tf-local-file/ +terraform +terraform -version +vim main.tf +terraform init +cleaf +terraform plan +terraform apply +ll +cat index.html +git add . && git commit-am"adding tf local" +git add . && git commit -am"adding tf local" +git push +resource "local_file" "foo" { +git push +cd .. +git add . && git commit -am"adding tf local" && git push +git config --global user.name "varun" +git add . && git commit -am"adding tf local" && git push +ll +ansible +ansible --version +ansible -m ping localhost +ansible -m ping localhost -v +ansible -m ping localhost -vv +ansible -m ping localhost -vvv +ansible -m ping localhost -vvvv +cd 6-ansible-terraform/6.8-tf-ec2-provisioning/ +ll +cd .. +ll +ls +cd 6.8-tf-ec2-provisioning/ +ls +ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key ../deployer +ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer +chmod 400 deployer +ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer +ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer -v +ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer -vv +ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer -vvvv +ansible all -i '3.87.250.203, 54.198.128.135, 107.22.117.179' -m ping -u ubuntu --private-key deployer +ansible all -i ' 54.198.128.135' -m ping -u ubuntu --private-key deployer +ls +ansible all -i '54.198.128.135' -m ping -u ubuntu --private-key deployer +vim ~/.ssh/known_hosts +ansible all -i '54.198.128.135' -m ping -u ubuntu --private-key deployer +ansible all -i '3.87.250.203,' -m ping -u ubuntu --private-key deployer +ansible all -i '54.198.128.135,' -m ping -u ubuntu --private-key deployer +ansible all -i '107.22.117.179,' -m ping -u ubuntu --private-key deployer +ll +cd ansible/ +ll +cd .. +ansible all -i ansible/inventory.ini -m ping +cd - +ll +ansible all -i inventory.ini -m ping +ansible all -i inventory.ini -m shell -a "la -l" +ansible all -i inventory.ini -m shell -a "ls -l" +ansible all -i inventory.ini -m shell -a "pwd" +ansible all -i inventory.ini -m shell -a "touch index.txt" +ansible all -i inventory.ini -m shell -a "ls -l" +ansible -m ping localhost -v +ansible -m ping localhost -vv +cd ../../.. +ansible -m ping localhost -vv +vim /etc/ansible/ansible.cfg +cd - +ansible all -m shell -a "ls -l" +ansible all -m shell -a "rm -rf index.txt" +ansible all -m shell -a "ls -l" +ansible all -m setup +ll +ansible-playbook ping.yaml +ansible all -m shell -a "ls -l" +ansible-playbook ping.yaml +ansible-doc -l +ansible-doc apt +q q +ansible-doc aptans +cd 6-ansible-terraform/6.8-tf-ec2-provisioning/ +terraform plan +terraform apply +terraform output +cd 6-ansible-terraform/6.7-S3-Bucket-Using-Terraform/ +ll +terraform ini +terraform init +terraform plan +terraform apply +terraform plan +terraform apply +terraform plan +terraform apply +cd .. +git add . +git commit -am "adding creds" +git push +ll +cd 6-ansible-terraform/ +ll +cd 6.8-tf-ec2-provisioning/ +ll +cd .. +cd - +terraform init +terraform plan +terraform apply +terraform plan +terraform apply +terraform destroy +git push +cd .. +git add . +git commit -am"adding cred.tf" +git push +cd DevOps-Tutorial/ +code . +history | cut -c 8- > ansible-cmd-history.txt