<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abiola Majek on Medium]]></title>
        <description><![CDATA[Stories by Abiola Majek on Medium]]></description>
        <link>https://medium.com/@abiolamajekodunmi2011?source=rss-663b5162e79b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mw_Pnj80k5UY26PXfKChpg.jpeg</url>
            <title>Stories by Abiola Majek on Medium</title>
            <link>https://medium.com/@abiolamajekodunmi2011?source=rss-663b5162e79b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 17:34:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abiolamajekodunmi2011/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Implementing Secure and Observant 3-Tier Deployments on AWS Using Terraform, EKS, Jenkins…]]></title>
            <link>https://medium.com/@abiolamajekodunmi2011/implementing-secure-and-observant-3-tier-deployments-on-aws-using-terraform-eks-jenkins-ea2572d239e1?source=rss-663b5162e79b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea2572d239e1</guid>
            <dc:creator><![CDATA[Abiola Majek]]></dc:creator>
            <pubDate>Wed, 14 Feb 2024 05:36:19 GMT</pubDate>
            <atom:updated>2024-02-14T05:36:19.158Z</atom:updated>
            <content:encoded><![CDATA[<h3>Implementing Secure and Observant 3-Tier Deployments on AWS Using Terraform, EKS, Jenkins, Prometheus</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*b5oR9tKEa8WPgtiGB-9Dyw.png" /></figure><p>Welcome to the Comprehensive DevSecOps Kubernetes Project guide! In this extensive project, we’ll take you through the steps of establishing a resilient Three-Tier architecture on AWS using Kubernetes, adhering to DevOps best practices, and implementing robust security measures. Our objective is to provide you with practical experience in deploying, securing, and monitoring a scalable application environment. This was inspired by a similar project from <a href="https://github.com/AmanPathak-DevOps">Aman-Pathak</a></p><p><strong>Project Overview:</strong></p><p>Throughout this project, we’ll delve into the following crucial components:</p><ol><li>IAM User Setup: We’ll create an IAM user on AWS with the necessary permissions to facilitate deployment and management activities.</li><li>Infrastructure as Code (IaC): Using Terraform and AWS CLI, we’ll establish the Jenkins server (EC2 instance) on AWS, ensuring seamless automation.</li><li>Jenkins Server Configuration: We’ll install and configure essential tools on the Jenkins server, including Jenkins itself, Docker, Sonarqube, Terraform, Kubectl, AWS CLI, and Trivy, streamlining our deployment process.</li><li>EKS Cluster Deployment: Leveraging eksctl commands, we’ll create an Amazon EKS cluster, a managed Kubernetes service on AWS, laying the foundation for our application infrastructure.</li><li>Load Balancer Configuration: We’ll set up the AWS Application Load Balancer (ALB) for the EKS cluster, optimizing traffic distribution and ensuring high availability.</li><li>Amazon ECR Repositories: Private repositories for both frontend and backend Docker images will be established on Amazon Elastic Container Registry (ECR), enhancing security and version control.</li><li>ArgoCD Installation: ArgoCD will be installed and configured for continuous delivery and GitOps, simplifying our deployment process and promoting automation.</li><li>Sonarqube Integration: We’ll integrate Sonarqube for comprehensive code quality analysis within our DevSecOps pipeline, ensuring code integrity throughout the development lifecycle.</li><li>Jenkins Pipelines: Jenkins pipelines will be created to streamline the deployment of backend and frontend code to the EKS cluster, enhancing efficiency and reliability.</li><li>Monitoring Setup: We’ll implement robust monitoring for the EKS cluster using Helm, Prometheus, and Grafana, enabling real-time insights into system performance and health.</li><li>ArgoCD Application Deployment: Utilizing ArgoCD, we’ll deploy the Three-Tier application, encompassing database, backend, frontend, and ingress components, ensuring seamless application delivery.</li><li>DNS Configuration: Custom subdomains will be configured through DNS settings, enabling convenient access to the application while maintaining security.</li><li>Data Persistence: We’ll implement persistent volume and persistent volume claims for database pods, ensuring data persistence and reliability.</li><li>Conclusion and Monitoring: To wrap up, we’ll summarize key achievements and monitor the EKS cluster’s performance using Grafana, ensuring ongoing optimization and efficiency.</li></ol><p>Get ready to embark on an enriching journey through the world of DevSecOps and Kubernetes deployment, where you’ll gain invaluable hands-on experience in building resilient and secure application environments. Let’s dive in!</p><p><strong>Prerequisites</strong></p><p>Before commencing the project, make sure you have the following prerequisites:</p><ol><li>An AWS account with appropriate resource creation permissions.<br>2. Terraform and AWS CLI installed locally.<br>3. Basic understanding of Kubernetes, Docker, Jenkins, and DevOps principles.</li></ol><h3>Step 1: Creating an IAM User and Generating AWS Access Key</h3><p>Step 1: Creating an IAM User and Generating AWS Access Key</p><ol><li>Go to the AWS IAM console and navigate to “Users”.</li></ol><p>2. Click on “Add user” and provide a name for the IAM user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*03smvKdncqiwMTIb70QMWA.png" /></figure><p>3. For practice purposes, attach policies granting full administrative access. Note: It’s recommended to follow the principle of least privilege in real-world scenarios.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NaXttZcNiKJxtT5eGfXtsw.png" /></figure><p>4. After creating the user, generate an access key by clicking on “Create access key”.</p><p>5. Choose “CLI” as the access type and click “Create access key”.<br>6. You can choose to download your access key or save the key and secret provided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qYpvrC_EjbcHVoC5CmYXxw.png" /></figure><h3>Step 2: We will install Terraform &amp; AWS CLI to deploy our Jenkins Server(EC2) on AWS.</h3><p>Install &amp; Configure Terraform and AWS CLI on your local machine to create Jenkins Server on AWS Cloud</p><p><strong>Terraform Installation Script</strong></p><pre>wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg - dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg<br>echo &quot;deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main&quot; | sudo tee /etc/apt/sources.list.d/hashicorp.list<br>sudo apt update<br>sudo apt install terraform -y</pre><p><strong>AWS CLI Installation Script</strong></p><pre>curl &quot;https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip&quot; -o &quot;awscliv2.zip&quot;<br>sudo apt install unzip -y<br>unzip awscliv2.zip<br>sudo ./aws/install</pre><p>Next, Configure terraform</p><p>Edit the file /etc/environment using the below command add the AWS_access _key_ID , AWS_secret_access_keys, AWS_account_ID</p><pre>sudo vim /etc/environment</pre><pre>export AWS_ACCESS_KEY_ID =ggffdfddg<br>export AWS_SECRET_ACCESS_KEY=hkvkgvkghvluhvluh<br>export AWS_DEFAULT_REGION=us-east-1<br>export AWS_CONFIG_FILE=&quot;/root/.aws/config&quot;<br>export TF_VAR_AWS_REGION=us-east-1<br>export TF_VAR_AWS_ACCOUNT_ID=123456789<br>export TF_VAR_ENDPOINT=<br>export TF_VAR_PEMFILE=<br>figlet Devops</pre><p>After doing the changes, save the changes and restart your machine to reflect the changes in your environment variables.</p><p>Configure AWS CLI</p><p>Run the below command, and add your keys</p><pre>sudo aws configure</pre><p>Follow the command and insert your AWS access key and secret key</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KSdv3Hx-5n6hE8z2PsUKmw.png" /></figure><p>save then exit</p><p><strong>Step 3: Deploy the Jenkins Server(EC2) using Terraform</strong></p><p>Clone the Git repository: <a href="https://github.com/Abiolamajek/DevSecOps-Kubernetes-Three-Tier-Project-using-AWS-EKS-ArgoCD-Prometheus-Grafana-and-Jenkins.git">https://github.com/Abiolamajek/DevSecOps-Kubernetes-Three-Tier-Project-using-AWS-EKS-ArgoCD-Prometheus-Grafana-and-Jenkins.git</a></p><p>Navigate to the Jenkins-Server-TF</p><p>Do some modifications to the backend.tf file such as changing the bucket name and dynamodb table(make sure you have created both manually on AWS Cloud — Ensure the ‘Lock-files’ table has a partition key named ‘LockID’ of type string).</p><pre>terraform {<br>  backend &quot;s3&quot; {<br>    bucket         = &quot;s3devsecopmomo&quot;<br>    region         = &quot;us-east-1&quot;<br>    key            = &quot;End-to-End-Kubernetes-Three-Tier-DevSecOps-Project/Jenkins-Server-TF/terraform.tfstate&quot;<br>    dynamodb_table = &quot;Lock-Files&quot;<br>    encrypt        = true<br>  }<br>  required_version = &quot;&gt;=0.13.0&quot;<br>  required_providers {<br>    aws = {<br>      version = &quot;&gt;= 2.7.0&quot;<br>      source  = &quot;hashicorp/aws&quot;<br>    }<br>  }<br>}</pre><p>On the variables.tfvars file, replace the key name with the Pem File name you have created on AWS. (If you have not, create a new one)</p><pre>vpc-name      = &quot;Jenkins-vpc&quot;<br>igw-name      = &quot;Jenkins-igw&quot;<br>subnet-name   = &quot;Jenkins-sub&quot;<br>rt-name       = &quot;Jenkins-rt&quot;<br>sg-name       = &quot;Jenkins-sg&quot;<br>instance-name = &quot;Devsecops&quot;<br>key-name      = &quot;momo&quot;<br>iam-role      = &quot;Devsecops_project&quot;</pre><p>Initialize the backend by running the below command</p><pre>terraform init</pre><p>Run the below command to check the syntax error</p><p>terraform validate</p><p>Run the below command to get the blueprint of what kind of AWS services will be created.</p><pre>terraform plan -var-file=variables.tfvars</pre><p>Now, run the below command to create the infrastructure on AWS Cloud which will take 3 to 4 minutes maximum</p><pre>terraform apply -var-file=variables.tfvars - auto-approve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4YIn52sQQuCYOanvj25UJw.png" /></figure><p>Now, connect to the Jenkins-Server from AWS console by clicking on Connect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j4E2_VEElV0ZoknN-C3_Dg.png" /></figure><p>You can also use ec2 instance by copying the ssh command to connect from your local machine (don’t forget to add your key name)</p><h3>Step 4: Configure the Jenkins</h3><p>Now, we logged into our Devsecops server. which is also my Jenkins server. We have installed some services such as Jenkins, Docker, Sonarqube, Terraform, Kubectl, AWS CLI, and Trivy.</p><p>Let’s validate whether all our installed or not.</p><pre>jenkins --version<br>docker --version<br>docker ps<br>terraform --version<br>kubectl version<br>aws --version<br>trivy --version<br>eksctl --version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UGI9XJEKAsug6wGyjFzQRg.png" /></figure><p>Now, we have to configure Jenkins. So, copy the public IP of your Jenkins Server and paste it on your favorite browser with an 8080 port.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S5SAe4IHJgxNoL-XZFq_yA.png" /></figure><p>to get the jenkins password, copy /var/lib/jenkins/secrets/initialAdminPassword and switch to home directory then run the command</p><pre>cat /var/lib/jenkins/secrets/initialAdminPassword</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K3SEoiAZ7QFEeYL29zjVpQ.png" /></figure><p>copy the password and log into jenkins</p><p>Click on Install suggested plugins and The plugins will be installed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3FNlKRGcDzvv0-libCk0UQ.png" /></figure><p>After installing the plugins, continue as admin, save and finish</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tVrApAQhCRLklrFY-2hGNA.png" /></figure><p>Click on Save and Finish. Click on ‘Start using Jenkins’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9TzgWf17Ok3FwmA84irX0Q.png" /></figure><h3>Step 5: We will deploy the EKS Cluster using eksctl commands</h3><p>Now, go to your new Devsecops Server <strong>terminal</strong> and configure the AWS.</p><pre>aws configure</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KSdv3Hx-5n6hE8z2PsUKmw.png" /></figure><p>Go to Manage Jenkins</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iP3vVlHtBFCZuZbO8XqEWg.png" /></figure><p>Click on Plugins, Select the Available plugins</p><p>Install the following plugins below and click on Install</p><p><em>AWS Credentials</em></p><p><em>Pipeline: AWS Steps</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sEVWZh-ti8vH_Fwb0rfcpA.png" /></figure><p>Once, both the plugins are installed, restart your Jenkins service by checking the <strong>Restart Jenkins </strong>option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FP4Xm8gJjn7Ba5iZkTmiJw.png" /></figure><p>Login again</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j9a2a6bSgsJ_Pn0NJ1fDvQ.png" /></figure><p>Now, we have to set our AWS credentials on Jenkins</p><p>Go to Manage Plugins and click on Credentials</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ioCy31yOmDNcLdqqyAHkNQ.png" /></figure><p>Click on global.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ux97LidrDqD8eEXn744gJw.png" /></figure><p>Select AWS Credentials as Kind and add the ID same as shown in the below snippet except for your AWS Access Key &amp; Secret Access key and click on Create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*usYhykEFrip-BmbcbzBAgQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FdG62ftA7y2lBlCB3CwA-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fATfDBWaNdxdzabJTw1aXA.png" /></figure><p>We need to add GitHub credentials as well because currently, my repository is Private.</p><p>I am performing this because in Industry Projects your repository will be private.</p><p>So, add the username and password of your GitHub account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-0_YQseeuDEcuT0Q-a5ZJw.png" /></figure><p>Both credentials will look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*93dSQ3QkKPJ6jVrs796EcA.png" /></figure><p>Create an eks cluster using the below commands.</p><pre>eksctl create cluster - name Three-Tier-K8s-EKS-Cluster - region us-east-1 - node-type t2.medium - nodes-min 2 - nodes-max 2<br>aws eks update-kubeconfig - region us-east-1 - name Three-Tier-K8s-EKS-Cluster</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M4gqvjmrxAQNf5vMV2TdBg.png" /></figure><p>Once your cluster is created, you can validate whether your nodes are ready or not by the below command</p><pre>kubectl get nodes</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KF57H3feaQtuEZGRAS0Eug.png" /></figure><h3>Step 6: Now, we will configure the Load Balancer on our EKS because our application will have an ingress controller.</h3><p>Download the policy for the LoadBalancer prerequisite.</p><pre>curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.5.4/docs/install/iam_policy.json</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zj3H_vJGy9PbcEKIYq-ilQ.png" /></figure><p>Create the IAM policy using the below command,</p><pre>aws iam create-policy - policy-name AWSLoadBalancerControllerIAMPolicy - policy-document file://iam_policy.json</pre><p>Create OIDC Provider</p><pre>eksctl utils associate-iam-oidc-provider - region=us-east-1 - cluster=Three-Tier-K8s-EKS-Cluster - approve</pre><p>Create Service Account</p><pre>eksctl create iamserviceaccount - cluster=Three-Tier-K8s-EKS-Cluster - namespace=kube-system - name=aws-load-balancer-controller - role-name AmazonEKSLoadBalancerControllerRole - attach-policy-arn=arn:aws:iam::&lt;your_account_id&gt;:policy/AWSLoadBalancerControllerIAMPolicy - approve - region=us-east-1</pre><p>Run the below command to deploy the AWS Load Balancer Controller</p><pre>sudo snap install helm - classic<br>helm repo add eks https://aws.github.io/eks-charts<br>helm repo update eks<br>helm install aws-load-balancer-controller eks/aws-load-balancer-controller -n kube-system - set clusterName=my-cluster - set serviceAccount.create=false - set serviceAccount.name=aws-load-balancer-controller</pre><p>After 2 minutes, run the command below to check whether your pods are running or not.</p><pre>kubectl get deployment -n kube-system aws-load-balancer-controller</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rS_IhuAMylAcBpPJ7mbxEA.png" /></figure><h3>Step 7: We need to create Amazon ECR Private Repositories for both Tiers (Frontend &amp; Backend)</h3><p>Go on to your AWS Console and search Elastic Container registory, then Click on private repository and next Create repository</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5blL1KQfS5FtoI-IhmrPnw.png" /></figure><p>Do the same for the backend repository and click on Save</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XhyP1L2LEwCA-PZ4qOgFgg.png" /></figure><p>Now, we need to configure ECR locally because we have to upload our images to Amazon ECR.</p><p>Copy the <strong>1st</strong> command for login</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZqBcCartY3HrxNc7wcyFFw.png" /></figure><p>Now, run the copied command on your <strong>Devsecops Server</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-EG0QTm_Rlx2QMC2x2yz8w.png" /></figure><h3>Install &amp; Configure ArgoCD</h3><p>We will be deploying our application on a three-tier namespace. To do that, we will create a three-tier namespace on EKS</p><pre>kubectl create namespace three-tier</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m9G-P-wd70RmOxjElXrqTw.png" /></figure><p>As you know, Our two ECR repositories are private. So, when we try to push images to the ECR Repos it will give us the error <strong>Imagepullerror.</strong></p><p>To get rid of this error, we will create a secret for our ECR Repo by the below command and then, we will add this secret to the deployment file.</p><p><strong>Note</strong>: The Secrets are coming from the .docker/config.json file which is created while login the ECR in the earlier steps</p><pre>kubectl create secret generic ecr-registry-secret \<br>  --from-file=.dockerconfigjson=${HOME}/.docker/config.json \<br>  --type=kubernetes.io/dockerconfigjson --namespace three-tier<br>kubectl get secrets -n three-tier</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W4D5WPExkOx0I3rjFo2iGQ.png" /></figure><p>Now, we will install argoCD. To do that, create a separate namespace for it and apply the argocd configuration for installation.</p><pre>kubectl create namespace argocd<br>kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v2.4.7/manifests/install.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9jYm_FsELsI56vJtgVGUXA.png" /></figure><p>All pods must be running, to validate run the below command</p><pre>kubectl get pods -n argocd</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p3-e961XDrHNQVVuUiF8bw.png" /></figure><p>Now, expose the argoCD server as LoadBalancer using the below command</p><pre>kubectl patch svc argocd-server -n argocd -p &#39;{&quot;spec&quot;: {&quot;type&quot;: &quot;LoadBalancer&quot;}}&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3eCK30PHvXHGT73-w1bp2A.png" /></figure><p>You can validate whether the Load Balancer is created or not by going to the AWS Console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VmDYa9U0r062_Xzx5BrJ2Q.png" /></figure><p>To access the argoCD, copy the LoadBalancer DNS and hit on your favorite browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xl_oZC9QAYSGhXHyHilnpA.png" /></figure><p>You will get a warning like this, Click on Advanced.</p><p>Click on the below link which appears below Hide advanced</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2-pdUffCuv7CjhfDOQ76TA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ykS61-N7plh7g0SycI-klg.png" /></figure><p>Now, we need to get the password for our argoCD server to perform the deployment.</p><p>To do that, we have a pre-requisite which is jq. Install it by the command below.</p><pre>sudo apt install jq -y<br>export ARGOCD_SERVER=&#39;kubectl get svc argocd-server -n argocd -o json | jq - raw-output &#39;.status.loadBalancer.ingress[0].hostname&#39;&#39;<br>export ARGO_PWD=$(kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath=&quot;{.data.password}&quot; | base64 -d)<br>echo $ARGO_PWD</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xwp3FPmoIHR_gwG6mr0y5A.png" /></figure><p>Enter the username (admin) and password in argoCD and click on SIGN IN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ykS61-N7plh7g0SycI-klg.png" /></figure><p>Here is our ArgoCD Dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x5Jk9kcTjKWXpKbaY7Zv_Q.png" /></figure><h3>Step 8: we have to configure Sonarqube for our DevSecOps Pipeline</h3><p>To do that, copy your Jenkins Server public IP and paste it on your favorite browser with a 9000 port</p><p>The username and password will be <strong>admin</strong></p><p>Click on <strong>Log In.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ScAv8ZvM-S_hie5CtiTABg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d4qeRN8IP7B_dYVgyQGoPA.png" /></figure><p>Update the password</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UC5x1Ax9EuX0znTbmYKZBw.png" /></figure><p>Click on Administration then Security, and select Users</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ryfKYEuhDy7IE0uHFkOJdA.png" /></figure><p>Click on Update tokens</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ExBwTd56B2RtiddCrgThww.png" /></figure><p>Click on Generate</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YqLRyZuW0C58PFuPqR2RXg.png" /></figure><p>Copy the token keep it somewhere safe and click on Done.</p><p>Now, we have to configure webhooks for quality checks.</p><p>Click on Administration then, Configuration and select Webhooks</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fjTRFKENVM6KdkUWdKPolA.png" /></figure><p>Click on Create</p><p>Provide the name of your project and in the URL, provide the Devsecops server public IP with port 8080 add sonarqube-webhook in the suffix, and click on Create.</p><p>http://&lt;Devsecops-server-public-ip&gt;:8080/sonarqube-webhook/</p><p>Here, you can see the webhook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o92DR9jxcP_HQjuuCC4N3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8VlM3Crqi7PfHdtielr0EQ.png" /></figure><p>Now, we have to create a Project for frontend code.</p><p>Click on Manually.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hdaillaKBisoPo8IbcG8qw.png" /></figure><p>Provide the display name to your Project (three-tier-frontend) and click on Setup</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EiXyn9IQifA0-Kb5miD3hg.png" /></figure><p>Click on Locally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hARIr0F3aC5US8qOWc8pgg.png" /></figure><p>Select the Use existing token and click on Continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zeUhg22hdhqxFUyz5CyvJQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uI8uudJNLGWGiiljPLRACw.png" /></figure><p>Select Other and Linux as OS.</p><p>After performing the above steps, you will get the command which you can see below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7h9qY6gNM5D-AMEz47qXpw.png" /></figure><p>Now, use the command in the Jenkins Frontend Pipeline where Code Quality Analysis will be performed.</p><p>Now, we have to create a Project for backend code.</p><p>Click on Create Project. Click Manually</p><p>Provide the display name (three-tier-backend)to your Project and click on Setup</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Uve-lNodixvXejeYffBow.png" /></figure><p>Click on Locally.</p><p>Select the Use existing token and click on Continue.</p><p>Select Other and Linux as OS.</p><p>After performing the above steps, you will get the command which you can see below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i3kV2Gz1lxzIKHyWXsP4gQ.png" /></figure><p>Use the command in the Jenkins Backend Pipeline where Code Quality Analysis will be performed.</p><p>Next, we have to store the sonar credentials in Jenkins</p><p>Go to Dashboard -&gt; Manage Jenkins -&gt; Credentials</p><p>Select the kind as Secret text paste your token in Secret and keep other things as it is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iAcmOkXPTUjSFIYcG_yQHQ.png" /></figure><p>Click on Create</p><p>Now, we have to store the GitHub Personal access token to push the deployment file which will be modified in the pipeline itself for the ECR image.</p><p>Add GitHub credentials</p><p>Select the kind as Secret text and paste your GitHub Personal access token(not password) in Secret and keep other things as it is.</p><p>Click on Create</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9PXJK_CdsleYX3Xs1hQLCA.png" /></figure><p>Note: If you have not generated your token then, you have it generated first in GitHub and then paste it into the Jenkins</p><p>Now, according to our Pipeline, we need to add an AWS Account ID in the Jenkins credentials because of the ECR repo URI.</p><p>Select the kind as Secret text paste your AWS Account ID in Secret and keep other things as it is.</p><p>Click on Create</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fWK4cE0c8t6P6u8MDao27g.png" /></figure><p>Now, we need to provide our AWS ECR image name for frontend which is frontend only.</p><p>Select the kind as Secret text paste your frontend repo name in Secret and keep other things as it is.</p><p>Click on Create</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qYmLeswPwSTzPtoMDD6SMg.png" /></figure><p>Now, we need to provide our ECR image name for the backend which is backend only.</p><p>Select the kind as Secret text, paste your backend repo name in Secret, and keep other things as it is.</p><p>Click on Create</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BeFRqyGEBaBQM7PUPK2FZA.png" /></figure><p>Final Snippet of all Credentials that we needed to implement this project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lkkx8hn3DQ6VxM0tTlvPUQ.png" /></figure><h3>Step 9: Install the required plugins and configure the plugins to deploy our Three-Tier Application</h3><p>Install the following plugins by going to Dashboard -&gt; Manage Jenkins -&gt; Plugins -&gt; Available Plugins</p><pre>Docker<br>Docker Commons<br>Docker Pipeline<br>Docker API<br>docker-build-step<br>Eclipse Temurin installer<br>NodeJS<br>OWASP Dependency-Check<br>SonarQube Scanner</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gMYItPA9oY8YqyQ3Lr1rvQ.png" /></figure><p>Now, we have to configure the installed plugins.</p><p>Go to Dashboard -&gt; Manage Jenkins -&gt; Tools</p><p>We are configuring jdk</p><p>Search for jdk and provide the configuration like the below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HfSFsquVmf6oFzZ6YA52cQ.png" /></figure><p>Now, we will configure the sonarqube-scanner</p><p>Search for the sonarqube scanner and provide the configuration like the below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8MKpwezrqxODbpiuQrKq_w.png" /></figure><p>Now, we will configure nodejs</p><p>Search for node and provide the configuration like the below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UP-v4Hb6G955Mi6jJoSj4Q.png" /></figure><p>Now, we will configure the OWASP Dependency check</p><p>Search for Dependency-Check and provide the configuration like the below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YR1nR-njZ09hfVIZQkagzA.png" /></figure><p>Now, we will configure the docker</p><p>Search for docker and provide the configuration like the below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5MPiyVP1W9tsRizENo9DAg.png" /></figure><p>Make sure you save all</p><p>Now, we have to set the path for Sonarqube in Jenkins</p><p>Go to Dashboard -&gt; Manage Jenkins -&gt; System</p><p>Search for SonarQube installations</p><p>Provide the name as it is, then in the Server URL copy the sonarqube public IP (same as Jenkins) with port 9000 select the sonar token that we have added recently, and click on Apply &amp; Save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*axHQmUhdARZWGD0R5iIEQA.png" /></figure><p>Now, we are ready to create our Jenkins Pipeline to deploy our Backend Code.</p><p>Go to Jenkins Dashboard</p><p>Click on New Item</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J-Y-PMMHGXV9hNXE16wQ3g.png" /></figure><p>Provide the name of your Pipeline and click on OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MtCaJ9PE6P5W0InfDnFzbQ.png" /></figure><p>This is the Jenkins file to deploy the Backend Code on EKS.</p><p>Copy and paste it into the Jenkins</p><p><a href="https://github.com/Abiolamajek/DevSecOps-Kubernetes-Three-Tier-Project-using-AWS-EKS-ArgoCD-Prometheus-Grafana-and-Jenkins/blob/master/Jenkins-Pipeline-Code/Jenkinsfile-Backend">https://github.com/Abiolamajek/DevSecOps-Kubernetes-Three-Tier-Project-using-AWS-EKS-ArgoCD-Prometheus-Grafana-and-Jenkins/blob/master/Jenkins-Pipeline-Code/Jenkinsfile-Backend</a></p><p>Click Apply &amp; Save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ohSm0RuZUIyJDkezPFNGEw.png" /></figure><p>Now, click on the build.</p><p>The pipeline was successful after troubleshooting some errors.</p><p>Note: Make changes in the Pipeline according to your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1TAzefnwidaNrBcogD3LRA.png" /></figure><p>Now, we are ready to create our Jenkins Pipeline to deploy our Frontend Code.</p><p>Go to Jenkins Dashboard</p><p>Click on New Item</p><p>Provide the name of your Pipeline and click on OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R02m5rw2cc9pBl__9HcHPg.png" /></figure><p>This is the Jenkins file to deploy the Frontend Code on EKS.</p><p>Copy and paste it into the Jenkins</p><p><a href="https://github.com/Abiolamajek/DevSecOps-Kubernetes-Three-Tier-Project-using-AWS-EKS-ArgoCD-Prometheus-Grafana-and-Jenkins/edit/master/Jenkins-Pipeline-Code/Jenkinsfile-Frontend">Build software better, together</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IW3jkXk1rNxLdrFBgFzAxA.png" /></figure><p>Click Apply &amp; Save.</p><p>Now, click on the build.</p><p>The pipeline was successfully run.</p><p>Note: Make changes in the Pipeline according to your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1_FZjgx_vQYmc79ItpIyQw.png" /></figure><p><strong>Setup 9: We will set up the Monitoring for our EKS Cluster. We can monitor the Cluster Specifications and other necessary things.</strong></p><p>We will achieve the monitoring using Helm</p><p>Add the prometheus repo by using the below command</p><pre>helm repo add stable https://charts.helm.sh/stable<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pnMzNJoarWJ5oOXpks-KYw.png" /></figure><p>Install Prometheus</p><pre>helm repo add prometheus-community https://prometheus-community.github.io/helm-charts</pre><p>Now, check the service by the below command</p><pre>kubectl get svc</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QX-DOC0WfSV1VyAdY9oJkA.png" /></figure><p>Next is to access our Prometheus and Grafana consoles from outside of the cluster.</p><p>For that, we need to change the Service type from ClusterType to LoadBalancer</p><p>and also Edit the stable-kube-prometheus-sta-prometheus service</p><pre>kubectl edit svc stable-kube-prometheus-sta-prometheus</pre><p>Modification in the 48th line from ClusterType to LoadBalancer</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sWv5n_jqsge6_fRiU7IDPw.png" /></figure><p>Next, Edit the stable-grafana service</p><pre>kubectl edit svc stable-grafana</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rjni4EnxY-wbMFWfffJlLg.png" /></figure><p>Modify the 39th line from ClusterType to LoadBalancer</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*OY_I-omZgvCiURcjOuXrhA.png" /></figure><p>Now, if you list again the service then, you will see the LoadBalancers DNS names</p><pre>kubectl get svc</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DhbIdtF_K07NZtpV76We7Q.png" /></figure><p>You can also validate from your console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rpoCT4ae5T43Uh5M0-ctog.png" /></figure><p>Now, access your Prometheus Dashboard</p><p>Paste the &lt;Prometheus-LB-DNS&gt;:9090 in your favorite browser and you will see like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*52OAhyOzAqOsif7I1h4GIg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gaEB_hubGXDccdBNsFj7Gw.png" /></figure><p>Click on Status and select Target.</p><p>You will see a lot of Targets</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K8njsh9y265uOZ_rGkog2A.png" /></figure><p>Now, access your Grafana Dashboard</p><p>Copy the ALB DNS of Grafana and paste it into your favorite browser.</p><p>The username will be admin and the password will be prom-operator for your Grafana Login</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_dpm8u9uaS_pWnmK_hOtsA.png" /></figure><p>Now, click on Add your first Data Source</p><p>Select Prometheus</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l-Pm6UYhgq_NQCo-X67-zw.png" /></figure><p>In the Connection, paste your &lt;Prometheus-LB-DNS&gt;:9090.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WCWae1cQXXJ_-Q9c1YKWUg.png" /></figure><p>If the URL is correct, then you will see a green notification/alerting</p><p>Click on Save &amp; test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8DN4FVKK87j2BnxebDfKGg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hctZcknxyo0ltPS-_72evQ.png" /></figure><p>Now, we will create a dashboard to visualize our Kubernetes Cluster Logs.</p><p>Click on Dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*iLsJmff774Rl8lmGHMzYiA.png" /></figure><p>Once you click on Dashboard. You will see a lot of Kubernetes components monitoring.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aQViACUzK074b-CChb1x0Q.png" /></figure><p>Lets try to import a type of Kubernetes Dashboard.</p><p>Click on New and select Import</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ye_KdKidfPRL2ybVa9PpnA.png" /></figure><p>Provide 6417 ID and click on Load</p><p>Note: 6417 is a unique ID from Grafana which is used to Monitor and visualize Kubernetes Data</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mVixUN7--xQASGDVHii64Q.png" /></figure><p>Select the data source that you have created earlier and click on Import.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sLIg8wLlt2C673kJBZCbmQ.png" /></figure><p>Here, you go.</p><p>You can view your Kubernetes Cluster Data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dmkbsTmWIXGeTRnZpEFUew.png" /></figure><p>Feel free to explore the other details of the Kubernetes Cluster.</p><h3>Step 10: Deploy TheThree-Tier Application using ArgoCD.</h3><p>As our repository is private. So, we need to configure the Private Repository in ArgoCD.</p><p>Click on Settings and select Repositories</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CBLGCBdJtoSQKTm3zSu1hQ.png" /></figure><p>Click on CONNECT REPO USING HTTPS</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LckDcWh9vB1v_F4w2SybKg.png" /></figure><p>Now, provide the repository name where your Manifests files are present.</p><p>Provide the username and GitHub Personal Access token and click on CONNECT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OSEJHbGb-Mk7CYA-XyEiUw.png" /></figure><p>If your Connection Status is Successful it means repository connected successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O4sXOS0GYB1epP3AltAugg.png" /></figure><p>Now, we will create our first application which will be a database.</p><p>Click on CREATE APPLICATION.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LI0j5Jn3lXAjeuCF4eWtkw.png" /></figure><p>Provide the details as it is provided in the below for the General section and scroll down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZkmR7Dj_IW1VoVUvs38UGg.png" /></figure><p>set the sync policy to automatic,</p><p>For the source select the same repository that you configured in the earlier step.</p><p>In the Path, provide the location where your Manifest files are presented and provide other things as shown in the below screenshot.</p><p>Click on CREATE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*APaUgWW0uncELd4gieLwAg.png" /></figure><p>While your database Application is starting to deploy, We will create an application for the backend.</p><p>Provide the details as it is provided in the below snippet and scroll down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LmdYcfptl-jVlZIEkv_iYw.png" /></figure><p>Select the same repository as configured in the earlier step.</p><p>In the Path, provide the location where the Manifest files are present and provide other details as shown in the below screenshot.</p><p>Click on CREATE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zxemxRnE4Eg_dAUxjAlD4g.png" /></figure><p>While your backend Application is starting to deploy, We will create an application for the frontend.</p><p>Provide the details as it is provided in the below snippet and scroll down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ossVFCvXpI2ktuEUUFoNQ.png" /></figure><p>Select the same repository that you configured in the earlier step.</p><p>In the <strong>Path</strong>, provide the location where your Manifest files are presented and provide other things as shown in the below screenshot.</p><p>Click on <strong>CREATE.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ubyx_Kp7G7pdAmzTGhEFCA.png" /></figure><p>While your frontend Application is starting to deploy, We will create an application for the ingress.</p><p>Provide the details as it is provided in the below snippet and scroll down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q5XrLOp3Ql2QRvraWzwBLQ.png" /></figure><p>Select the same repository that you configured in the earlier step.</p><p>In the Path, provide the location where your Manifest files are presented and provide other things as shown in the below screenshot.</p><p>Click on CREATE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GvvBbRwm6DnocYzEdqhcYA.png" /></figure><p>Once your Ingress application is deployed. It will create an Application Load Balancer</p><p>You can check out the load balancer named with k8s-three.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y2VBJido5gdzoJMbOQAH7w.png" /></figure><p>Now, Copy the ALB-DNS and go to your Domain Provider in my case AWS route53 is the domain provider.</p><p>Go to route 53 click the hosted zone and click Create Record,</p><p>For record name i added backend and record type select CNAME and then value is the DNS name from the load balancer, click Create</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*RihVM1Sv2rAdRIUdTpKocg.png" /></figure><p>Note: I have created a subdomain <a href="http://backend.abiolamajek.net/">http://backend.abiolamajek.net/</a></p><p>You can see all 4 application deployments below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*smV7rn5248qc-sYVKwRsjA.png" /></figure><p>Now, hit your subdomain after 2 to 3 minutes in your browser to see the magic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*On16cGPYjHncPBzahc9Syw.png" /></figure><p>You can play with the application by adding the records.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A5Z3Kx-ER-xknU6wSWhGng.png" /></figure><p>You can play with the application by deleting the records.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6dgY_pb7ewPeECzoeyHo2Q.png" /></figure><p>Now, you can see your Grafana Dashboard to view the EKS data such as pods, namespace, deployments, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e5GFUAkeiEw8g358YgVZrw.png" /></figure><p>This is the Ingress Application Deployment in ArgoCD</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BA5CKQHpRaWxn2EkR59L2Q.png" /></figure><p>This is the Frontend Application Deployment in ArgoCD</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vUx3MkEkBguwcWZJtH4VlA.png" /></figure><p>This is the Backend Application Deployment in ArgoCD</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sp3IjZIA1QngvEUfYrW8kw.png" /></figure><p>This is the Database Application Deployment in ArgoCD</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LtlKFyALugyUL0fxjB59Ig.png" /></figure><p>Observation: Persistent Volume and Persistent Volume Claim configurations ensure data persistence, preventing loss if pods are deleted. Data remains stored on the host machine.</p><p>Conclusion: In this extensive DevSecOps Kubernetes project, the following accomplishments were made:</p><ol><li>Establishment of IAM user and Terraform setup for AWS.</li><li>Deployment of Jenkins on AWS, tool configuration, and integration with Sonarqube.</li><li>Setup of an EKS cluster, Load Balancer configuration, and creation of private ECR repositories.</li><li>Implementation of monitoring using Helm, Prometheus, and Grafana.</li><li>Installation and configuration of ArgoCD for GitOps practices.</li><li>Creation of Jenkins pipelines for CI/CD, facilitating Three-Tier application deployment.</li><li>Assurance of data persistence through persistent volumes and claims.</li></ol><p>Resource Cleanup: Execute Terraform destroy and navigate to the AWS console to remove other resources created to prevent additional costs. Delete ECR repositories, DynamoDB table, EKS nodegroup, EKS cluster, NAT gateway, detach and delete network interfaces, VPC, security groups, load balancers, and any other resources.</p><p>Thank you so much for your time, I do hope you like it.</p><p>kindly follow me <a href="http://www.linkedin.com/in/abiola-majekodunmi-">www.linkedin.com/in/abiola-majekodunmi-</a></p><p>kindly follow on medium as well <a href="https://medium.com/@abiolamajekodunmi2011">https://medium.com/@abiolamajekodunmi2011</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea2572d239e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[USING TERRAFORM TO CREATE AUTOSCALLING FOR EC2 INSTANCES]]></title>
            <link>https://medium.com/@abiolamajekodunmi2011/using-terraform-to-create-autoscalling-for-ec2-instances-d39f24a7d66e?source=rss-663b5162e79b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d39f24a7d66e</guid>
            <dc:creator><![CDATA[Abiola Majek]]></dc:creator>
            <pubDate>Tue, 19 Sep 2023 17:19:49 GMT</pubDate>
            <atom:updated>2023-09-19T17:19:49.091Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uQzastQ7jl6WSKHqk6SJ4Q.jpeg" /></figure><p>Today I will work you through yet another interesting topic in Terraform which is how to create autoscaling using Terraform. Today, we will use Terraform code to create the infrastructure to launch an Auto Scaling group, configure security groups, set up an Apache web server on instances, and use an S3 bucket as the remote backend for Terraform.</p><p>In my previous project <a href="https://medium.com/@abiolamajekodunmi2011/how-to-set-up-jenkins-to-run-on-aws-ec2-instance-using-terraform-dab3ff73479b">click here</a>, I gave an understanding of Terraform and how Infrastructure as code is so important. In this new project, I will be using a provider.tf, variable.tf. For this project I will ;</p><ol><li>Launch an Auto Scaling group that spans 2 subnets in a default Vpc.</li><li>Create a security group that allows traffic from the internet and associate it with the Auto Scaling group instances.</li><li>Include a script in your user data to launch an Apache webserver. The Auto Scaling group should have a min of 2 and a max of 5.</li><li>To verify everything is working check the public IP addresses of the two instances. Manually terminate one of the instances to verify that another one spins up to meet the minimum requirement of 2 instances.</li><li>Create an S3 bucket and set it as your remote backend.</li></ol><p>For this project, I will be using Amazon Linux OS. Another essential resource that I will be using is the Terraform Registry. You can go on your Google and search terraform registry, then you register an account to have access to the terraform registry.</p><p>For this project, I used cloud9 IDE because it has Terraform automatically installed on it.</p><p>After I set up cloud9 IDE I will clone my git repository into the cloud9 environment.</p><p>I will organize my resources by creating separate files for each resource. To do this, I simply copy all the resource information from the Terraform registry, paste it into the appropriate folder, and save it.</p><p>I will create the terraform file for the provider, security group, auto-scaling file, and user data script.</p><p>I created a security group and saved it. I used the terraform registry to create the security group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HjTvi5z55cg7mzJ9WTYpGA.png" /></figure><p>Next, I created a provider.tf file that is typically used to configure and define the cloud or service providers that you intend to use within your Terraform configuration. This is found in the terraform registry.</p><pre>touch provider.tf</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EIjLapHwEGsnnZh95Gv4dA.png" /></figure><p>I created my variable file. These input variables allow you to parameterize your infrastructure code, making it more flexible and reusable. You can think of variables as placeholders that can be assigned values when you apply your Terraform configuration.</p><pre>touch variable.tf</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cIbtULppct1snnNX9d442Q.png" /></figure><p>I created the variable files from the resources in the AWS console.</p><p>region: us west -1</p><p>keypair -</p><p>Instance type -t.2 micro</p><p>the AMI ID which is the Amazon ID.</p><p>I also install_apache.sh as the user data on our template. I created the file using the below. Then I opened the file on Cloud 9 pasted the user data to run httpd on Linux OS and then saved it.</p><pre>touch install_apache.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aGlZ7qfOCk-1j1AOx3G4IQ.png" /></figure><p>I will manually create an s3 bucket in the AWS console, and give it a unique name for me I used my-terraform-state-s3-blackteam2023. Then I copied the name and used it to set the remote backend in Terraform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XDnBztxALiGhD7P3SoTvcg.png" /></figure><p>Next is to create the auto-scaling group. First, I created the file.</p><pre>touch black-asg</pre><p>From the terraform registry I will add a min instance to 2 and a max instance to 5 instances, the desired instance is 2 instances. I also included variables I created in the variable.tf files to create the instances. They include ;</p><p>The Image ID, Instance type, Key pair. Also, I included the security group file and the user data path I created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bkevn_CD-uaaYVrvKjZz9A.png" /></figure><p>I will make sure your files are saved then I run</p><pre>terraform init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OXQSP6Nn67ZRkDuIBr5czw.png" /></figure><pre>terraform validate</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EYGTFSRFCgf3kAOvzWePpg.png" /></figure><pre>terraform plan</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A-5-ylF-4Rf-iU6-fE9Ijw.png" /></figure><pre>terraform apply</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lJUnAdixCLubUXt1SRWEgw.png" /></figure><p>Now I will go to my EC2 dashboard in aws and see if 2 instances were created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YGnk8nI1y_S2F-C8Ay9ppA.png" /></figure><p>You will see my security group is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hDNnqmJNMsLNffzcCXqqxA.png" /></figure><p>I will copy the 1st public IP address and paste it on my browser and you will see. I also did the same for the 2nd public IP address from the desired number of instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uVmOxg4zwtPY34AfUS9UYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AwXjrivFMEccRvJt-fzpoQ.png" /></figure><p>Now I will terminate of the instances to verify the auto scaling is working. Now another is created and it is working perfectly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R_VwHsTtFBfAHSPp0rN3Qw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AKIwtotSdoSx8xao-OuP5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-29sQa506azKfjb6Ww2SKQ.png" /></figure><p>Also, the s3 bucket is working perfectly with the remote.tfstate is also in the s3 bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VYOXyVsAbNBjYFFpj_mJNg.png" /></figure><p>I will push all my code to GitHub <a href="https://github.com/Abiolamajek/terraform_projects/">click here</a></p><p>lastly, I will run the command</p><pre>terraform destroy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6oxqzFlInfYfJ_-SXJqSOw.png" /></figure><p>Thank you and I hope you like it</p><p>Kindly follow me on Linkedln <a href="https://www.linkedin.com/in/abiola-majekodunmi-/">https://www.linkedin.com/in/abiola-majekodunmi-/</a> for more stories and also on Medium here.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d39f24a7d66e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to set up Jenkins to Run on AWS EC2 Instance Using Terraform]]></title>
            <link>https://medium.com/@abiolamajekodunmi2011/how-to-set-up-jenkins-to-run-on-aws-ec2-instance-using-terraform-dab3ff73479b?source=rss-663b5162e79b------2</link>
            <guid isPermaLink="false">https://medium.com/p/dab3ff73479b</guid>
            <dc:creator><![CDATA[Abiola Majek]]></dc:creator>
            <pubDate>Mon, 18 Sep 2023 16:31:20 GMT</pubDate>
            <atom:updated>2023-09-18T16:31:20.040Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uQzastQ7jl6WSKHqk6SJ4Q.jpeg" /></figure><p>Hello today I will be doing some projects using Terraform and I will also be doing a simple project on</p><p>1. How to create an AWS EC2 instance and also use Terraform to set up and start Jenkins.</p><p>2. Create and assign a Security Group to the Jenkins Security Group that allows traffic on port 22 from your IP and allows traffic from port 8080.</p><p>3. Create a S3 bucket for your Jenkins Artifacts that is not open to the public.</p><p>4. Verify that you can reach your Jenkins install via port 8080 in your browser</p><p>For simplicity, I will be using AWS Cloud9 for this project because Cloud9 already has Terraform installed on it, so once I set up Cloud9 Terraform is automatically installed on my IDE</p><p>I will push all this code to my GitHub once this project is complete.</p><p>Let me give a simple explanation of Terraform and why Terraform is effective in terms of infrastructure as a code tool.</p><p>Terraform is infrastructure as a code that will help automate software-defining deployment networks<br>Terraform supports a vast range of public/private networks. <br>Terraform is used to deploy an environment across multiple clouds. With the help of Terraform, you deploy in AWS, Azure, and GCP. This makes your job environment AGONSTICS.<br>With Terraform you can track the state of each resource deployed</p><p>Terraform workflow</p><p>Here is the complete workflow of Terraform <br>1) Write down IAC and that infrastructure and the infrastructure must be written in Hashicorp Configuration Language (HCL)<br>2) Terraform Init. Then you will execute the terraform in the directory to initialize the terraform. Then it will download the plugins and necessary modules.<br>3)Terraform Plan: It will show you all the resources you have written down in your configuration files and it will display what will deploy once you execute the terraform apply so here if you want any changes in any resource you can make it and update your code file and execute the terraform plan<br>4)Terraform apply: `It will execute or deploy all the resources you have mentioned on the code file.<br>5) Terraform destroy is used to destroy the deployment. It will look at the state file and start destroying the resources in our state file.</p><p>For this project, I will be using Amazon Linux OS. Another essential resource that I will be using is the Terraform Registry. You can go on your Google and search terraform registry, then you register an account to have access to the terraform registry.</p><p>For this project, I used cloud9 IDE because it has Terraform automatically installed on it.</p><p>After i set up cloud9 IDE i will clone my git repository and next is create a main.tf file and bash file which I called blackteam_jenkins.sh.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7U_iCmeRG-PW3SAyquKfqw.png" /></figure><p>Firstly I will create my AWS provider which i copied from harshicorp registry by navigating to the AWS and click the documentation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MZ9rUutB_QVtj8BEWzOTjA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*wgtm1twMb0A--__Its7v4w.png" /></figure><p>Please note that for this project I will be using only <a href="http://main.tf/">main.tf</a> so all my code will be hardcoded on <a href="http://main.tf/">main.tf</a></p><p>Let’s create an AWS instance for Jenkins and I will be using the user data to install Jenkins.I created a bash script from above for Jenkins that will run as user data when the EC2 instance is up. I call it “blackteam_jenkins.sh” then I save it</p><pre>#!/bin/bash<br>sudo yum update -y<br>sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo<br>sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key<br>sudo yum upgrade -y # Add required dependencies for the jenkins package<br>sudo dnf install java-11-amazon-corretto -y<br>sudo yum install jenkins -y<br>sudo systemctl enable jenkins<br>sudo systemctl start jenkins</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B65rUAIOcJzjvbQ9MYRepQ.png" /></figure><p>I will be using a default vpc so I will not be including vpc in my main.tf code. Terraform adds the default vpc itself</p><p>I will create a resource for the security group this will be done by using the Terraform registry</p><pre>#Jenkins Security Group Resource<br>resource &quot;aws_security_group&quot; &quot;jenkins-sg&quot; {<br>  name        = &quot;jenkins-sg&quot;<br>  description = &quot;Allow Port 22 and 8080&quot;<br><br>  ingress {<br>    description = &quot;Allow SSH Traffic&quot;<br>    from_port   = 22<br>    to_port     = 22<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    description = &quot;Allow HTTPS Traffic&quot;<br>    from_port   = 443<br>    to_port     = 443<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    description = &quot;Allow 8080 Traffic&quot;<br>    from_port   = 8080<br>    to_port     = 8080<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>}</pre><p>Next is to create an S3 bucket</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pbKgUozYadDlXPqeJX7uyQ.png" /></figure><p>Now i will create the EC2 instance which will include</p><ol><li>ami which i got from aws launch instance console</li><li>Instance type: Which is the t2.micro</li><li>Key_name : This is the keypair</li><li>vpc_security_group_ids: These are the ports where the ec2 instance will be connected. I created this identity file</li><li>user data is the bash script created to run jenkins</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DVPjLSd35sU5_wjrV8Vqig.png" /></figure><p>This is how your main.tf file will look like</p><pre>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;5.16.2&quot;<br>    }<br>  }<br>}<br><br># Configure the AWS Provider<br>provider &quot;aws&quot; {<br>  region = &quot;us-west-1&quot;<br>}<br><br><br>resource &quot;aws_instance&quot; &quot;black_jenkins&quot; {<br>  ami           = &quot;ami-073e64e4c237c08ad&quot; # use free tier AMI other than Amazon Linux 2023 AMI as it has some issue insatlling Jenkins<br>  instance_type = &quot;t2.micro&quot;<br>  key_name                    = &quot;danny&quot;<br>  associate_public_ip_address = true<br>  vpc_security_group_ids      = [aws_security_group.jenkins-sg.id]<br>  user_data                   = file(&quot;blackteam_jenkins.sh&quot;)<br>  #iam_instance_profile        = aws_iam_instance_profile.s3-jenkins-profile.name<br><br>  tags = {<br>    Name = &quot;Jenkins-Server&quot;<br>  }<br>}<br><br><br>#Jenkins Security Group Resource<br>resource &quot;aws_security_group&quot; &quot;jenkins-sg&quot; {<br>  name        = &quot;jenkins-sg&quot;<br>  description = &quot;Allow Port 22 and 8080&quot;<br><br>  ingress {<br>    description = &quot;Allow SSH Traffic&quot;<br>    from_port   = 22<br>    to_port     = 22<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    description = &quot;Allow HTTPS Traffic&quot;<br>    from_port   = 443<br>    to_port     = 443<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    description = &quot;Allow 8080 Traffic&quot;<br>    from_port   = 8080<br>    to_port     = 8080<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>}<br><br>resource &quot;aws_s3_bucket&quot; &quot;black_bucket_team23&quot; {<br>  bucket = &quot;jenkins-s3-bucket-black-bucket-team2323&quot;<br><br>  tags = {<br>    Name = &quot;Jenkins-Server&quot;<br>  }<br>}<br><br><br>resource &quot;aws_s3_bucket_acl&quot; &quot;s3_bucket_acl&quot; {<br>  bucket = aws_s3_bucket.black_bucket_team23.id<br>  acl    = &quot;private&quot;<br>  depends_on = [aws_s3_bucket_ownership_controls.s3_bucket_acl_ownership]<br>}<br><br># Resource to avoid error &quot;AccessControlListNotSupported: The bucket does not allow ACLs&quot;<br>resource &quot;aws_s3_bucket_ownership_controls&quot; &quot;s3_bucket_acl_ownership&quot; {<br>  bucket = aws_s3_bucket.black_bucket_team23.id<br>  rule {<br>    object_ownership = &quot;ObjectWriter&quot;<br>  }<br>}</pre><p>Please make sure you save all these file before you run</p><pre>terraform init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x3vuR-5v6hVsEFvd2zAWLg.png" /></figure><p>run terraform validate and next is run</p><pre>terraform plan</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ow6qgiQhZSbNHAPhRuc5og.png" /></figure><p>Then run</p><pre>terraform apply </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vsxXqjpnV6LUmFkbsCusYQ.png" /></figure><p>We will check if the ec2 instance, security group, and s3 is running</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y9pDnbbF11v8PDqlis4KfQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uIDlnlQqQYsEGweWrbPo3A.png" /></figure><p>Now we will be using EC2 to ssh into the created Jenkins_server after connecting we will check the Jenkins which is input in the user data</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nuDi2Ls1w0NvWquB8P5XLw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DTIzsiDrHO7330VEBLuA7w.png" /></figure><p>Next is we run</p><pre>systemctl status jenkins</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5kEwYg9Z9MgINSrGSB8bUA.png" /></figure><p>we will see the status active running. Also important is the password to log in to Jenkins that is generated from checking the Jenkins status. Now I will copy the password and use it to log in to Jenkins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gzm8LQ3FMyMt0a8Gk6X77Q.png" /></figure><p>Now I will copy the public IP address and paste it on the browser using port 8080 set in the security group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zy3SexIM-AnXAjEdcpyJIQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kTZ61P1mftfbn7kVRpS-cQ.png" /></figure><p>I will paste the password generated to access Jenkins. I will complete the registration and we have Jenkins running</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TFwX0LPoTYNkNzvhmMQW-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zdLqtABq77gacaakiJ0p2w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0GsM_j0G0imwCkrIl8H4GA.png" /></figure><p>Lastly, run</p><pre>terraform destroy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DSIX6ch-K_eYoDjkGH23eA.png" /></figure><p>To delete the created EC2 instance and and s3 bucket.Now we have completed this project and i am going to push my terraform code to GitHub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iwoqbPUYwtGU8Z3N_K3jUA.png" /></figure><p>Thank you and i hope you like it . please like this if you find interesting.</p><p>Kindly follow me <a href="http://www.linkedin.com/in/abiola-majekodunmi-">www.linkedin.com/in/abiola-majekodunmi-</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dab3ff73479b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create 3 Nodes of Docker Swarm and create a network between My SQL, And WordPress]]></title>
            <link>https://medium.com/@abiolamajekodunmi2011/how-to-create-3-nodes-of-docker-swarm-and-create-a-network-between-my-sql-and-wordpress-600e0034bd53?source=rss-663b5162e79b------2</link>
            <guid isPermaLink="false">https://medium.com/p/600e0034bd53</guid>
            <dc:creator><![CDATA[Abiola Majek]]></dc:creator>
            <pubDate>Wed, 23 Aug 2023 18:58:52 GMT</pubDate>
            <atom:updated>2023-08-23T18:58:52.622Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, I will walk you through another interesting topic in docker which is the networking between nodes, so I will be using the CLI:</p><ol><li>Deploy a 3-node Docker Swarm cluster.</li><li>Create 2 networks. One for the front end and another for the back end.</li><li>Create MySQL service and associate with the backend network with Only 1 replica and make the database service resilient and its data persistent across container restarts, use Docker Volumes.</li><li>Create the WordPress service, associated with the frontend network and use port 80. It should be accessible from the browser. Also create3 replicas</li><li>Associated with the MySQL service</li></ol><p>For this project, I will be using the AWS instance, Ubuntu OS, VS code, and my docker hub for referencing.</p><p>In order to set up a 3-node docker swarm cluster click <a href="https://medium.com/@abiolamajekodunmi2011/how-to-set-up-3-node-docker-swarm-3969ce557841">here</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kkDAzelW0gAGrJgib9uldg.jpeg" /></figure><p>Let&#39;s understand what it means to create a network between docker services. It is simply how the services connect to each other which is connecting the MySQL database in the backend and WordPress which will be in the front end.</p><p>To create a network, I will be using the — driver overlay which is the simple way by which containers connect to each other in the virtual cloud. the driver is to manage the Network (default ‘bridge’)</p><p>Before you can create an overlay network, you need to either initialize your Docker daemon as a swarm manager using docker swarm init</p><p>First, let&#39;s do the docker swarm init on the manager node</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N39VhKPeoMZXLjRSuke3Lw.png" /></figure><p>Step 1. Create 2 networks. One for the front end and another for the back end. Next is to create an overlay network by creating a driver for the front and backend</p><p>docker network create--driver overlay frontend</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ruoM0XdRyGUAQQ2r3N2wxQ.png" /></figure><p>docker network create--driver overlay backend</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NGrgDgDG17lcby2tUAsvgg.png" /></figure><p>Step 2. Create MySQL service associated with the backend network with Only 1 replica and make the database service resilient and its data persistent across container restarts, using Docker Volumes.</p><pre>docker service create --name myblacksql \<br>--network backend \<br>--replicas 1 \<br>--mount type=volume,source=mysql-data,target=/var/lib/mysql \<br> -e MYSQL_ROOT_PASSWORD=blackteam \<br> -e MYSQL_DATABASE=wordpress \<br> mysql:latest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*U_JhB_hrD_SCazU8CjtzOQ.png" /></figure><p>Step 3. Create the WordPress service, associated with the frontend network and use port 80. It should be accessible from the browser. Also, create 3 replicas and associate them with the MySQL service.</p><pre>docker service create - name wordpress <br>--network frontend <br>--network backend <br>--publish 80:80<br>--replicas 3 <br>--env WORDPRESS_DB_HOST=myblacksql<br>--env WORDPRESS_DB_USER=root<br>--env WORDPRESS_DB_PASSWORD=blackteam<br>--env WORDPRESS_DB_NAME=wordpress<br>wordpress:latest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*F646sVjC0in4xDGC1rwaoQ.png" /></figure><p>To view the 2 created services and the attached</p><p>docker service ls</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eKb4ES_ZspT8SMdkbnIFkQ.png" /></figure><p>To view the 2 networks created for the front and back I will run</p><p>docker network ls</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DNAS0WO3_sstJHISzmNxuw.png" /></figure><p>Also,</p><p>docker service ps (service id) to know the node that is running your container</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ilwwdMRqysuIGwvLve84IQ.png" /></figure><p>As you can see MYSQL is running on the node and WordPress is running on the node</p><p>How do I know they are talking to each other? I will be using the service names use Step 4</p><p>Step 4. Now copy the manager node public ipv4 IP address and paste it on the browser. We have WordPress. Select the English language fill in the registration form MySQL details and click install and you see the success.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NP2L-2D7tAmydP0UWAMhGA.png" /></figure><p>Now we are able to log in with MySQL details and create a first page on WordPress.</p><p><strong>Step 5</strong>. To use the docker-compose I will create a YAML file and run the stack then I copy the IP address just like we did in Step 4 above. This is the fun of using docker-compose.</p><p>Here quick walkthrough ;</p><p>From the root user of the manager node, create a folder called docker-compose</p><pre>mkdir docker-compose<br>cd docker-compose<br>vi docker_compose.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PCZXnfbfbr0zKFI9LYRqBg.png" /></figure><p>i created the docker_compose.yaml file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*exfNyE6T4Nl33LdM5GWxlA.png" /></figure><p>I created a network for the front end and the back end from step 1.</p><p>docker network create --driver overlay frontend</p><p>docker network create --driver overlay backend</p><p>Now run the stack to create MySQL and WordPress</p><p><strong><em>docker stack deploy -c docker-compose.yaml &lt;stackname&gt;</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yzrcsKeeDjyisOezy6qlGg.png" /></figure><p>Continue with step 4 from above by pasting the manager node public IP address and logging into WordPress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y2SwHmd64Jyri3p3vYBryQ.png" /></figure><p>complete the WordPress registration with the login used in my docker composer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FvPmRrDGadph6mpUxQERtQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*62pzGqrq0klzhsnASR7ZDg.png" /></figure><p>Next is to log in and continue to use my WordPress</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Xl0bSk1dIwqnWH8bPkOwQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XfWLH4IyqFXVxUF5S3IR6w.png" /></figure><p>This is the end of the interesting docker-compose method.</p><p>Please do not forget to remove your services when you are done to avoid charges</p><p>Thank you and I hope you like this. Please Follow me on <a href="http://www.linkedin.com/in/abiola-majekodunmi">www.linkedin.com/in/abiola-majekodunmi</a>- for more projects and also watch out for my next project.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=600e0034bd53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Set Up 3 Node Docker Swarm]]></title>
            <link>https://medium.com/@abiolamajekodunmi2011/how-to-set-up-3-node-docker-swarm-3969ce557841?source=rss-663b5162e79b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3969ce557841</guid>
            <dc:creator><![CDATA[Abiola Majek]]></dc:creator>
            <pubDate>Thu, 17 Aug 2023 02:43:50 GMT</pubDate>
            <atom:updated>2023-08-17T02:43:50.044Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello, in this week&#39;s project, I will be walking you through how I created 3 node swarms where I made 1 manager node and 2 worker nodes. Let’s assume as the junior engineer, you are responsible for only configuring Docker Swarm and providing your team with a step-by-step guide to setting up the Swarm. Your swarm creation should include the following steps via your remote ssh terminal in VSCode:</p><ul><li>Installing docker on all hosts</li><li>Verifying that docker is in an active state</li><li>Change the hostname on each node to identify the master node and the two worker nodes</li><li>Validating the worker nodes all share the same security group as the master node</li><li>Be sure to add your ssh key to each node</li><li>Running the necessary containers using the CLI</li><li>Creating the Swarm using one master node and two worker nodes</li><li>Show your team members the status of the docker node</li></ul><p>What is a docker swarm?</p><p>Docker Swarm is a container orchestration tool that allows users to create and manage a cluster of Docker nodes to deploy and manage containerized applications at scale. It also enables developers to package applications and their dependencies into lightweight, portable containers, ensuring consistent behavior across various environments.</p><p>Node: There are two types of nodes: manager nodes and worker nodes. These nodes serve different roles within the Swarm cluster.</p><ul><li>Manager Nodes: Manager nodes are responsible for the overall management and orchestration of the Swarm cluster.</li><li>Worker Nodes or Slave Nodes: Worker nodes are responsible for running the actual containerized applications and services that make up the applications you want to deploy</li></ul><p>Now let’s get to work</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f6YaMZX3EN-hQhranO001w.jpeg" /></figure><p>For this project, I will be using AWS cloud service. create your EC2 Instance account I will call it my Manager Node, and select t2.micro select the latest Ubuntu, and configure your security group.</p><p>For the Security group, I will create a new security group, give it the name docker_swarm and modify the Security Group associated with the EC2 (Manager Node) to allow all traffic from the VPC CIDR. This will be the default Vpc I created my EC2 instance from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZENc0vfiXimatXmyDiCdvg.png" /></figure><p>Using vs code we will ssh into my terminal. I choose to use the VS code. You can choose another IDE.</p><p>(Use user data to install docker)</p><pre>#!/bin/bash<br>sudo apt-get update -y<br>sudo curl -fsSL https://get.docker.com -o get-docker.sh<br>sudo sh get-docker.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fmO_MKL7sEhwcwmJdPILWw.png" /></figure><p>Next is to install docker on your cloud environment</p><p>After I SSH into my instance, for clarity, I will change my EC2 instance name on the terminal to ManagerNode1. Run the command</p><p>sudo hostnamectl set-hostname MangerNode1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*B9whL-N95KXV7Osat_ETBQ.png" /></figure><p>Next is to reboot the instance so the name can appear. you run the command</p><p>sudo reboot</p><p>you will be logged out so you will go ssh again into your instance and the name will appear. Now our manager node is ready.</p><p>Next is to create 2 worker nodes. follow this step to do so</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*piWomi3Z_x4Yuh6qxlxa4w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*Cz_SLMvxxUMqN1x3j_Ec4Q.png" /></figure><p>In the MangerNode1 terminal use the command below one at a time</p><p>cd /root<br> cd .ssh</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*be-4eySaCw2-RJ-hi9UkVA.png" /></figure><p>Use a text editor to copy and paste your keypair. pem file. Make<br>sure it’s the same name. Run the command</p><p>vi yourkeypair.pem</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*pv7L6TiNgblaDOQ99Vnb0g.png" /></figure><p>Then paste your encrypted keys into the created file. ( make sure it is the same name used in the file) save the file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qHs9QjPsQWAcNTF0lTxsDw.png" /></figure><p>Also, add a config file.</p><p>A config file consists of the details of the worker nodes this will include the following</p><p>Host Node2<br> HostName 172.31.12.166<br> User ubuntu<br> IdentityFile /root/.ssh/keypair.pem</p><p>Host Node3<br> HostName 172.31.14.151<br> User ubuntu<br> IdentityFile /root/.ssh/keypair.pem</p><p>A little breakdown of this means</p><ul><li>The host is the name of the worker node from the AWS console (Node2 and Node3)</li><li>The hostname is the private ipv4 address of Node2 and Node3. This is where the address the MangerNode1 will use to connect via SSH Node2 and Node3 to control and distribute traffic to the services in the worker nodes. I will navigate to my Aws console of the Node2 instance and Node3 to copy the ipV4 private addresses.</li><li>User Ubuntu is the OS on the worker Nodes</li><li>IdentityFile this path to the keypair we created earlier which is the keypair. pem. To find just run the command: PWD or readlink -f keypair.pem</li></ul><p>Now I run the command</p><p>vi config</p><p>Paste the config file above and save it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*VNa0cbK6U0EJE7OjKd9Y0Q.png" /></figure><p>Next, to ensure your keypair is not publicly viewable run the command</p><p>chmod 400 jola.pem</p><p>You should now be able to run ssh node1 or ssh node2 and connect to either. SSH into both and verify docker is installed by running<br>Docker version</p><p>Now let’s ssh into Node2. Run the command</p><p>ssh node2</p><p>For clarity, we will change the name on the virtual machine to Node2 so I will run</p><p>sudo hostnamectl set-hostname Node2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2fvNmWcDeit02rqmaO_nqg.png" /></figure><p>then I will use the command exit and run the command</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*LHvfW2pe4ixrlRbQg6YI-A.png" /></figure><p>ssh Node2</p><p>We have the name changed to Node2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*LHvfW2pe4ixrlRbQg6YI-A.png" /></figure><p>On your VS Code Split the terminal to 3 and ssh Node 2 and Node 3 also remember to change the hostname for Node 3</p><p>We are able to ssh from the Master node / Manager Node to the worker node seamlessly.</p><p>Run the docker version to be sure you have it all installed on the nodes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YEQAQFuGqf7hR0FqfshfEg.png" /></figure><p>Let&#39;s configure the docker swarm on our nodes and also specify the Manager node and the worker Node which will be Node2 and Node3</p><p>From the command</p><p>docker swarm init — help</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*Y5GOGDuMaKvpRB5LMlzU5w.png" /></figure><p>I found a way to assign the manager node and join the worker nodes so,</p><p>docker swarm init — advertise-addr &lt;manager-private-ipv4 address&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HcfGJRHtAkluDVLG0YES0A.png" /></figure><p>Now the manager has been officially created by the swarm and I will join the 2 worker nodes from the command given.</p><p>The token to join the nodes is given from the created manager node</p><p>I have the 2 nodes assigned to workers</p><p>so now let’s confirm if our nodes are working</p><p>run the command on the manager</p><p>docker node ls</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g7lmdu8SjT8RJKt5wTDoog.png" /></figure><p>we will see if our nodes are up and running.</p><p>Service in the swarm replaces the docker run command. Docker run from the ground up and created a single host solution that run on the local machine. service is different as it throws a command at the clusters and it will run the command on all the containers, unlike the docker run command which will talk to individual hosts to run the command.</p><p>I will be creating a service in Alpine and on the manager node and I will scale it up to 3 replicas. Run;</p><p><em>docker service create alpine ping 8.8.8.8</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nCBml8SqSmw5n57CY0EvqA.png" /></figure><p><em>docker service ls </em>(This will check the list of created services, it will give it a random name because we didn&#39;t specify, also the replica will show service is up)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sU5bZgZ1kSc6NoOg7ea8SA.png" /></figure><p>To show the running container we will run</p><p><em>docker service ps (ID of the service)</em></p><p>We can also run the <em>docker container ls</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jsRsvJxsrQgDRwgkG-ihrw.png" /></figure><p>Let&#39;s scale up our container service to 3</p><p>docker service update (ID of the service) — replicas 3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_DTVLxSUCmLnyAvN8h9-VQ.png" /></figure><p>we can run <em>docker service inspect (service ID)</em>to see the replica we created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yuFDtJePGPd40I_iJ5buJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6vA4p1jKyIDDejwjq4MgLQ.png" /></figure><p>docker service ps (Service ID) will show the list of containers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qYgd16ezcnz_BsBQFGhNew.png" /></figure><p>To Inspect the nodes and see the replicated Nodes run</p><p>docker service (name of service)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_DTVLxSUCmLnyAvN8h9-VQ.png" /></figure><p>I want to remove all these containers, I will have to remove the service first. I simply run</p><p>docker service rm (put your service name)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*85HzCxSb2GH5jGTfENw6YA.png" /></figure><p>docker service ls</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*VUilxFenp47aoe7aspG9FA.png" /></figure><p>docker container ls ( you will see all is deleted)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oc-O7W8GB_SjFvhG3s7GwQ.png" /></figure><p>Thank you for your time and I hope you like this project, kindly like and share and also follow me on LinkedIn and on here.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3969ce557841" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Build A Jenkins Pipeline Using CLI]]></title>
            <link>https://medium.com/@abiolamajekodunmi2011/how-to-build-a-jenkins-pipeline-using-cli-87f1f38277d2?source=rss-663b5162e79b------2</link>
            <guid isPermaLink="false">https://medium.com/p/87f1f38277d2</guid>
            <category><![CDATA[how-to-build]]></category>
            <dc:creator><![CDATA[Abiola Majek]]></dc:creator>
            <pubDate>Wed, 09 Aug 2023 17:56:35 GMT</pubDate>
            <atom:updated>2023-08-09T17:56:35.680Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IyeettdrUrygBPcSy2X5yw.jpeg" /></figure><p>This week I will continue on docker projects where I will be using my Command Line Interface(CLI ) to do the following below.</p><ol><li>Pull the Jenkins LTS image from Docker Hub.</li><li>Create a Docker volume for Jenkins to persist its data.</li><li>Run the container with the volume and correct port mapped to the container.</li><li>Retrieve the Admin password.</li><li>Login and create a new user.</li><li>Launch a new Jenkins container using the same volume and verify that the data has persisted by logging in as the newly created user.</li></ol><p>Let me remind you what a container, docker hub, and image simply means</p><h4>Container</h4><p>A container is a standard unit of software bundled with dependencies so that applications can be deployed fast and reliably b/w different computing platforms.</p><h4>Docker hub</h4><p>In simple terms, this is an area where the docker images are stored.</p><p>Search docker hub on Google and open the docker hub website. Register a docker hub account because that is where images are stored.</p><h4>Image</h4><p>It is application binaries and dependencies for your app and the metadata on how to run it.</p><h4>Jenkins</h4><p>open-source automation server that enables developers to build, test, and deploy their software. It is an open-source automation tool for Continuous Integration (CI) and Continuous Deployment (CD).</p><p>Environment setup: Create an instance in AWS and install Ubuntu OS on the environment set up. Ensure you have your port set up on port 22 for the security group.SSH into your virtual system and install docker.</p><p>For this project, I will be using my vs code for this project, SSH into your vs code. updating the Ubuntu OS</p><p>apt-get update</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pf3rytuxnBNbr9lwQkNW7Q.png" /></figure><p>Next is to pull your Jenkins from the docker hub. Go to the docker hub and search Jenkins from your registered docker hub</p><p>If you read the Jenkins page on the docker hub you will see the deprecation so if you use the command docker pull Jenkins it won&#39;t work. On docker hub, we are directed to use</p><p>docker pull <a href="https://hub.docker.com/r/jenkins/jenkins">jenkins/jenkins:lts</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*_HUM1TlImMvE59yIoR-jAg.png" /></figure><p>Next, create a Docker volume for Jenkins to persist its data. Before the volume is created we have to know the port volume will be listening from. we use inspect command to find the port Jenkins will listen from</p><p>Run docker inspect jenkins/jenkins:lts</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IR8T7ClN--Jjcb4a7-txCQ.png" /></figure><p>Here we see that the image is exposed to 2 ports which are 50000 and 8080</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*T_XNfCTDSyR-yiaGKvhXYQ.png" /></figure><p>I will create the volume and make sure it is exposed to ports 50000 and 8080 and put the volume in the ./var/jenkins_home/</p><p>docker container run -d -it -p 50000:50000 -p 8080:8080 -v jenkins:/var/jenkins_home jenkins/jenkins</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*peM8Kom8r55OU0PiYL1qCA.png" /></figure><p>run the docker volume ls to see the created volume</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*Kkd0QVab98kOMtq32UGARA.png" /></figure><p>and also docker container ls to see the created Jenkins container from jenkins/jenkins:lts</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AQKvVbPTc4_-xt8R17XTDg.png" /></figure><p>The next step is to Retrieve the Admin password. To do so we will open the installed Jenkins.</p><p>To do so copy the AWS public address and paste it on the browser. If you do so you won&#39;t see the Jenkins page.</p><p>So we need to add port:8080 to be able to see our Jenkins on the browser Go to the vs code and click port, add 8080 and location add localhost. and refresh the page you will see the Jenkins page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*D8BMgtHryXwKHQP3q8HOiA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3iJxmLHg3rylDXyy_bSEnQ.png" /></figure><p>Copy the path shown on the browser to retrieve the Jenkins admin password and add the container id</p><p>docker exec 7fc1de39f5ec cat /var/jenkins_home/secrets/initialAdminPassword</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*am6BzDrTNirvbSu5CEZ6Sw.png" /></figure><p>copy the password and paste it into the space on the Jenkins page.</p><p>create a user</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PkeGANCjl3EYDW47mfSECg.png" /></figure><p>click start using Jenkins</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*0Q0STigvhVRwNfSouFhXQA.png" /></figure><p>Go to manage Jenkins and you will see the created account. you can also add new users to your Jenkins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yxnBltCh0ibkh7ZFHqVF1w.png" /></figure><p>Launch a new Jenkins container using the same volume and verify that the data has persisted by logging in as the newly created user.</p><p>Data persistence is the longevity of data after an application that created it stops. When data is persisted, the data can be retrieved by an application once it’s opened again; the data remains the same and nothing is lost.</p><p>I will stop my first container by running docker container stop 7fc1de39f5ec</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*HGjfeDkNpNcZFat_oO8gjg.png" /></figure><p>Now we run a new container with the name docker_black</p><p>docker container run -d -it -p 50000:50000 -p 8080:8080 --name black_jenkins -v jenkins:/var/jenkins_home jenkins/jenkins</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t3ZYIwBip6zXCC_-0bIXtg.png" /></figure><p>Now run docker ls and see the new container created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g_wOH-nGoq53mzn6PMDeZA.png" /></figure><p>let&#39;s go and verify on Jenkins copy the Aws public address or localhost on port 8080 and you will be able to log in</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RWIZnM3-LuSRcf84SKdhsw.png" /></figure><p>input the username and password from the stopped container and it will log and you see the dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hC3c9T_t68C3m1c3ZQJC-A.png" /></figure><p>This is the end of our project. Please don&#39;t forget to like and follow us on LinkedIn and on here for more projects.</p><p>Thank you and I hope you like it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87f1f38277d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[INSTALLING APACHE ON A DOCKER UBUNTU CONTAINER]]></title>
            <link>https://medium.com/@abiolamajekodunmi2011/installing-apache-on-a-docker-ubuntu-container-4ba6a8595c9?source=rss-663b5162e79b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ba6a8595c9</guid>
            <dc:creator><![CDATA[Abiola Majek]]></dc:creator>
            <pubDate>Mon, 31 Jul 2023 19:04:19 GMT</pubDate>
            <atom:updated>2023-07-31T19:04:19.165Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f6YaMZX3EN-hQhranO001w.jpeg" /></figure><p>Today I will be going into the Docker project. I will explain docker and I will do a simple docker project</p><p>1. Run a Docker Ubuntu container running detached and on port 80. Keep in mind that there are different Ubuntu images. Depending on the one you use, you may have to install some tools that come standard in other images.</p><p>2. Using the BASH shell update all packages within the container.</p><p>3. Using BASH install Apache2 on the Ubuntu container.</p><p>4. Add a custom webpage.</p><p>5. Verify you can reach the web server from your browser.</p><p>6. Push to Docker Hub.</p><p>7. Pull your new image and run on a different port than 80 while still mapping to 80 on the container. Verify you can reach the web server using the updated port.</p><p>So now let&#39;s get started.</p><h4>Docker</h4><p>Docker is a very popular and powerful open-source containerization platform that is used for building, deploying, and running applications. Docker allows you to decouple the application/software from the underlying infrastructure.</p><h4>Container</h4><p>A container is a standard unit of software bundled with dependencies so that applications can be deployed fast and reliably b/w different computing platforms.</p><h4>Docker file</h4><p>These are text files that contain all the files and libraries that will create an image. Using the docker build to turn all the docker files into a docker image.</p><h4>Namespace</h4><p>A namespace is basically a Linux feature that ensures OS resources partition in a mutually exclusive manner.</p><h4>Image Registry</h4><p>A Docker image registry, in simple terms, is an area where Docker images are stored.</p><p>Search docker hub on Google and open the docker hub website. Register a docker hub account because that is where images are stored.</p><p>Let&#39;s set up an environment in the cloud for docker containers</p><p>I will be using vs code for this project.</p><p>I will create an instance in AWS, and on my instance, I will be using Ubuntu as my Operating system.</p><p>After my instance is created. Navigate to the blue icon on your vs code, click on it, and select Connect to Host. I will connect to the host of my virtual studio code which I will start a virtual terminal.</p><p>You can run the command below and input your key pair from my aws and put it in the path as stated below. save the file with a name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0nhcwwEHYrGDFCnSxjVNYA.png" /></figure><p>I will go to the blue icon below on my vs code again and click the connect to host. and select the name I saved the file as and a ssh vs code is created .</p><p>I will switch to the root user using Sudo su. Just avoid running the sudo command all the time</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*8TyF_ETakRgeE9ewVDGpsw.png" /></figure><p>Next is to install the latest docker version in my environment.</p><p>curl -fsSL <a href="https://get.docker.com/">https://get.docker.com</a> -o get-docker.sh</p><p>sh get-docker. sh</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HMrTXxkGR5suaK-l_1w-Ew.png" /></figure><p>Now my docker environment is installed, to verify run the command;</p><p>docker -- version</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*_9G0tGHCQGFf87M2Xtid6Q.png" /></figure><p>Run a Docker Ubuntu container running detached and on port 80</p><p>docker container run -d -it --name my-ubuntu -p 80:80 ubuntu</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BF9VROnReO0Wv7kRSZsdBg.png" /></figure><p>( This means I tell docker to create a container Ubuntu from the image registry (docker hub), give the container the name ubuntu, the container should only listen at port 80:80 from the host and it should be detached meaning running in the background of the container.)</p><p>Verify if the Ubuntu container is running</p><p>Docker container ls</p><p>You will see your Ubuntu container with the details</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JIKWLmkubGLBnWP-M8dNYQ.png" /></figure><p>Docker container inspect Ubuntu</p><p>I installed version 22.04. if you go to your registered docker hub and search ubuntu in the search bar, you will see version 22.04.</p><p>Using the BASH shell update all packages within the container.</p><p>I will create an executable bash shell inside my running Ubuntu container.</p><p>docker container exec -it my-ubuntu bash</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*lDPy72vq7360AQV_BoljrQ.png" /></figure><p>Now we will be in the shell of our running container</p><p>apt-get update</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ayj3CTgA2ZyTKC3M-pfZJA.png" /></figure><p>Next, we install Apache 2 on the Ubuntu container</p><p>apt-get install -y apache2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*UOKm018Gc-wmPV6NDTZrLQ.png" /></figure><p>Add a custom webpage on the shell</p><p>I will need to add a text into my index.html file which I will simply use the echo command</p><pre>cd /var/www/html<br>echo &quot; We made it!!!!! &quot; &gt; index.html</pre><p>Next is to start your apache2</p><p>service apache2 restart</p><p>check the status by running</p><p>service apache2 status</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oyeBWHJQtKXEMAOkCHJrcw.png" /></figure><p>you will see it is running</p><p>Copy your public IP address and paste it into the browser and you will see it running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TE_0k0QOqggYCBHZdCDPKA.png" /></figure><p>Congratulations we have come to the end of this project!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ba6a8595c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use a lambda function to send messages to the SQS queue from the API gateway.]]></title>
            <link>https://medium.com/@abiolamajekodunmi2011/how-to-use-a-lambda-function-to-send-messages-to-the-sqs-queue-from-the-api-gateway-46bd125dee1b?source=rss-663b5162e79b------2</link>
            <guid isPermaLink="false">https://medium.com/p/46bd125dee1b</guid>
            <category><![CDATA[lambda-function]]></category>
            <category><![CDATA[how-to-use]]></category>
            <dc:creator><![CDATA[Abiola Majek]]></dc:creator>
            <pubDate>Wed, 26 Jul 2023 03:09:54 GMT</pubDate>
            <atom:updated>2023-07-26T03:09:54.350Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>SERVERLESS ARCHITECTURE</strong></p><p>Hello guys, A company wants to create a system that can track customer orders and send notifications when orders have been shipped. They want to use AWS services to build the system. They have decided to use SQS, Lambda, and Python for the project. I will walk you through how I will create a system that can track customer orders and send notifications when orders have been shipped. For this project, I will be using boto3 documentation for reference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qgrN1p0Ul7hJDismf8wpgQ.jpeg" /></figure><p>This is a serverless architecture and for this project, we will be using it.</p><ol><li>AWS lambda: AWS Lambda is a <strong>Serverless</strong> computing service provided by Amazon Web Services (AWS) that allows you to run code without provisioning or managing servers. With Lambda, you can upload your code, specify the runtime environment, and AWS takes care of the rest, automatically scaling and managing the infrastructure required to run your code.</li></ol><p>2. AWS SQS: this is a fully managed message queuing service provided by Amazon Web Services (AWS)</p><p>3. Amazon API Gateway: Amazon API Gateway is a fully managed service provided by Amazon Web Services (AWS) that allows you to create, publish, maintain, monitor, and secure APIs (Application Programming Interfaces) at any scale</p><p>4. Boto 3 Documentation: Boto3 provides a Python API for AWS infrastructure services. Using the SDK for Python, you can directly create, update and delete AWS resources using Python scripts.</p><p>5. IAM This is an AWS account to generate AWS access keys and secret keys</p><p>6. Python programming language</p><p>We need to set up our environment:</p><p>The first step is to create a cloud9 IDE by going to the AWS console and searching cloud9 and creating an environment, Make sure your VPC is also set up before creating your cloud9 IDE because you will use it to create your IDE Then go to your GitHub account and create a repo. Copy your repo URL and clone your GitHub repo on your cloud9.</p><p>Next is to install the boto3 pip install boto3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pc3xcVLAfWMEWIy83mDguw.png" /></figure><p>Also, install Aws configure using aws configure</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*_mMbWAZBuiBmP57PISC1nA.png" /></figure><p>This will ask you for your access key and secret keys, You can set us-east-1 For force updates that will pop up cancel and and disable it.</p><p>Now our Cloud 9 environment is ready.</p><p>Create a Standard SQS Queue using Python: This involves using the Boto3 library (AWS SDK for Python) to programmatically create an SQS queue. Create a Python file on your cloud 9, I will go to my boto3 documentation and search for SQS.</p><p>I created my SQS file name black-sqs using the script below which can also be found on my GitHub page;</p><pre>import boto3<br>sqs = boto3.client(&#39;sqs&#39;)<br>sqs_blacksales = sqs.create_queue(QueueName=&#39;black-sqs&#39;)<br>print(&#39;The SQS has been created&#39;, sqs_blacksales[&#39;QueueUrl&#39;])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QpnyZhjT7yxkjK201NANYQ.png" /></figure><p>Create a Lambda function in the console with a Python 3.7 or higher runtime: In the AWS Lambda console, create a new function and configure it to use Python 3.7 or a higher version.</p><p>Go to the AWS console and search lambda, Create a function. Black-sqs-lambda</p><p>In the execution role, select an existing role and create a policy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n8MHpos6AmuaAQIOmKJ21A.png" /></figure><p>Create a role and search for AmazonSQSFullAccess (for this sample we used full access but for the live project you will only great the required permission for) security reasons</p><p>Give the role call it black-sqs-lamba-role and create</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*thmRJjR5wXXuH_RmDXyQug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eQ7L2Bkr547VHn5A0OMAog.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kzj4GT8ZMz6p6nz1qTAVyA.png" /></figure><p>Go back to your lambda and refresh the execution role and select the role you created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fpcx3nrIWt4IRraDc0JknA.png" /></figure><p>Modify the Lambda to send a message to the SQS queue: Update the Lambda function code to send a message to the SQS queue. You can use the current time or a random number as the message content. Make sure to use the Boto3 library to interact with SQS.</p><p>I will create a script from my cloud9 using send message from boto3 documentation and paste it on my lambda code</p><pre>import json<br>import boto3<br>from datetime import datetime<br>date_time = datetime.now()<br># Create SQS client<br>sqs = boto3.client(&#39;sqs&#39;)<br>queue_url_sales = &#39;https://sqs.us-east-1.amazonaws.com/620227247341/black-sqs&#39;<br>def lambda_handler(event, context):<br>#using current time as a message<br>  sales_date_time = date_time.strftime(&quot;%d/%m/%Y %H:%M:%S&quot;)<br>  message_time = (&quot;This order has been shipped at date and time: &quot; + str(sales_date_time) + &quot;.&quot;)<br># Send message to SQS queue<br>  response = sqs.send_message(<br>  QueueUrl= queue_url_sales,<br>  MessageBody=(message_time)<br>  )<br>  return {<br>  &quot;statusCode&quot;: 200,<br>  &#39;body&#39;: JSON.dumps(message_time)<br>  }</pre><p>Select deploy, ‘Before you deploy make sure your syntax are correct before you click the deploy button’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*riJL7RCQfVtAO6DUBq5fiw.png" /></figure><p>Click test it will take you a configure test event .Then create the event name Select shareable and for the template option select API gateway Proxy. Save the changes and test</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hQKWNXcNXEVSaUtjKuZV7g.png" /></figure><p>Next is click the test and you will a status code of 200.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3fVAV5ZLBCQdOgfG_JIoRw.png" /></figure><p>Create an API Gateway HTTP API type trigger: Set up an HTTP API trigger for the Lambda function in the API Gateway console. This allows you to invoke the Lambda function through an API endpoint.</p><p>On the lambda page click Trigger and from add trigger select API gateway and select create new API and select HTTP API, for security select open. For additional settings add the name ‘black-sqs-lambda-API’ and for environment set default. click Add</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m9g6yGEeuVrjyaMgbb3lvQ.png" /></figure><p>We will go back to our role to add another policy that will grant permission for the API gateway, so we will add Amazon API gateway administrator permission to the black-sqs-lambda-role</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9MSN6KJ3bAu37NInB5LLfQ.png" /></figure><p>Go to IAM and click the role and click add permission then attach policies search amazon Api gateway administrator</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hutV_8cemZ-WtzoICzjsvQ.png" /></figure><p>Then add permissions and the policy is added.</p><p>Test the trigger to verify the message was sent: Use a tool like a curl or a web browser to send a request to the API endpoint and verify that the Lambda function sends a message to the SQS queue.</p><p>Go to your terminal, copy your API endpoint from your lambda function, and type: $ curl -X POST <a href="https://wwjpr49knh.execute-api.us-east-1.amazonaws.com/default/black-sqs-lambda"><strong>https://wwjpr49knh.execute-api.us-east-1.amazonaws.com/default/black-sqs-lambda</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O8mH-nsln1V5oZlk8e6sow.png" /></figure><p>The trigger message will appear, You can also go on your console and click on send and receive message</p><p>Go to the “Configuration” tab of your Lambda function, select Triggers, then click on the URL API endpoint a webpage will be opened and you will get the message in your message.</p><p>Go to the sqs created earlier black-sqs. Then click send and receive messages and scroll down to receive messages and I will see 3 messages and I click poll messages</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UIAriq3ZbcR66dQRhv_kSQ.png" /></figure><p>scroll down to receive messages and I will see 3 messages I click poll messages</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cYJyehJsXMnxSFkD4bLuDQ.png" /></figure><p>Then on the message you will see the message, ‘ This order has been shipped at date and time: 24/07/2023 20:12:31.’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wlQ5gWyO1b3BM2lUH-UqpQ.png" /></figure><p>I will push my code to my GitHub repo and this is the end of this project. Thank you. Don’t forget to like and follow me on LinkedIn: <a href="http://www.linkedin.com/in/abiola-majekodunmi">www.linkedin.com/in/abiola-majekodunmi</a>-</p><p>Github: <a href="https://github.com/Abiolamajek/abiola2023py">https://github.com/Abiolamajek/abiola2023py</a></p><h4><strong>Advance (Creating SQS to send and The message to be published with SNS subscriber)</strong></h4><ol><li>The first step is to create a Create-sns-topic file on cloud9, using boto3 documentation and give it a name, save the file, and run it. Then SNS is created on our AWS console.</li></ol><pre>import boto3<br>#create a sns topic<br>sns = boto3.client(&#39;sns&#39;)<br>black_sns = sns.create_topic(<br>Name=&#39;black-message&#39;,<br>)<br>print(black_sns[&#39;TopicArn&#39;])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B5A3d1AKxHDe0Vb1a03bCw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QgNmho_crFzKeOPsqxXFzA.png" /><figcaption>check your console and the topic has been created.</figcaption></figure><p>2 ) Next is to subscribe an email to the SNS topic: Configure an email address to subscribe to the SNS topic, so that notifications can be sent to it. Go to Cloud 9 and create a Python file from the boto3 documentation, give it a name, and run the command. The email will be pending so you click the confirmation and your email is subscribed</p><pre>import boto3<br>#create a sns topic<br>sns = boto3.client(&#39;sns&#39;)<br>topicArn = &#39;arn:aws:sns:us-east-1:311855008889:black-message&#39;<br>black_sub = sns.subscribe(<br>TopicArn= topicArn,<br>Protocol=&#39;email&#39;,<br>Endpoint=&#39;abiolamajekodunmi20@gmail.com&#39;,<br>)<br>print(&#39;This is will subscriber ARN for SNS : &#39;,black_sub[&#39;SubscriptionArn&#39;])import boto3<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*utexgnE145OLkFNcVPk6DA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BpIV6-FKRevUy0EyGiUaWw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_WPWAbJP3Lv8Llxw4DNB6Q.png" /></figure><p>3)Add the SNS destination to our lambda function. On the destination, Icon click add destination and it will give you add destination.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hyPIrDNvjFpuO6lD0h4bkQ.png" /></figure><p>For the destination type, select SNS topic and the destination will be black-message then save.</p><p>We need to create a policy for IAM to be granted access to SNS. So I will go to the IAM then click role, Click the role name we created and click add permission then attach policy, search for AmazonSNSFull Access to give full access permission “note that this is just for training purposes. You cannot give full access when working on a live environment. you only grant the required permission”.Save this permission.</p><p>Next is to modify our lambda function to trigger a message and also publish the message. To do so I will create a new script, then I will paste my script on my lambda and deploy it, then test it.</p><pre>import json<br>import boto3<br>def lambda_handler(event, context):<br># Create SQS client<br>sqs = boto3.client(&#39;sqs&#39;)<br>sns = boto3.client(&#39;sns&#39;)<br>queue_url_sales = &#39;https://sqs.us-east-1.amazonaws.com/311855008889/black-sqs&#39;<br>topicArn = &#39;arn:aws:sns:us-east-1:311855008889:black-message&#39;<br># Receive message from SQS queue<br>response = sqs.receive_message(<br>QueueUrl=queue_url_sales,<br>MaxNumberOfMessages=1,<br>WaitTimeSeconds=20<br>)<br># Check if any messages were received<br>if &#39;Messages&#39; in response:<br>message = response[&#39;Messages&#39;][0][&#39;Body&#39;]<br>receipt_handle = response[&#39;Messages&#39;][0][&#39;ReceiptHandle&#39;]<br># Publish message to SNS topic<br>sns.publish(<br>TopicArn=topicArn,<br>Message=&#39;Order received: &#39; + message,<br>)<br># Delete received message from queue<br>sqs.delete_message(<br>QueueUrl=queue_url_sales,<br>ReceiptHandle=receipt_handle<br>)<br>return {<br>&quot;statusCode&quot;: 200,<br>&#39;body&#39;: json.dumps(&#39;Order has been Received and deleted message: %s&#39; % message)<br>}<br>else:<br>return {<br>&quot;statusCode&quot;: 200,<br>&#39;body&#39;: json.dumps(&#39;No messages received from the queue.&#39;)<br>}<br>Empty messages-sns(Lambda)<br><br>Make sure you grant permission to allow sns full access…This is a testing we wont grant all access.<br>import json<br>import boto3<br>def lambda_handler(event, context):<br># Create SQS client<br>sqs = boto3.client(&#39;sqs&#39;)<br>queue_url_sales = &#39;https://sqs.us-east-1.amazonaws.com/311855008889/black-sqs&#39;<br># Receive message from SQS queue<br>response = sqs.receive_message(<br>QueueUrl=queue_url_sales,<br>MaxNumberOfMessages=1,<br>WaitTimeSeconds=20<br>)<br>message = response[&#39;Messages&#39;][0]<br>receipt_handle = message[&#39;ReceiptHandle&#39;]<br># Delete received message from queue<br>sqs.delete_message(<br>QueueUrl=queue_url_sales,<br>ReceiptHandle=receipt_handle<br>)<br>return {<br>&quot;statusCode&quot;: 200,<br>&#39;body&#39;: json.dumps(&#39;Order has been Received and deleted message: %s&#39; % message)<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1aIprMBgo7FIif3EWCPQQg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4uH-Com1VDyGik-O2xAqXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RrgZlIFgZPs5XPEp_hkWQA.png" /></figure><p>If you got a 200 response, then go to you your email and check for the notification from AWS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EhW0rAUWSOePF1xWXv8rsg.png" /></figure><p>Now we are able to send and receive the message. This comes to the end of our project. I hope you like it. Don&#39;t forget to delete all these services so you do not get charges from AWS.</p><p>Now I will push all my codes on the cloud9 environment to the GitHub repository. Github: <a href="https://github.com/Abiolamajek/abiola2023py">https://github.com/Abiolamajek/abiola2023py</a></p><p>Please do not forget to like and follow me here and also on my LinkedIn page for more interesting projects.</p><p>Don’t forget to like and follow me on LinkedIn: <a href="http://www.linkedin.com/in/abiola-majekodunmi">www.linkedin.com/in/abiola-majekodunmi</a>-</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46bd125dee1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HOW TO CREATE AND STOP AN EC2 INSTANCE USING PYTHON BOTO3]]></title>
            <link>https://medium.com/@abiolamajekodunmi2011/how-to-create-and-stop-an-ec2-instance-using-python-boto3-55c1faee2010?source=rss-663b5162e79b------2</link>
            <guid isPermaLink="false">https://medium.com/p/55c1faee2010</guid>
            <dc:creator><![CDATA[Abiola Majek]]></dc:creator>
            <pubDate>Wed, 19 Jul 2023 01:51:57 GMT</pubDate>
            <atom:updated>2023-07-20T02:43:01.594Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>HOW TO CREATE AND STOP AN EC2 INSTANCE USING PYTHON BOTO3</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IffE9vctnzSVIgjOgOjE3w.jpeg" /></figure><p>Hello Team, This is going to be a very interesting topic today.</p><p>Scenario: Our DevOps engineering team often uses a development lab to test releases of our application. The Managers are complaining about the rising cost of our development lab and need to save money by stopping our (for this example) 4 Ec2 instances after all engineers are clocked out.</p><p>I will create a Python script that you can run that will stop all instances.</p><p>Using Python script to run AWS services is a shortcut to many services, relax while I take you for a smooth ride</p><p>The prerequisite for the projects are;</p><ol><li>AWS account</li><li>Boto3 Documentation. click <a href="https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services">https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services</a></li></ol><p>We will be using this documentation to create our Python scripts. This has really simplified the creation of the scripts.</p><p>For simplicity let&#39;s break this project into steps</p><p>The first step is to set up the cloud9environment. After the cloud9 set up go to your IAM in the Aws console and generate Access Key and Secret Keys because without it you won&#39;t be able to perform this task. Next, go to your terminal on Cloud 9 and install Boto3 use the command below</p><pre>pip install boto3</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t6geK5rmj6dLV4EX2TK9hg.png" /></figure><pre>aws configure</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xiswaei2PCth9wGNfv0HSw.png" /></figure><p>Paste your access key and secret key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xiswaei2PCth9wGNfv0HSw.png" /></figure><p>Do not click forced update when it pops up</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NCjc86d1XFH-sAiXDCc_UA.png" /></figure><p>Click continue without an update.</p><p>Next step, I will create an AMI from my boto3 instance. Create a new file from the Cloud 9 template and select Python. Go to the boto3 documentation and search for create_AMI and we will see the request to create the AMI. Here we only need the Required to create AMI which is the InstanceId ‘string’ and Name ‘String’.The instance Id I got from the EC2 I created from the cloud9 from boto3. The response we need is just the Image Id. Which we will use to create the EC2 instance.</p><p>Another method is to use the Image ID from the AWS console when we launch the ec2 instance we will see the AMI for Amazon Linux and so many AMIs that we can copy the AMI ID.</p><p>Save and run this file and the Image ID is created. Check the AWS console to confirm</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M9x_vCWmXlv9xNfz5MpAhA.png" /></figure><p>Next, I created my key pair in the AWS console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W03OLdJ-T2RX7guJ5mXaKw.png" /></figure><p>Create 4 ec2 instances. Make sure with 4 different names.</p><ul><li>Create a file on your cloud9 IDE</li><li>Click New Python template file.</li><li>Go to the boto3 documentation and find ‘run_instance’. This is the script to create the ec2 instances. So we have the following ;</li><li><strong>ImageId:</strong> It is an Amazon Machine Image (AMI) id. When we create an EC2 instance the first step is to select AMI id. And it changes according to the region you choose. Here I am using us-east-1 (N. Virginia Region).</li><li><strong>MinCount:</strong> This specifies the minimum number of EC2 instances you want to create. You can also change it if you want.</li><li><strong>MaxCount:</strong> This specifies the maximum number of EC2 instances you want to create. You can also change it if you want.</li><li><strong>InstanceType:</strong> This specifies the type of EC2 instance you want to create. t2.micro is the free instance type.</li><li>Keypair: This will be the key pair we created from our console.</li><li>Tag: the Key and value of the instances awe created. The key will be the name and the value I used in the environment. So I used the dev environment and test environment and production environment</li><li>Save and run the script and we will see our instances created.</li></ul><pre>import boto3<br>ec2 = boto3.client(&#39;ec2&#39;)<br>response = ec2.run_instances(ImageId=&#39;ami-0f1d81f096d85d94b&#39;,<br>KeyName=&#39;dade&#39;,<br>MaxCount=3,<br>MinCount=3,<br>InstanceType=&#39;t2.micro&#39;,<br>TagSpecifications=[<br>{<br>&#39;ResourceType&#39;: &#39;instance&#39;,<br>&#39;Tags&#39;: [<br>{<br>&#39;Key&#39;: &#39;Name&#39;,<br>&#39;Value&#39;: &#39;dev environment&#39;<br>},<br>{&#39;Key&#39;: &#39;Name1&#39;,<br>&#39;Value&#39;: &#39;dev1 environment&#39;<br>},<br>{&#39;Key&#39;: &#39;Name2&#39;,<br>&#39;Value&#39;: &#39;dev2 environment&#39;<br>}<br>]<br>},<br>],<br>)<br>for i in response[&#39;Instances&#39;]:<br>print(&#39;Instance ID Created is :{} Instance Type Created is : {}&#39; .format(i[&#39;InstanceId&#39;],i[&#39;InstanceType&#39;]))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4xEmDGNiK6WUoVB6B7_50A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GDLRLBOOKhGwuAW7zpkcFA.png" /><figcaption>Created EC2 Instances</figcaption></figure><p>Now, Let&#39;s Create a script to automate the Stop of the instance</p><p>Create a new file. Click on the file and select New from a template file. Select the python</p><ul><li>Go to the boto3 documentation and find ‘stop_instances’. This is the script to stop the ec2 instances.</li><li>We find the required field which is the instanceId which is the name of the instance we want to stop. Then we select Force to True. As seen below</li></ul><p>`Next is to click save and run the file and the instance is stopped</p><pre>import boto3<br>ec2 = boto3.client(&#39;ec2&#39;)<br>response = ec2.stop_instances(<br>    InstanceIds=[<br>        &#39;i-03b4f6fa75e5c4006&#39;,&#39;i-0b85b05870e480b5a&#39;, &#39;i-0f264250358099bb4&#39;<br>    ],<br>    Force=True<br>)<br>print (response)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BFM7XU1je1nAOe2vaF3rrA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i9vguFRv2txpOGEQKk_zgQ.png" /><figcaption>Stopped EC2</figcaption></figure><p>The next step is to Create a script to automate the restart of the instance</p><ul><li>Create a new file. Click on the file and select New from a template file. Select the python</li><li>Go to the boto3 documentation and find ‘start_instances’. This is the script to start a stopped or hibernated ec2 instance.</li><li>find the required field which is the instanceId which is the name of the instance we want to start.</li><li>Click save and run the file and all the instances are back running.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xm0hv3f5npXKEhLbCQJE8w.png" /></figure><pre>import boto3<br>ec2 = boto3.client(&#39;ec2&#39;)<br>response = ec2.start_instances(<br>InstanceIds=[<br>&#39;i-0f856e79240fc3baa&#39;,&#39;i-0d25018aa9f104363&#39;<br>]<br>)<br>print(response)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j7IzJEdisDjjoqXxmmJrlw.png" /></figure><p>Now we are able to create, stop and start EC2 instances.</p><p>I will push my codes to my GitHub repo.</p><p>In my next project, We want to ensure that only our Development instances are stopped to make sure nothing in Production is accidentally stopped. Add logic to your script that only stops <strong>running</strong> instances that have the <strong>Environment: Dev</strong> tag.</p><p>Kindly check out my link here for the concluding Part <a href="https://medium.com/@abiolamajekodunmi2011/how-to-stop-ec2-instances-using-lambda-function-1f0d3625494b">https://medium.com/@abiolamajekodunmi2011/how-to-stop-ec2-instances-using-lambda-function-1f0d3625494b</a></p><p>If this was helpful, kindly follow me on linkedln: <a href="http://www.linkedin.com/in/abiola-majekodunmi">www.linkedin.com/in/abiola-majekodunmi</a>- for more projects also watch out for my next project and like on here.</p><p>Github : <a href="https://github.com/Abiolamajek/abiola2023py">https://github.com/Abiolamajek/abiola2023py</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55c1faee2010" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Create a Dictionary Script With Python.]]></title>
            <link>https://medium.com/@abiolamajekodunmi2011/how-to-create-a-dictionary-script-with-python-53cd3d3c5816?source=rss-663b5162e79b------2</link>
            <guid isPermaLink="false">https://medium.com/p/53cd3d3c5816</guid>
            <dc:creator><![CDATA[Abiola Majek]]></dc:creator>
            <pubDate>Wed, 05 Jul 2023 19:34:06 GMT</pubDate>
            <atom:updated>2023-07-05T19:34:06.460Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IffE9vctnzSVIgjOgOjE3w.jpeg" /></figure><p>Hello team, I will be walking you through how I built a Python script to extract the names and sizes of each file inside my current working directory and stores the data in a list of dictionaries.</p><p>Python is an open-source computer programming language used to build web applications, software development, image processing, machine learning/artificial intelligence, and even gaming development. Some everyday common Python applications are Instagram, Dropbox, Spotify, and YouTube.</p><p>Dictionary are collections used to store key-value parse. In a dictionary, we can access their specific values by providing the key within the same square bracket. Dictionaries are created with {} and inside you provide a key value parse. To make it simpler we provide keys and their values for each. Each key must be unique in the dictionary. Keys cannot be a list but its values can be a list. Dictionary is mutable which means it cannot be altered.</p><p>A list a is used to store multiple values of the same types which can be strings, integers, and floats.</p><p>Now let&#39;s get to work;</p><p>For this project, I will be using the AWS Cloud 9 IDE</p><ul><li>First I will go to the AWS console and create and Cloud 9 environment</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mnYqjz0-KMWCxCL2ppN7Jg.png" /></figure><ul><li>Make sure you set up the VPC with 1 private subnet and public subnet in one AZ.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*nhHVbvTCo7b6nv2Tjyl54A.png" /></figure><ul><li>Select the VPC created VPC and select a private subnet then click Create an environment</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MSZlV3r-ZR9unW5tER2TXQ.png" /></figure><p>Now that we have our cloud9 ready, the Next is to create a repository in your GitHub account and clone the repository into my cloud9.</p><p>I will go ahead and create a new Python file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*Dc81tjZt-HpBbTPSSRArZQ.png" /></figure><p>I will name it python_list_of_directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KWV3_ZOmw3Z3C4NxrpaN3w.png" /></figure><p>make sure to save it into your repo, after this we can now ls to see what we have in the file and cd into the folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*turop9hcWLudK_4JF-23eA.png" /></figure><p>Next is to write my Python script.</p><p>First, the line of code will be ‘import os’ statement imports the os module, this provides a way to interact with the operating system, including working with files and directories.</p><p>I created the working directory cwd = os. getcwd() assigns the current working directory to the variable cwd.</p><p>I also created an empty list to store dictionary data dict_list = []</p><p>Used for loop to iterate over the files in the current working directory ‘os. listdir(cwd).</p><p>For each file, it constructs the absolute file path by joining the cwd and file_name using os.path.join(). It then checks if the item is a file using os. path. is file (file_path).</p><p>Next, create a dictionary called dict_info with keys ‘name of file’ and ‘size (kb)’, and assigns the respective values of file_name and file_size. This dictionary represents the information about a single file.</p><p>Finally, append the dict_info dictionary to the dict_list using dict_list.append(dict_info)</p><p>Lastly, use another for loop to iterate over each dictionary in the dict list. It then prints each dictionary, resulting in the output that displays the name and size of each file in the current working directory.</p><p>Also, I introduced the shebang in the first line above the ‘import os’</p><p>#!/usr/bin/env python3.7 is called a shebang. It specifies the interpreter that should be used to execute the script, in this case, Python version 3.7.</p><p>I have created a screenshot below and for this dictionary to be viewed on the terminal, make sure you are in the right directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RAAJEZ-su9EhmHEa2V0FYg.png" /></figure><p>and run the command on your terminal in cloud9. make sure you are in the directory of your python_script</p><p>chmod +x python_lists0f_dictionaries</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SInd3OwBCa-Dq_TvsjbBzg.png" /></figure><p>use command</p><p>./python_listof_dictionaries</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*7r3CgKPlMUijiknCYSuIeg.png" /></figure><p>You will see the name and sizes of files in the directory. Save this script and push the back to your repository so it can be used in any directory and environment to generate, data and size.</p><p>check out my GitHub account here <a href="https://github.com/Abiolamajek">https://github.com/Abiolamajek</a></p><p>Thank you, if you find this useful kindly follow me on me here.</p><p><a href="https://medium.com/@abiolamajekodunmi2011">Abiola Majek - Medium</a></p><p>and also on Linkedin <a href="https://www.linkedin.com/in/abiola-majekodunmi-/">https://www.linkedin.com/in/abiola-majekodunmi-/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53cd3d3c5816" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>