<?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 Akurathi Sri Krishna Sagar on Medium]]></title>
        <description><![CDATA[Stories by Akurathi Sri Krishna Sagar on Medium]]></description>
        <link>https://medium.com/@asks1012?source=rss-909287abb261------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*R-UtMsMq3lxi-xCkAfkHkw.jpeg</url>
            <title>Stories by Akurathi Sri Krishna Sagar on Medium</title>
            <link>https://medium.com/@asks1012?source=rss-909287abb261------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 19:00:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@asks1012/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[Industry Uses of Openshift]]></title>
            <link>https://asks1012.medium.com/industry-uses-of-openshift-f6b2f935e2c9?source=rss-909287abb261------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6b2f935e2c9</guid>
            <dc:creator><![CDATA[Akurathi Sri Krishna Sagar]]></dc:creator>
            <pubDate>Wed, 07 Sep 2022 18:11:53 GMT</pubDate>
            <atom:updated>2022-09-07T18:11:53.589Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*N2dToLoBD9lzGTWk.png" /></figure><h3><strong>What is Openshift?</strong></h3><p>Openshift is an orchestration software developed by Red Hat. Openshift Container Platform is flagship product built on top of Kubernetes. OpenShift is an enterprise-ready Kubernetes container platform. Red Hat OpenShift’s full-stack automated operations and self-service provisioning for developers lets teams work together more efficiently to move ideas from development to production.</p><p>Red Hat’s open hybrid cloud strategy is built on the technological foundation of Linux, containers, and automation. An open hybrid cloud approach gives you the flexibility to run your applications anywhere you need them.</p><blockquote><strong>Industry Use Cases of OpenShift:</strong></blockquote><h3>Work with traditional, modernized, and cloud-native applications</h3><p>Openshift Supports the most demanding workloads including AI/ML, Java, data analytics, databases, and more. It helps to Automate deployment and life-cycle management with the vast ecosystem of technology partners.</p><h3>Edge computing</h3><p>Edge computing is the processing of applications and information at or near the physical location of either the end user (like at the API) or the source of the data or datacenter, providing faster response times, more reliable services, and a better application experience back to the user.</p><p>That’s where <a href="https://www.redhat.com/en/resources/innovate-edge-computing-brief">Kubernetes and Red Hat OpenShift</a> come in. Red Hat OpenShift brings full Kubernetes capabilities to edge computing environments, creating the ability to use the same tools and processes while easing the burden of configuring, deploying, provisioning, managing, tracking metrics, and monitoring even the largest-scale containerized applications.</p><h3>Improve security of the full application life cycle</h3><p>Openshift decreases operational risk by shifting security left and automating DevSecOps, using built-in policy templates to enforce security and configuration best practices, and protecting application workloads at runtime.</p><p>Red Hat Advanced Cluster Security (ACS) for Kubernetes is the pioneering Kubernetes-native security platform, equipping organizations to more securely build, deploy, and run cloud-native applications anywhere.</p><p>Red Hat Advanced Cluster Security integrates with <a href="https://www.redhat.com/en/topics/devops">DevOps</a> and security tools to help you mitigate threats and enforce security policies that minimize operational risk to your applications within your Kubernetes environment. By integrating with your CI/CD pipelines and image registries, Red Hat Advanced Cluster Security provides continuous scanning and assurance.</p><h3>End-to-end visibility and control for Kubernetes clusters</h3><p>Red Hat OpenShift helps for deploying applications, managing multiple clusters, and enforcing policies across clusters at scale, all from a single console.</p><h3>Innovate and go to market faster</h3><p>OpenShift enables your development team to focus on doing what they do best designing and testing applications. When they are freed from spending excessive time managing and deploying containers, they can speed up the development process and get products to market more rapidly.</p><h3>Accelerate application development</h3><p>Deploying and managing containers at scale is a complicated process. OpenShift enables efficient container orchestration, allowing rapid container provisioning, deploying, scaling, and management. The tool enhances the DevOps process by streamlining and automating the container management process. Cutting down on time that would otherwise be spent managing containers improves your company’s productivity and speeds up application development.</p><h3>Self-service provisioning</h3><p>Assembling the proper tools to create applications on your system architecture can be a challenge, especially at the enterprise level. OpenShift makes the process easy by allowing for the integration of the tools you use most across your entire operating environment.</p><h3>Enable DevOps and department-wide collaboration</h3><p>The DevOps process relies upon transparent communication between all involved parties. Containerization provides a convenient means of enabling your IT operations staff to test instances of a new app. OpenShift assists this process by making it easy to test apps throughout your IT architecture without being impeded by framework conflicts, deployment issues, or language discrepancies.</p><p><strong>Summary :</strong></p><p>OpenShift offers a platform for managing your containers across a variety of operating environments, significantly reducing the time necessary to build, deploy, and scale them. As an open source next-generation virtualization tool, OpenShift provides you with the all the functionality you need to optimize containerization usage with your existing IT resources.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6b2f935e2c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Allow specific amout of storage to hadoop datanode]]></title>
            <link>https://asks1012.medium.com/allow-specific-amout-of-storage-to-hadoop-datanode-4a7a563c6864?source=rss-909287abb261------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a7a563c6864</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[hadoop]]></category>
            <dc:creator><![CDATA[Akurathi Sri Krishna Sagar]]></dc:creator>
            <pubDate>Wed, 07 Sep 2022 17:52:31 GMT</pubDate>
            <atom:updated>2022-09-07T17:52:31.527Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9yRCS0_kaT2ZM_A9akVRiQ.png" /></figure><p>Normally when you configure hadoop datanode, the entire hark disk space will be given to hadoop. But this creates issues when the disk space is full. So, to avoid these, we can contribute only a limited amount of space for the hadoop. We can achieve this task with the help of linux partitions.</p><p>Now, let’s create linux partitions.</p><p>The following are the current hard disks in my system :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*uJoLIs-KR9pbUOv8PPDuiQ.png" /></figure><p>Now I’m entering into my disk <strong>/dev/nvme0n2 :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*AiC3tCUglyiaS5lrcbpKqg.png" /></figure><p>You can see the partitions inside <strong>/dev/nvme0n1p2 </strong>in the above image. Now, I’m creating a new partition in that disk :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*ZbJX_2fMcPYbYkFZK65YaQ.png" /></figure><p>Now you can see the new partitions below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*rqgro9MzlM9Tb676Ha0x6w.png" /></figure><p>Next, format the above newly created partition as shown below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*ZRW7JNIzCpKdJUc7T8d1RA.png" /></figure><p>Now mount the above partition as shown :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*wgSWPKnYSXPF50SpuLfHVA.png" /></figure><p>Now while configuring the hadoop datanode, specify the data directory as the above newly mounted folder :</p><pre>&lt;property&gt;<br>&lt;name&gt;dfs.data.dir&lt;/name&gt;<br>&lt;value&gt;/dn&lt;/value&gt;<br>&lt;/property&gt;</pre><p>Now I’ve started the cluster services :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*mSvK7fHtr6og0nmjajnR7g.png" /></figure><p>In the below screenshot, you can see that only 2GB is given to the hadoop cluster :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HkYuAsggjNfrTWArN4YQJA.png" /></figure><p>In this way we can configure custom sized hard disk contribution to hadoop datanode.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a7a563c6864" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Verifying Parallel Data Processing by Hadoop]]></title>
            <link>https://asks1012.medium.com/verifying-parallel-data-processing-by-hadoop-983d146c2ddc?source=rss-909287abb261------2</link>
            <guid isPermaLink="false">https://medium.com/p/983d146c2ddc</guid>
            <category><![CDATA[tcpdump]]></category>
            <category><![CDATA[hadoop]]></category>
            <dc:creator><![CDATA[Akurathi Sri Krishna Sagar]]></dc:creator>
            <pubDate>Wed, 07 Sep 2022 16:02:26 GMT</pubDate>
            <atom:updated>2022-09-07T16:02:26.306Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4y60Brt50ebFS0Uh.png" /></figure><p>In this article, we are going to test if hadoop processes the data that is being uploaded to the cluster parallelly or serially.</p><p>For this, we need to setup a master node and 2 or more slave nodes configured with hadoop.</p><p>In my previous <a href="https://asks1012.medium.com/providing-elasticity-to-data-node-storage-in-hadoop-through-lvm-3d9296ccdcc3">article</a> I’ve explained how to setup masternode and slavenode in hadoop. Remember to setup more than 1 slave node.</p><p>You can go to the url : <a href="http://localhost:50070/">http://localhost:50070</a> to visit the webview of hadoop.</p><p>For Example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kMkjdnPD-gxmSS2aofn4yQ.png" /></figure><p>You can do the setup either in local Virtual Machines or Cloud Instances.</p><p>Now create a file with suitable size and copy it to master node in hadoop cluster. Install tcpdump command in both the slave nodes and run the following command in both the slave nodes :</p><pre>tcpdump -i eth0 tcp port 50010 -n -X | tee dn1.txt</pre><p>In the below video I’ve done the same thing as above :</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FDuPfh7KU8RM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DDuPfh7KU8RM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FDuPfh7KU8RM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/81ca64e846aaa19c5d063f121079fa7c/href">https://medium.com/media/81ca64e846aaa19c5d063f121079fa7c/href</a></iframe><p>In the video you can observe that, at start , the packets came only to one data node. After the packets stopped in that data node, they started coming to the other data node. From this, we can say that, hadoop doesn’t implement the parallel processing of split data by default.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=983d146c2ddc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create Terraform Module and Publish to Terraform Registry]]></title>
            <link>https://asks1012.medium.com/create-terraform-module-and-publish-to-terraform-registry-1c59cdcd1ee5?source=rss-909287abb261------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c59cdcd1ee5</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[terraform-modules]]></category>
            <dc:creator><![CDATA[Akurathi Sri Krishna Sagar]]></dc:creator>
            <pubDate>Wed, 07 Sep 2022 11:34:55 GMT</pubDate>
            <atom:updated>2022-09-07T11:34:55.329Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G0FGDpuXDZa9H3JI.png" /></figure><p>In this article, we’re going to create a terraform module for launching azure vm with all the backend infrastructure and upload it to the terraform public registry.</p><p><strong>Let’s Start</strong></p><p>First, you need to have Azure CLI installed on your system and configure with the command :</p><pre>az login</pre><p>Next, gather the subscription_id, client_id, tenant_id, client_secret.</p><p>Now create a file <strong>providers.tf (</strong>for specifying the provider<strong>) </strong>with the following content :</p><pre>terraform {<br>  required_providers {<br>    azurerm = {<br>      source  = &quot;hashicorp/azurerm&quot;<br>      version = &quot;3.14.0&quot;<br>    }<br>  }<br>}</pre><pre>provider &quot;azurerm&quot; {<br>  features {}<br>  subscription_id = &quot;YOUR_SUBSCRIPTION_ID&quot;<br>  tenant_id       = &quot;YOUR_TENANT_ID&quot;<br>  client_id       = &quot;YOUR_CLIENT_ID&quot;<br>  client_secret   = &quot;YOUR_CLIENT_SECRET&quot;<br>}</pre><p>Update the above file with your credentials.</p><p>Now create a file <strong>main.tf </strong>. This file contains all the resources to be created :</p><pre>resource &quot;azurerm_resource_group&quot; &quot;terr_azure_rg&quot; {<br>  name     = &quot;terr_rg&quot;<br>  location = var.location<br>}</pre><pre>resource &quot;azurerm_virtual_network&quot; &quot;terr_azure_vn&quot; {<br>  name                = &quot;terr_network&quot;<br>  address_space       = [&quot;10.0.0.0/16&quot;]<br>  location            = azurerm_resource_group.terr_azure_rg.location<br>  resource_group_name = azurerm_resource_group.terr_azure_rg.name<br>}</pre><pre>resource &quot;azurerm_subnet&quot; &quot;terr_azure_subnet&quot; {<br>  name                 = &quot;terr_subnet&quot;<br>  resource_group_name  = azurerm_resource_group.terr_azure_rg.name<br>  virtual_network_name = azurerm_virtual_network.terr_azure_vn.name<br>  address_prefixes     = [&quot;10.0.2.0/24&quot;]<br>}</pre><pre>resource &quot;azurerm_network_security_group&quot; &quot;terr_azure_sg&quot; {<br>  name                = &quot;azure_sg&quot;<br>  location            = azurerm_resource_group.terr_azure_rg.location<br>  resource_group_name = azurerm_resource_group.terr_azure_rg.name</pre><pre>security_rule {<br>    name                       = &quot;allow_all_inbound&quot;<br>    priority                   = 100<br>    direction                  = &quot;Inbound&quot;<br>    access                     = &quot;Allow&quot;<br>    protocol                   = &quot;*&quot;<br>    source_port_range          = &quot;*&quot;<br>    destination_port_range     = &quot;*&quot;<br>    source_address_prefix      = &quot;*&quot;<br>    destination_address_prefix = &quot;*&quot;<br>  }<br>  security_rule {<br>    name                       = &quot;allow_all_outbound&quot;<br>    priority                   = 100<br>    direction                  = &quot;Outbound&quot;<br>    access                     = &quot;Allow&quot;<br>    protocol                   = &quot;*&quot;<br>    source_port_range          = &quot;*&quot;<br>    destination_port_range     = &quot;*&quot;<br>    source_address_prefix      = &quot;*&quot;<br>    destination_address_prefix = &quot;*&quot;<br>  }<br>}</pre><pre>resource &quot;azurerm_subnet_network_security_group_association&quot; &quot;terr_azure_sgAssoc&quot; {<br>  subnet_id                 = azurerm_subnet.terr_azure_subnet.id<br>  network_security_group_id = azurerm_network_security_group.terr_azure_sg.id<br>}</pre><pre>resource &quot;azurerm_public_ip&quot; &quot;terr_azure_ip&quot; {<br>  name                = &quot;terr_ip&quot;<br>  resource_group_name = azurerm_resource_group.terr_azure_rg.name<br>  location            = azurerm_resource_group.terr_azure_rg.location<br>  allocation_method   = &quot;Static&quot;<br>  ip_version          = &quot;IPv4&quot;<br>  sku                 = &quot;Standard&quot;<br>}</pre><pre>resource &quot;azurerm_network_interface&quot; &quot;terr_azure_ni&quot; {<br>  name                = &quot;terr_ni&quot;<br>  location            = azurerm_resource_group.terr_azure_rg.location<br>  resource_group_name = azurerm_resource_group.terr_azure_rg.name</pre><pre>ip_configuration {<br>    name                          = &quot;internal&quot;<br>    subnet_id                     = azurerm_subnet.terr_azure_subnet.id<br>    private_ip_address_allocation = &quot;Dynamic&quot;<br>    public_ip_address_id          = azurerm_public_ip.terr_azure_ip.id<br>  }<br>}</pre><pre>resource &quot;azurerm_linux_virtual_machine&quot; &quot;terr_azure_vm&quot; {<br>  name                  = &quot;terr-vm&quot;<br>  resource_group_name   = azurerm_resource_group.terr_azure_rg.name<br>  location              = azurerm_resource_group.terr_azure_rg.location<br>  size                  = var.vm_size<br>  admin_username        = var.admin_username<br>  network_interface_ids = [<br>    azurerm_network_interface.terr_azure_ni.id,<br>  ]</pre><pre>admin_ssh_key {<br>    username   = var.admin_username<br>    public_key = file(var.azure_public_key)<br>  }</pre><pre>os_disk {<br>    caching              = &quot;ReadWrite&quot;<br>    storage_account_type = &quot;Standard_LRS&quot;<br>  }</pre><pre>source_image_reference {<br>    publisher = &quot;Canonical&quot;<br>    offer     = &quot;UbuntuServer&quot;<br>    sku       = &quot;16.04-LTS&quot;<br>    version   = &quot;latest&quot;<br>  }<br>}</pre><p>You can view various resources that will be created by terraform in the above file. This file uses some variables which are to be declared in the file <strong>variables.tf </strong>:</p><pre>variable &quot;location&quot; {<br>  type = string<br>  description = &quot;Region name for the VM&quot;<br>}<br>variable &quot;vm_size&quot; {<br>  type = string<br>  description = &quot;Size of the VM&quot;<br>}<br>variable &quot;admin_username&quot; {<br>  type = string<br>  description = &quot;Username for the admin account of VM&quot;<br>}<br>variable &quot;azure_private_key&quot; {<br>  type = string<br>  description = &quot;Location of private key file created with ssh-keygen&quot;<br>}<br>variable &quot;azure_public_key&quot; {<br>  type = string<br>  description = &quot;Location of public key file created with ssh-keygen&quot;<br>}</pre><p>The actual values for the variables are to be given inside the file <strong>terraform.tfvars </strong>:</p><pre>location           = &quot;Central India&quot;<br>vm_size            = &quot;Standard_D2s_v3&quot;<br>admin_username     = &quot;adminuser&quot;<br>azure_private_key  = &quot;/home/YOUR_USERNAME/.ssh/id_rsa&quot;<br>azure_public_key   = &quot;/home/YOUR_USERNAME/.ssh/id_rsa.pub&quot;</pre><p>You can change the values of the variables in the above file.</p><p>Now create another file <strong>outputs.tf </strong>which is used to display the Public IP of the VM created, in this case :</p><pre>output &quot;vm_public_ip&quot; {<br>  value = azurerm_linux_virtual_machine.terr_azure_vm.public_ip_address<br>  description = &quot;Public IP Address of the VM Launched&quot;<br>}</pre><p>Finally, create a README and LICENSE files (optional).</p><p>The directory structure of the terraform module created above is :</p><pre>.<br>├── LICENSE<br>├── main.tf<br>├── outputs.tf<br>├── providers.tf<br>├── README.md<br>├── terraform.tfvars<br>└── variables.tf</pre><p>Now the terraform module is ready. You can test the module by running the following commands :</p><pre>terraform init<br>terraform plan<br>terraform apply</pre><p>To destroy all the resources, you can use the following command :</p><pre>terraform destroy</pre><p>Now go to the <a href="https://www.terraform.io/registry/modules/publish">link</a> and follow the instructions to create a GitHub repository with specified naming convention and don’t forget to add a Tag with proper version number in the GitHub, otherwise terraform registry won’t accept your repository.</p><p>Now go to <a href="https://registry.terraform.io/">https://registry.terraform.io/</a> and login with your GitHub and click on Publish-&gt;Module and select your GitHub repository and it’s done. If you followed all the requirements correctly, your module will be published withing seconds.</p><p>I’ve uploaded my module to the terraform registry :</p><p><a href="https://registry.terraform.io/modules/asks1012/azure-vm/azurerm/1.0.0">Terraform Registry</a></p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c59cdcd1ee5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multi-Cloud Kubernetes Cluster Setup with Automation]]></title>
            <link>https://asks1012.medium.com/multi-cloud-kubernetes-cluster-setup-with-automation-3255de917341?source=rss-909287abb261------2</link>
            <guid isPermaLink="false">https://medium.com/p/3255de917341</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Akurathi Sri Krishna Sagar]]></dc:creator>
            <pubDate>Wed, 07 Sep 2022 07:38:39 GMT</pubDate>
            <atom:updated>2022-09-07T07:38:39.087Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aVwWlUy5AWxxsNT-aJDAzw.png" /></figure><p>In this article, we will create a Multi-Cloud Kubernetes Cluster (Master node on AWS EC2 Instance and a Slave Node on Azure VM) using the Ansible Roles. Terraform is used to create the entire Cloud Infrastructure required for this setup. In my previous articles, I’ve explained about Ansible Roles for single cloud setup of K8s cluster. We are going to use the same roles for multi cloud setup also.</p><h3>Infrastructure Setup</h3><p>We are using Terraform for creating an AWS EC2 instance with Amazon Linux2 AMI and an Azure VM with all it’s associated backend with an Ubuntu image.</p><p>First you need to install the AWS CLI and Azure CLI in your machine and the following commands to setup :</p><pre>aws configure<br>az login</pre><p>Create a folder for terraform and write the following in providers.tf file :</p><pre>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;4.22.0&quot;<br>    }<br>    azurerm = {<br>      source  = &quot;hashicorp/azurerm&quot;<br>      version = &quot;3.14.0&quot;<br>    }<br>  }<br>}</pre><pre>provider &quot;aws&quot; {<br>  region                   = &quot;ap-south-1&quot;<br>  shared_credentials_files = [&quot;/home/sagar/.aws/credentials&quot;]<br>  profile                  = &quot;default&quot;<br>}</pre><pre>provider &quot;azurerm&quot; {<br>  features {}<br>  subscription_id = &quot;YOUR_SUBSCRIPTION_ID&quot;<br>  tenant_id       = &quot;YOUR_TENANT_ID&quot;<br>  client_id       = &quot;YOUR_CLIENT_ID&quot;<br>  client_secret   = &quot;YOUR_CLIENT_SECRET&quot;<br>}</pre><p>Now create a file <strong>variables.tf</strong> and copy the following :</p><pre># AWS Variables<br>variable &quot;aws_ami_id&quot; {<br>  type = string<br>}<br>variable &quot;aws_instance_type&quot; {<br>  type = string<br>}<br>variable &quot;aws_key_name&quot; {<br>  type = string<br>}<br>variable &quot;aws_key_location&quot; {<br>  type = string<br>}</pre><pre># Azure Variables<br>variable &quot;location&quot; {<br>  type = string<br>}<br>variable &quot;vm_size&quot; {<br>  type = string<br>}<br>variable &quot;admin_username&quot; {<br>  type = string<br>}<br>variable &quot;azure_private_key&quot; {<br>  type = string<br>}<br>variable &quot;azure_public_key&quot; {<br>  type = string<br>}</pre><p>After that create another file with name <strong>terraform.tfvars :</strong></p><pre># AWS Variables<br>aws_ami_id         = &quot;ami-08df646e18b182346&quot;<br>aws_instance_type  = &quot;t2.micro&quot;<br>aws_key_name       = &quot;YOUR_AWS_KEY_NAME&quot;<br>aws_key_location   = &quot;/home/sagar/Downloads/YOUR_KEY_NAME.pem&quot;</pre><pre># Azure Variables<br>location           = &quot;Central India&quot;<br>vm_size            = &quot;Standard_D2s_v3&quot;<br>admin_username     = &quot;adminuser&quot;<br>azure_private_key  = &quot;/home/YOUR_USERNAME/.ssh/id_rsa&quot;<br>azure_public_key   = &quot;/home/YOUR_USERNAME/.ssh/id_rsa.pub&quot;</pre><p><strong>Note : </strong>For AWS, create a new key and download the key to your computer. For azure, you need to create a private and public key with the command :</p><pre>ssh-keygen</pre><p>Now create a file <strong>aws.tf </strong>and copy the following :</p><pre>resource &quot;aws_default_vpc&quot; &quot;default&quot; {<br>  tags = {<br>    Name = &quot;Default VPC&quot;<br>  }<br>}</pre><pre>resource &quot;aws_security_group&quot; &quot;terr_aws_sg&quot; {<br>  name               = &quot;terr_sg&quot;<br>  vpc_id             = aws_default_vpc.default.id</pre><pre>ingress {<br>    from_port        = 0<br>    to_port          = 0<br>    protocol         = &quot;-1&quot;<br>    cidr_blocks      = [&quot;0.0.0.0/0&quot;]<br>    ipv6_cidr_blocks = [&quot;::/0&quot;]<br>  }</pre><pre>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>    ipv6_cidr_blocks = [&quot;::/0&quot;]<br>  }<br>}</pre><pre>resource &quot;aws_instance&quot; &quot;terr_aws_instance&quot; {<br>  ami                    = var.aws_ami_id<br>  instance_type          = var.aws_instance_type<br>  key_name               = var.aws_key_name<br>  vpc_security_group_ids = [aws_security_group.terr_aws_sg.id]<br>  tags                   = {<br>    Name = &quot;Master&quot;<br>  }<br>}</pre><pre>resource &quot;null_resource&quot;  &quot;master_ip&quot; {<br>  depends_on = [<br>    aws_instance.terr_aws_instance<br>  ]<br>  provisioner &quot;local-exec&quot; {<br>    command = &quot;echo \&quot;[master_node]\n${aws_instance.terr_aws_instance.public_ip} ansible_ssh_private_key_file=${var.aws_key_location} ansible_ssh_user=ec2-user\n\n[slave_nodes]\&quot; &gt; ../inventory.txt&quot;<br>  }<br>}</pre><p>The above file is for creating an EC2 instance with default vpc and security group and allowing all traffic. At the last it copies the public ip of aws instance with the aws key location inside the inventory file which is used by the ansible roles later.</p><p>Now creater another file <strong>azure.tf </strong>and copy the following :</p><pre>resource &quot;null_resource&quot;  &quot;depends_on_master&quot; {<br>  depends_on = [<br>    null_resource.master_ip<br>  ]<br>}</pre><pre>resource &quot;azurerm_resource_group&quot; &quot;terr_azure_rg&quot; {<br>  name     = &quot;terr_rg&quot;<br>  location = var.location<br>}</pre><pre>resource &quot;azurerm_virtual_network&quot; &quot;terr_azure_vn&quot; {<br>  name                = &quot;terr_network&quot;<br>  address_space       = [&quot;10.0.0.0/16&quot;]<br>  location            = azurerm_resource_group.terr_azure_rg.location<br>  resource_group_name = azurerm_resource_group.terr_azure_rg.name<br>}</pre><pre>resource &quot;azurerm_subnet&quot; &quot;terr_azure_subnet&quot; {<br>  name                 = &quot;terr_subnet&quot;<br>  resource_group_name  = azurerm_resource_group.terr_azure_rg.name<br>  virtual_network_name = azurerm_virtual_network.terr_azure_vn.name<br>  address_prefixes     = [&quot;10.0.2.0/24&quot;]<br>}</pre><pre>resource &quot;azurerm_network_security_group&quot; &quot;terr_azure_sg&quot; {<br>  name                = &quot;azure_sg&quot;<br>  location            = azurerm_resource_group.terr_azure_rg.location<br>  resource_group_name = azurerm_resource_group.terr_azure_rg.name</pre><pre>security_rule {<br>    name                       = &quot;allow_all_inbound&quot;<br>    priority                   = 100<br>    direction                  = &quot;Inbound&quot;<br>    access                     = &quot;Allow&quot;<br>    protocol                   = &quot;*&quot;<br>    source_port_range          = &quot;*&quot;<br>    destination_port_range     = &quot;*&quot;<br>    source_address_prefix      = &quot;*&quot;<br>    destination_address_prefix = &quot;*&quot;<br>  }<br>  security_rule {<br>    name                       = &quot;allow_all_outbound&quot;<br>    priority                   = 100<br>    direction                  = &quot;Outbound&quot;<br>    access                     = &quot;Allow&quot;<br>    protocol                   = &quot;*&quot;<br>    source_port_range          = &quot;*&quot;<br>    destination_port_range     = &quot;*&quot;<br>    source_address_prefix      = &quot;*&quot;<br>    destination_address_prefix = &quot;*&quot;<br>  }<br>}</pre><pre>resource &quot;azurerm_subnet_network_security_group_association&quot; &quot;terr_azure_sgAssoc&quot; {<br>  subnet_id                 = azurerm_subnet.terr_azure_subnet.id<br>  network_security_group_id = azurerm_network_security_group.terr_azure_sg.id<br>}</pre><pre>resource &quot;azurerm_public_ip&quot; &quot;terr_azure_ip&quot; {<br>  name                = &quot;terr_ip&quot;<br>  resource_group_name = azurerm_resource_group.terr_azure_rg.name<br>  location            = azurerm_resource_group.terr_azure_rg.location<br>  allocation_method   = &quot;Static&quot;<br>  ip_version          = &quot;IPv4&quot;<br>  sku                 = &quot;Standard&quot;<br>}</pre><pre>resource &quot;azurerm_network_interface&quot; &quot;terr_azure_ni&quot; {<br>  name                = &quot;terr_ni&quot;<br>  location            = azurerm_resource_group.terr_azure_rg.location<br>  resource_group_name = azurerm_resource_group.terr_azure_rg.name</pre><pre>ip_configuration {<br>    name                          = &quot;internal&quot;<br>    subnet_id                     = azurerm_subnet.terr_azure_subnet.id<br>    private_ip_address_allocation = &quot;Dynamic&quot;<br>    public_ip_address_id          = azurerm_public_ip.terr_azure_ip.id<br>  }<br>}</pre><pre>resource &quot;azurerm_linux_virtual_machine&quot; &quot;terr_azure_vm&quot; {<br>  name                  = &quot;terr-vm&quot;<br>  resource_group_name   = azurerm_resource_group.terr_azure_rg.name<br>  location              = azurerm_resource_group.terr_azure_rg.location<br>  size                  = var.vm_size<br>  admin_username        = var.admin_username<br>  network_interface_ids = [<br>    azurerm_network_interface.terr_azure_ni.id,<br>  ]</pre><pre>admin_ssh_key {<br>    username   = var.admin_username<br>    public_key = file(var.azure_public_key)<br>  }</pre><pre>os_disk {<br>    caching              = &quot;ReadWrite&quot;<br>    storage_account_type = &quot;Standard_LRS&quot;<br>  }</pre><pre>source_image_reference {<br>    publisher = &quot;Canonical&quot;<br>    offer     = &quot;UbuntuServer&quot;<br>    sku       = &quot;16.04-LTS&quot;<br>    version   = &quot;latest&quot;<br>  }<br>}</pre><pre>resource &quot;null_resource&quot;  &quot;slave_ip1&quot; {<br>  provisioner &quot;local-exec&quot; {<br>    command = &quot;echo \&quot;${azurerm_linux_virtual_machine.terr_azure_vm.public_ip_address} ansible_ssh_private_key_file=${var.azure_private_key} ansible_ssh_user=${var.admin_username}\n\&quot; &gt;&gt; ../inventory.txt&quot;<br>  }<br>}</pre><p>The file is long because it has to create a resource group, virtual netork and a subnet inside it, security group, security rule for allowing all traffic, associate security group to subnet, public ip, network interface, and finally a Virtual Machine!</p><p>At last, the above file writes the public IP of Azure VM to the previous inventory file for ansible roles.</p><p>Now I’m not explaning again the whole ansible roles for configuring master, configuring slave, etc., You can find the roles in the GitHub link provided at the end of article.</p><p>The following is the <strong>main.yaml </strong>file which uses all the ansible roles in the order :</p><pre>- hosts: localhost<br>  gather_facts: False<br>  tasks:<br>  - name: &quot;Initializing terraform providers&quot;<br>    shell:<br>      cmd: terraform init<br>      chdir: ./terraform<br>  - name: &quot;Provisioning 1 AWS Instance , 1 Azure VM&quot;<br>    community.general.terraform:<br>      project_path: ./terraform<br>      state: present<br>  - meta: refresh_inventory</pre><pre>- hosts: all<br>  gather_facts: False<br>  tasks:<br>  - name: &quot;Waiting for SSH port&quot;<br>    wait_for_connection:</pre><pre>- hosts: master_node<br>  gather_facts: False<br>  roles:<br>  - configure-master<br>  tasks:<br>  - name: &quot;Getting token from master&quot;<br>    shell: &quot;kubeadm token create --print-join-command&quot;<br>    register: token<br>  - add_host:<br>      name: &quot;token_for_worker&quot;<br>      link: &quot;{{ token[&#39;stdout&#39;] }}&quot;</pre><pre>- hosts: slave_nodes<br>  gather_facts: False<br>  roles:<br>  - configure-slave<br>  tasks:<br>  - name: &quot;Worker Nodes joining the cluster&quot;<br>    shell: &quot;{{ hostvars[&#39;token_for_worker&#39;][&#39;link&#39;] }}&quot;</pre><pre>- hosts: master_node<br>  gather_facts: False<br>  roles:<br>  - wordpress-mysql</pre><p>First it runs the terraform commands for the creation of entire infrastructure and later configures the master node and then the slave nodes and at last it launches the wordpress with mysql as backend in the kubernetes cluster.</p><p>GitHub link for the entire terraform files and ansible roles :</p><p><a href="https://github.com/asks1012/Multi-Cloud-K8s-Cluster">GitHub - asks1012/Multi-Cloud-K8s-Cluster</a></p><p>The following are the screenshots when the above <strong>main.yaml </strong>file is run :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GygUOCPI_flCkpRKVMPPvQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zsB0ZcctOaArLvqUv159RA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LNsWs4SaDzSERI7T1rAheA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UH6bZEkoe0I8NllLag8iXQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qiC8jYGV3jVVSfh773lLVw.png" /></figure><p>The following is the inventory.txt file created automatically by terraform :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*axltm4QvVfoUmOZ1K8kA-A.png" /></figure><p>So, the multi cloud K8s cluster is ready. Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3255de917341" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ansible Roles for launching Wordpress with MySQL in Kubernetes Cluster over AWS]]></title>
            <link>https://asks1012.medium.com/ansible-roles-for-launching-wordpress-with-mysql-in-kubernetes-cluster-over-aws-2390adadfb50?source=rss-909287abb261------2</link>
            <guid isPermaLink="false">https://medium.com/p/2390adadfb50</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[wordpress]]></category>
            <dc:creator><![CDATA[Akurathi Sri Krishna Sagar]]></dc:creator>
            <pubDate>Mon, 11 Jul 2022 08:50:45 GMT</pubDate>
            <atom:updated>2022-07-11T09:46:36.693Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GlpqlGgz2Deql4vSM3D5Wg.png" /></figure><p>In this Article, we are going to launch our custom Kubernetes cluster over the AWS instances and after that launch the wordpress and mysql pods inside the K8s cluster — All with <strong>ONE</strong> command by using Ansible Roles!</p><p>GitHub Link containing Ansible Roles :</p><p><a href="https://github.com/asks1012/Ansible-Roles-for-launching-Wordpress-MySQL-in-K8s-Cluster">GitHub - asks1012/Ansible-Roles-for-launching-Wordpress-MySQL-in-K8s-Cluster</a></p><h3>Get Ansible Ready</h3><p>The first step is to configure the /etc/ansible/ansible.cfg file. The following is my ansible.cfg file :</p><pre>[defaults]<br>inventory = /home/sagar/inventory.txt<br>host_key_checking = false<br>command_warnings = false<br>deprecation_warnings = false<br>roles_path = /home/sagar/wordpress_k8s<br>ask_pass = false<br>remote_user = ec2-user<br>private_key_file = /home/sagar/Downloads/kubernetes.pem</pre><pre>[privilege_escalation]<br>become = true<br>become_method = sudo<br>become_user = root<br>become_ask_pass = false</pre><p>You need to change some things in above file. Create an inventory file (.txt) and specify that location in above file. My ansible roles are created under the directory “/home/sagar/wordpress_k8s” — You can change it. My private key file for attaching it to the AWS instances is at “/home/sagar/Downloads/kubernetes.pem”.</p><p>In the project I’m using 4 ansible roles :</p><ul><li><strong>launch_ec2_instances </strong>: For launching AWS EC2 Instances</li><li><strong>configure-master-slave</strong> : For setting up K8s Cluster over the above created AWS Instances</li><li><strong>start-master</strong> : For starting cluster services on the master and making worder nodes join the cluster</li><li><strong>wordpress-mysql </strong>: For launching the wordpress and mysql pods with respective services, pv’s and pvc’s inside the K8s cluster.</li></ul><p>You can create the directory structure for above ansible roles with the command : (inside the location specified in ansible.cfg file)</p><pre>ansible-galaxy init &lt;&lt;ROLE NAME&gt;&gt;</pre><p>The tasks/main.yml files in the 4 roles are given below :</p><h3>Role-1 : launch_ec2_instances</h3><p>tasks/main.yml :</p><pre>---<br># tasks file for launch_ec2_instances<br>- name: &quot;Installing boto python library&quot;<br>  pip:<br>    name: boto</pre><pre>- name: &quot;Launching K8s Master&quot;<br>  ec2:<br>    key_name: &quot;{{ key_name }}&quot;<br>    instance_type: &quot;{{ instance_type }}&quot;<br>    image: &quot;{{ AMI_ID }}&quot;<br>    wait: yes<br>    group: &quot;{{ master_security_group }}&quot;<br>    count: 1<br>    vpc_subnet_id: &quot;{{ subnet_id }}&quot;<br>    assign_public_ip: yes<br>    region: &quot;{{ region_name }}&quot;<br>    aws_access_key: &quot;{{ access_key }}&quot;<br>    aws_secret_key: &quot;{{ secret_key }}&quot;<br>    instance_tags:<br>      &quot;Name&quot;: &quot;Master&quot;<br>  register: master_info</pre><pre>- name: &quot;Launching K8s Slave Nodes&quot;<br>  ec2:<br>    key_name: &quot;{{ key_name }}&quot;<br>    instance_type: &quot;{{ instance_type }}&quot;<br>    image: &quot;{{ AMI_ID }}&quot;<br>    wait: yes<br>    group: &quot;{{ worker_security_group }}&quot;<br>    count: &quot;{{ number_of_slave_nodes }}&quot; <br>    vpc_subnet_id: &quot;{{ subnet_id }}&quot;<br>    assign_public_ip: yes<br>    region: &quot;{{ region_name }}&quot;<br>    aws_access_key: &quot;{{ access_key }}&quot;<br>    aws_secret_key: &quot;{{ secret_key }}&quot;<br>    instance_tags:<br>      &quot;Name&quot;: &quot;Slave&quot;<br>  register: slave_info</pre><pre>- name: &quot;Adding Master and Slave Nodes Public IP&#39;s to the Inventory&quot;<br>  template:<br>    src: inventory.txt<br>    dest: &quot;{{ inventory_location }}&quot;</pre><pre>- name: &quot;Waiting for Master SSH port 22&quot;<br>  wait_for:<br>    port: 22<br>    host: &quot;{{ item.public_dns_name }}&quot;<br>    state: started<br>  loop: &quot;{{ master_info[&#39;instances&#39;] }}&quot;</pre><pre>- name: &quot;Waiting for Slave SSH port 22&quot;<br>  wait_for:<br>    port: 22<br>    host: &quot;{{ item.public_dns_name }}&quot;<br>    state: started<br>  loop: &quot;{{ slave_info[&#39;instances&#39;] }}&quot;</pre><p>You need to specify the values for above used variables inside vars/main.yml file :</p><pre>---<br># vars file for launch_ec2_instances</pre><pre>key_name: &quot;YOUR_KEY_NAME&quot;<br>instance_type: &quot;t2.micro&quot;<br>AMI_ID : &quot;ami-08df646e18b182346&quot;<br>master_security_group: &quot;YOUR_SG_NAME&quot;<br>worker_security_group: &quot;YOUR_SG_NAME&quot;<br>subnet_id: &quot;YOUR_SUBNET_ID&quot;<br>region_name: &quot;ap-south-1&quot;<br>access_key: &quot;YOUR_ACCESS_KEY&quot;<br>secret_key: &quot;YOUR_SECRET_KEY&quot;<br>number_of_slave_nodes: &quot;2&quot;<br>inventory_location: &quot;/home/sagar/inventory.txt&quot;</pre><p>I’m using Amazon Linux instance of t2.micro type. Make sure to provide your credentials, subnet id, SG, inventory_location in above file.</p><p><strong>IMP! </strong>One important step here is configuring proper Inbound rules for your security group. Otherwise this will lead to connectivity issues between the nodes in your K8s cluster. The following are the Inbound rules for my Security Group : (I’ve used same SG for both master and worker Instances)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4XL2HlXbWjlQxg0Q4XlKIg.png" /></figure><p>In this role, I’ve used a template for storing the public IP’s of launched Instances : templates/inventory.txt :</p><pre>[master_node]<br>{% for i in master_info[&#39;instances&#39;] %}<br>{{ i.public_ip }}<br>{% endfor %}<br>[slave_nodes]<br>{% for i in slave_info[&#39;instances&#39;] %}<br>{{ i.public_ip }}<br>{% endfor %}</pre><p>The hosts inside the above template file will be used by the Roles following…</p><h3>Role-2 : configure-master-slave</h3><p>tasks/main.yml :</p><pre>---<br># tasks file for configure-master-slave</pre><pre>- name: &quot;Turning off Swap&quot;<br>  command: &quot;swapoff -a&quot;</pre><pre>- name: &quot;Configuring k8s.conf file&quot;<br>  copy:<br>    content: |<br>      overlay<br>      br_netfilter<br>    dest: &quot;/etc/modules-load.d/k8s.conf&quot;</pre><pre>- name: &quot;Configuring Kernel Modules&quot;<br>  shell: |<br>    modprobe overlay<br>    modprobe br_netfilter</pre><pre>- name: &quot;Configuring sysctl params&quot;<br>  copy:<br>    content: |<br>      net.bridge.bridge-nf-call-iptables  = 1<br>      net.bridge.bridge-nf-call-ip6tables = 1<br>      net.ipv4.ip_forward                 = 1<br>    dest: &quot;/etc/sysctl.d/k8s.conf&quot;</pre><pre>- name: &quot;Applying sysctl params&quot;<br>  shell: sudo sysctl --system</pre><pre>- name: &quot;Installing Docker&quot;<br>  package:<br>    name: docker<br>    state: present</pre><pre>- name: &quot;Creating docker directory&quot;<br>  file:<br>    path: /etc/docker<br>    state: directory</pre><pre>- name: &quot;Configuring cgroup driver for docker&quot;<br>  copy:<br>    content: |<br>      {<br>        &quot;exec-opts&quot;: [&quot;native.cgroupdriver=systemd&quot;]<br>      }<br>    dest: &quot;/etc/docker/daemon.json&quot;</pre><pre>- name: &quot;Enabling Docker service&quot;<br>  service:<br>    name: docker<br>    enabled: yes</pre><pre>- name: &quot;Reloading systemd files&quot;<br>  shell: &quot;sudo systemctl daemon-reload&quot;</pre><pre>- name: &quot;Restarting Docker service&quot;<br>  service:<br>    name: docker<br>    state: restarted</pre><pre>- name: &quot;Configuring YUM repository for kubernetes&quot;<br>  yum_repository:<br>    name: kubernetes<br>    baseurl: <a href="https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64">https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64</a><br>    enabled: yes<br>    gpgcheck: yes<br>    gpgkey: <a href="https://packages.cloud.google.com/yum/doc/yum-key.gpg">https://packages.cloud.google.com/yum/doc/yum-key.gpg</a> <a href="https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg">https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg</a><br>    exclude:<br>    - kubelet<br>    - kubeadm<br>    - kubectl<br>    description: yum repo for kubernetes</pre><pre>- name: &quot;Disabling SELinux&quot;<br>  shell: |<br>    sudo setenforce 0<br>    sudo sed -i &#39;s/^SELINUX=enforcing$/SELINUX=permissive/&#39; /etc/selinux/config</pre><pre>- name: &quot;Installing kubeadm, kubelet, kubectl in Master and Worker&quot;<br>  yum:<br>    name: &quot;{{ item }}&quot;<br>    state: present<br>    disable_excludes: kubernetes<br>  loop:<br>  - kubelet<br>  - kubeadm<br>  - kubectl</pre><pre>- name: &quot;Starting and Enabling kubelet&quot;<br>  service:<br>    name: kubelet<br>    state: started<br>    enabled: yes</pre><pre>- name: &quot;Downloading required Docker Images&quot;<br>  command: kubeadm config images pull<br>  ignore_errors: yes</pre><pre>- name: &quot;Installing iproute-tc in Master and Worker&quot;<br>  package:<br>    name: iproute-tc<br>    state: present</pre><p>I’ve used docker as my CRI and systemd as a Cgroup driver for docker. The above steps should be run on both the master and worker ec2 instances as these steps are common for both K8s master and worker node.</p><p>Next, we’ve to start the master node…</p><h3>Role-3 : start-master</h3><p>tasks/main.yml :</p><pre>---<br># tasks file for start-master</pre><pre>- name: &quot;Starting the Master&quot;<br>  command: &quot;kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=NumCPU --ignore-preflight-errors=Mem&quot;</pre><pre>- name: &quot;Kubeconfig&quot;<br>  shell: |<br>    mkdir -p $HOME/.kube<br>    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config<br>    sudo chown $(id -u):$(id -g) $HOME/.kube/config</pre><pre>- name: &quot;Applying Flannel&quot;<br>  shell: kubectl apply  -f <a href="https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml">https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml</a></pre><p>I’ve used flannel as my AddOn for the overlay network as seen above.</p><p>Next, the worker nodes has to join the cluster which I’ll show in the <strong>main.yml </strong>file.</p><h3>Role-4 : wordpress-mysql</h3><p>tasks/main.yml :</p><pre>---<br># tasks file for wordpress-mysql</pre><pre>- name: &quot;Creating directory for storing kubernetes files&quot;<br>  file:<br>    path: /home/ec2-user/k8s-files<br>    state: directory</pre><pre>- name: &quot;Copying Kubernetes Files&quot;<br>  copy:<br>    src: ./<br>    dest: /home/ec2-user/k8s-files</pre><pre>- name: &quot;Applying Kubernetes Files&quot;<br>  shell: kubectl apply -f /home/ec2-user/k8s-files/</pre><pre>- name: &quot;Getting ClusterIP of MySQL&quot;<br>  shell: &quot;kubectl describe svc wordpress-mysql | grep IP: | tr -s &#39; &#39;&quot;<br>  register: ip</pre><pre>- name: &quot;Extracting ClusterIP&quot;<br>  set_fact:<br>    clusterIP: &quot;{{ ip[&#39;stdout_lines&#39;][0] | regex_replace(&#39;^IP: &#39;, &#39;&#39;) }}&quot;</pre><pre>- name: &quot;Copying wordpress yml file&quot;<br>  template:<br>    src: wordpress-deployment.yaml<br>    dest: /home/ec2-user/k8s-files</pre><pre>- name: &quot;Applying wordpress yml file&quot;<br>  shell: kubectl apply -f /home/ec2-user/k8s-files/wordpress-deployment.yaml</pre><pre>- name: &quot;Getting Port Number of Wordpress&quot;<br>  shell: kubectl get svc wordpress<br>  register: NodePort</pre><pre>- name: &quot;Displaying Port Number of Wordpress&quot;<br>  debug:<br>    var: NodePort[&#39;stdout_lines&#39;]</pre><p>The above roles contains the following yml files for launching pv’s, pvc’s, secret, serivces, pods :</p><p><strong>files/pv1.yaml : </strong>(for creating 2GiB of physical volume)</p><pre>apiVersion: v1<br>kind: PersistentVolume<br>metadata:<br>  name: mypv1<br>spec:<br>  capacity:<br>    storage: 2Gi<br>  accessModes:<br>    - ReadWriteOnce<br>  storageClassName: &quot;&quot;<br>  hostPath:<br>    path: &quot;/pv1&quot;</pre><p><strong>files/pv2.yaml : </strong>(for creating another 2GiB of physical volume)</p><pre>apiVersion: v1<br>kind: PersistentVolume<br>metadata:<br>  name: mypv2<br>spec:<br>  capacity:<br>    storage: 2Gi<br>  accessModes:<br>    - ReadWriteOnce<br>  storageClassName: &quot;&quot;<br>  hostPath:<br>    path: &quot;/pv2&quot;</pre><p><strong>files/secret.yaml : </strong>(for storing the password of mysql database)</p><pre>apiVersion: v1<br>data:<br>  password: c2FnYXI=<br>kind: Secret<br>metadata:<br>  name: mysql-pass</pre><p>In the above file, the password is base64 encoded. Make sure you change the password in the above file.</p><p><strong>files/mysql-deployment.yaml : </strong>(for creating a service for mysql deployment, claiming pv using pvc and launching mysql deployment)</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: wordpress-mysql<br>  labels:<br>    app: wordpress<br>spec:<br>  selector:<br>    app: wordpress<br>    tier: mysql<br>  ports:<br>    - port: 3306<br>  type: ClusterIP<br>---<br>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: mysql-pv-claim<br>  labels:<br>    app: wordpress<br>spec:<br>  accessModes:<br>    - ReadWriteOnce<br>  resources:<br>    requests:<br>      storage: 1Gi<br>---<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: wordpress-mysql<br>  labels:<br>    app: wordpress<br>spec:<br>  selector:<br>    matchLabels:<br>      app: wordpress<br>      tier: mysql<br>  strategy:<br>    type: Recreate<br>  template:<br>    metadata:<br>      labels:<br>        app: wordpress<br>        tier: mysql<br>    spec:<br>      containers:<br>      - image: mysql:5.7<br>        name: mysql<br>        env:<br>        - name: MYSQL_DATABASE<br>          value: wordpress<br>        - name: MYSQL_ROOT_PASSWORD<br>          valueFrom:<br>            secretKeyRef:<br>              name: mysql-pass<br>              key: password<br>        ports:<br>        - containerPort: 3306<br>          name: mysql<br>        volumeMounts:<br>        - name: mysql-persistent-storage<br>          mountPath: /var/lib/mysql<br>      volumes:<br>      - name: mysql-persistent-storage<br>        persistentVolumeClaim:<br>          claimName: mysql-pv-claim</pre><p>Next, I’ve used a template in which the <strong>clusterIP </strong>of MySQL database will be loaded into the environmental variable : WORDPRESS_DB_HOST :</p><p><strong>templates/wordpress-deployment.yaml </strong>: (for creating a NodePort service for wordpress and for claiming pv using pvc and creating a deployment for wordpress)</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: wordpress<br>  labels:<br>    app: wordpress<br>spec:<br>  ports:<br>    - port: 80<br>      targetPort: 80<br>  selector:<br>    app: wordpress<br>    tier: frontend<br>  type: NodePort<br>---<br>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: wp-pv-claim<br>  labels:<br>    app: wordpress<br>spec:<br>  accessModes:<br>    - ReadWriteOnce<br>  resources:<br>    requests:<br>      storage: 2Gi<br>---<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: wordpress<br>  labels:<br>    app: wordpress<br>spec:<br>  selector:<br>    matchLabels:<br>      app: wordpress<br>      tier: frontend<br>  strategy:<br>    type: Recreate<br>  template:<br>    metadata:<br>      labels:<br>        app: wordpress<br>        tier: frontend<br>    spec:<br>      containers:<br>      - image: wordpress:5.1.1-php7.3-apache<br>        name: wordpress<br>        env:<br>        - name: WORDPRESS_DB_HOST<br>          value: &quot;{{clusterIP}}:3306&quot;<br>        - name: WORDPRESS_DB_USER<br>          value: root<br>        - name: WORDPRESS_DB_PASSWORD<br>          valueFrom:<br>            secretKeyRef:<br>              name: mysql-pass<br>              key: password<br>        - name: WORDPRESS_DB_NAME<br>          value: wordpress<br>        - name: WORDPRESS_TABLE_PREFIX<br>          value: wp_<br>        volumeMounts:<br>        - name: wordpress-persistent-storage<br>          mountPath: /var/www/html<br>      volumes:<br>      - name: wordpress-persistent-storage<br>        persistentVolumeClaim:<br>          claimName: wp-pv-claim</pre><p>Note how tasks/main.yml file extracts the clusterIP of mysql service.</p><h3>main.yml</h3><p>Now we need a driver playbook which run all of the above roles sequentially and pass the cluster joining command to the worker nodes. The following is that main.yml file :</p><pre>- hosts: localhost<br>  gather_facts: False<br>  roles:<br>  - launch_ec2_instances<br>  tasks:<br>  - meta: refresh_inventory</pre><pre>- hosts: master_node:slave_nodes<br>  gather_facts: False<br>  roles:<br>  - configure-master-slave</pre><pre>- hosts: master_node<br>  gather_facts: False<br>  roles:<br>  - start-master<br>  tasks:<br>  - name: &quot;Getting token from master&quot;<br>    shell: &quot;kubeadm token create --print-join-command&quot;<br>    register: token<br>  - add_host:<br>      name: &quot;token_for_worker&quot;<br>      link: &quot;{{ token[&#39;stdout&#39;] }}&quot;</pre><pre>- hosts: slave_nodes<br>  gather_facts: False<br>  tasks:<br>  - name: &quot;Worker Nodes joining the cluster&quot;<br>    shell: &quot;{{ hostvars[&#39;token_for_worker&#39;][&#39;link&#39;] }}&quot;</pre><pre>- hosts: master_node<br>  gather_facts: False<br>  roles:<br>  - wordpress-mysql</pre><p>The above file, after launching instances, refreshes the inventory file so that further roles can connect to the ec2 instances. After launching ec2 instances, the above playbook configures the master and worker nodes and finally launches the deployments for wordpress and mysql pods.</p><h3>It’s time to test</h3><p>Now run the <strong>main.yml </strong>driver playbook with sudo. The following is the output for me :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FoG1G5doOF138l58nDJd-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zVRCna3Kgc5Nuw8LGrb_2A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l9L_9SUn5hy8TvjZBGvpNw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NlCC754y63VIhB5dSYbQdw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hPIEHPuBchmXMB2121tuPw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*weWaxFmmDjyLX0XRlKnuKw.png" /></figure><p>That was long!</p><p>In the last screenshot, we can see the PORT exposed (32243) of wordpress service. Now, you can view your wordpress website by heading to the url : http://&lt;&lt;Any EC2 Instance Public IP&gt;&gt;:&lt;&lt;PORT Exposed. In my case, it is :</p><pre><a href="http://13.127.98.228:32243/wp-admin/install.php">http://13.127.98.228:32243</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ie8kC2a5QwwmdtF0a8LD0Q.png" /></figure><p>You can see my instances are launched :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0F-YCk5nfEuQtzKucAruiw.png" /></figure><p>The wordpress website can also be accessed with the worker node public IP’s also.</p><p>You can log into the master node and see the cluster info :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3RClsE17HuTvq0L6axg7zg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FAs0bcLQtx0PpeFrbcIFLg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*agh6Y6c_DHRhFFEypyrBrA.png" /></figure><p>After some setup, you can use your own hosted wordpress :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rPTWEWUf11wE6w36hsAqeQ.png" /></figure><p><strong>Thanks for Reading</strong> 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2390adadfb50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Cases of Jenkins :]]></title>
            <link>https://asks1012.medium.com/use-cases-of-jenkins-770e260817fa?source=rss-909287abb261------2</link>
            <guid isPermaLink="false">https://medium.com/p/770e260817fa</guid>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[vimal-daga]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Akurathi Sri Krishna Sagar]]></dc:creator>
            <pubDate>Sun, 26 Sep 2021 14:53:40 GMT</pubDate>
            <atom:updated>2021-09-26T14:53:40.334Z</atom:updated>
            <content:encoded><![CDATA[<h3>Use Cases of Jenkins :</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/0*7Tjtm98ajKecfIsm.png" /></figure><h3>What is Jenkins?</h3><p>Jenkins is an open source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery. It is a server-based system that runs in servlet containers such as Apache Tomcat.</p><h3>Features of Jenkins</h3><p><strong>Continuous Integration and Continuous Delivery :</strong></p><p>As an extensible automation server, Jenkins can be used as a simple CI server or turned into the continuous delivery hub for any project.</p><p><strong>Easy installation :</strong></p><p>Jenkins is a self-contained Java-based program, ready to run out-of-the-box, with packages for Windows, Linux, macOS and other Unix-like operating systems.</p><p><strong>Easy configuration :</strong></p><p>Jenkins can be easily set up and configured via its web interface, which includes on-the-fly error checks and built-in help.</p><p><strong>Plugins :</strong></p><p>With hundreds of plugins in the Update Center, Jenkins integrates with practically every tool in the continuous integration and continuous delivery toolchain.</p><p><strong>Extensible :</strong></p><p>Jenkins can be extended via its plugin architecture, providing nearly infinite possibilities for what Jenkins can do.</p><p><strong>Distributed :</strong></p><p>Jenkins can easily distribute work across multiple machines, helping drive builds, tests and deployments across multiple platforms faster.</p><h3>Jenkins Use Cases in various other technologies</h3><h4>Android :</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dsEYUSqoBDLrXgfq.jpg" /></figure><p>As one of the predominant mobile platforms, Android is attractive to a number of developers, but it does bring it’s own set of challenges with it. With an extremely broad set of devices available on the market, building and testing for the matrix of device configurations can be very challenging. With the <a href="https://plugins.jenkins.io/android-emulator">Android emulator plugin</a> however, it is possible to build and test on a myriad of emulated devices.</p><p>When combined with the <a href="https://plugins.jenkins.io/google-play-android-publisher">Google Play Publisher plugin</a>, Android developers can build true continuous delivery pipeline, sending builds to an alpha channel in Google Play for release or further testing.</p><h4>GitHub :</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p9QNeN5HjNOS9i_m.jpeg" /></figure><p>With the help of the <a href="https://plugins.jenkins.io/git">Git plugin</a> Jenkins can easily pull source code from any Git repository that the Jenkins build node can access.</p><p>The <a href="https://plugins.jenkins.io/github">GitHub plugin</a> extends upon that integration further by providing improved bi-directional integration with GitHub. Allowing you to set up a <a href="https://developer.github.com/webhooks/#service-hooks">Service Hook</a> which will hit your Jenkins instance every time a change is pushed to GitHub.</p><h4>Java :</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/0*Pn5gIEib9mw4sPIQ.jpg" /></figure><p>Jenkins supports building Java projects since its inception. If you want to build a Java project, there are a bunch of different options. The most typical ones nowadays are generally Apache Maven, or Gradle.</p><h4>Python :</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/0*CCB98EjitY5SJsMu.png" /></figure><p>Unlike compiled languages, Python doesn’t need a “build” per se. Python projects can still benefit greatly from using Jenkins for continuous integration and delivery.</p><p>In the Python ecosystem there are tools which can be integrated into Jenkins for testing/reporting such as <a href="https://github.com/nose-devs/nose2">nose2</a> and <a href="https://docs.pytest.org/en/latest">pytest</a> for executing unit tests, <a href="https://www.pylint.org/">pylint</a> for generating code quality reports.</p><h4>PHP :</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kCeAxdRXAgM5qG2l.png" /></figure><p>Most web applications are changed and adapted quite frequently and quickly. Their environment, for example the size and the behaviour of the user base, are constantly changing. What was sufficient yesterday can be insufficient today. Especially in a web environment it is important to monitor and continuously improve the internal quality not only when developing, but also when maintaining the software.</p><p>Many of the plugins referenced (right) can be used to integrate with PHP projects, but may first need to be configured the create appropriately formatted files when working with PHP projects.</p><p>There are many more use cases solved by Jenkins…</p><blockquote>Thanks for Reading</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=770e260817fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Cases of AWS SQS]]></title>
            <link>https://asks1012.medium.com/use-cases-of-aws-sqs-e8670d9e348e?source=rss-909287abb261------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8670d9e348e</guid>
            <category><![CDATA[amazon]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[sqs]]></category>
            <category><![CDATA[vimal-daga]]></category>
            <category><![CDATA[message-queue]]></category>
            <dc:creator><![CDATA[Akurathi Sri Krishna Sagar]]></dc:creator>
            <pubDate>Sun, 26 Sep 2021 14:04:41 GMT</pubDate>
            <atom:updated>2021-09-26T14:04:41.944Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/711/0*P32gabWdRdI_mUWk" /></figure><h4>What is Amazon SQS service ?</h4><p>Amazon <strong>S</strong>imple<strong> Q</strong>ueue<strong> S</strong>ervice (SQS) is a distributed message queuing service introduced in late 2004. It supports programmatic sending of messages via web service applications as a way to communicate over the Internet. Messages can contain up to 256 KB of text in any format such as json, xml, etc.</p><p>SQS enables you to decouple and scale microservices, distributed systems, and server less applications. SQS eliminates the complexity and overhead associated with managing and operating message-oriented middleware, and empowers developers to focus on differentiating work.</p><p>Using SQS, you can send, store, and receive messages between software components at any volume, without losing messages or requiring other services to be available.</p><p>SQS offers two types of message queues. Standard queues offer maximum throughput, best-effort ordering, and at-least-once delivery. SQS FIFO queues are designed to guarantee that messages are processed exactly once, in the exact order that they are sent.</p><h3>Benefits of using Amazon SQS</h3><h4>Eliminate administrative overhead</h4><p>With SQS, there is no upfront cost, no need to acquire, install, and configure messaging software, and no time-consuming maintenance of supporting infrastructure. SQS queues are dynamically created and scale automatically so you can build and grow applications quickly and efficiently.</p><h4>Reliably deliver messages</h4><p>SQS lets you decouple application components so that they run and fail independently, increasing the overall fault tolerance of the system. Multiple copies of every message are stored redundantly across multiple availability zones so that they are available whenever needed.</p><h4>Keep sensitive data secure</h4><p>You can use Amazon SQS to exchange sensitive data between applications using server-side encryption (SSE) to encrypt each message body. Amazon SQS SSE integration with AWS Key Management Service (KMS) allows you to centrally manage the keys that protect SQS messages.</p><h4>Scale elastically and cost-effectively</h4><p>SQS scales elastically with your application so you don’t have to worry about capacity planning and pre-provisioning. There is no limit to the number of messages per queue, and standard queues provide nearly unlimited throughput.</p><h3>What if we don’t have Amazon SQS ?</h3><p>A web server passes the information to an application server and then application server queried an Airline service. If an Application server crashes, then a user loses its query.</p><p>One of the great thing about SQS is that data is queued in the SQS even if the application server crashes, the message in the queue is marked as an invisible in a timeout interval window. When the timeout runs out, message reappears in the queue; then a new EC2 instance can use this message to perform its job. Therefore, we can say that SQS removes the application server dependency.</p><h3>Queue Types of Amazon SQS</h3><p><strong>Standard Queue :</strong></p><ul><li>SQS offers a standard queue as the default queue type.</li><li>It allows you to have an unlimited number of transactions per second.</li><li>It guarantees that a message is delivered at least once. However, sometime, more than one copy of a message might be delivered out of order.</li><li>It provides best-effort ordering which ensures that messages are generally delivered in the same order as they are sent but it does not provide a guarantee.</li></ul><p><strong>FIFO Queue :</strong></p><ul><li>The FIFO Queue complements the standard Queue.</li><li>It guarantees ordering, i.e., the order in which they are sent is also received in the same order.</li><li>The most important features of a queue are FIFO Queue and exactly-once processing, i.e., a message is delivered once and remains available until consumer processes and deletes it.</li><li>FIFO Queue does not allow duplicates to be introduced into the Queue.</li><li>It also supports message groups that allow multiple ordered message groups within a single Queue.</li><li>FIFO Queues are limited to 300 transactions per second but have all the capabilities of standard queues.</li></ul><h3>SQS Visibility Timeout</h3><ul><li>The visibility timeout is the amount of time that the message is invisible in the SQS Queue after a reader picks up that message.</li><li>If the provided job is processed before the visibility time out expires, the message will then be deleted from the Queue. If the job is not processed within that time, the message will become visible again and another reader will process it. This could result in the same message being delivered twice.</li><li>The Default Visibility Timeout is 30 seconds.</li><li>Visibility Timeout can be increased if your task takes more than 30 seconds.</li><li>The maximum Visibility Timeout is 12 hours.</li></ul><h3>Properties of Amazon SQS :</h3><ul><li>SQS is pull-based, not push-based.</li><li>Messages can be 256 KB in size.</li><li>Messages are kept in a queue from 1 minute to 14 days.</li><li>The default retention period is 4 days.</li><li>It guarantees that your messages will be processed at least once.</li></ul><blockquote>Thanks for Reading.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8670d9e348e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RHCSA + Python Training]]></title>
            <link>https://asks1012.medium.com/rhcsa-python-training-134a407d6fb7?source=rss-909287abb261------2</link>
            <guid isPermaLink="false">https://medium.com/p/134a407d6fb7</guid>
            <category><![CDATA[vimal-daga]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[redhat-linux]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python3]]></category>
            <dc:creator><![CDATA[Akurathi Sri Krishna Sagar]]></dc:creator>
            <pubDate>Tue, 24 Aug 2021 08:58:45 GMT</pubDate>
            <atom:updated>2021-08-24T08:58:45.648Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gSsosdKSd81IMXhh.jpg" /></figure><p>I’ve successfully completed my RHCSA8+Python3 integration training under Mr. Vimal Daga under IIEC Community. I’ve learnt almost all basic to advanced linux commands and the core concepts of Python :</p><ul><li>Basic Linux Commands : date, cal, mkdir, ls, wc, grep, tee, curl, ps, rm, mv, cp, aliasetc.,</li><li>Software related commands : rpm, yum, dnf</li><li>Yum configuration</li><li>Loading Python modules</li><li>Input, Output, Error channels in linux</li><li>SSH, Scp for remote connection and remote file sharing</li><li>Firewall, SELinux</li><li>Configuring HTTPD web server</li><li>Network commands such as ifconfig, netstat, nmap, route and the concept of netmask, prefix length</li><li>Generator functions and List Comprehension in Python</li><li>Storage related commands such as fdisk, lsblk, df, mount, umount</li><li>Creating logical volumes with volume groups and physical volumes with the help of lvcreate, vgcreate, pvcreate etc., commands</li><li>Setting up NFS server for sharing of storage over network</li><li>Reducing and Increasing the Logical Volumes capacity with the commands lvreduce and lvextend</li><li>Fstab, Swap</li><li>Creating and modifying users with customizing uid, gid, post execution command, home directory</li><li>Meaning of root account in Linux</li><li>Working with CLI version of Redhat Linux</li><li>Core concepts of SELinux</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=134a407d6fb7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrate Flask with MongoDB]]></title>
            <link>https://asks1012.medium.com/integrate-flask-with-mongodb-7fb0ee467434?source=rss-909287abb261------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fb0ee467434</guid>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[vimal-daga]]></category>
            <category><![CDATA[full-stack]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Akurathi Sri Krishna Sagar]]></dc:creator>
            <pubDate>Mon, 09 Aug 2021 06:24:11 GMT</pubDate>
            <atom:updated>2021-08-09T06:24:11.922Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zy4RLYX5NRpXPRVbi7UfRA.png" /></figure><h3>Flask</h3><p>Flask is a Python Web Framework. It is a Python library used for developing Web Applications.</p><h3>MongoDB</h3><p>MongoDB is an Opensource Cross-Platform Document-Oriented Database program. It uses JSON like documents to store the data. It’s a NoSQL Database with optional Schema.</p><p>First, Install the <strong>Flask</strong> python library with the command :</p><pre>pip install flask<br>or<br>pip3 install flask</pre><p>Next, Install the <strong>Flask-PyMongo</strong> library, (which bridges <strong>Flask </strong>and <strong>PyMongo</strong> library) with the command :</p><pre>pip install Flask-PyMongo</pre><p>Now, go to <a href="https://www.mongodb.com/try/download/community">MongoDB Community Download | MongoDB</a> and download the MongoDB software for your respective OS. I’ve downloaded for Windows.</p><p>After downloading, install it and open it. Click on the <strong>Connect</strong> Button to start a local MongoDB Instance :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2fI_Zh5kqMRDWAyZeDz5g.png" /></figure><p>Now Click on the <strong>CREATE DATABASE </strong>button and provide the Database name and Collection name (Collection is similar to a Table in SQL) and click <strong>Create Database </strong>button :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tebOraflKviNBBXYVlBsnA.jpeg" /></figure><p>At present, there is no data inside the collection we created :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ATIhFSbGPzsluMKJN8DHsQ.jpeg" /></figure><p>Now we can test a Write operation to the Database with the following Flask Code :</p><pre>from flask import Flask<br>from flask_pymongo import PyMongo</pre><pre>app = Flask(&quot;MongoDB App&quot;)<br>app.config[&quot;MONGO_URI&quot;] = &quot;mongodb://localhost:27017/flask-mongo&quot;<br><em># Replace &quot;</em><strong><em>flask-mongo</em></strong><em>&quot; with the Database Name you created.</em></pre><pre>mongo_client = PyMongo(app)<br>db = mongo_client.db</pre><pre><em># Replace &quot;</em><strong><em>mycollection</em></strong><em>&quot; with the collection name you created. The below function is used for adding a single document to collection :</em></pre><pre>def add():<br>    db.mycollection.insert_one(<br>        {<br>            &quot;name&quot;: &quot;sagar&quot;,<br>            &quot;tech&quot;: &quot;mongo&quot;<br>        }<br>    )<br>add()</pre><p>Run the above python file and go to MongoDB and you can view the data you entered in the above function inside the collection :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mFv-20Pl9uGdZP8hM6_bdw.jpeg" /></figure><p>Now I’m going to show you how to use MongoDB with the HTML forms and create a Login Portal which takes in the input <strong>username </strong>and <strong>password </strong>and stores them in MongoDB collection. The user has the facility to Update username, Update Password, Delete the user, which are CRUD operations of the Database. The usernames are unique.</p><p>First create a file <strong>app.py </strong>and the following blocks explain the content in it :</p><p>The following block of code helps us to make a connection with the mongodb Database. Finally, the variable “<strong>mycollection</strong>” holds the connection with the collection in a database in MongoDB. This variable is used to perform CRUD operations on MongoDB :</p><pre>from logging import error<br>from flask import Flask, render_template, request<br>from flask_pymongo import PyMongo</pre><pre>app = Flask(&quot;MongoDB App&quot;)<br>app.config[&quot;MONGO_URI&quot;] = &quot;mongodb://localhost:27017/flask-mongo&quot;</pre><pre>mongo_client = PyMongo(app)<br>mycollection = mongo_client.db.mycollection</pre><p>Next, there is <strong>form() </strong>function which is the starting point of the WebApp. Any user must enter this route to go inside the WebApp further :</p><pre>@app.route(&quot;/form&quot;)<br>def form():<br>    return render_template(&quot;form.html&quot;)</pre><p>The output of <strong>form.html </strong>looks like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6WnsqR0dyEl8DuvfNrGo_w.png" /></figure><p>The <strong>&lt;body&gt;</strong> part of <strong>form.html </strong>:</p><pre>&lt;body&gt;<br>    &lt;p id=&quot;error&quot;&gt;{{ error }}&lt;/p&gt;<br>    &lt;form action=&quot;/home&quot; method=&quot;POST&quot; id=&quot;form&quot;&gt;<br>        &lt;h1&gt;Login/SignUp&lt;/h1&gt;<br>        &lt;br&gt;</pre><pre>        &lt;input type=&quot;text&quot; class=&quot;inputBox&quot; placeholder=&quot;Enter Username&quot; name=&quot;username&quot; pattern=&quot;[a-zA-Z0-9_-]{6,25}&quot; required title=&quot;Must be alphanumeric in 6-25 chars&quot;&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;</pre><pre>        &lt;input type=&quot;password&quot; class=&quot;inputBox&quot; placeholder=&quot;Enter Password&quot; name=&quot;password&quot; pattern=&quot;[a-zA-Z0-9_-]{6,25}&quot; required title=&quot;must be alphanumeric in 6-25 chars&quot;&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;</pre><pre>        &lt;button type=&quot;submit&quot; id=&quot;runBtn&quot;&gt;Submit&lt;/button&gt;<br>    &lt;/form&gt;<br>&lt;/body&gt;</pre><p><strong>form.html </strong>takes the <strong>username </strong>and <strong>password </strong>as input from the user and submits it to the route : <strong>/home </strong>with POST method so that, username and password won’t be visible as the query strings. I’ve also set the constraints to the username and password with the help of Regex as you can see above. In the above code, <strong>{{ error }} </strong>is a variable in jinja syntax, whose value can be passed by various other html files.</p><p>I’ve defined the <strong>/home </strong>route in the <strong>app.py </strong>file as below :</p><pre><a href="http://twitter.com/app">@app</a>.route(&quot;/home&quot;, methods = [&quot;GET&quot;,&quot;POST&quot;])<br>def home():<br>    if request.method == &quot;POST&quot;:<br>        username = request.form.get(&quot;username&quot;)<br>        password = request.form.get(&quot;password&quot;)<br>        found = mycollection.find({<br>            &quot;username&quot;: username,<br>        })<br>        l = [i for i in found]</pre><pre>        if len(l)==0 :<br>            mycollection.insert_one(<br>                {<br>                    &quot;username&quot;: username,<br>                    &quot;password&quot;: password<br>                }<br>            )<br>            return render_template(&quot;home.html&quot;,text=&quot;Hi Newbie,&quot;,username=username)</pre><pre>        elif len(l)==1 and l[0][&quot;username&quot;]==username and l[0][&quot;password&quot;]==password:<br>            return render_template(&quot;home.html&quot;, text=&quot;Welcome Back,&quot;,username=username)</pre><pre>        elif len(l)==1 and l[0][&quot;username&quot;]==username and l[0][&quot;password&quot;]!=password:<br>            return render_template(&quot;form.html&quot;, error=&quot;Incorrect Password&quot;)</pre><p>The <strong>form.html </strong>submits the username and password to the above function or the route. The above <strong>home() </strong>function does the following :</p><ul><li>Get the <strong>username </strong>and <strong>password</strong> from the form.</li><li>Find if any document in MongoDB already exists with the same <strong>username.</strong></li><li>If <strong>no</strong> username is found already, then, create a document in the MongoDB with the help of <strong>CollectionName.insert_one({data}) </strong>function and redirect the user to <strong>home.html </strong>file by passing the <strong>username </strong>and some <strong>text </strong>as arguments which we will catch in the <strong>home.html </strong>with the help of jinja syntax.</li><li>Else if, the username already exists in the MongoDB, and the <strong>username </strong>and <strong>password </strong>provided by user matches with the values previously in the database, then redirect the user to <strong>home.html </strong>by passing the <strong>username </strong>and <strong>text </strong>as arguments.</li><li>Else if, the username already exists in the MongoDB, but the <strong>password </strong>provided by the user doesn’t match the <strong>password </strong>present in the MongoDB, then keep the user in the <strong>form.html </strong>itself, without redirecting and pass the <strong>error </strong>argument to the <strong>form.html </strong>showing that the password is incorrect.</li></ul><p>Now, I’m entering a username and password in the <strong>/form </strong>page :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sc6PoRZhVWHZRmBBojDUZw.jpeg" /></figure><p>And click the <strong>Submit </strong>button. As there are no users now, a new user will be created in MongoDB. Now, I’m in the <strong>/home</strong> route :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*disf2yQtbveek4J7Y3jXkg.jpeg" /></figure><p>The &lt;body&gt; part of the above <strong>home.html</strong> :</p><p>It contains 2 &lt;p&gt; elements and 3 buttons for Update Username, Update Password and Delete User and they redirect the user to the /form2, /form4 and /delete routes respectively.</p><pre>&lt;body&gt;<br>    &lt;div id=&quot;main&quot;&gt;<br>        &lt;p id=&quot;text&quot;&gt;{{ text }}&lt;/p&gt;<br>        &lt;p id=&quot;text&quot;&gt;{{ username }}&lt;/p&gt;<br>        &lt;div id=&quot;mainDiv&quot;&gt;</pre><pre>            &lt;form action=&quot;/form2&quot;&gt;<br>                &lt;button type=&quot;submit&quot; id=&quot;runBtn&quot;&gt;Update Username&lt;/button&gt;<br>            &lt;/form&gt;</pre><pre>            &lt;form action=&quot;/form4&quot;&gt;<br>                &lt;button type=&quot;submit&quot; id=&quot;runBtn&quot;&gt;Update Password&lt;/button&gt;<br>            &lt;/form&gt;</pre><pre>            &lt;form action=&quot;/delete&quot;&gt;<br>                &lt;button type=&quot;submit&quot; id=&quot;runBtn&quot;&gt;Delete User&lt;/button&gt;<br>            &lt;/form&gt;</pre><pre>        &lt;/div&gt;<br>    &lt;/div&gt;<br>&lt;/body&gt;</pre><p>A new document is created in MongoDB :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U9A2xAJ2U-QSNcKPS7YM5w.jpeg" /></figure><p>Now click on <strong>Update Username </strong>button. You will be directed to the following page :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eicHZCmQM9uh7S5M2By5xQ.jpeg" /></figure><p>Python code for the above <strong>/form2 </strong>route :</p><pre>@app.route(&quot;/form2&quot;)<br>def form2():<br>    return render_template(&quot;update_username.html&quot;)</pre><p>&lt;body&gt; part of <strong>update_username.html</strong> :</p><pre>&lt;body&gt;<br>    &lt;p id=&quot;error&quot;&gt;{{ error }}&lt;/p&gt;<br>    &lt;form action=&quot;/form3&quot; method=&quot;POST&quot; id=&quot;form&quot;&gt;<br>        &lt;h1&gt;Change Username&lt;/h1&gt;<br>        &lt;br&gt;</pre><pre>        &lt;input type=&quot;text&quot; class=&quot;inputBox&quot; placeholder=&quot;Enter old username&quot; name=&quot;username&quot; pattern=&quot;[a-zA-Z0-9_-]{6,25}&quot; required title=&quot;Must be alphanumeric in 6-25 chars&quot;&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;</pre><pre>        &lt;input type=&quot;password&quot; class=&quot;inputBox&quot; placeholder=&quot;Enter Password&quot; name=&quot;password&quot; pattern=&quot;[a-zA-Z0-9_-]{6,25}&quot; required title=&quot;must be alphanumeric in 6-25 chars&quot;&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;</pre><pre>        &lt;input type=&quot;text&quot; class=&quot;inputBox&quot; placeholder=&quot;Enter new username&quot; name=&quot;new_username&quot; pattern=&quot;[a-zA-Z0-9_-]{6,25}&quot; required title=&quot;Must be alphanumeric in 6-25 chars&quot;&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;</pre><pre>        &lt;button type=&quot;submit&quot; id=&quot;runBtn&quot;&gt;Submit&lt;/button&gt;<br>    &lt;/form&gt;<br>&lt;/body&gt;</pre><p><strong>update_username.html </strong>collects the already existing username and password and the <strong>new_username </strong>and submits them to <strong>/form3 </strong>route.</p><p>Now, I’m updating my username by providing the required details :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GdXFLHv3m0fmwND-ssZXOA.jpeg" /></figure><p>Click on Submit button. When you click on Submit button, you will be directed to <strong>/form3 </strong>route. The python code for <strong>/form3 </strong>:</p><pre>@app.route(&quot;/form3&quot;, methods=[&quot;GET&quot;,&quot;POST&quot;])<br>def form3():<br>    if request.method == &quot;POST&quot;:<br>        username = request.form.get(&quot;username&quot;)<br>        password = request.form.get(&quot;password&quot;)<br>        new_username = request.form.get(&quot;new_username&quot;)<br>        found = mycollection.find({<br>            &quot;username&quot;: username,<br>        })<br>        l = [i for i in found]</pre><pre>        if len(l)==0 :<br>            return render_template(&quot;update_username.html&quot;, error=&quot;Username not found!&quot;)</pre><pre>        elif len(l)==1 and l[0][&quot;username&quot;]==username and l[0][&quot;password&quot;]==password:<br>            mycollection.update_one(<br>                {&quot;username&quot;: username},<br>                {&quot;$set&quot;: {&quot;username&quot;: new_username}}<br>            )<br>            return render_template(&quot;form.html&quot;, error=&quot;Username Updated&quot;)</pre><pre>        elif len(l)==1 and l[0][&quot;username&quot;]==username and l[0][&quot;password&quot;]!=password:<br>            return render_template(&quot;update_username.html&quot;, error=&quot;Incorrect Password&quot;)</pre><p>The above python code checks the old username and password. If both of them are correct and the new username matches the constraints, then the <strong>username </strong>will be updated in the MongoDB with the help of <strong>.update_one({find}, {replace}) </strong>function and you will be directed to <strong>form.html </strong>again to login with the new credentials.</p><p>I’ve submitted my new username. It’s saying “username updated” at the top :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oR0CVRMLa5YXZm5BhzEv7g.jpeg" /></figure><p>REFRESH the MongoDB also :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ClvMrEWcXuLmFoxzJSmBw.jpeg" /></figure><p>In the <strong>/home </strong>route, if you click <strong>Update Password, </strong>you will be directed to the <strong>/form4 </strong>route. Python code for <strong>/form4 :</strong></p><pre>@app.route(&quot;/form4&quot;)<br>def form4():<br>    return render_template(&quot;update_password.html&quot;)</pre><p>&lt;body&gt; part of <strong>update_password.html </strong>:</p><pre>&lt;body&gt;<br>    &lt;p id=&quot;error&quot;&gt;{{ error }}&lt;/p&gt;<br>    &lt;form action=&quot;/form5&quot; method=&quot;POST&quot; id=&quot;form&quot;&gt;<br>        &lt;h1&gt;Change Password&lt;/h1&gt;<br>        &lt;br&gt;</pre><pre>        &lt;input type=&quot;text&quot; class=&quot;inputBox&quot; placeholder=&quot;Enter username&quot; name=&quot;username&quot; pattern=&quot;[a-zA-Z0-9_-]{6,25}&quot; required title=&quot;Must be alphanumeric in 6-25 chars&quot;&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;</pre><pre>        &lt;input type=&quot;password&quot; class=&quot;inputBox&quot; placeholder=&quot;Enter old password&quot; name=&quot;password&quot; pattern=&quot;[a-zA-Z0-9_-]{6,25}&quot; required title=&quot;must be alphanumeric in 6-25 chars&quot;&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;</pre><pre>        &lt;input type=&quot;password&quot; class=&quot;inputBox&quot; placeholder=&quot;Enter new password&quot; name=&quot;new_password&quot; pattern=&quot;[a-zA-Z0-9_-]{6,25}&quot; required title=&quot;Must be alphanumeric in 6-25 chars&quot;&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;</pre><pre>        &lt;button type=&quot;submit&quot; id=&quot;runBtn&quot;&gt;Submit&lt;/button&gt;<br>    &lt;/form&gt;<br>&lt;/body&gt;</pre><p>The above file takes the username, old password and the new password and submits them to <strong>/form5 </strong>for validation.</p><p>Python Code for <strong>/form5 </strong>route :</p><pre><a href="http://twitter.com/app">@app</a>.route(&quot;/form5&quot;, methods=[&quot;GET&quot;,&quot;POST&quot;])<br>def form5():<br>    if request.method == &quot;POST&quot;:<br>        username = request.form.get(&quot;username&quot;)<br>        password = request.form.get(&quot;password&quot;)<br>        new_password = request.form.get(&quot;new_password&quot;)<br>        found = mycollection.find({<br>            &quot;username&quot;: username,<br>        })<br>        l = [i for i in found]</pre><pre>        if len(l)==0 :<br>            return render_template(&quot;update_password.html&quot;, error=&quot;Username not found!&quot;)</pre><pre>        elif len(l)==1 and l[0][&quot;username&quot;]==username and l[0][&quot;password&quot;]==password:<br>            mycollection.update_one(<br>                {&quot;username&quot;: username},<br>                {&quot;$set&quot;: {&quot;password&quot;: new_password}}<br>            )<br>            return render_template(&quot;form.html&quot;, error=&quot;Password Updated&quot;)</pre><pre>        elif len(l)==1 and l[0][&quot;username&quot;]==username and l[0][&quot;password&quot;]!=password:<br>            return render_template(&quot;update_password.html&quot;, error=&quot;Incorrect Password&quot;)</pre><p>I’m providing the following details :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rtAWrFPI8Huc8fb9aaEtbQ.jpeg" /></figure><p>Click on Submit button and view the MongoDB database (password will change) :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BLiKkfFtRRw8pQuvzJGGQw.jpeg" /></figure><p>Finally, we have a <strong>Delete User </strong>button in the <strong>/home </strong>route. When you click on that button, you will be directed to <strong>/delete </strong>route.</p><p>Python code for <strong>/delete :</strong></p><pre>@app.route(&quot;/delete&quot;)<br>def delete():<br>    return render_template(&quot;delete_user.html&quot;, error=&quot;Provide the Crendentials&quot;)</pre><p>&lt;body&gt; part of <strong>delete_user.html</strong> :</p><pre>&lt;body&gt;<br>    &lt;p id=&quot;error&quot;&gt;{{ error }}&lt;/p&gt;<br>    &lt;form action=&quot;/form6&quot; method=&quot;POST&quot; id=&quot;form&quot;&gt;<br>        &lt;h1&gt;Login&lt;/h1&gt;<br>        &lt;br&gt;</pre><pre>        &lt;input type=&quot;text&quot; class=&quot;inputBox&quot; placeholder=&quot;Enter Username&quot; name=&quot;username&quot; pattern=&quot;[a-zA-Z0-9_-]{6,25}&quot; required title=&quot;Must be alphanumeric in 6-25 chars&quot;&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;</pre><pre>        &lt;input type=&quot;password&quot; class=&quot;inputBox&quot; placeholder=&quot;Enter Password&quot; name=&quot;password&quot; pattern=&quot;[a-zA-Z0-9_-]{6,25}&quot; required title=&quot;must be alphanumeric in 6-25 chars&quot;&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;</pre><pre>        &lt;button type=&quot;submit&quot; id=&quot;runBtn&quot;&gt;Submit&lt;/button&gt;<br>    &lt;/form&gt;<br>&lt;/body&gt;</pre><p>The <strong>delete_user.html </strong>takes the already existing username and password and submits them to <strong>/form6 </strong>route.</p><p>Python code for <strong>/form6 </strong>:</p><pre><a href="http://twitter.com/app">@app</a>.route(&quot;/form6&quot;, methods=[&quot;GET&quot;,&quot;POST&quot;])<br>def form6():<br>    if request.method == &quot;POST&quot;:<br>        username = request.form.get(&quot;username&quot;)<br>        password = request.form.get(&quot;password&quot;)<br>        found = mycollection.find({<br>            &quot;username&quot;: username,<br>        })<br>        l = [i for i in found]</pre><pre>        if len(l)==0 :<br>            return render_template(&quot;delete_user.html&quot;, error=&quot;Username not found!&quot;)</pre><pre>        elif len(l)==1 and l[0][&quot;username&quot;]==username and l[0][&quot;password&quot;]==password:<br>            mycollection.delete_one({<br>                &quot;username&quot;: username<br>            })<br>            return render_template(&quot;form.html&quot;, error=&quot;User Deleted&quot;)</pre><pre>        elif len(l)==1 and l[0][&quot;username&quot;]==username and l[0][&quot;password&quot;]!=password:<br>            return render_template(&quot;delete_user.html&quot;, error=&quot;Incorrect Password&quot;)</pre><p>If the username and password matches, then that user document in MongoDB will be deleted with the help of <strong>.delete_one({data}) </strong>function.</p><p>After providing the username and password for deletion, click on Submit button. Check the MongoDB, and you can see that the document will be deleted.</p><p>In the <strong>app.py </strong>file, finally add the following line of code to start the server :</p><pre>app.run(host=&quot;&quot;, port=1234)<br># You can provide any non occupied port number.</pre><h4>GitHub Link for the Code :</h4><p><a href="https://github.com/asks1012/flask_mongoDB">asks1012/flask_mongoDB (github.com)</a></p><p>In this article, I’ve discussed the CRUD operations on MongoDB with the help of Flask Framework.</p><p>Thanks for Reading 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fb0ee467434" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>