<?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: Emmanuel Ogar</title>
    <description>The latest articles on DEV Community by Emmanuel Ogar (@emmanuelogar).</description>
    <link>https://dev.to/emmanuelogar</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%2F1145705%2Fadbb6ebd-9323-4275-830b-366fa7e23041.png</url>
      <title>DEV Community: Emmanuel Ogar</title>
      <link>https://dev.to/emmanuelogar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/emmanuelogar"/>
    <language>en</language>
    <item>
      <title>Deploying a Nodejs app using Terraform to kind Kubernetes cluster.</title>
      <dc:creator>Emmanuel Ogar</dc:creator>
      <pubDate>Sun, 22 Oct 2023 14:57:20 +0000</pubDate>
      <link>https://dev.to/emmanuelogar/deploying-a-nodejs-app-using-terraform-to-kind-kubernetes-cluster-3kfl</link>
      <guid>https://dev.to/emmanuelogar/deploying-a-nodejs-app-using-terraform-to-kind-kubernetes-cluster-3kfl</guid>
      <description>&lt;p&gt;This article explains how terraform is used to deploy the kubectl manifest of a simple Node.js app to the kind cluster installed locally and set up monitoring and observability using the kubectl terraform provider.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
Docker to run kind cluster locally.&lt;/li&gt;
&lt;li&gt;
Kubectl to perform basic Kubernetes functions on our cluster&lt;/li&gt;
&lt;li&gt;
Terraform CLI.&lt;/li&gt;
&lt;li&gt;
Helm to setup monitoring and observability for the prometheus cluster.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Install Docker&lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Run the below command to install Docker&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update &lt;span class="nt"&gt;-y&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;docker.io &lt;span class="nt"&gt;-y&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable&lt;/span&gt; &lt;span class="nt"&gt;--now&lt;/span&gt; docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify Docker Installation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Install Kubectl&lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update &amp;amp;&amp;amp; sudo snap install kubectl --classic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify Kubectl Installation&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Install Terraform&lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Install Terraform from APT repository&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;software-properties-common gnupg2 curl &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://apt.releases.hashicorp.com/gpg | gpg &lt;span class="nt"&gt;--dearmor&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; hashicorp.gpg
&lt;span class="nb"&gt;sudo install&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; root &lt;span class="nt"&gt;-g&lt;/span&gt; root &lt;span class="nt"&gt;-m&lt;/span&gt; 644 hashicorp.gpg /etc/apt/trusted.gpg.d/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-add-repository &lt;span class="s2"&gt;"deb [arch=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;dpkg &lt;span class="nt"&gt;--print-architecture&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;] https://apt.releases.hashicorp.com &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;lsb_release &lt;span class="nt"&gt;-cs&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; main"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now install terraform on your Ubuntu Linux system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;terraform
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify Terraform Installation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ terraform --version
Terraform v1.5.7
on linux_amd64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Install Helm&lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg &amp;gt; /dev/null
sudo apt-get install apt-transport-https --yes
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
sudo apt-get update
sudo apt-get install helm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Lets Begin
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Clone this repo:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/emmanuelogar/Node.js_app_using_terraform.git &amp;amp;&amp;amp; cd Node.js_app_using_terraform
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;run&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;./install_kind.sh&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 to install kind and create a local kind cluster with the specified name, provides cluster information, downloads the kubeconfig for the cluster and store in a file.&lt;/p&gt;

&lt;p&gt;Run the following terraform commands to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deploy the kubernetes manifest to the running kind cluster using the kubectl terraform provider.&lt;/li&gt;
&lt;li&gt;setup monitoring and observability for the prometheus cluster using the kube-prometheus stack with terraform helm provider.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform init
terraform plan -out=tfplan
terraform apply "tfplan"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;#### Connecting to Prometheus:
Port Forward to Prometheus
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl port-forward -n monitoring svc/kube-prometheus-kube-prome-prometheus 9090
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This command forwards local port 9090 to the Prometheus service's port within the monitoring namespace.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Access Prometheus Web UI:&lt;/strong&gt;&lt;br&gt;
Open your web browser and navigate to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
. You should see the Prometheus web user interface, where you can query metrics and create custom dashboards.

- #### Connecting to Grafana:
Port Forward to Grafana:


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

&lt;/div&gt;

&lt;p&gt;kubectl port-forward -n monitoring svc/kube-prometheus-grafana 3000:80&lt;/p&gt;

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

This command forwards local port 3000 to the Grafana service's port within the monitoring namespace.

**Access Grafana Web UI:**
Open your web browser and go to

 ``` http://localhost:3000```

. Grafana's default login credentials are typically:

Username: admin
Password: You might need to obtain the password from your Grafana configuration or secret.

To retrieve the Grafana admin password from the secret


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

&lt;/div&gt;

&lt;p&gt;kubectl get secrets -n monitoring&lt;br&gt;
kubectl describe secret kube-prometheus-grafana -n monitoring&lt;br&gt;
kubectl get secret kube-prometheus-grafana -n monitoring -o jsonpath="{.data.admin-password}" | base64 --decode&lt;/p&gt;

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

After logging in, you can set up dashboards and visualize your Kubernetes cluster's metrics.

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

&lt;/div&gt;

</description>
    </item>
  </channel>
</rss>
