diff --git a/Ansible/Ansible_installation_on_RHEL8.MD b/Ansible/Ansible_installation_on_RHEL8.MD new file mode 100644 index 0000000..7a01a87 --- /dev/null +++ b/Ansible/Ansible_installation_on_RHEL8.MD @@ -0,0 +1,64 @@ +# Ansible Installation on RHEL 8.x server + +1. Install Python latest version (on Control node and Managed host) + ```sh + yum install python3 -y + ``` + +1. By default, python3 is the command to run python commands. to use just python, use "alternatives" command. (on Control node and Managed host) + ```sh + alternatives --set python /usr/bin/python3 + ``` + +1. Check for Python version + ```sh + python --version + ``` +1. Install python-pip package manager (on Control node) + ```sh + yum -y install python3-pip + ``` + +1. Create a new user for ansible administration & grant admin access to the user (on Control node and Managed host) + ```sh + useradd ansadmin + passwd ansadmin + ``` +1. Below command adds ansadmin to sudoers file. But we strongly recommended using "visudo" command if you are aware vi or nano editor. (on Control node and Managed host) + ```sh + echo "ansadmin ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + ``` +1. Using key-based authentication is advised. If you are still at the learning stage use password-based authentication (on Control node and Managed host) + ```sh + # sed command replaces "PasswordAuthentication no to yes" without editing file + sed -ie 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config + sudo service sshd reload + ``` + + #### Install Ansible as a ansadmin user (on Control node) + ```sh + su - ansadmin + pip3 install ansible --user + ``` + Note: Ansible must be installed as a user (here ansadmin) +1. check for ansible version + ```sh + ansible --version + ``` + +1. Log in as a ansadmin user on master and generate ssh key (on Control node) + ```sh + ssh-keygen + ``` +1. Copy keys onto all ansible managed hosts (on Control node) + ```sh + ssh-copy-id ansadmin@ + ``` +### Validation test + +1. Create a directory /etc/ansible and create an inventory file called "hosts" add control node IP address in it. + +1. Run ansible command as ansadmin user it should be successful (Master) + ```sh + ansible all -m ping + ``` diff --git a/Ansible/Dynamic_Inventory.MD b/Ansible/Dynamic_Inventory.MD new file mode 100644 index 0000000..70ffb70 --- /dev/null +++ b/Ansible/Dynamic_Inventory.MD @@ -0,0 +1,36 @@ +# Ansible Dynamic Inventory + +### Pre-requisites: + 1. Ansible Server - Get [Click here](https://www.youtube.com/watch?v=-Y8Oatd49qA) to install on RHEL 8 and [click here](https://www.youtube.com/watch?v=79xFyOc_eEY) to install on Amazon Linux + + +### Setup + +To get help on dynamic inventory please follow [Ansible Official Document](https://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html#inventory-script-example-aws-ec2) + +1. Download [ec2.py](https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.py) and [ec2.ini](https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.ini) files + +1. Create IAM Programmatic access user with EC2 full access on AWS console + + `IAM` --> `users` --> `Add user` + +1. Export IAM user credentials on Ansible server. + + ```bash + export AWS_ACCESS_KEY_ID='1bc123' + export AWS_SECRET_ACCESS_KEY='abc123' + ``` +1. To export keys permanently make sure that you have installed pip and boto and add credentials ~/.boto file + +1. add executing permissions to ec2.py script + ```sh + chmod 755 ec2.py + ``` +1. test the script + ``` + ./ec2.py --list + ``` +1. List out servers which are running on ap-south-1a AZ + ``` + ansible -i ec2.py ap-south-1a --list-hosts + ``` diff --git a/Jenkins/Git_plugin_install.MD b/Jenkins/Git_plugin_install.MD index 09c15b1..09cad2a 100644 --- a/Jenkins/Git_plugin_install.MD +++ b/Jenkins/Git_plugin_install.MD @@ -12,11 +12,11 @@ Install git packages on jenkins server yum install git -y ``` -#### Setup maven on jenkins console -- Install maven plugin without restart +#### Setup Git on jenkins console +- Install git plugin without restart - `Manage Jenkins` > `Jenkins Plugins` > `available` > `github` -- Configure java path +- Configure git path - `Manage Jenkins` > `Global Tool Configuration` > `git` #### Next Steps diff --git a/Jenkins/S3_Artifact_for_Jenkins.md b/Jenkins/S3_Artifact_for_Jenkins.md new file mode 100644 index 0000000..bf493a5 --- /dev/null +++ b/Jenkins/S3_Artifact_for_Jenkins.md @@ -0,0 +1,35 @@ + +# S3 as a artifact for Jenkins + +Follow this in **[YouTube](https://youtu.be/GQZYpIRxi-g)** + +### Prerequisites +1. Create Jenkins Server + Jenkins server **[Get Help here](https://www.youtube.com/watch?v=M32O4Yv0ANc)** + + ### Setup steps +1. Create a S3 bucket to store artifacts + `S3 --> Create bucket ` + ```sh + Bucket name: valaxy-s3-artifact + Region: Singapore + ``` +1. Create new IAM role with "S3 full access" and assign it to jenkins server + `IAM --> Create role --> EC2` + ```ssh + Permission: AmazonS3FullAccess + Tags: key - Name, Value - S3FullAccess Role + name: S3_Full_Access + ``` + +1. Install "S3 Publisher" plugin on Jenkins + `Manage Jenkins --> Manage Plugins --> Availabe --> S3 publisher` + +1. Configure S3 profile on Jenkins + `Manage Jenkins --> Configure Systems --> Amazon S3 profiles` + ```sh + Profile name : s3-artifact-repository + Use IAM Role : chose + ``` + +1. Create a job to store artifacts under S3. diff --git a/Kubernetes/k8s-setup.md b/Kubernetes/k8s-setup.md new file mode 100644 index 0000000..31412b0 --- /dev/null +++ b/Kubernetes/k8s-setup.md @@ -0,0 +1,81 @@ + +#### Setup Kubernetes (K8s) Cluster on AWS + + +1. Create Ubuntu EC2 instance +1. install AWSCLI + ```sh + curl https://s3.amazonaws.com/aws-cli/awscli-bundle.zip -o awscli-bundle.zip + apt install unzip python + unzip awscli-bundle.zip + #sudo apt-get install unzip - if you dont have unzip in your system + ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws + ``` + +1. Install kubectl + ```sh + curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl + chmod +x ./kubectl + sudo mv ./kubectl /usr/local/bin/kubectl + ``` +1. Create an IAM user/role with Route53, EC2, IAM and S3 full access +1. Attach IAM role to ubuntu server + + #### Note: If you create IAM user with programmatic access then provide Access keys. + ```sh + aws configure + ``` +1. Install kops on ubuntu instance: + ```sh + curl -LO https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64 + chmod +x kops-linux-amd64 + sudo mv kops-linux-amd64 /usr/local/bin/kops + ``` +1. Create a Route53 private hosted zone (you can create Public hosted zone if you have a domain) +1. create an S3 bucket + ```sh + aws s3 mb s3://dev.k8s.valaxy.in + ``` +1. Expose environment variable: + ```sh + export KOPS_STATE_STORE=s3://dev.k8s.valaxy.in + ``` +1. Create sshkeys before creating cluster + ```sh + ssh-keygen + ``` +1. Create kubernetes cluster definitions on S3 bucket + ```sh + kops create cluster --cloud=aws --zones=ap-southeast-1b --name=dev.k8s.valaxy.in --dns-zone=valaxy.in --dns private + ``` +1. Create kubernetes cluser + ```sh + kops update cluster dev.k8s.valaxy.in --yes + ``` +1. Validate your cluster + ```sh + kops validate cluster + ``` + +1. To list nodes + ```sh + kubectl get nodes + ``` + +#### Deploying Nginx container on Kubernetes +1. Deploying Nginx Container + ```sh + kubectl run sample-nginx --image=nginx --replicas=2 --port=80 + kubectl get pods + kubectl get deployments + ``` + +1. Expose the deployment as service. This will create an ELB in front of those 2 containers and allow us to publicly access them: + ```sh + kubectl expose deployment sample-nginx --port=80 --type=LoadBalancer + kubectl get services -o wide + ``` + 1. To delete cluster + ```sh + kops delete cluster dev.k8s.valaxy.in --yes + ``` diff --git a/SimpeDevOpsProjects/Project-3.MD b/SimpeDevOpsProjects/Project-3.MD index 8edc7d9..9da214d 100644 --- a/SimpeDevOpsProjects/Project-3.MD +++ b/SimpeDevOpsProjects/Project-3.MD @@ -26,7 +26,7 @@ mkdir /opt/docker From tomcat:8-jre8 # Maintainer -MAINTAINER "valaxytech@gmail.com" +MAINTAINER "valaxytech" # copy war file on to container COPY ./webapp.war /usr/local/tomcat/webapps @@ -47,14 +47,21 @@ B) Build C) send files or execute commands over SSH Name: docker_host - Source files : webapp/target/*.war - Remove prefix : webapp/target - Remote directory : //opt//docker - Exec command : docker stop valaxy_demo; docker rm -f valaxy_demo; docker image rm -f valaxy_demo; cd /opt/docker; docker build -t valaxy_demo . + Source files : `webapp/target/*.war` + Remove prefix : `webapp/target` + Remote directory : `//opt//docker` + Exec command[s] : + ```sh + docker stop valaxy_demo; + docker rm -f valaxy_demo; + docker image rm -f valaxy_demo; + cd /opt/docker; + docker build -t valaxy_demo . + ``` D) send files or execute commands over SSH - Name: docker_host - Exec command : docker run -d --name valaxy_demo -p 8090:8080 valaxy_demo + Name: `docker_host` + Exec command : `docker run -d --name valaxy_demo -p 8090:8080 valaxy_demo` 7. Login to Docker host and check images and containers. (no images and containers) @@ -63,4 +70,6 @@ D) send files or execute commands over SSH 9. check images and containers again on Docker host. This time an image and container get creates through Jenkins job 10. Access web application from browser which is running on container +``` :8090 +``` diff --git a/SimpeDevOpsProjects/Project-4.MD b/SimpeDevOpsProjects/Project-4.MD index ef91b2c..444b552 100644 --- a/SimpeDevOpsProjects/Project-4.MD +++ b/SimpeDevOpsProjects/Project-4.MD @@ -61,7 +61,7 @@ In *part-01* we create Docker image on ansible server through Jenkins job and pu #### Troubleshooting: 1. Docker should be installed on ansible server 1. Should login to "docker hub" on ansible server -1. Docker admin user should be part of `docker` group +1. ansadmin user should be part of `docker` group In *Part-02* we create *create_docker_container.yml* playbook. this get intiated by jenkins job, run by ansible and exected on dokcer_host diff --git a/testfile b/testfile deleted file mode 100644 index 4a576e5..0000000 --- a/testfile +++ /dev/null @@ -1 +0,0 @@ -this is a test file diff --git a/testfile2 b/testfile2 deleted file mode 100644 index 8b13789..0000000 --- a/testfile2 +++ /dev/null @@ -1 +0,0 @@ - diff --git a/testfile3 b/testfile3 deleted file mode 100644 index e11b757..0000000 --- a/testfile3 +++ /dev/null @@ -1,2 +0,0 @@ -djalfjadsd -dsjfadlj