<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Suraj Warbhe</title>
    <description>The latest articles on DEV Community by Suraj Warbhe (@surajwarbhe).</description>
    <link>https://dev.to/surajwarbhe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F693571%2Fc870001b-c100-4858-b933-5026954dfa13.jpeg</url>
      <title>DEV Community: Suraj Warbhe</title>
      <link>https://dev.to/surajwarbhe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/surajwarbhe"/>
    <language>en</language>
    <item>
      <title>Launching WordPress on AWS with RDS</title>
      <dc:creator>Suraj Warbhe</dc:creator>
      <pubDate>Sun, 05 Sep 2021 05:06:28 +0000</pubDate>
      <link>https://dev.to/surajwarbhe/launching-wordpress-on-aws-with-rds-2ee7</link>
      <guid>https://dev.to/surajwarbhe/launching-wordpress-on-aws-with-rds-2ee7</guid>
      <description>&lt;h1&gt;
  
  
  USE-CASE
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Create an AWS EC2 instance
&lt;/li&gt;
&lt;li&gt;Configure the instance with Apache webserver&lt;/li&gt;
&lt;li&gt;Download php application name "WordPress".&lt;/li&gt;
&lt;li&gt;Setup a MySQL server using AWS RDS service using Free Tier as a backend&lt;/li&gt;
&lt;li&gt;Provide the endpoint/connection string to the WordPress application to make it work&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Pre-requisite:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;AWS Account&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  STEP 1 : Create an EC2 Instance
&lt;/h3&gt;

&lt;p&gt;🔶 We need to launch an EC2 Instance on AWS which we will use to configure Apache Webserver and run WordPress.&lt;/p&gt;

&lt;p&gt;🔶 Click on &lt;code&gt;Launch Instance&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;🔶 Select 'Amazon Linux` as a Instance Flavor.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcf750g51p3g1crsjk787.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcf750g51p3g1crsjk787.png" alt="Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_07_48 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶 Select &lt;code&gt;t2.micro&lt;/code&gt; as a &lt;code&gt;instance type&lt;/code&gt;. It is free for eligible.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faf4qde5o34ggtbb6d6a1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faf4qde5o34ggtbb6d6a1.png" alt="Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_08_00 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶 Provide configuration details and click on &lt;code&gt;Add Storage&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpcm5mrraeo5ndnkj0q7n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpcm5mrraeo5ndnkj0q7n.png" alt="Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_08_06 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶 Add &lt;code&gt;storage&lt;/code&gt;. I will keep it default. And click on &lt;code&gt;Add Tag&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjarywbww9xy7slr907g2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjarywbww9xy7slr907g2.png" alt="Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_08_20 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶 Add &lt;code&gt;tag&lt;/code&gt; if you want. For this, click on &lt;code&gt;Add another tag&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9kzd0hzveavwmty8o3hf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9kzd0hzveavwmty8o3hf.png" alt="Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_08_43 PM"&gt;&lt;/a&gt;&lt;br&gt;
🔶 After this click on &lt;code&gt;Configure Security Group&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;🔶 Click on &lt;code&gt;Add Rule&lt;/code&gt;. I will allow &lt;code&gt;All traffic&lt;/code&gt; to avoid any firewall issue. Then click on &lt;code&gt;Review and Launch&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;🔶 Attach &lt;code&gt;key pair&lt;/code&gt; then Instance will launched successfully.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy8vvq77usiutd6px6whv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy8vvq77usiutd6px6whv.png" alt="Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_09_27 PM"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ibv8gdutzshum4xsc4q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ibv8gdutzshum4xsc4q.png" alt="Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_09_57 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶 Click on &lt;code&gt;Instance ID&lt;/code&gt;. You will get all the details of your created instance.&lt;/p&gt;

&lt;p&gt;🔶 You will get &lt;code&gt;Public IP&lt;/code&gt; and &lt;code&gt;Private IP&lt;/code&gt; from this.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7jy6dzqyrkaaumzrbxy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7jy6dzqyrkaaumzrbxy.png" alt="Launch instance wizard _ EC2 Management Console - Google Chrome 04-09-2021 10_10_32 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you can use &lt;code&gt;Public IP address&lt;/code&gt; any Key to connect this Instance. You can use Putty(Recommended) or CLI Browser provided by Amazon to Connect Instance.&lt;/p&gt;

&lt;p&gt;Lets go for Next to Configure the instance as Apache Webserver:&lt;/p&gt;
&lt;h3&gt;
  
  
  STEP 2 : Configure the Instance with Apache Webserver
&lt;/h3&gt;

&lt;p&gt;🔶 Here we are going to configure the &lt;code&gt;Apache Web Server&lt;/code&gt; in Amazon Linux 2 Instance.&lt;/p&gt;

&lt;p&gt;🔶 To run WordPress, we need to run a web server on our EC2 instance. The open source Apache web server is the most popular web server used with WordPress.&lt;br&gt;
🔶 Install Apache Web Server.&lt;br&gt;
`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo su -
yum install httpd -y 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 Then we are Starting Webserver and Enable it Permanently.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl start httpd

systemctl enable httpd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  STEP 3 : Installation and configuration of php software name &lt;code&gt;WordPress&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;🔶 WordPress is a php Application, let’s install &lt;code&gt;php 7.2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;🔶 With Amazon Linux 2, you can use the Extras Library to install application and software updates on your instances.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; amazon-linux-extras install -y php7.2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 After that download WordPress file!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget http://wordpress.org/latest.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 After download the "TAR" file "UNTAR" it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tar -xvzf latest.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 Next you see &lt;code&gt;wordpress&lt;/code&gt; name &lt;code&gt;dir&lt;/code&gt; come up. So now you can copy all Content inside &lt;code&gt;wordpress folder&lt;/code&gt; to Document Root &lt;code&gt;/var/www/html&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cp -rf wordpress/* /var/www/html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Note:
&lt;/h5&gt;

&lt;p&gt;Make Sure where you download your &lt;code&gt;tar&lt;/code&gt; file and where you &lt;code&gt;Untar&lt;/code&gt; it.&lt;/p&gt;

&lt;h3&gt;
  
  
  STEP 4 : Setup a MySQL server using AWS RDS service with Free Tier Account
&lt;/h3&gt;

&lt;p&gt;🔶 Let’s now launch a MySql database using &lt;code&gt;Amazon RDS&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;🔶 Click on &lt;code&gt;Create Database&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9o6013f3v5gsozxzzoag.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9o6013f3v5gsozxzzoag.png" alt="RDS Management Console - Google Chrome 04-09-2021 10_16_24 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶 Choose &lt;code&gt;Standard Create&lt;/code&gt; and &lt;code&gt;MySQL&lt;/code&gt; as a engine option.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F412xa1rf8iwtwx3evupv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F412xa1rf8iwtwx3evupv.png" alt="RDS Management Console - Google Chrome 04-09-2021 10_16_55 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶 Select Version &lt;code&gt;MySQL 8.0.20&lt;/code&gt; and template as &lt;code&gt;Free tier&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftz7jwakay9o39i2brny4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftz7jwakay9o39i2brny4.png" alt="RDS Management Console - Google Chrome 04-09-2021 10_17_14 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶 Provide DB Instance name, Username &amp;amp; Password&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqtqxdoq3jg186p48hs84.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqtqxdoq3jg186p48hs84.png" alt="RDS Management Console - Google Chrome 04-09-2021 10_26_22 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶 Here this DB instance have No Connectivity to Internet. We will access it through EC2 Instance.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Futmybrrxb6ru9ojuq0wh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Futmybrrxb6ru9ojuq0wh.png" alt="RDS Management Console - Google Chrome 04-09-2021 10_23_51 PM"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffc74erj62llfcv1h1ol3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffc74erj62llfcv1h1ol3.png" alt="RDS Management Console - Google Chrome 04-09-2021 10_24_30 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶 Now after Launching this DB Instance &lt;code&gt;mydb&lt;/code&gt; named Database will be created inside this DB server.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4qak8y43nr5lbjuz3nf2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4qak8y43nr5lbjuz3nf2.png" alt="RDS Management Console - Google Chrome 04-09-2021 10_25_20 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶 Now click on &lt;code&gt;Launch Database&lt;/code&gt;. It will take around 10 minutes.&lt;/p&gt;

&lt;p&gt;🔶 Once the Database is available, click on &lt;code&gt;Connectivity &amp;amp; Security&lt;/code&gt;. You will get &lt;code&gt;hostname&lt;/code&gt; and &lt;code&gt;Port no.&lt;/code&gt; there.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuuurfyjk2l72iowgxsc7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuuurfyjk2l72iowgxsc7.png" alt="RDS Management Console - Google Chrome 04-09-2021 10_36_48 PM"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  STEP 5 : Provide the Endpoint/Connection string to the WordPress Application
&lt;/h3&gt;

&lt;p&gt;🔶 Go to the created EC2 Instances instance. In the Description below, find the &lt;code&gt;Public DNS (IPv4)&lt;/code&gt; of your instance.&lt;/p&gt;

&lt;p&gt;🔶 Enter this IP Address into your web browser. And type Enter.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkh7w8tkxrf1sefago6rg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkh7w8tkxrf1sefago6rg.png" alt="WordPress › Setup Configuration File - Google Chrome 05-09-2021 08_56_01 AM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd10c8wlvnx13gogvkgco.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd10c8wlvnx13gogvkgco.png" alt="WordPress › Setup Configuration File - Google Chrome 05-09-2021 08_56_08 AM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔅 Provide Following Information:&lt;br&gt;
🌀 Database Name: Provide Name of Database which created at time of launching DB!&lt;/p&gt;

&lt;p&gt;🌀 Username: The username you given while launching DB Instance!&lt;/p&gt;

&lt;p&gt;🌀 Password: Provide Password!&lt;/p&gt;

&lt;p&gt;🌀 Database Host: Provide the ENDPOINT which you get from "wordpress-database"!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4cdzq3tzeds4k6ggwf6l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4cdzq3tzeds4k6ggwf6l.png" alt="(4) Launching WordPress on AWS with RDS _ LinkedIn - Google Chrome 05-09-2021 09_06_58 AM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶 Now our WordPress is running on the AWS using AWS RDS as a service and in the backend it is using MySQL. &lt;br&gt;
Let's check from CLI.&lt;br&gt;
Use command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# mysql -h &amp;lt;endpoint_url&amp;gt; -u &amp;lt;username&amp;gt; -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And provide our password.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkjamk2n50v8rafc9ynr0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkjamk2n50v8rafc9ynr0.png" alt="root@ip-172-31-45-40_~ 05-09-2021 09_19_29 AM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶 Provide Following Details and Install WordPress!&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjmlgpt9fr7r296q778mz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjmlgpt9fr7r296q778mz.png" alt="WordPress › Installation - Google Chrome 05-09-2021 09_09_20 AM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶 After Login with the credentials and Login to WordPress!&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwuse2led2assp3rv0r49.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwuse2led2assp3rv0r49.png" alt="WordPress › Installation - Google Chrome 05-09-2021 09_09_31 AM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fawk644ey1wx5vi0dhveu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fawk644ey1wx5vi0dhveu.png" alt="WordPress › Installation - Google Chrome 05-09-2021 09_17_13 AM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Successfully done! We have Login in to WordPress and we can continue to write Blogs etc., All your Data will Be stored in RDS MySQL DB.
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyybi3w53tdcy9ct6uk38.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyybi3w53tdcy9ct6uk38.gif" alt="68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f776174747061642d6d656469612d736572766963652f53746f7279496d6167652f69346776387341505f5f586746673d3d2d3931363135303430372e3136316636643238343363343039646134303138393"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>mysql</category>
      <category>wordpress</category>
      <category>devops</category>
    </item>
    <item>
      <title>Automating Kubernetes Cluster on AWS using Ansible and deploying WordPress with MySQL on k8s cluster</title>
      <dc:creator>Suraj Warbhe</dc:creator>
      <pubDate>Sat, 04 Sep 2021 09:17:44 +0000</pubDate>
      <link>https://dev.to/surajwarbhe/automating-kubernetes-cluster-on-aws-using-ansible-and-deploying-wordpress-with-mysql-on-k8s-cluster-3p4c</link>
      <guid>https://dev.to/surajwarbhe/automating-kubernetes-cluster-on-aws-using-ansible-and-deploying-wordpress-with-mysql-on-k8s-cluster-3p4c</guid>
      <description>&lt;h1&gt;
  
  
  USE-CASE
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Create Ansible Playbook to launch 3 AWS EC2 Instance&lt;/li&gt;
&lt;li&gt;Create Ansible Playbook to configure Docker over those instances&lt;/li&gt;
&lt;li&gt;Create Playbook to configure K8S Master, K8S Worker Nodes on the above created EC2 Instances using kubeadm&lt;/li&gt;
&lt;li&gt;Launch a WordPress and MySQL database connected to it in the respective slaves&lt;/li&gt;
&lt;li&gt;Expose the WordPress pod and the client able to hit the WordPress IP with its respective port.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Pre-requisite: (FOR RHEL-8)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Controller node should be setup with ansible installation and configuration, when controller node is RHEL8&lt;/li&gt;
&lt;li&gt;Create one &lt;code&gt;IAM&lt;/code&gt; user having Administrator Access and note down their &lt;code&gt;access key&lt;/code&gt; and &lt;code&gt;secret key&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create one &lt;code&gt;Key pair&lt;/code&gt; in &lt;code&gt;(.pem)&lt;/code&gt; format on AWS Cloud, download it in your local system and transfer it over RHEL-8 through &lt;code&gt;WinSCP&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  STEP 1 : Ansible Installation and Configuration
&lt;/h3&gt;

&lt;p&gt;Install Ansible on Base OS (RHEL8), configure ansible configuration file. &lt;br&gt;
To do this use below commands-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yum install python3 -y

pip3 install ansible -y

vim /etc/ansible/ansible.cfg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOTE: &lt;code&gt;Python&lt;/code&gt; should be installed on your OS to setup Ansible.&lt;br&gt;
Write below commands in your configuration &lt;code&gt;ansible.cfg&lt;/code&gt; file. For this you can prefer any editor like &lt;code&gt;vi&lt;/code&gt;, &lt;code&gt;vim&lt;/code&gt;, &lt;code&gt;gedit&lt;/code&gt;-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[defaults]
inventory=/root/ip.txt  #inventory path
host_key_checking=False
command_warnings=False
deprecation_warnings=False
ask_pass=False
roles_path= /root/roles      #roles path
force_valid_group_names = ignore
private_key_file= /root/awskey.pem   #your key-pair 
remote_user=ec2-user

[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  STEP 2 : Create Ansible Roles
&lt;/h3&gt;

&lt;p&gt;🔶 Go inside your roles workspace&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /roles
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use Below commands to create 3 different roles&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For Kubernetes Cluster&lt;/li&gt;
&lt;li&gt;For Kubernetes Master&lt;/li&gt;
&lt;li&gt;For Kubernetes Slaves
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ansible-galaxy init &amp;lt;role_name&amp;gt;

ansible-galaxy init kube_cluster
ansible-galaxy init k8s_master
ansible-galaxy init k8s_slave
ansible-galaxy init wordpress_mysql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  STEP 3 : Write role for Kubernetes Cluster
&lt;/h3&gt;

&lt;p&gt;🔶 Go inside the tasks folder. We have to write entire tasks inside this folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /roles/kube_cluster/tasks

vim main.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;🔶 I am going to create cluster over &lt;code&gt;Amazon Linux instances&lt;/code&gt;.&lt;br&gt;
Write below source code inside it-&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- name: Installing boto &amp;amp; boto3 libraries
  pip:
    name: "{{ item }}"
    state: present
  loop: "{{ lib_names }}"

- name: Creating Security Group for K8s Cluster
  ec2_group:
    name: "{{ sg_name }}"
    description: Security Group for allowing all port
    region: "{{ region_name }}"
    aws_access_key: "{{ access_key }}"
    aws_secret_key: "{{ secret_key }}"
    rules:
    - proto: all
      cidr_ip: 0.0.0.0/0
    rules_egress:
    - proto: all
      cidr_ip: 0.0.0.0/0

- name: Launching three EC2 instances on AWS
  ec2:
    key_name: "{{ keypair }}"
    instance_type: "{{ instance_flavour }}"
    image: "{{ ami_id }}"
    wait: true
    group: "{{ sg_name }}"
    count: 1
    vpc_subnet_id: "{{ subnet_name }}"
    assign_public_ip: yes
    region: "{{ region_name }}"
    state: present
    aws_access_key: "{{ access_key }}"
    aws_secret_key: "{{ secret_key }}"
    instance_tags:
      Name: "{{ item }}"
  register: ec2
  loop: "{{ instance_tag }}"

- name: Add 1st instance to host group ec2_master
    add_host:
    hostname: "{{ ec2.results[0].instances[0].public_ip }}"
    groupname: ec2_master

- name: Add 2nd instance to host group ec2_slave
  add_host:
    hostname: "{{ ec2.results[1].instances[0].public_ip }}"
    groupname: ec2_slave

- name: Add 3rd instance to host group ec2_slave
  add_host:
    hostname: "{{ ec2.results[2].instances[0].public_ip }}"
    groupname: ec2_slave

- name: Waiting for SSH
  wait_for:
    host: "{{ ec2.results[2].instances[0].public_dns_name }}"
    port: 22
    state: started

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Explanation of Source Code:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We are using &lt;code&gt;pip&lt;/code&gt; module to install two packages — &lt;code&gt;boto&lt;/code&gt; &amp;amp; &lt;code&gt;boto3&lt;/code&gt;, because these packages has the capability to contact to AWS to launch the EC2 instances. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ec2_group&lt;/code&gt; module to create Security Group on AWS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ec2&lt;/code&gt; module to launch instance on AWS. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;register&lt;/code&gt; keyword will store all the Metadata in a variable called &lt;code&gt;ec2&lt;/code&gt; so that in future we can parse the required information from it. &lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;loop&lt;/code&gt; which again using one variable which contains one list. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;item&lt;/code&gt; keyword we are calling the list values one after another.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;add_host&lt;/code&gt; module which has the capability to create one dynamic inventory while running the playbook. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;hostname&lt;/code&gt; keyword tells the values to store in the dynamic host group.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;wait_for&lt;/code&gt; module to hold the playbook for few seconds till all the node’s SSH service started.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;access key&lt;/code&gt; and &lt;code&gt;secret key&lt;/code&gt; are stored inside &lt;code&gt;vault&lt;/code&gt; files to hide it from other users.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🔶 Go inside the vars folder. We have to write entire variables inside this folder. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We can directly mention variables inside tasks file but it is good practice to write them inside &lt;code&gt;vars&lt;/code&gt; files so that we can change according to our requirements.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /roles/kube_cluster/vars

vim main.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Write below source code inside it-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;instance_tag:
        - master
        - slave1
        - slave2

lib_names:
        - boto
        - boto3

sg_name: Allow_All_SG
region_name: ap-south-1
subnet_name: subnet-49f0e521
ami_id: ami-010aff33ed5991201
keypair: awskey
instance_flavour: t2.small
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  STEP 4 : Write role for Kubernetes Master
&lt;/h3&gt;

&lt;p&gt;🔶 Following are the steps which have to include in role for configuring the k8s master-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Installing docker and iproute-tc&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configuring the Yum repo for Kubernetes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Installing kubeadm, kubelet &amp;amp; kubectl program&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enabling the docker and Kubernetes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pulling the config images&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configuring the docker daemon.json file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Restarting the docker service&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configuring the Ip tables and refreshing sysctl&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Starting kubeadm service&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Setting HOME directory for .kube Directory&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copying file config file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Installing Addons e.g flannel&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Creating the token&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Store output of token in a file.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;🔶 Go inside the tasks folder. We have to write entire tasks inside this folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /roles/k8s_master/tasks

vim main.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Write below source code inside it-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- name: "Installing docker and iproute-tc"
  package:
     name:
         - docker
         - iproute-tc
     state: present

- name: "Configuring the Yum repo for kubernetes"
  yum_repository:
     name: kubernetes
     description: Yum for k8s
     baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
     enabled: yes
     gpgcheck: yes
     repo_gpgcheck: yes
     gpgkey: https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

- name: "Installing kubeadm,kubelet kubectl program"
  yum:
     name:
        - kubelet
        - kubectl
        - kubeadm
     state: present

- name: "Enabling the docker and kubenetes"
  service:
     name: "{{ item }}"
     state: started
     enabled: yes
  loop:
        - kubelet
        - docker

- name: "Pulling the config images"
  shell: kubeadm config images pull

- name: "Confuring the docker daemon.json file"
  copy:
    dest: /etc/docker/daemon.json
    content: |
      {
      "exec-opts": ["native.cgroupdriver=systemd"]
      }

- name: "Restarting the docker service"
  service:
     name: docker
     state: restarted

- name: "Configuring the Ip tables and refreshing sysctl"
  copy:
    dest: /etc/docker/daemon.json
    content: |
      {
      "exec-opts": ["native.cgroupdriver=systemd"]
      }

- name: "systemctl"
  shell: "sysctl --system"

- name: "Starting kubeadm service"
  shell: "kubeadm init  --ignore-preflight-errors=all"

- name: "Creating .kube Directory"
  file:
     path: $HOME/.kube
     state: directory

- name: "Copying file config file"
  shell: "cp -i /etc/kubernetes/admin.conf $HOME/.kube/config"
  ignore_errors: yes

- name: "Installing Addons e.g flannel"
  shell: "kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml"

- name: "Creating the token"
  shell: "kubeadm token create --print-join-command"
  register: token

- debug:
       msg: "{{ token.stdout }}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Explanation of Source Code:
&lt;/h4&gt;

&lt;p&gt;1.We need to install &lt;code&gt;kubeadm&lt;/code&gt; program on our master node to setup K8s cluster.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We are installing &lt;code&gt;Docker&lt;/code&gt;, &lt;code&gt;Kubeadm&lt;/code&gt; &amp;amp; &lt;code&gt;iproute-tc&lt;/code&gt; packages on our Master Instance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;service&lt;/code&gt; module is used to start the docker &amp;amp; kubelet service. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;command&lt;/code&gt; module to run kubeadm command which will pull all the Docker Images required to run Kubernetes Cluster. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We need to change our Docker default cgroup to &lt;code&gt;systemd&lt;/code&gt;, otherwise kubeadm won't be able to setup K8s cluster. To do that at first using &lt;code&gt;copy&lt;/code&gt; module we are creating one file &lt;code&gt;/etc/docker/daemon.json&lt;/code&gt; &amp;amp; putting some content in it. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next using &lt;code&gt;command&lt;/code&gt; module we are initializing the cluster &amp;amp; then using &lt;code&gt;shell&lt;/code&gt; module we are setting up &lt;code&gt;kubectl&lt;/code&gt; command on our Master Node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next using &lt;code&gt;command&lt;/code&gt; module I deployed &lt;code&gt;Flannel&lt;/code&gt; on the Kubernetes Cluster so that it create the overlay network setup.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Also the 2nd &lt;code&gt;command&lt;/code&gt; module is used to get the token for the slave node to join the cluster. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using &lt;code&gt;register&lt;/code&gt; I stored the output of 2nd &lt;code&gt;command&lt;/code&gt; module in a variable called &lt;code&gt;token&lt;/code&gt;. Now this token variable contain the command that we need to run on slave node, so that it joins the master node.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  STEP 5 : Write role for Kubernetes Slaves
&lt;/h3&gt;

&lt;p&gt;🔶 Following are the steps which have to include in role for configuring the k8s slaves-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Installing docker and iproute-tc&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configuring the Yum repo for Kubernetes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Installing kubeadm,kubelet kubectl program&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enabling the docker and Kubernetes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pulling the config images&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configuring the docker daemon.json file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Restarting the docker service&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configuring the IP tables and refreshing sysctl&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy the join command which we store while configuring master&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;🔶 Go inside the tasks folder. We have to write entire tasks inside this folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /roles/k8s_slave/tasks

vim main.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Write below source code inside it-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- name: "Installing docker and iproute-tc"
  package:
     name:
         - docker
         - iproute-tc
     state: present

- name: "Configuring the Yum repo for kubernetes"
  yum_repository:
     name: kubernetes
     description: Yum for k8s
     baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
     enabled: yes
     gpgcheck: yes
     repo_gpgcheck: yes
     gpgkey: https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

- name: "Installing kubeadm,kubelet kubectl program"
  yum:
     name:
        - kubelet
        - kubectl
        - kubeadm
     state: present

- name: "Enabling the docker and kubenetes"
  service:
     name: "{{ item }}"
     state: started
     enabled: yes
  loop:
        - kubelet
        - docker

- name: "Pulling the config images"
  shell: kubeadm config images pull

- name: "Confuring the docker daemon.json file"
  copy:
    dest: /etc/docker/daemon.json
    content: |
      {
      "exec-opts": ["native.cgroupdriver=systemd"]
      }

- name: "Restarting the docker service"
  service:
     name: docker
     state: restarted

- name: "Configuring the Ip tables and refreshing sysctl"
  copy:
    dest: /etc/sysctl.d/k8s.conf
    content: |
      net.bridge.bridge-nf-call-ip6tables = 1
      net.bridge.bridge-nf-call-iptables = 1

- name: "systemctl"
  shell: "sysctl --system"

- name: joining to Master
  command: "{{ hostvars[groups['ec2_master'][0]]['token']['stdout'] }}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  STEP 6 : Write role for Wordpress and MySQL Setup
&lt;/h3&gt;

&lt;p&gt;🔶 Following are the steps which have to include in role for configuring the Wordpress-&lt;/p&gt;

&lt;p&gt;🔶 Go inside the &lt;code&gt;files&lt;/code&gt; folder of &lt;code&gt;wordpress_mysql&lt;/code&gt; role. We have to write entire configuration files inside this folder.&lt;br&gt;
🔶 We have to create 5 files here to create pods, setup of PVC and secrets' file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /roles/wordpress_mysql/files

vim wordpress.yml

vim pvc_wordpress.yml

vim mysql.yml

vim pvc_mysql.yml

vim secret.yml

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 Write Below source to configure &lt;code&gt;Wordpress&lt;/code&gt; installation part inside &lt;code&gt;wordpress.yml&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: v1
kind: Service
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  ports:
    - port: 80
      nodePort: 30333
  selector:
    app: wordpress
    tier: frontend
  type: LoadBalancer
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: frontend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: frontend
    spec:
      volumes:
      - name: wordpress-persistent-storage
        persistentVolumeClaim:
          claimName: wordpress-pv-claim
      containers:
      - image: wordpress:4.8-apache
        name: wordpress
        env:
        - name: WORDPRESS_DB_HOST
          value: wordpress-mysql
        - name: WORDPRESS_DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysqlsecret
              key: password
        ports:
        - containerPort: 80
          name: wordpress
        volumes:
        volumeMounts:
        - name: wordpress-persistent-storage
          mountPath: /var/www/html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 Write Below source to setup PVC for Wordpress in &lt;code&gt;pvc_wordpress.yml&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: v1
kind: PersistentVolumeClaim
metadata:
   name: wordpress-pv-claim
   labels:
        app: wordpress
        tier: frontend
spec:
   storageClassName: ""
   resources:
        requests:
             storage: 1Gi
   accessModes:
     - ReadWriteOnce
---

apiVersion: v1
kind: PersistentVolume
metadata:
  name: wordpress-pv
spec:
  storageClassName: ""
  capacity:
     storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /wordpressdata
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 Write Below source to configure MYSQL installation part inside &lt;code&gt;mysql.yml&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: v1
kind: Service
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  ports:
    - port: 3306
  selector:
    app: wordpress
    tier: mysql
  clusterIP: None
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: mysql
    spec:
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysqlsecret
              key: password
        - name: MYSQL_USER
          value: udit
        - name: MYSQL_DATABASE
          value: task23db
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 Write Below source to setup PVC for MySQL in &lt;code&gt;pvc_mysql.yml&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: v1
kind: PersistentVolumeClaim
metadata:
   name: mysql-pv-claim
   labels:
        app: wordpress
        tier: mysql
spec:
   storageClassName: ""
   resources:
        requests:
             storage: 1Gi
   accessModes:
     - ReadWriteOnce
---

apiVersion: v1
kind: PersistentVolume
metadata:
  name: msql-pv
spec:
  storageClassName: ""
  capacity:
     storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /mysqldata
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 Lastly, create a secrete file &lt;code&gt;secret.yml&lt;/code&gt; which will contain the password of the MySQL database-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: v1
kind: Secret
metadata:
  name: Suraj
data:
   password: Mysqlpass@2001
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 Go inside the tasks folder. We have to write entire tasks inside this folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /roles/wordpress_mysql/tasks

vim main.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 Write below source code inside it-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  - name: Copying Wordpress and MySQL files to K8s Master Node
    copy:
        src: "{{ item }}"
        dest: /root/
    loop:
        - mysql.yml
        - pvc_mysql.yml
        - pvc_wordpress.yml
        - secret.yml
        - wordpress.yml

  - name: Creating directory over which MySQL container mounts the PersistentVolume at /var/lib/mysql.
    file:
        path: /mysqldata
        state: directory

  - name: Creating directory over which WordPress container mounts the PersistentVolume at /var/www/html.
    file:
        path: /wordpressdata
        state: directory


  - name: Configuration and Setup of Wordpress and MySQL
    shell: "kubectl create -f /root/{{ item }}"
    loop:
        - mysql.yml
        - pvc_mysql.yml
        - pvc_wordpress.yml
        - wordpress.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  STEP 7 : Write Ansible Vault Files
&lt;/h3&gt;

&lt;p&gt;🔶 Go to your roles workspace&lt;br&gt;
🔶 Run below command and create vault file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ansible-vault create &amp;lt;filename&amp;gt;.yml

ansible-vault create cred.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 It will ask to provide one vault password &amp;amp; provide as per your choice.&lt;br&gt;
🔶 Then, open it with editor, create two variables in this file &amp;amp; put your AWS &lt;code&gt;access key&lt;/code&gt; &amp;amp; &lt;code&gt;secret key&lt;/code&gt; as values. &lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;access_key: ABCDEFGHIJKLMN
secret_key: abcdefghijklmn12345
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 Save the file with command &lt;code&gt;(:wq)&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  STEP 8 : Create Setup file
&lt;/h3&gt;

&lt;p&gt;Now it's finally the time to create the &lt;code&gt;setup.yml&lt;/code&gt; file inside same workspace which we gonna run to setup this entire infrastructure on AWS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- hosts: localhost
  gather_facts: no
  vars_files:
         - cred.yml
  tasks:
         - name: "Running kube_cluster role"
           include_role:
                name: kube_cluster


- hosts: ec2_master
  gather_facts: no
  tasks:
    - name: Running K8s_Master Role
      include_role:
        name: k8s_master

- hosts: ec2_slave
  gather_facts: no
  tasks:
    - name: Running K8s_Slave Role
      include_role:
        name: k8s_slave

- hosts: ec2_master
  gather_facts: no
  tasks:
    - name: Running Wordpress-MySQL Role
      include_role:
        name: wordpress_mysql

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;🔶 Write proper &lt;code&gt;hostname&lt;/code&gt;, &lt;code&gt;vault file name&lt;/code&gt; and &lt;code&gt;role name&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  STEP 9 : RUN your Ansible Playbook
&lt;/h3&gt;

&lt;p&gt;🔶 use below commands to run your ansible playbook.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ansible-playbook setup.yml --ask-vault-pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 Next it will prompt you to pass the password of your Ansible Vault (cred.yml file), provide your password.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fld3ws1d8924uk8my86jt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fld3ws1d8924uk8my86jt.png" alt="root@localhost__roles 01-09-2021 02_48_38 PM"&gt;&lt;/a&gt;&lt;br&gt;
 &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdgb8fos6gc47z1d042zb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdgb8fos6gc47z1d042zb.png" alt="root@localhost__roles 01-09-2021 02_49_15 PM"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa77ho2409cm8gq3sh7kd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa77ho2409cm8gq3sh7kd.png" alt="root@localhost__roles 01-09-2021 02_49_46 PM"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuhw9qqk65eeg14q75enb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuhw9qqk65eeg14q75enb.png" alt="root@localhost__roles 04-09-2021 10_56_25 AM"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;h5&gt;
  
  
  YAY!, IT RUN SUCCESSFULLY AND SETUP ENTIRE INFRASTRUCTURE
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu5ex40ovdf3i6bbhn6hh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu5ex40ovdf3i6bbhn6hh.png" alt="Connect to instance _ EC2 Management Console - Google Chrome 01-09-2021 02_57_17 PM"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  STEP 8 : TESTING...
&lt;/h3&gt;

&lt;p&gt;🔶 Now lets check our multi-node cluster is using below commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get nodes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk6nvsc2xhy6msybh71b4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk6nvsc2xhy6msybh71b4.png" alt="Select root@ip-172-31-35-184_~ 01-09-2021 02_53_32 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  🔶 Here we can see our who cluster is launched successfully and our all nodes is ready phase.
&lt;/h6&gt;

&lt;p&gt;🔶 Now once your pods are ready, then you can take the public of any node either master or slave with the exposed port you will landed to the Wordpress login page and then enter password and username of the mysql database and hit the run installation button. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia-exp1.licdn.com%2Fdms%2Fimage%2FC4D12AQHI3rjKrMsInA%2Farticle-inline_image-shrink_1000_1488%2F0%2F1619173264511%3Fe%3D1635984000%26v%3Dbeta%26t%3DwEnFMEJAXEeo8ApTznSo11MwKGqqQNpOZAt5Z80FRGw" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia-exp1.licdn.com%2Fdms%2Fimage%2FC4D12AQHI3rjKrMsInA%2Farticle-inline_image-shrink_1000_1488%2F0%2F1619173264511%3Fe%3D1635984000%26v%3Dbeta%26t%3DwEnFMEJAXEeo8ApTznSo11MwKGqqQNpOZAt5Z80FRGw" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia-exp1.licdn.com%2Fdms%2Fimage%2FC4D12AQGdGcY2TIK2pQ%2Farticle-inline_image-shrink_1000_1488%2F0%2F1619173275736%3Fe%3D1635984000%26v%3Dbeta%26t%3DtweyV51yrIL7wFBWw4_ogB_CYKy7RPwhwW0zXZeEo0w" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia-exp1.licdn.com%2Fdms%2Fimage%2FC4D12AQGdGcY2TIK2pQ%2Farticle-inline_image-shrink_1000_1488%2F0%2F1619173275736%3Fe%3D1635984000%26v%3Dbeta%26t%3DtweyV51yrIL7wFBWw4_ogB_CYKy7RPwhwW0zXZeEo0w" alt="image"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;🔶 YAY! Your Wordpress application is ready !! &lt;/p&gt;

&lt;h5&gt;
  
  
  GitHub Link: &lt;a href="https://github.com/surajwarbhe/Ansible-Playbook-K8-Wordpress-MySQL" rel="noopener noreferrer"&gt;https://github.com/surajwarbhe/Ansible-Playbook-K8-Wordpress-MySQL&lt;/a&gt;
&lt;/h5&gt;

&lt;h5&gt;
  
  
  LinkedIn profile: &lt;a href="https://www.linkedin.com/in/suraj-warbhe/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/suraj-warbhe/&lt;/a&gt;
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyybi3w53tdcy9ct6uk38.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyybi3w53tdcy9ct6uk38.gif" alt="68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f776174747061642d6d656469612d736572766963652f53746f7279496d6167652f69346776387341505f5f586746673d3d2d3931363135303430372e3136316636643238343363343039646134303138393"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>mysql</category>
      <category>ansible</category>
      <category>devops</category>
    </item>
    <item>
      <title>Deploying Multi-Node Kubernetes Cluster on AWS Using Ansible Automation</title>
      <dc:creator>Suraj Warbhe</dc:creator>
      <pubDate>Wed, 01 Sep 2021 11:31:55 +0000</pubDate>
      <link>https://dev.to/surajwarbhe/deploying-multi-node-kubernetes-cluster-on-aws-using-ansible-automation-1b7e</link>
      <guid>https://dev.to/surajwarbhe/deploying-multi-node-kubernetes-cluster-on-aws-using-ansible-automation-1b7e</guid>
      <description>&lt;h1&gt;
  
  
  USE-CASE
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Create Ansible Playbook to launch 3 AWS EC2 Instance&lt;/li&gt;
&lt;li&gt;Create Ansible Playbook to configure Docker over those instances&lt;/li&gt;
&lt;li&gt;Create Playbook to configure K8S Master, K8S Worker Nodes on the above created EC2 Instances using kubeadm&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Pre-requisite: (FOR RHEL-8)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Controller node should be setup with ansible installation and configuration, when controller node is RHEL8&lt;/li&gt;
&lt;li&gt;Create one &lt;code&gt;IAM&lt;/code&gt; user having Administrator Access and note down their &lt;code&gt;access key&lt;/code&gt; and &lt;code&gt;secret key&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create one &lt;code&gt;Key pair&lt;/code&gt; in &lt;code&gt;(.pem)&lt;/code&gt; format on AWS Cloud, download it in your local system and transfer it over RHEL-8 through &lt;code&gt;WinSCP&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  STEP 1 : Ansible Installation and Configuration
&lt;/h3&gt;

&lt;p&gt;Install Ansible on Base OS (RHEL8), configure ansible configuration file. &lt;br&gt;
To do this use below commands-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yum install python3 -y

pip3 install ansible -y

vim /etc/ansible/ansible.cfg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOTE: &lt;code&gt;Python&lt;/code&gt; should be installed on your OS to setup Ansible.&lt;br&gt;
Write below commands in your configuration &lt;code&gt;ansible.cfg&lt;/code&gt; file. For this you can prefer any editor like &lt;code&gt;vi&lt;/code&gt;, &lt;code&gt;vim&lt;/code&gt;, &lt;code&gt;gedit&lt;/code&gt;-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[defaults]
inventory=/root/ip.txt  #inventory path
host_key_checking=False
command_warnings=False
deprecation_warnings=False
ask_pass=False
roles_path= /root/roles      #roles path
force_valid_group_names = ignore
private_key_file= /root/awskey.pem   #your key-pair 
remote_user=ec2-user

[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  STEP 2 : Create Ansible Roles
&lt;/h3&gt;

&lt;p&gt;🔶 Go inside your roles workspace&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /roles
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use Below commands to create 3 different roles&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For Kubernetes Cluster&lt;/li&gt;
&lt;li&gt;For Kubernetes Master&lt;/li&gt;
&lt;li&gt;For Kubernetes Slaves
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ansible-galaxy init &amp;lt;role_name&amp;gt;

ansible-galaxy init kube_cluster
ansible-galaxy init k8s_master
ansible-galaxy init k8s_slave
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  STEP 3 : Write role for Kubernetes Cluster
&lt;/h3&gt;

&lt;p&gt;🔶 Go inside the tasks folder. We have to write entire tasks inside this folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /roles/kube_cluster/tasks

vim main.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;🔶 I am going to create cluster over &lt;code&gt;Amazon Linux instances&lt;/code&gt;.&lt;br&gt;
Write below source code inside it-&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- name: Installing boto &amp;amp; boto3 libraries
  pip:
    name: "{{ item }}"
    state: present
  loop: "{{ lib_names }}"

- name: Creating Security Group for K8s Cluster
  ec2_group:
    name: "{{ sg_name }}"
    description: Security Group for allowing all port
    region: "{{ region_name }}"
    aws_access_key: "{{ access_key }}"
    aws_secret_key: "{{ secret_key }}"
    rules:
    - proto: all
      cidr_ip: 0.0.0.0/0
    rules_egress:
    - proto: all
      cidr_ip: 0.0.0.0/0

- name: Launching three EC2 instances on AWS
  ec2:
    key_name: "{{ keypair }}"
    instance_type: "{{ instance_flavour }}"
    image: "{{ ami_id }}"
    wait: true
    group: "{{ sg_name }}"
    count: 1
    vpc_subnet_id: "{{ subnet_name }}"
    assign_public_ip: yes
    region: "{{ region_name }}"
    state: present
    aws_access_key: "{{ access_key }}"
    aws_secret_key: "{{ secret_key }}"
    instance_tags:
      Name: "{{ item }}"
  register: ec2
  loop: "{{ instance_tag }}"

- name: Add 1st instance to host group ec2_master
    add_host:
    hostname: "{{ ec2.results[0].instances[0].public_ip }}"
    groupname: ec2_master

- name: Add 2nd instance to host group ec2_slave
  add_host:
    hostname: "{{ ec2.results[1].instances[0].public_ip }}"
    groupname: ec2_slave

- name: Add 3rd instance to host group ec2_slave
  add_host:
    hostname: "{{ ec2.results[2].instances[0].public_ip }}"
    groupname: ec2_slave

- name: Waiting for SSH
  wait_for:
    host: "{{ ec2.results[2].instances[0].public_dns_name }}"
    port: 22
    state: started

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Explanation of Source Code:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We are using &lt;code&gt;pip&lt;/code&gt; module to install two packages — &lt;code&gt;boto&lt;/code&gt; &amp;amp; &lt;code&gt;boto3&lt;/code&gt;, because these packages has the capability to contact to AWS to launch the EC2 instances. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ec2_group&lt;/code&gt; module to create Security Group on AWS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ec2&lt;/code&gt; module to launch instance on AWS. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;register&lt;/code&gt; keyword will store all the Metadata in a variable called &lt;code&gt;ec2&lt;/code&gt; so that in future we can parse the required information from it. &lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;loop&lt;/code&gt; which again using one variable which contains one list. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;item&lt;/code&gt; keyword we are calling the list values one after another.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;add_host&lt;/code&gt; module which has the capability to create one dynamic inventory while running the playbook. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;hostname&lt;/code&gt; keyword tells the values to store in the dynamic host group.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;wait_for&lt;/code&gt; module to hold the playbook for few seconds till all the node’s SSH service started.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;access key&lt;/code&gt; and &lt;code&gt;secret key&lt;/code&gt; are stored inside &lt;code&gt;vault&lt;/code&gt; files to hide it from other users.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🔶 Go inside the vars folder. We have to write entire variables inside this folder. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We can directly mention variables inside tasks file but it is good practice to write them inside &lt;code&gt;vars&lt;/code&gt; files so that we can change according to our requirements.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /roles/kube_cluster/vars

vim main.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Write below source code inside it-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;instance_tag:
        - master
        - slave1
        - slave2

lib_names:
        - boto
        - boto3

sg_name: Allow_All_SG
region_name: ap-south-1
subnet_name: subnet-49f0e521
ami_id: ami-010aff33ed5991201
keypair: awskey
instance_flavour: t2.small
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  STEP 4 : Write role for Kubernetes Master
&lt;/h3&gt;

&lt;p&gt;🔶 Following are the steps which have to include in role for configuring the k8s master-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Installing docker and iproute-tc&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configuring the Yum repo for Kubernetes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Installing kubeadm, kubelet &amp;amp; kubectl program&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enabling the docker and Kubernetes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pulling the config images&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configuring the docker daemon.json file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Restarting the docker service&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configuring the Ip tables and refreshing sysctl&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Starting kubeadm service&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Setting HOME directory for .kube Directory&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copying file config file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Installing Addons e.g flannel&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Creating the token&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Store output of token in a file.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;🔶 Go inside the tasks folder. We have to write entire tasks inside this folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /roles/k8s_master/tasks

vim main.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Write below source code inside it-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- name: "Installing docker and iproute-tc"
  package:
     name:
         - docker
         - iproute-tc
     state: present

- name: "Configuring the Yum repo for kubernetes"
  yum_repository:
     name: kubernetes
     description: Yum for k8s
     baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
     enabled: yes
     gpgcheck: yes
     repo_gpgcheck: yes
     gpgkey: https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

- name: "Installing kubeadm,kubelet kubectl program"
  yum:
     name:
        - kubelet
        - kubectl
        - kubeadm
     state: present

- name: "Enabling the docker and kubenetes"
  service:
     name: "{{ item }}"
     state: started
     enabled: yes
  loop:
        - kubelet
        - docker

- name: "Pulling the config images"
  shell: kubeadm config images pull

- name: "Confuring the docker daemon.json file"
  copy:
    dest: /etc/docker/daemon.json
    content: |
      {
      "exec-opts": ["native.cgroupdriver=systemd"]
      }

- name: "Restarting the docker service"
  service:
     name: docker
     state: restarted

- name: "Configuring the Ip tables and refreshing sysctl"
  copy:
    dest: /etc/docker/daemon.json
    content: |
      {
      "exec-opts": ["native.cgroupdriver=systemd"]
      }

- name: "systemctl"
  shell: "sysctl --system"

- name: "Starting kubeadm service"
  shell: "kubeadm init  --ignore-preflight-errors=all"

- name: "Creating .kube Directory"
  file:
     path: $HOME/.kube
     state: directory

- name: "Copying file config file"
  shell: "cp -i /etc/kubernetes/admin.conf $HOME/.kube/config"
  ignore_errors: yes

- name: "Installing Addons e.g flannel"
  shell: "kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml"

- name: "Creating the token"
  shell: "kubeadm token create --print-join-command"
  register: token

- debug:
       msg: "{{ token.stdout }}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Explanation of Source Code:
&lt;/h4&gt;

&lt;p&gt;1.We need to install &lt;code&gt;kubeadm&lt;/code&gt; program on our master node to setup K8s cluster.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We are installing &lt;code&gt;Docker&lt;/code&gt;, &lt;code&gt;Kubeadm&lt;/code&gt; &amp;amp; &lt;code&gt;iproute-tc&lt;/code&gt; packages on our Master Instance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;service&lt;/code&gt; module is used to start the docker &amp;amp; kubelet service. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;command&lt;/code&gt; module to run kubeadm command which will pull all the Docker Images required to run Kubernetes Cluster. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We need to change our Docker default cgroup to &lt;code&gt;systemd&lt;/code&gt;, otherwise kubeadm won't be able to setup K8s cluster. To do that at first using &lt;code&gt;copy&lt;/code&gt; module we are creating one file &lt;code&gt;/etc/docker/daemon.json&lt;/code&gt; &amp;amp; putting some content in it. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next using &lt;code&gt;command&lt;/code&gt; module we are initializing the cluster &amp;amp; then using &lt;code&gt;shell&lt;/code&gt; module we are setting up &lt;code&gt;kubectl&lt;/code&gt; command on our Master Node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next using &lt;code&gt;command&lt;/code&gt; module I deployed &lt;code&gt;Flannel&lt;/code&gt; on the Kubernetes Cluster so that it create the overlay network setup.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Also the 2nd &lt;code&gt;command&lt;/code&gt; module is used to get the token for the slave node to join the cluster. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using &lt;code&gt;register&lt;/code&gt; I stored the output of 2nd &lt;code&gt;command&lt;/code&gt; module in a variable called &lt;code&gt;token&lt;/code&gt;. Now this token variable contain the command that we need to run on slave node, so that it joins the master node.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  STEP 5 : Write role for Kubernetes Slaves
&lt;/h3&gt;

&lt;p&gt;🔶 Following are the steps which have to include in role for configuring the k8s slaves-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Installing docker and iproute-tc&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configuring the Yum repo for Kubernetes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Installing kubeadm,kubelet kubectl program&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enabling the docker and Kubernetes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pulling the config images&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configuring the docker daemon.json file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Restarting the docker service&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configuring the IP tables and refreshing sysctl&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy the join command which we store while configuring master&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;🔶 Go inside the tasks folder. We have to write entire tasks inside this folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /roles/k8s_slave/tasks

vim main.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Write below source code inside it-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- name: "Installing docker and iproute-tc"
  package:
     name:
         - docker
         - iproute-tc
     state: present

- name: "Configuring the Yum repo for kubernetes"
  yum_repository:
     name: kubernetes
     description: Yum for k8s
     baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
     enabled: yes
     gpgcheck: yes
     repo_gpgcheck: yes
     gpgkey: https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

- name: "Installing kubeadm,kubelet kubectl program"
  yum:
     name:
        - kubelet
        - kubectl
        - kubeadm
     state: present

- name: "Enabling the docker and kubenetes"
  service:
     name: "{{ item }}"
     state: started
     enabled: yes
  loop:
        - kubelet
        - docker

- name: "Pulling the config images"
  shell: kubeadm config images pull

- name: "Confuring the docker daemon.json file"
  copy:
    dest: /etc/docker/daemon.json
    content: |
      {
      "exec-opts": ["native.cgroupdriver=systemd"]
      }

- name: "Restarting the docker service"
  service:
     name: docker
     state: restarted

- name: "Configuring the Ip tables and refreshing sysctl"
  copy:
    dest: /etc/sysctl.d/k8s.conf
    content: |
      net.bridge.bridge-nf-call-ip6tables = 1
      net.bridge.bridge-nf-call-iptables = 1

- name: "systemctl"
  shell: "sysctl --system"

- name: joining to Master
  command: "{{ hostvars[groups['ec2_master'][0]]['token']['stdout'] }}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  STEP 6 : Write Ansible Vault Files
&lt;/h3&gt;

&lt;p&gt;🔶 Go to your roles workspace&lt;br&gt;
🔶 Run below command and create vault file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ansible-vault create &amp;lt;filename&amp;gt;.yml

ansible-vault create cred.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 It will ask to provide one vault password &amp;amp; provide as per your choice.&lt;br&gt;
🔶 Then, open it with editor, create two variables in this file &amp;amp; put your AWS &lt;code&gt;access key&lt;/code&gt; &amp;amp; &lt;code&gt;secret key&lt;/code&gt; as values. &lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;access_key: ABCDEFGHIJKLMN
secret_key: abcdefghijklmn12345
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 Save the file with command &lt;code&gt;(:wq)&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  STEP 7 : Create Setup file
&lt;/h3&gt;

&lt;p&gt;Now it's finally the time to create the &lt;code&gt;setup.yml&lt;/code&gt; file inside same workspace which we gonna run to setup this entire infrastructure on AWS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- hosts: localhost
  gather_facts: no
  vars_files:
         - cred.yml
  tasks:
         - name: "Running kube_cluster role"
           include_role:
                name: kube_cluster


- hosts: ec2_master
  gather_facts: no
  tasks:
    - name: Running K8s_Master Role
      include_role:
        name: k8s_master

- hosts: ec2_slave
  gather_facts: no
  tasks:
    - name: Running K8s_Slave Role
      include_role:
        name: k8s_slave
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;🔶 Write proper &lt;code&gt;hostname&lt;/code&gt;, &lt;code&gt;vault file name&lt;/code&gt; and &lt;code&gt;role name&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  STEP 8 : RUN your Ansible Playbook
&lt;/h3&gt;

&lt;p&gt;🔶 use below commands to run your ansible playbook.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ansible-playbook setup.yml --ask-vault-pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 Next it will prompt you to pass the password of your Ansible Vault (cred.yml file), provide your password.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fld3ws1d8924uk8my86jt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fld3ws1d8924uk8my86jt.png" alt="root@localhost__roles 01-09-2021 02_48_38 PM"&gt;&lt;/a&gt;&lt;br&gt;
 &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdgb8fos6gc47z1d042zb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdgb8fos6gc47z1d042zb.png" alt="root@localhost__roles 01-09-2021 02_49_15 PM"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa77ho2409cm8gq3sh7kd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa77ho2409cm8gq3sh7kd.png" alt="root@localhost__roles 01-09-2021 02_49_46 PM"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  YAY!, IT RUN SUCCESSFULLY AND SETUP ENTIRE INFRASTRUCTURE
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu5ex40ovdf3i6bbhn6hh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu5ex40ovdf3i6bbhn6hh.png" alt="Connect to instance _ EC2 Management Console - Google Chrome 01-09-2021 02_57_17 PM"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  STEP 9 : TESTING...
&lt;/h3&gt;

&lt;p&gt;🔶 Now lets check our multi-node cluster is using below commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get nodes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk6nvsc2xhy6msybh71b4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk6nvsc2xhy6msybh71b4.png" alt="Select root@ip-172-31-35-184_~ 01-09-2021 02_53_32 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  🔶 Here we can see our who cluster is launched successfully and our all nodes is ready phase.
&lt;/h6&gt;

&lt;p&gt;🔶 Now lets create a deployment on master node&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create deployment myd --image=httpd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5w9w3hjsnzg5xg3rvlkg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5w9w3hjsnzg5xg3rvlkg.png" alt="root@ip-172-31-35-184_~ 01-09-2021 02_57_06 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔶 here we can see our deployment is created successfully&lt;/p&gt;

&lt;h5&gt;
  
  
  GitHub Link: &lt;a href="https://github.com/surajwarbhe/K8s-master-slave-on-aws" rel="noopener noreferrer"&gt;https://github.com/surajwarbhe/K8s-master-slave-on-aws&lt;/a&gt;
&lt;/h5&gt;

&lt;h5&gt;
  
  
  LinkedIn profile: &lt;a href="https://www.linkedin.com/in/suraj-warbhe/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/suraj-warbhe/&lt;/a&gt;
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyybi3w53tdcy9ct6uk38.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyybi3w53tdcy9ct6uk38.gif" alt="68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f776174747061642d6d656469612d736572766963652f53746f7279496d6167652f69346776387341505f5f586746673d3d2d3931363135303430372e3136316636643238343363343039646134303138393"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ansible</category>
      <category>kubernetes</category>
      <category>aws</category>
      <category>devops</category>
    </item>
    <item>
      <title>Ansible Playbook that will configure Docker &amp; dynamically update the inventory with newly created Docker Container IP</title>
      <dc:creator>Suraj Warbhe</dc:creator>
      <pubDate>Tue, 31 Aug 2021 07:51:56 +0000</pubDate>
      <link>https://dev.to/surajwarbhe/ansible-playbook-that-will-configure-docker-dynamically-update-the-inventory-with-newly-created-docker-container-ip-41fn</link>
      <guid>https://dev.to/surajwarbhe/ansible-playbook-that-will-configure-docker-dynamically-update-the-inventory-with-newly-created-docker-container-ip-41fn</guid>
      <description>&lt;h1&gt;
  
  
  STEPS: (For RHEL 8)
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Enable SSH in the Container using Dockerfile&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Build and Push this image to the Docker Hub&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ansible Play that will launch and configure the Docker Container and webserver inside it&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  STEP 1: Enable SSH in the Container using Dockerfile
&lt;/h2&gt;

&lt;p&gt;Dockerfile has two types of keyword that helps to configure Image.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Build Time: Executes at build time and in the build phase all run time commands are skipped. 
examples are &lt;code&gt;FROM&lt;/code&gt;, &lt;code&gt;RUN&lt;/code&gt;, etc.&lt;/li&gt;
&lt;li&gt;Run Time: Run time commands are &lt;code&gt;ENTRYPOINT&lt;/code&gt;, &lt;code&gt;CMD&lt;/code&gt;, etc.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  DockerFile
&lt;/h3&gt;

&lt;p&gt;It is compulsory to give the docker/image file name as &lt;code&gt;Dockerfile&lt;/code&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To use Base OS from container Image: Dockerfile Keyword: &lt;code&gt;FROM&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM centos:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;To run OS Specific command: Dockerfile keyword: &lt;code&gt;RUN&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RUN yum install openssh-server -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Installing OpenSSH-server
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RUN yum install openssh-server -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Configure SSH Server for password authentication
By Default password authentication is disabled we need to add the below string in the SSHd service configuration file to enable password authentication.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RUN echo "PasswordAuthentication yes" &amp;gt;&amp;gt; /etc/ssh/sshd_config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Generating Keys
For each of the key types (RSA, DSA, ECDSA, and ED25519) for which host keys do not exist, generate the host keys with the default key file path, an empty passphrase, default bits for the key type, and default comment.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RUN ssh-keygen -A
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Changing the Password of the root user
&lt;code&gt;chpasswd&lt;/code&gt; command is used to change the password although &lt;code&gt;passwd&lt;/code&gt; command can also do the same. But it changes the password of one user at a time so for multiple users, &lt;code&gt;chpasswd&lt;/code&gt; is used.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# RUN echo "user_name:password" | chpasswd
RUN echo "root:centos" | chpasswd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Default password for this image will be &lt;code&gt;centos&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;To start service at runtime
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CMD ["/usr/sbin/sshd", "-D"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Final Image:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM centos:latest
RUN yum install openssh-server -y
RUN yum install openssh-server -y
RUN echo "PasswordAuthentication yes" &amp;gt;&amp;gt; /etc/ssh/sshd_config
RUN ssh-keygen -A
RUN echo "root:centos" | chpasswd
CMD ["/usr/sbin/sshd", "-D"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  STEP 2 : Build and push Docker Image to the Docker Hub
&lt;/h2&gt;

&lt;p&gt;Use below command this build your created image&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t dockerhub_id/imagename:image_version fileLocation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  To push the image to the Docker registry.
&lt;/h4&gt;

&lt;p&gt;First, we need to give a username and password of the Docker Hub &lt;br&gt;
For this run the below command-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run below command to push your created Image&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker push dockerhub_id/imagename:image_version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;You can use my Docker Image to perform further task.&lt;br&gt;
To Pull my Docker image, use below command-&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker pull surajwarbhe/ssh_centos:v1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  STEP 3 : Ansible Configuration and Playbooks
&lt;/h2&gt;

&lt;h4&gt;
  
  
  1. Create an Inventory file
&lt;/h4&gt;

&lt;p&gt;🔶 Create an inventory file with the extension &lt;code&gt;(.txt)&lt;/code&gt; and leave it blank.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vim ip.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Create Ansible Configuration file
&lt;/h4&gt;

&lt;p&gt;🔶 Create a file with the extension &lt;code&gt;(.cfg)&lt;/code&gt; in the directory &lt;code&gt;/etc/ansible/&lt;/code&gt;, here I have a configuration file with named &lt;code&gt;ansible.cfg&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vim  /etc/ansible/ansible.cfg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 Write below statements in the configuration file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[defaults]
inventory=/root/ip.txt
host_key_checking=false
deprecation_warnings=false
command_warnings=false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Create and Run Ansible Playbook (To setup Docker)
&lt;/h4&gt;

&lt;p&gt;🔶 Create an Ansible playbook with an extension &lt;code&gt;(.yml)&lt;/code&gt; or &lt;code&gt;(.yaml)&lt;/code&gt;, here I have created a playbook with named &lt;code&gt;dockertask.yaml&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- hosts: localhost
  vars_prompt:
      - name: container_name
        prompt: "Docker Container Name: "
        private: no

  vars:
          - image_name: surajwarbhe/ssh_centos:v1

  tasks:
      - name: Creating Repo for yum
        yum_repository:
            name: docker
            file: docker
            description: Docker Yum Repo
            baseurl: https://download.docker.com/linux/centos/7/x86_64/stable/
            gpgcheck: no

      - name: Installing Python3...
        command: "yum -y install python3"
      - name: Installing Docker Software...
        command: "yum install -y  docker-ce --nobest"

      - name: Starting Docker services...
        service:
            name: "docker"
            state: started
            enabled: yes

      - name: Installing Docker Library...
        command: "pip3 install docker-py"

      - name: pull an image
        docker_image:
            name: "{{ image_name }}"
            source: pull

      - name: "Launching {{ container_name }} Container"
        docker_container:
            name: "{{ container_name }}"
            image: "{{ image_name }}"
            state: started
            interactive: yes
            detach: yes
            tty: yes

      - name: "Container Info"
        docker_container_info:
            name: "{{ container_name }}"
        register: dinfo

      - name: "Printing IP of Docker container..."
        debug:
              msg: "{{ dinfo.container.NetworkSettings.IPAddress}}"

      - name: updating ansible inventory  with new docker info.......
        blockinfile:
            path: "/root/ip.txt"
            block: |
                    [docker]
                    {{ dinfo['container']['NetworkSettings']['IPAddress'] }} ansible_user=root ansible_ssh_pass=centos  ansible_connection=ssh

  handlers:
  - name: docker
    yum:
        name: docker-ce
        state: present
        allow_downgrade: yes
        skip_broken: yes

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 To run the playbook use the below command-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ansible-playbook &amp;lt;filename&amp;gt;

ansible-playbook dockertask.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initially, it will ask us container name.&lt;br&gt;
I have provided container name as &lt;code&gt;Arth14&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwln2l5z1cnmjmofe684w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwln2l5z1cnmjmofe684w.png" alt="root@localhost_~_ansible_tasks 31-08-2021 09_48_59 AM"&gt;&lt;/a&gt;&lt;br&gt;
Yesss, Our playbook run successfully !&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;And we got a &lt;code&gt;IP address&lt;/code&gt; of newly created Docker Container as &lt;code&gt;172.17.0.3&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🔶 Let’s Check ip.txt file&lt;br&gt;
Earlier, we had leave ip.txt as empty but now it is updated dynamically with newly created &lt;code&gt;IP address&lt;/code&gt; Docker container.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2mc25d11xbpg675v496e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2mc25d11xbpg675v496e.png" alt="root@localhost_~_ansible_tasks 31-08-2021 09_56_10 AM"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  STEP 4 : Check connectivity with Docker Container
&lt;/h4&gt;

&lt;p&gt;We have to check ansible connectivity with newly created Docker Container so that we can perform &lt;code&gt;SSH&lt;/code&gt; and perform further operations on that. &lt;br&gt;
Use below command to check connectivity-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ansible all -m ping
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcnkqiwvj27vv9dtjqp2z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcnkqiwvj27vv9dtjqp2z.png" alt="root@localhost_~_ansible_tasks 31-08-2021 09_55_55 AM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you get &lt;code&gt;Success&lt;/code&gt; message in a green color and &lt;code&gt;Ping Pong&lt;/code&gt; at the end, it means everything is OKAY!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  STEP 5 : Configuration of Apache Webserver, Copying the testing Page, and Starting the Apache web service
&lt;/h4&gt;

&lt;p&gt;🔶 Create an Ansible playbook with an extension &lt;code&gt;(.yml)&lt;/code&gt; or &lt;code&gt;(.yaml)&lt;/code&gt;, here I have created a playbook with named &lt;code&gt;webserver.yaml&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- hosts: docker
  tasks:
    - name: "Installing Httpd service"
      package:
          name: "httpd"
          state: present

    - name: "Creating html file"
      copy:
          content : "&amp;lt;b&amp;gt;&amp;lt;center&amp;gt;HEY! TASK 14.2 Done successfully &amp;lt;/center&amp;gt;&amp;lt;/b&amp;gt;"
          dest: "/var/www/html/index.html"

    - name: "Starting Httpd Service"
      command: "/usr/sbin/httpd"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔶 To run the playbook use the below command-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ansible-playbook &amp;lt;filename&amp;gt;

ansible-playbook webserver.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0se46wapnpxzo6lxr7oy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0se46wapnpxzo6lxr7oy.png" alt="root@localhost_~_ansible_tasks 31-08-2021 09_56_45 AM"&gt;&lt;/a&gt;&lt;br&gt;
Yesss, Our playbook run successfully !&lt;/p&gt;
&lt;h4&gt;
  
  
  STEP 6 : Testing
&lt;/h4&gt;

&lt;p&gt;Use below command to test your configuration OR you can directly type your Docker container's IP address over Browser-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# curl &amp;lt;ip_address_of_Docker_container&amp;gt;

curl 172.17.0.3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu9u2hlg7qhrrd9os4z1a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu9u2hlg7qhrrd9os4z1a.png" alt="root@localhost_~_ansible_tasks 31-08-2021 10_15_50 AM"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feejaohv6pr6c6gcdq7wc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feejaohv6pr6c6gcdq7wc.png" alt="567 (2)"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;YAY! The Web-Server is configured successfully inside Container.&lt;/strong&gt; 💥💥&lt;/p&gt;

&lt;h4&gt;
  
  
  GitHub Link: &lt;a href="https://github.com/surajwarbhe/Ansible-Webser-inside-Docker-Container" rel="noopener noreferrer"&gt;https://github.com/surajwarbhe/Ansible-Webser-inside-Docker-Container&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp.kindpng.com%2Fpicc%2Fs%2F646-6464705_thanks-for-reading-png-transparent-png.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fp.kindpng.com%2Fpicc%2Fs%2F646-6464705_thanks-for-reading-png-transparent-png.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ansible</category>
      <category>docker</category>
      <category>devops</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Creating a Helm Chart for Grafana</title>
      <dc:creator>Suraj Warbhe</dc:creator>
      <pubDate>Thu, 26 Aug 2021 07:32:45 +0000</pubDate>
      <link>https://dev.to/surajwarbhe/creating-a-helm-chart-for-grafana-3055</link>
      <guid>https://dev.to/surajwarbhe/creating-a-helm-chart-for-grafana-3055</guid>
      <description>&lt;h1&gt;
  
  
  What's Minikube ?
&lt;/h1&gt;

&lt;p&gt;minikube is a tool that lets you run Kubernetes locally. minikube runs a single-node Kubernetes cluster on your personal computer (including Windows, macOS and Linux PCs) so that you can try out Kubernetes, or for daily development work.&lt;/p&gt;

&lt;p&gt;🔸 Start the Minikube&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;minikube start --vm-driver=none
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔸 Our single node cluster is ready to use so run the below command to check the minikube status&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;minikube status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💠 you will get output such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Asus_1\minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Setup has been completed...&lt;/strong&gt;&lt;br&gt;
But before creating it, let's try to understand &lt;strong&gt;Helm&lt;/strong&gt; and &lt;strong&gt;Grafana&lt;/strong&gt;.&lt;/p&gt;
&lt;h1&gt;
  
  
  What's Grafana ?
&lt;/h1&gt;

&lt;p&gt;Grafana is a multi-platform open source analytics and interactive visualization web application. It provides charts, graphs, and alerts for the web when connected to supported data sources and End users can create complex monitoring dashboards using interactive query builders. Grafana is divided into a front end and back end, written in TypeScript and Go, respectively.&lt;/p&gt;
&lt;h1&gt;
  
  
  What is Helm?
&lt;/h1&gt;

&lt;p&gt;In simple terms, Helm is a package manager for Kubernetes. Helm is the K8s equivalent of yum or apt. Helm deploys charts, which you can think of as a packaged application. It is a collection of all your versioned, per-configured application resources which can be deployed as one unit. You can then deploy another version of the chart with a different set of configuration.&lt;/p&gt;

&lt;p&gt;Helm helps in three key ways:&lt;br&gt;
🔷 Improves productivity&lt;br&gt;
🔷 Reduces the complexity of deployments of micro services&lt;br&gt;
🔷 Enables the adaptation of cloud native applications&lt;/p&gt;
&lt;h1&gt;
  
  
  Why we need Helms?
&lt;/h1&gt;

&lt;p&gt;Writing and maintaining Kubernetes YAML manifests for all the required Kubernetes objects can be a time-consuming and tedious task. For the simplest of deployments, you would need at least 3 YAML manifests with duplicated and hard-coded values. Helm simplifies this process and creates a single package that can be advertised to your cluster.&lt;/p&gt;
&lt;h1&gt;
  
  
  What are Charts?
&lt;/h1&gt;

&lt;p&gt;In Kubernetes, we package all the running resources in a zip file known as the chart. A Helm chart can contain any number of Kubernetes objects, all of which are deployed as part of the chart. &lt;strong&gt;A Helm chart will usually contain at least a Deployment and a Service, but it can also contain an Ingress, Persistent Volume Claims, or any other Kubernetes object.&lt;/strong&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Installing Helm
&lt;/h1&gt;

&lt;p&gt;🔷 Helm had the client-server architecture till version 2, We have to need to install a server-side program Tiller in the Kubernetes cluster.&lt;/p&gt;

&lt;p&gt;🔷 In version 3 helm provides more facilities i.e. install helm on the client-side only. It provides more security than version 2. We can install helm in Mac, Windows, and Linux.&lt;/p&gt;

&lt;p&gt;🔷 The URL where you can download helm according to your operating system. &lt;a href="https://github.com/helm/helm/releases" rel="noopener noreferrer"&gt;Link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔷 In windows after downloading the helm, we got a zip file,&lt;br&gt;
Extract the zip and go to folder that will come after extracting&lt;/p&gt;

&lt;p&gt;🔷 Copy the path and add it into the environment variable because in the command line everywhere we can do access helm.&lt;/p&gt;

&lt;p&gt;🔷 To check the helm installation run the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;helm version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💠 you will get output such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Asus_1&amp;gt;helm version
version.BuildInfo{Version:"v3.6.3", GitCommit:"d506314abfb5d21419df8c7e7e68012379db2354", GitTreeState:"clean", GoVersion:"go1.16.5"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After successfully done the installation part, let’s create a chart for Grafana.&lt;/p&gt;

&lt;h1&gt;
  
  
  Create a Helm Chart
&lt;/h1&gt;

&lt;p&gt;let's create a new Helm Chart from the scratch. Helm created a bunch of files for you that are usually important for a production-ready service in Kubernetes. To concentrate on the most important parts, we can remove a lot of the created files. Let’s go through the only required files for this example.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fpracticaldev%2Fimage%2Ffetch%2Fs--7p9BafMf--%2Fc_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_880%2Fhttps%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8bg2vbgdbu7687novaki.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fpracticaldev%2Fimage%2Ffetch%2Fs--7p9BafMf--%2Fc_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_880%2Fhttps%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8bg2vbgdbu7687novaki.jpg" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔸 Create a Helm Chart for Grafana.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir grafana
cd grafana
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💠 But here we need a project file that is called Chart.yaml and contains all the metadata information.&lt;br&gt;
🔸 So, create this file. Also, C should be capital in the Chart.yaml.&lt;br&gt;
&lt;strong&gt;For Windows:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;notepad Chart.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;For Linux:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vim Chart.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔸 Write the below code inside Chart.yaml.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: v1
name: Grafana
description: A Helm chart to setup Grafana
type: application
version: 0.1.0
appVersion: 0.1.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔸 Make a templates folder inside grafana and go inside it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir templates
cd templates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔸 You can use my image to download Docker image of Grafana.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://hub.docker.com/repository/docker/surajwarbhe/grafana" rel="noopener noreferrer"&gt;https://hub.docker.com/repository/docker/surajwarbhe/grafana&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🔸 Use below command to pull my docker image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker push surajwarbhe/grafana:v1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔸 Use this command to create a code of the deployment.yaml file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create deployment grafana --image=surajwarbhe/grafana:v1 --dry-run -o yaml &amp;gt; deployment.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💠 The output should be similar to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Asus_1\grafana\templates&amp;gt;kubectl create deployment grafana --image=surajwarbhe/grafana:v1 --dry-run -o yaml &amp;gt; deployment.yaml
W0826 09:59:25.756492    1640 helpers.go:535] --dry-run is deprecated and can be replaced with --dry-run=client.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔸 Go outside the grafana directory and install the helm chart.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd 
helm install grafana grafana/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; Here grafana is the name of Helm Chart and grafana/ is the path of the chart.&lt;br&gt;
💠 After running above command, the output should be similar to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Asus_1&amp;gt;helm install grafana grafana/
NAME: grafana
LAST DEPLOYED: Thur Aug 26 10:25:45 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔸 Now again go inside grafana/templates and use the below command to create a code of the service.yaml file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd grafana/templates/
kubectl expose deployment grafana --port=3000 --type=NodePort --dry-run -o yaml &amp;gt; service.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💠 The output should be similar to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Asus_1\grafana\templates&amp;gt;kubectl expose deployment grafana --port=3000 --type=NodePort --dry-run -o yaml &amp;gt; service.yaml
W0826 10:03:55.911918    6892 helpers.go:535] --dry-run is deprecated and can be replaced with --dry-run=client.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔸 After it, run the below command for exposing the grafana pod.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f service.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💠 To ensure your pod is working well with the below commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get pods
kubectl get deployment
kubectl get svc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💠 After running these commands, the output should be similar to the following:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdrive.google.com%2Ffile%2Fd%2F1P7aZ-sBT_NxjsOpOj7TuENWYoxH6q5cA%2Fview%3Fusp%3Dsharing" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdrive.google.com%2Ffile%2Fd%2F1P7aZ-sBT_NxjsOpOj7TuENWYoxH6q5cA%2Fview%3Fusp%3Dsharing" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔸 You can check the list of the helm you have using the &lt;strong&gt;helm list&lt;/strong&gt; command. Now we can check the pods in which slaves are running in the Kubernetes cluster.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Asus_1&amp;gt;helm list
NAME            NAMESPACE       REVISION        UPDATED                                         STATUS          CHART                   APP VERSION
grafana         default         1               2021-08-25 09:38:04.967518153 -0400 -0400       deployed        Grafana-0.1.0           0.1.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔸 After running the command pick the port number that has been exposed Grafana service. And also run one more command if you run a single node cluster minikube.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;minikube ip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So let's check that Grafana is working fine or not. For this, you have to take the &lt;code&gt;minikube_ip&lt;/code&gt; and &lt;code&gt;port no.&lt;/code&gt; of your pod.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;eg. 192.168.99.102:30147&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;💠 After browsing it, login page will pop up. So login with by-default username and password admin.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F75n32wtzyfmf668o5fvi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F75n32wtzyfmf668o5fvi.png" alt="192.168.56.1 - Google Chrome 26-08-2021 10_13_32 AM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔸 After logging you will get the page for changing the username and password, So you can if you want.&lt;/p&gt;

&lt;h1&gt;
  
  
  Packing resources inside the Helm Chart.
&lt;/h1&gt;

&lt;p&gt;So helm chart ready inside the grafana/ directory, but we can’t publish it as it is. Firstly, we have to create a package for this helm chart.&lt;/p&gt;

&lt;p&gt;🔸 Create one directory named charts. Make sure this directory should be inside grafana directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir charts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔸 Now, run the following command to packages the chart and store it inside the charts/ directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;helm package C:\Users\Asus_1\grafana -d charts\
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💠 you will get output something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Successfully packaged chart and saved it to: charts/Grafana-0.1.0.tgz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Creating an index.yaml file&lt;/strong&gt;&lt;br&gt;
For every Helm repository, we must require an &lt;code&gt;index.yaml&lt;/code&gt; file. The &lt;code&gt;index.yaml&lt;/code&gt; file contains the information about the chart that is present inside the current repository/directory.&lt;/p&gt;

&lt;p&gt;🔸 For generating &lt;code&gt;index.yaml&lt;/code&gt; file inside charts/ directory, run following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;helm repo index charts/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Pushing the charts in the GitHub repository
&lt;/h1&gt;

&lt;p&gt;🔸 Create a new repository in GitHub and upload charts/ source code into the GitHub repository.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3vkcabyxqibcevcdy2u7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3vkcabyxqibcevcdy2u7.png" alt="surajwarbhe_grafana - Google Chrome 26-08-2021 10_20_11 AM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Hosting Chart using Github Pages
&lt;/h1&gt;

&lt;p&gt;🔸 We must require a URL where we had hosted our helm chart for publishing the Helm chart on &lt;a href="//artifacthub.io/."&gt;artifacthub.io/.&lt;/a&gt; 🔸 One of the ways to host the charts is using GitHub pages.&lt;br&gt;
🔸 So, we will first host our charts using GitHub pages.&lt;br&gt;
🔸 Go to the settings of your &lt;code&gt;Github&lt;/code&gt; repository and go down where you can see the GitHub Pages section.&lt;br&gt;
🔸 Select &lt;code&gt;main&lt;/code&gt; as a branch and click on save.&lt;br&gt;
 &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk2mgkgewnuz5ifpvpq7r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk2mgkgewnuz5ifpvpq7r.png" alt="surajwarbhe_grafana - Google Chrome 26-08-2021 10_22_45 AM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Publishing helm chart on artifact hub
&lt;/h1&gt;

&lt;p&gt;🔸 Go to this URL &lt;a href="//artifacthub.io/"&gt;artifacthub.io/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F875%2F1%2A0aR2MQF1N12Wpy8rb5F81Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F875%2F1%2A0aR2MQF1N12Wpy8rb5F81Q.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔸 Sign in with your account if you have otherwise you have to need to create an account.&lt;/p&gt;

&lt;p&gt;🔸 After signed in successfully, In the right top corner click on the face you have seen.&lt;/p&gt;

&lt;p&gt;🔸 Now click on &lt;code&gt;profile icon &amp;gt; control Panel&amp;gt; Add repository.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; Make sure your repository's url should be like &lt;code&gt;https://username.github.io/repository_name/chart/&lt;/code&gt; when you're adding repository in &lt;code&gt;ArtifactHub&lt;/code&gt;. Otherwise, it can create some issues related to url.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp4wnbl3xuocr69dp70ne.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp4wnbl3xuocr69dp70ne.png" alt="surajwarbhe_grafana - Google Chrome 26-08-2021 10_26_17 AM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🔸 After giving the required information to your Helm repository, click on &lt;code&gt;Add&lt;/code&gt;. if you had provided the right information then it will create a Helm repository.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcmb9ff1lep6wivr7yacw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcmb9ff1lep6wivr7yacw.png" alt="surajwarbhe_grafana - Google Chrome 26-08-2021 10_26_25 AM"&gt;&lt;/a&gt;&lt;br&gt;
So, we had successfully published our Helm chart to the ArtifactHub.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;In this tutorial, you created a helm chart for installing GRAFANA and How to upload our repository on ArtifactHub.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep learning keep sharing&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Thank You&lt;/strong&gt; &lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
      <category>helm</category>
      <category>grafana</category>
    </item>
  </channel>
</rss>
