<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tinkal Shakya on Medium]]></title>
        <description><![CDATA[Stories by Tinkal Shakya on Medium]]></description>
        <link>https://medium.com/@tinkal.shakya?source=rss-32dbd15475a5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*il1pN3CKaAU-v5-T</url>
            <title>Stories by Tinkal Shakya on Medium</title>
            <link>https://medium.com/@tinkal.shakya?source=rss-32dbd15475a5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 02:08:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tinkal.shakya/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Setup WRF and WPS With Gfortran compiler in GCP Slurm HPC Cluster]]></title>
            <link>https://blog.thecloudside.com/setup-wrf-and-wps-with-gfortran-compiler-in-gcp-slurm-hpc-cluster-1892d124fce5?source=rss-32dbd15475a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1892d124fce5</guid>
            <category><![CDATA[slurm]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[wrf]]></category>
            <category><![CDATA[google-cloud]]></category>
            <category><![CDATA[gcp]]></category>
            <dc:creator><![CDATA[Tinkal Shakya]]></dc:creator>
            <pubDate>Tue, 10 Dec 2024 11:19:20 GMT</pubDate>
            <atom:updated>2024-12-10T11:20:59.095Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*iiPdwTNmk0YavielGmhCVw.png" /></figure><p>We recently helped a large Power company in India with the deployment of a Slurm cluster on Google Cloud to run their massive weather research and forecasting jobs. As part of that, we had to <a href="https://medium.com/cloudside/setting-up-an-hpc-slurm-cluster-on-gcp-with-rhel-7-3adcd1ea96e1">add custom image support</a> for the existing Terraform template. In this post, we will take you through setting up of WFR and WPS Gfortran compiler in a GCP Slurm HPC cluster. This guide covers the setup of necessary libraries, compilers, and environment configurations to ensure that WRF and WPS function correctly.</p><p>Note: To setup WRF and WPS With Intel MPI compiler in GCP Slurm HPC Cluster, follow the following <a href="https://blog.thecloudside.com/setup-wrf-and-wps-with-intel-mpi-compiler-in-gcp-slurm-hpc-cluster-31793e903a4b">document</a> by <a href="https://medium.com/u/94864c7683da">Writtick Sengupta</a></p><p><strong>Prerequisites:-</strong></p><p><strong>1. Enable API’s.</strong></p><pre>serviceusage.googleapis.com<br>cloudresourcemanager.googleapis.com</pre><p><strong>2. Enabled private Google Access in the subnet.</strong></p><p>Select the subnet where the HPC cluster will be created. Edit the subnet and enable Private Google Access.</p><p><strong>3. Create a Filestore (optional).<br></strong>Create a filestore for a shared Filesystem. In the GCP console, search for Filestore. Create a new Filestore. Screenshots attached below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/0*WcDyoxVa1PsIYnyk" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/0*ru4KNjEPUTJqxQoC" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/0*o-orX04Xt-ULOPGt" /></figure><p>In the terraform code, update the following block in the example.tfvars.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/0*3Oi_-lXMBxIw0_cv" /></figure><p><strong>Note:- You can find the server(Filestore) IP in the GCP console. Search filestore in the console and click on the Filestore created above. Copy the Private IP of the filestore and paste in server_ip in terraform</strong></p><p><strong>4. </strong><a href="https://blog.thecloudside.com/setting-up-an-hpc-slurm-cluster-on-gcp-with-rhel-7-3adcd1ea96e1"><strong>Create Slurm HPC Cluster in GCP</strong></a><strong> (follow the Article to setup the HCP cluster).</strong></p><h3><strong>Setup Working Directory</strong></h3><p><strong>Folder structure:-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*d8FaaqrsJAou2AqJB3cEqQ.png" /></figure><p>Create directories for building WRF and testing compilers:</p><pre>mkdir Build_WRF<br>mkdir TESTS</pre><h4>Step 1: Install Required Libraries and Compilers</h4><p>WRF requires <strong>Gfortran</strong>, <strong>GCC</strong>, and <strong>CPP</strong> compilers. Check if these compilers are installed:</p><pre>which gfortran cpp gcc g++</pre><p>If they are not installed, run the following command:</p><pre>sudo yum install gfortran cpp gcc g++</pre><p>Verify the installation with:</p><pre>gcc --version</pre><p>Additionally, WRF requires <strong>csh</strong>, <strong>perl</strong>, and <strong>sh</strong> for scripting. Check if these are installed:</p><pre>which csh perl</pre><p>If not, install them:</p><pre>sudo yum install csh perl wget cmake -y</pre><h4>Test Fortran and C Compiler Compatibility</h4><p>Navigate to the TESTS directory and download the test files:</p><pre>cd TESTS<br>wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/Fortran_C_tests.tar<br>tar -xvf Fortran_C_tests.tar</pre><p>Create a file named fortran-c-test.sh in the TESTS directory with the following content:</p><pre>#!/bin/bash<br># System Environment Tests<br># Test1<br>echo &quot;Test #1: Fixed Format Fortran Test&quot;<br>gfortran TEST_1_fortran_only_fixed.f<br>./a.out<br>echo &quot;&quot;<br># Test2<br>echo &quot;Test #2: Free Format Fortran&quot;<br>gfortran TEST_2_fortran_only_free.f90<br>./a.out<br>echo &quot;&quot;<br># Test3<br>echo &quot;Test #3: C: TEST_3_c_only.c&quot;<br>gcc TEST_3_c_only.c<br>./a.out<br>echo &quot;&quot;<br># Test4<br>echo &quot;Test #4: Fortran Calling a C Function&quot;<br>gcc -c -m64 TEST_4_fortran+c_c.c<br>gfortran -c -m64 TEST_4_fortran+c_f.f90<br>gfortran -m64 TEST_4_fortran+c_f.o TEST_4_fortran+c_c.o<br>./a.out<br>echo &quot;&quot;<br># Test5<br>echo &quot;Test #5: csh&quot;<br>./TEST_csh.csh<br>echo &quot;&quot;<br># Test6<br>echo &quot;Test #6: perl&quot;<br>./TEST_perl.pl<br>echo &quot;&quot;<br># Test7<br>echo &quot;Test #7: sh&quot;<br>./TEST_sh.sh<br>echo &quot;&quot;</pre><p>Run the script to verify the setup:</p><pre>sh fortran-c-test.sh</pre><p>Ensure that all seven tests return a <strong>SUCCESS</strong> message. If they do, proceed to the next step.</p><h4>Install JSON-C and Valgrind</h4><p>These libraries are required for the <strong>MPICH</strong> test. To install the latest versions, use the following commands:</p><p>Update your package list:</p><pre>sudo yum update</pre><p>Install <strong>JSON-C</strong>:</p><pre>git clone https://github.com/json-c/json-c.git<br>mkdir json-c-build<br>cd json-c-build<br>cmake ../json-c<br>make<br>make test</pre><h4>Building Libraries for WRF</h4><p>Navigate to the Build_WRF directory and create a LIBRARIES folder:</p><pre>cd ~/Build_WRF<br>mkdir LIBRARIES<br>cd LIBRARIES</pre><p>Download the required libraries:</p><pre>wget https://github.com/pmodels/mpich/releases/download/v3.4.3/mpich-3.4.3.tar.gz<br>wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/zlib-1.2.11.tar.gz<br>wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/libpng-1.2.50.tar.gz<br>wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/jasper-1.900.1.tar.gz<br>wget https://docs.hdfgroup.org/archive/support/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.0/src/hdf5-1.12.0.tar.gz<br>wget https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.8.1.tar.gz -O netcdf-c-4.8.1.tar.gz<br>wget https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.5.4.tar.gz -O netcdf-fortran-4.5.4.tar.gz</pre><h4>Library Installation Order and Compiler Choices</h4><ol><li><strong>MPICH</strong>: Install this first, as it provides MPI libraries required for parallel computing.</li><li><strong>Zlib</strong>: Use GCC for compression capabilities.</li><li><strong>Libpng</strong>: Compile using a standard C compiler.</li><li><strong>Jasper</strong>: Handle JPEG2000 files with a standard C compiler.</li><li><strong>HDF5</strong>: Compile with MPICH for parallel I/O support.</li><li><strong>NetCDF-C</strong>: Build on top of HDF5 with MPICH.</li><li><strong>NetCDF-Fortran</strong>: Provide a Fortran interface for NetCDF-C.</li></ol><h4>Configure Environment Variables</h4><p>Set paths for libraries and compilers by editing .zshrc</p><pre>vim ~/.zshrc</pre><p>Add the following configuration, adjusting the directories to match your setup:</p><pre># WRF Configuration Setting<br># Compilers<br>export CC=/usr/bin/gcc<br>export CXX=/usr/bin/g++<br>export FC=/usr/bin/gfortran<br>export FCFLAGS=&quot;-m64&quot;<br>export F77=/usr/bin/gfortran<br>export FFLAGS=&quot;-m64&quot;<br># Directory<br>export DIR=/home/&lt;your_user&gt;/Build_WRF/LIBRARIES  # Update with your path<br>export WRF_DIR=/home/&lt;your_user&gt;/Build_WRF/WRF    # Update with your path<br>export MPICH=$DIR/mpich<br>export NETCDF=$DIR/netcdf<br>export JASPERLIB=$DIR/grib2/lib<br>export JASPERINC=$DIR/grib2/include<br>export PATH=$DIR/grib2/bin:$MPICH/bin:$NETCDF/bin:$PATH<br># Libraries<br>export LD_LIBRARY_PATH=$DIR/grib2/lib:$LD_LIBRARY_PATH<br>export LDFLAGS=&quot;-L$DIR/grib2/lib&quot;<br>export CPPFLAGS=&quot;-I$DIR/grib2/include&quot;</pre><p><strong>Note:</strong></p><ul><li>Update the paths as necessary to match your directory structure.</li><li>Adjust these paths if you need to reinstall any of the libraries.</li></ul><p>Save and exit the file. Apply the changes:</p><pre>source ~/.zshrc<br>echo $DIR</pre><p>These steps will help you set up the WRF and WPS with all necessary libraries, ensuring compatibility for parallel computing environments.</p><h4>Step 2: Building and Installing Libraries for WRF</h4><p>You&#39;ll need several libraries installed in a specific order to run the Weather Research and Forecasting (WRF) model. Follow the below-mentioned guide to build and install the libraries:</p><h4>Building and installing Libraries:</h4><ol><li><strong>Mpich:</strong></li></ol><p>Details on installation and configuration are available at <a href="https://github.com/pmodels/mpich">https://github.com/pmodels/mpich</a></p><pre># Untar the mpich library<br>tar xzvf mpich-3.4.3.tar.gz<br># Entering the directory<br>cd mpich-3.4.3<br># Configuration and install<br>./configure - prefix=$DIR/mpich - with-device=ch3:nemesis - enable-fast=all,O3 - disable-float - enable-threads=multiple<br>make check<br>make install<br># Set mpich path<br>export PATH=$DIR/mpich/bin:$PATH<br># Back to LIBRARIES folder<br>cd ..</pre><p><strong>Note: You may receive the following error when you run the make check command</strong></p><pre>CC tools/bootstrap/external/slurm_query_node_list.lo<br>tools/bootstrap/external/slurm_query_node_list.c: In function &#39;list_to_nodes&#39;:<br>tools/bootstrap/external/slurm_query_node_list.c:28:16: error: storage size of &#39;hostlist&#39; isn&#39;t known<br> hostlist_t hostlist;<br> ^~~~~~~~<br>make[3]: *** [Makefile:1562: tools/bootstrap/external/slurm_query_node_list.lo] Error 1<br>make[3]: Leaving directory &#39;/home/tinkal_shakya_thecloudside_com/Build_WRF/LIBRARIES/mpich-3.4.3/src/pm/hydra&#39;<br>make[2]: *** [Makefile:1730: check-recursive] Error 1<br>make[2]: Leaving directory &#39;/home/tinkal_shakya_thecloudside_com/Build_WRF/LIBRARIES/mpich-3.4.3/src/pm/hydra&#39;<br>make[1]: *** [Makefile:43560: check-recursive] Error 1<br>make[1]: Leaving directory &#39;/home/tinkal_shakya_thecloudside_com/Build_WRF/LIBRARIES/mpich-3.4.3&#39;<br>make: *** [Makefile:43849: check] Error 2</pre><p>To solve this issue, follow the steps mentioned below</p><pre>vim src/pm/hydra/tools/bootstrap/external/slurm_query_node_list.c</pre><p>Add a * before the hostlist as shown in the screenshot below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/0*1ekcwpWMnulCeiAY" /></figure><p>After making the change, please rerun the make check command and continue the Mpich installation.</p><p><strong>2. Zlib:</strong></p><p>Details on installation and configuration are available at <a href="https://www.zlib.net/zlib_faq.html#faq14">https://www.zlib.net/zlib_faq.html#faq14</a></p><pre># Untar the zlib library<br>tar xzvf zlib-1.2.11.tar.gz<br># Entering the directory<br>cd zlib-1.2.11<br># Configuration and install<br>./configure - prefix=$DIR/grib2<br>make check <br>make install<br># Back to LIBRARIES folder<br>cd ..</pre><p><strong>3. Libpng:</strong></p><p>Details on installation and configuration are available at <a href="https://github.com/pnggroup/libpng/blob/libpng16/INSTALL">https://github.com/pnggroup/libpng/blob/libpng16/INSTALL</a></p><pre># Untar the libpng library<br>tar xzvf libpng-1.2.50.tar.gz<br># Entering the directory<br>cd libpng-1.2.50<br># Configuration and install<br>./configure - prefix=$DIR/grib2<br>make check <br>make install<br># Back to LIBRARIES folder<br>cd ..</pre><p><strong>4. Jesper:</strong></p><p>Jasper handles JPEG2000 files, useful in weather data processing. Details on installation and configuration are available at <a href="https://github.com/jasper-software/jasper/blob/master/INSTALL.txt">https://github.com/jasper-software/jasper/blob/master/INSTALL.txt</a></p><pre># Untar the jasper library<br>tar xzvf jasper-1.900.1.tar.gz<br># Entering the directory<br>cd jasper-1.900.1<br># Configuration and install<br>./configure - prefix=$DIR/grib2<br>make <br>make install<br># Back to LIBRARIES folder<br>cd ..</pre><p><strong>5. HDF5:</strong></p><p>HDF5 is required for NetCDF which is used to store large datasets. When you build hdf5, please specify the location of the zlib library. Details on compiling steps are available at (https://docs.hdfgroup.org/hdf5/develop/_l_b_compiling.html)</p><pre># Untar the hdf5 library<br>tar xzvf hdf5–1.12.0.tar.gz<br># Entering the directory<br>cd hdf5–1.12.0<br># Configuration and install<br>## Remove the enable-parallel option<br>./configure - prefix=$DIR/grib2 - with-zlib=$DIR/grib2 - enable-fortran - enable-hl <br>make<br>make install<br># Back to LIBRARIES folder<br>cd ..</pre><p><strong>6. NetCDF:</strong></p><p>NetCDF-C is necessary for handling scientific data. Follow the below-mentioned steps to install NetCDF.</p><pre># Untar the netcdf library<br>tar xzvf netcdf-c-4.8.1.tar.gz<br># Entering the directory<br>cd netcdf-c-4.8.1<br># Configuration and install<br>CPPFLAGS=-I$DIR/grib2/include LDFLAGS=-L$DIR/grib2/lib<br>./configure - prefix=$DIR/netcdf - with-hdf5=$DIR/grib2 - disable-dap - enable-netcdf-4 - enable-netcdf4 - enable-hdf5 - enable-nczarr<br>make<br>make install<br># Registering library<br>libtool - finish $DIR/netcdf/lib<br># Back to LIBRARIES folder<br>cd ..</pre><p>Edit the .zshrc file</p><pre>ls -al ~/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/0*0j66YjpllbQGw6We" /></figure><pre>vim ~/.zshrc</pre><p>Manually update the .zshrc file, replace &amp; add the following lines.</p><pre># Libraries<br>export LD_LIBRARY_PATH=$DIR/grib2/lib:$LD_LIBRARY_PATH<br>export LDFLAGS=&quot;-L$DIR/grib2/lib&quot;<br>export CPPFLAGS=&quot;-I$DIR/grib2/include&quot;</pre><p>With the following values.</p><pre># Libraries<br>export CPPFLAGS=&quot;-I$DIR/netcdf/include -I$DIR/grib2/include&quot;<br>export LDFLAGS=&quot;-L$DIR/netcdf/lib -L$DIR/grib2/lib&quot;<br>export LD_LIBRARY_PATH=$DIR/netcdf/lib:$DIR/grib2/lib:$LD_LIBRARY_PATH<br>export LIBS=&quot;-lnetcdf -lz -lhdf5_hl -lhdf5 -lm&quot;</pre><p>Here’s how the updated file looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/0*4B_-c7_ZELLME1Ql" /></figure><p>To update the variables and add the new variables, run the following command</p><pre>source ~/.zshrc</pre><p><strong>7. netcdf-fortran</strong></p><p>This provides a Fortran interface for NetCDF. Follow the below-mentioned steps to install NetCDF-Fortran.</p><pre># Untar the netcdf-fortran library<br>tar xzvf netcdf-fortran-4.5.4.tar.gz<br># Entering the directory<br>cd netcdf-fortran-4.5.4<br># Configuration and install<br>./configure --prefix=$DIR/netcdf <br>make <br>make install<br># Back to LIBRARIES folder<br>cd ..</pre><pre>cd ~/TESTS<br>wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/Fortran_C_NETCDF_MPI_tests.tar<br>tar -xf Fortran_C_NETCDF_MPI_tests.tar</pre><p>Now create a file called fortran-lib-test.sh and update the script mentioned below</p><pre>vim fortran-lib-test.sh</pre><p><strong>fortran-lib-test.sh</strong></p><pre>#!/bin/bash<br># Library Compatibility Tests<br># Test1<br>echo &quot;Test #1: Fortran + C + NetCDF&quot;<br>echo &quot;The NetCDF-only test requires the netcdf.inc file from the NETCDF package be in this directory. Copying the file.&quot;<br>cp ${NETCDF}/include/netcdf.inc .<br>echo &quot;Compile the Fortran and C codes for the purpose of this test (the -c option says to not try to build an executable).&quot;<br>gfortran -c 01_fortran+c+netcdf_f.f<br>gcc -c 01_fortran+c+netcdf_c.c<br>gfortran 01_fortran+c+netcdf_f.o 01_fortran+c+netcdf_c.o -L${NETCDF}/lib -lnetcdff -lnetcdf<br>./a.out<br>echo &quot;&quot;<br># Test2<br>echo &quot;Test #2: Fortran + C + NetCDF + MP&quot;<br>echo &quot;The NetCDF+MPI test requires include files from both of these packages be in this directory,&quot;<br>echo &quot;but the MPI scripts automatically make the mpif.h file available without assistance,&quot;<br>echo &quot;so no need to copy that one. Copying the NetCDF file&quot;<br>cp ${NETCDF}/include/netcdf.inc .<br>echo &quot;Note that the MPI executables mpif90 and mpicc are used below when compiling.&quot;<br>mpif90 -c 02_fortran+c+netcdf+mpi_f.f<br>mpicc -c 02_fortran+c+netcdf+mpi_c.c<br>mpif90 02_fortran+c+netcdf+mpi_f.o 02_fortran+c+netcdf+mpi_c.o -L${NETCDF}/lib -lnetcdff -lnetcdf<br>mpirun ./a.out<br>echo &quot;&quot;</pre><p>Once the file is updated and saved, run the following command to execute the script.</p><pre>sh fortran-lib-test.sh</pre><p>If the script runs successfully, you will see the following output as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*spsE_U1C9igeGLPH" /></figure><p>Now, We can move to install WRF &amp; WPS</p><h3>Building WRF and WPS</h3><p>This guide will help you through the process of building the WRF (Weather Research and Forecasting) model and the WPS (WRF Preprocessing System). Follow the step-by-step approach for compiling these components:</p><h4>1. Build WRF</h4><ol><li><strong>Clone the WRF repository</strong> and navigate to the WRF directory:</li></ol><pre>cd ~/Build_WRF git clone https://github.com/wrf-model/WRF cd WRF</pre><p><strong>2. Source the environment variables</strong>:</p><pre>source ~/.zshrc</pre><p><strong>3. Configure WRF</strong>:</p><pre>./configure</pre><ul><li>Choose <strong>Option 34</strong> for gfortran compiler with gcc (dmpar) for distributed memory parallelism.</li><li>For nesting, choose <strong>basic</strong>.</li></ul><p>After finishing the configuration, a configure.wrf file will be generated.</p><p><strong>4. Compile WRF</strong>: Choose the type of case you want to compile:</p><ul><li>For real data simulations, use em_real.</li></ul><p>Run the compile command:</p><pre>./compile -j 4 em_real &gt;&amp; log.compile</pre><ul><li>The -j 4 flag allows using 4 processors for faster compilation. Adjust 4 based on the number of processors available.</li><li>Alternatively, you can use:</li></ul><pre>./compile -j 4 em_real 2&gt;&amp;1 | tee compile.log</pre><p><strong>5. Check Compilation Success</strong>: After compiling, verify that the executables are generated in the WRF/main directory:</p><pre>ls -ls main/*.exe</pre><p>If successful, you should see:</p><ul><li>wrf.exe (Model executable)</li><li>real.exe (For real data initialization)</li><li>ndown.exe (For one-way nesting)</li><li>tc.exe (For TC bogusing—serial only)</li></ul><p>The executables will be linked to:</p><ul><li>WRF/run</li><li>WRF/test/em_real</li></ul><p>You can run WRF from either of these directories.</p><h4>2. Build WPS</h4><p>After building the WRF model, proceed to build WPS if you plan to run real data cases.</p><ol><li><strong>Clone the WPS repository</strong>: Navigate to the Build_WRF directory, where you already have the WRF folder:</li></ol><pre>cd ~/Build_WRF <br>git clone https://github.com/wrf-model/WPS <br>cd WPS</pre><p><strong>2. Configure WPS</strong>: Run the configuration command:</p><pre>./configure</pre><ul><li>Select the option that matches the compiler used for WRF</li><li>Choose <strong>Option 3</strong> for Linux x86_64, gfortran (dmpar).</li></ul><p><strong>3. Compile WPS</strong>: Compile the WPS programs:</p><pre>./compile &gt;&amp; log.compile</pre><p>Compilation should take just a few minutes.</p><p><strong>4. Check Compilation Success</strong>: Verify that the following executables are generated in the WPS top-level directory:</p><ul><li>geogrid.exe</li><li>ungrib.exe</li><li>metgrid.exe</li></ul><p><strong>Note: </strong>Ensure that the file size is not 0 Byte.</p><pre>ls -ls geogrid/src/geogrid.exe</pre><p>Repeat the above command for ungrib.exe and metgrid.exe.</p><p>With these steps, both WRF and WPS should be properly configured and compiled. You can now proceed to run simulations using WRF and utilizing real-world data through the WPS preprocessing.</p><h4>Prepare sample data for the WRF job</h4><p>To create real-data simulations with WRF, you first need to determine the location of the domain. This requires a dataset containing fields like topography and land use categories. These datasets are available for download on the WRF website: <a href="http://www2.mmm.ucar.edu/wrf/users/download/getsourceswps_geog.html">WRF Geographic Data</a>.</p><pre>cd ~/Build_WRF<br>mkdir DATA<br>cd DATA<br>wget https://www2.mmm.ucar.edu/wrf/src/wps_files/geog_high_res_mandatory.tar.gz<br>tar xzvf geog_high_res_mandatory.tar.gz<br>wget https://www2.mmm.ucar.edu/wrf/TUTORIAL_DATA/matthew_1deg.tar.gz<br>tar xzvf matthew_1deg.tar.gz</pre><p><strong>Edit namelist.wps:</strong></p><p>WPS and WRF make use of various variables to define the data format, the time and space scope of the computation, etc. For detailed explanations of all the variables, see these links: <a href="https://www2.mmm.ucar.edu/wrf/users/namelist_best_prac_wps.html">WPS</a>.</p><p>The table below illustrates how to modify the WPS settings file, <em>namelist.wps</em>, to suit our case study. For variables with multiple values, you only need to adjust the first one, as we’re focusing solely on the first domain in a single-domain scenario.</p><pre>cd ../WPS/<br>vim namelist.wps</pre><p>Change the following data as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*zuiYXijl9qvU5Mo8nGUDug.png" /></figure><p><strong>Note: </strong>To find the $WRFDATADIR run a pwd command where the data (WPS_GEOG) is present. Copy the absolute path and replace it with $WRFDATADIR. We have used the following :-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/0*TaRdwZ1CL2fIWaAR" /></figure><pre>ln -sf ungrib/Variable_Tables/Vtable.GFS Vtable</pre><p>ln -sf ungrib/Variable_Tables/Vtable.GFS Vtable: This command creates a symbolic link named Vtable that points to the GFS variable table, which WPS uses to interpret GFS data.</p><pre>./link_grib.csh ~/Build_WRF/DATA/matthew/fnl*:</pre><p>./link_grib.csh ~/Build_WRF/DATA/matthew/fnl*: This command links all the GRIB data files located in ~/Build_WRF/DATA/matthew with filenames starting with fnl to the WPS working directory. This allows WPS to access and process the GRIB data during the ungrib stage.</p><p>Both commands prepare WPS for processing weather data.</p><pre>./ungrib.exe</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/0*58HbOu3gEDCV31I5" /></figure><p>It will create the following files:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/189/0*ikczhxkw-67lYDgQ" /></figure><pre>./geogrid.exe</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/0*nTnXrnPPs-JXn3W7" /></figure><p>This will process the files (FILE:2016–10–06-*) using vtable</p><pre>./metgrid.exe</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/0*_LcqgUIkW55ibaFH" /></figure><p>This will create the following files:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/0*aZfJtNd4g6RCltA1" /></figure><p>Now go to the WRF folder and run the following commands:</p><pre>cd ../WRF/test/em_real/<br>ln -sf ../../../WPS/met_em.d01.2016–10* .</pre><p><strong>Edit namelist.input:-</strong><br>The following table lists how to Modify WRF’s setting file <a href="https://www2.mmm.ucar.edu/wrf/users/namelist_best_prac_wrf.html"><strong>namelist.input</strong></a> to make it fit our case study. Note that for the variables having multiple values, you can only modify the first one since in the single domain case we only care about the first domain.</p><pre>vim namelist.input</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*SlbFpyP14dfk8FLLtMkY1A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*vgR1aQRt9CLi0uRAKGsNCw.png" /></figure><h4>Create jobs</h4><p>In the root directory, create a job using the following command</p><pre>cd<br>vim wrf.slurm</pre><p>Paste the following script</p><pre>#!/bin/bash<br>#SBATCH --job-name=wrfJob1<br>#SBATCH --nodes=6<br>#SBATCH --ntasks-per-node=2<br>#SBATCH --cpus-per-task=1<br>#SBATCH --time=24:00:00<br>#SBATCH --output=/home/tinkal_shakya_thecloudside_com/Build_WRF/results/WrfJob_%j.out<br>#SBATCH --error=/home/tinkal_shakya_thecloudside_com/Build_WRF/results/WrfJob_%j.err<br># Load necessary environment<br>source ~/.zshrc<br>cd ~/Build_WRF/WRF/run/<br>mkdir -p ~/Build_WRF/results<br># Run the WRF model&#39;s real.exe and wrf.exe with MPI<br>mpirun ./real.exe<br>if [ $? -ne 0 ]; then<br> echo &quot;Error: real.exe did not complete successfully.&quot; &gt;&amp;2<br> exit 1<br>fi<br>mpirun ./wrf.exe<br>if [ $? -ne 0 ]; then<br> echo &quot;Error: wrf.exe did not complete successfully.&quot; &gt;&amp;2<br> exit 1<br>fi<br># Create directory for results<br>mkdir -p ~/Build_WRF/results/WrfJob_%j<br>mv ~/Build_WRF/WRF/run/wrfout_d01* ~/Build_WRF/results/WrfJob_%j/.<br>mv ~/Build_WRF/WRF/run/wrfrst_d01* ~/Build_WRF/results/WrfJob_%j/.</pre><p><strong>Note:</strong></p><ol><li><strong>You can adjust the value of </strong><strong>#SBATCH --ntasks-per-node from 2to any, depending on the machine type. In my case, I used, </strong><strong>c2d-standard-4, which has only a 2-core CPU, so I set it to 2.</strong></li><li><strong>please update the path in </strong><strong>#SBATCH --output &amp; </strong><strong>#SBATCH --error with your absolute path</strong></li></ol><p>Now save and run the script/job</p><pre>sbatch wrf.slurm</pre><p>To check the status of the job you can run the following commands</p><pre>squeue</pre><p><a href="https://slurm.schedmd.com/squeue.html">squeue job state code(ST) &amp; flags</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/0*-AplnWzLRyl2K2mE" /></figure><p><strong>Note:</strong> The time to complete this test varies based on factors such as the number of cores, vCPUs, and batch job configurations. Depending on the size of the dataset being processed, it can take anywhere from 1 to 3 hours.</p><p>To verify if the process is running, navigate to the Build_WRF/WRF/test/em_real folder and check for files named <strong>wrfout_d01_2016–10–06_*</strong>. As shown in the screenshot below, these output files will be generated one by one as the process progresses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/0*wlku9hPIvKwlV6OT" /></figure><p><strong>Note: The time interval is set to 3 hours in the namelist.input file, and the output will be generated for 48 hours, as specified in the same file.</strong></p><pre>sacct --jobs=3 --format=JobID,JobName,Partition,AllocCPUs,Elapsed,State,Node,ntasks</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TZyycya5vWc4_Pp0" /></figure><h3>Summary</h3><p>The process of building, configuring, and running the WRF model with WPS using Slurm was successful. Leveraging parallel processing and effective job scheduling with Slurm significantly optimized the simulation’s performance, making it well-suited for further testing or operational forecasting.</p><p>This workflow provides a solid foundation for future experiments or production-level runs with WRF, enabling flexibility in adjusting domain size, resolution, or input data to meet diverse research and forecasting requirements.</p><p>We hope this guide has been useful and insightful in your journey to setting up WRF and WPS with the Gfortran compiler in a GCP Slurm HPC Cluster. If you have any questions or feedback, don’t hesitate to share them in the comments below. Thank you for taking the time to read!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1892d124fce5" width="1" height="1" alt=""><hr><p><a href="https://blog.thecloudside.com/setup-wrf-and-wps-with-gfortran-compiler-in-gcp-slurm-hpc-cluster-1892d124fce5">Setup WRF and WPS With Gfortran compiler in GCP Slurm HPC Cluster</a> was originally published in <a href="https://blog.thecloudside.com/">The Cloudside View</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying Monorepo Java Applications in GKE using Istio and Gitlab]]></title>
            <link>https://blog.thecloudside.com/deploying-monorepo-java-applications-in-gke-using-istio-and-gitlab-d6b06d8c3495?source=rss-32dbd15475a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6b06d8c3495</guid>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[java-applications]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[gitlab-ci]]></category>
            <dc:creator><![CDATA[Tinkal Shakya]]></dc:creator>
            <pubDate>Thu, 05 Dec 2024 07:14:17 GMT</pubDate>
            <atom:updated>2024-12-05T15:20:52.971Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*fEzz-uci2tZ5KAuiwkQ75Q.png" /></figure><p>We recently helped a large enterprise deploy its Java monorepo applications on Google Kubernetes Engine (GKE) using GitLab CI/CD and Istio for advanced traffic management. As part of this, we customized the CI/CD pipelines to integrate Docker builds and Istio configurations, ensuring a smooth deployment process for their microservices architecture.</p><p>Deploying a mono repo application in Google Kubernetes Engine (GKE) with Istio service mesh and GitLab for CI/CD can streamline your development and deployment processes. This blog will guide you through setting up your environment and deploying your application.</p><h3>Prerequisites</h3><p>Before you start, ensure you have the following:</p><ol><li>A Google Cloud Platform (GCP) account.</li><li>GitLab repository with your monorepo application.</li><li>gcloud CLI installed and configured.</li><li>kubectl and helm installed on your local machine.</li></ol><p>Note:- To install the gcloud cli</p><pre>sudo apt update<br>sudo apt install apt-transport-https ca-certificates gnupg curl sudo<br><br>echo &quot;deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main&quot; | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list<br><br>curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -<br><br>sudo apt update &amp;&amp; sudo apt install google-cloud-cli<br>sudo apt install google-cloud-sdk-gke-gcloud-auth-plugin</pre><h3>Step 1: Set Up Google Kubernetes Engine</h3><p><strong>Create a GKE Cluster</strong>:</p><pre>gcloud container clusters create my-cluster --zone us-central1-a</pre><p>This command creates a new Kubernetes cluster named my-cluster.</p><p><strong>Connect to the GKE Cluster:</strong></p><p>After creating the cluster, configure kubectl to interact with it:</p><pre>gcloud container clusters get-credentials my-cluster --zone us-central1-a</pre><p>This command fetches the credentials for the cluster and configures kubectl to use it.</p><h3>Step 2: Install Istio</h3><p><strong>Install Istio with Helm</strong>:</p><pre>git clone https://gitlab.com/tinkalshakya/monorepo-deploy-gitlab-ci.git<br>cd monorepo-deploy-gitlab-ci/istio-system<br>helm install istio-base ./base -n istio-system --create-namespace<br>helm install istiod ./istiod -n istio-system<br>helm install pvt-istio-ingressgateway ./gateway -n istio-system</pre><p>This installs the Istio base, discovery, and ingress gateway components in your cluster.</p><p><strong>Verify Installation</strong>:</p><pre>kubectl get pods -n istio-system</pre><p>Ensure all pods are running correctly.</p><h3>Step 3: Configure GitLab CI/CD</h3><p><strong>gitlab application hierarchy</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*EGLb_EmHFwTvg8DMCv5xOw.png" /></figure><h3><strong>1. Create a GitLab CI/CD Pipeline</strong>:</h3><p>In your GitLab repository, create a .gitlab-ci-template.yml file:</p><pre>######################################################<br>## gitlab CI templates for app build and deployment ##<br>######################################################<br>.filter-tail: &amp;filter-tail<br>  only:<br>    - /^feature-.*$/<br>    - /^release-.*$/<br><br><br>image: docker:dind<br>services:<br>  - docker:dind<br><br>variables:<br>  DEV_PROJECT_ID: &lt;Project_ID&gt;<br>  DEV_CLUSTER_NAME: my-cluster<br>  GCP_REGION: us-central1-a<br>  DOCKER_REGISTRY: &lt;Docker_Registry_URI&gt;<br>  BASE_CHART_NAME: &quot;base-app-chart&quot;<br>  GCLOUD_DOCKER_IMAGE: tinkalshakya/google-cloud-sdk:latest<br>  MAVEN_IMAGE: maven:3.5.0-jdk-8 #maven:3.9.0-eclipse-temurin-17-alpine<br>  MVN_CMD: mvn install -U -P jar -DskipTests  #mvn clean package #<br>  IMG_VERSION: &quot;1.0&quot;<br>  EXTENSIONS_TO_CHECK: xml,java,yml,yaml,sql,js,json,html,png,css,scss,gradle<br><br>stages:<br>  - package-build<br>  - image-build<br>  - update-helm-and-deploy-dev<br>  - deploy-dev-hc<br>  - dev-rollabck<br><br><br>#############################################################<br>## Running App Build Scripts based on the templates below. ##<br>#############################################################<br><br>#Maven 3 JDK 8 Build<br>.maven3-build-script-template: &amp;maven3-build-script<br>  stage: package-build<br>  image: ${MAVEN_IMAGE}<br>  before_script:<br>    - echo $BUILD_TYPE<br>    - echo $appName<br>    - echo $folderName<br>  script:<br>    - cd $folderName<br>    - ${MVN_CMD}<br>  artifacts:<br>    paths:<br>      - ${folderName}/target/*.jar<br>    expire_in: 1 day<br><br>.maven3-build-vars: &amp;maven3-build-vars<br>  variables:<br>    appName: $appName<br>    folderName: $folderName<br><br><br>maven3-build:<br>  &lt;&lt;: *maven3-build-vars<br>  &lt;&lt;: *maven3-build-script<br><br><br><br>###############################################################################<br>## Running Docker Image Build and Push Scripts based on the templates below. ##<br>###############################################################################<br>.docker-image-build-and-push-template: &amp;docker-image-build-and-push-script<br>  stage: image-build<br>  services:<br>    - docker:18-dind<br>  before_script:<br>    - echo $GCP_SA_KEY &gt; ${HOME}/gcloud-service-key.json<br>    - export TIMESTAMP=$(date  +%y%m%d-%H%M)<br>    - echo &quot;TIMESTAMP=$TIMESTAMP&quot; &gt;&gt; timestamp-${CI_PIPELINE_IID}.env<br>    - export IMG_VERSION=${IMG_VERSION}<br>    - echo &quot;IMG_VERSION=$IMG_VERSION&quot; &gt;&gt; timestamp-${CI_PIPELINE_IID}.env<br>    - echo $TIMESTAMP<br>    - export DOCKER_BUILDKIT=0<br>    - docker login -u _json_key --password-stdin us-east1-docker.pkg.dev &lt; ${HOME}/gcloud-service-key.json<br>  script:<br>    - cd $folderName<br>    - sed -i &quot;s/APP_NAME/${folderName}/g&quot; Dockerfile<br>    - docker build -t ${DOCKER_REGISTRY}/${appName}:${IMG_VERSION}.${CI_PIPELINE_IID}-${CI_COMMIT_SHORT_SHA}-${TIMESTAMP} .<br>    - docker push ${DOCKER_REGISTRY}/${appName}:${IMG_VERSION}.${CI_PIPELINE_IID}-${CI_COMMIT_SHORT_SHA}-${TIMESTAMP}<br>    - echo -e &quot;\n \n ${YELLOWCOLOR} DOCKER IMAGE BUILT AND PUSHED TO DOCKER REGISTRY:${NOCOLOR}&quot;<br>    - echo -e &quot;${DOCKER_REGISTRY}/${appName}:${IMG_VERSION}.${CI_PIPELINE_IID}-${CI_COMMIT_SHORT_SHA}-${TIMESTAMP}&quot;<br>    - echo -e &quot;\n \n&quot;<br>  artifacts:<br>    reports:<br>      dotenv: timestamp-${CI_PIPELINE_IID}.env<br>    expire_in: 30 days<br>  &lt;&lt;: *filter-tail<br><br>.docker-image-build-and-push-vars: &amp;docker-image-build-and-push-vars<br>  variables:<br>    appName: $appName<br>    folderName: $folderName<br><br>docker-image-build-push:<br>  &lt;&lt;: *docker-image-build-and-push-vars<br>  &lt;&lt;: *docker-image-build-and-push-script<br><br>#######################################################################################<br>## Running Dev Base Helm Chart Pull and Update Scripts based on the templates below. ##<br>#######################################################################################<br>.base-helm-chart-pull-and-update-template: &amp;base-helm-chart-pull-and-update-script<br>  stage: update-helm-and-deploy-dev<br>  image: ${GCLOUD_DOCKER_IMAGE}<br>  before_script:<br>    - echo $GCP_SA_KEY &gt; ${HOME}/gcloud-service-key.json<br>    - gcloud auth activate-service-account $GCP_SA_ID --key-file ${HOME}/gcloud-service-key.json<br>    - gcloud container clusters get-credentials ${DEV_CLUSTER_NAME} --region ${GCP_REGION} --project ${DEV_PROJECT_ID}<br>  needs:<br>    - job: docker-image-build-push<br>      artifacts: true<br>  script:<br>    - rm -rf ${appName}<br>    - cp -r ${BASE_CHART_NAME} ${appName}<br>    - yq e -i &#39;(.name=env(appName))&#39;  ${appName}/Chart.yaml<br>    - yq e -i &#39;(.version=strenv(IMG_VERSION)+&quot;.&quot;+strenv(CI_PIPELINE_IID)+&quot;-&quot;+strenv(CI_COMMIT_SHORT_SHA)+&quot;-&quot;+strenv(TIMESTAMP))&#39; ${appName}/Chart.yaml<br>    - yq e -i &#39;(.appVersion=strenv(IMG_VERSION)+&quot;.&quot;+strenv(CI_PIPELINE_IID)+&quot;-&quot;+strenv(CI_COMMIT_SHORT_SHA)+&quot;-&quot;+strenv(TIMESTAMP))&#39; ${appName}/Chart.yaml<br>    - yq e -i &#39;(.image.repository=env(DOCKER_REGISTRY)+&quot;/&quot;+env(appName))&#39; ${appName}/values.yaml<br>    - yq e -i &#39;(.image.tag=strenv(IMG_VERSION)+&quot;.&quot;+strenv(CI_PIPELINE_IID)+&quot;-&quot;+strenv(CI_COMMIT_SHORT_SHA)+&quot;-&quot;+strenv(TIMESTAMP))&#39; ${appName}/values.yaml<br>    - yq e -i &#39;(.gateway.non_prod_domain=env(DOMAIN_NAME))&#39; ./app_chart_config/${appName}/dev.values.yaml<br>    - helm upgrade --install ${appName} ${appName} --create-namespace -n ${namespace} -f ./app_chart_config/${appName}/dev.values.yaml --debug<br>  &lt;&lt;: *filter-tail<br>  when: manual<br><br><br>.k8s-deploy-body-template-dev-vars: &amp;k8s-deploy-body-template-dev-vars<br>  variables:<br>    appName: $appName<br>    namespace: $NAMESPACE<br><br>update-helm-and-deploy-dev:<br>  &lt;&lt;: *k8s-deploy-body-template-dev-vars<br>  &lt;&lt;: *base-helm-chart-pull-and-update-script<br><br>########################################################<br>## Health Check Scripts based on the templates below. ##<br>########################################################<br>.k8s-deployment-health-check-script: &amp;k8s-deployment-health-check-script<br>  image: ${GCLOUD_DOCKER_IMAGE}<br>  before_script:<br>    - echo &quot;Checking the health check of deployment&quot;<br>    - cd app_health_check<br>    - sed -i &quot;s/APP_NAME/${appName}/g&quot; health-check-script.sh<br>    - sed -i &quot;s/NAMESPACE/${namespace}/g&quot; health-check-script.sh<br>    - sed -i &quot;s/HOST_NAME/${appName}/g&quot; health-check-script.sh<br>    - sed -i &quot;s/ENV/${CI_ENVIRONMENT_SLUG}/g&quot; health-check-script.sh<br>    - sed -i &quot;s/DOMAIN_NAME/${DOMAIN_NAME}/g&quot; health-check-script.sh<br>    - sed -i &quot;s/FOLDER_NAME/${folderName}/g&quot; health-check-script.sh<br>    - chmod +x health-check-script.sh<br>  script:<br>    - echo $GCP_SA_KEY &gt; ${HOME}/gcloud-service-key.json<br>    - gcloud auth activate-service-account $GCP_SA_ID --key-file ${HOME}/gcloud-service-key.json<br>    - gcloud container clusters get-credentials ${DEV_CLUSTER_NAME} --region ${GCP_REGION} --project ${DEV_PROJECT_ID}    <br>    - ./health-check-script.sh<br>  &lt;&lt;: *filter-tail<br><br>.k8s-dev-deployment-health-check-vars: &amp;k8s-dev-deployment-health-check-var<br>  stage: deploy-dev-hc<br>  environment:<br>    name: dev<br>  variables:<br>    appName: $appName<br>    namespace: $NAMESPACE<br>    folderName: $folderName<br>  needs:<br>    - job: update-helm-and-deploy-dev<br><br>dev-health-check:<br>  &lt;&lt;: *k8s-deployment-health-check-script<br>  &lt;&lt;: *k8s-dev-deployment-health-check-var<br><br>###########################################################################<br>## Rollback Helm charts on Dev Env Scripts based on the templates below. ##<br>###########################################################################<br>.k8s-rollback-body-template-dev-script: &amp;k8s-rollback-body-template-dev-script<br>  stage: dev-rollabck<br>  image: ${GCLOUD_DOCKER_IMAGE}<br>  before_script:<br>    - echo &quot;Rolling back to previous deployment&quot;<br>    - echo $GCP_SA_KEY &gt; ${HOME}/gcloud-service-key.json<br>    - gcloud auth activate-service-account $GCP_SA_ID --key-file ${HOME}/gcloud-service-key.json<br>    - gcloud container clusters get-credentials ${DEV_CLUSTER_NAME} --region ${GCP_REGION} --project ${DEV_PROJECT_ID}<br>  script:<br>    - helm rollback ${appName} -n ${namespace}<br>    - echo -e &quot;\n \n ${YELLOWCOLOR} HELM CHART VERSION ROLLEDBACK:${NOCOLOR}&quot;<br>    - echo -e &quot;\n \n ${YELLOWCOLOR} HELM CHART STATUS:${NOCOLOR}&quot;<br>    - helm status ${appName} -n ${namespace}<br>    - echo -e &quot;\n \n&quot;<br>  needs:<br>    - job: dev-health-check<br>  when: on_failure<br>  &lt;&lt;: *filter-tail<br><br>.k8s-rollback-body-template-dev-vars: &amp;k8s-rollback-body-template-dev-vars<br>  variables:<br>    appName: $appName<br>    namespace: $NAMESPACE<br><br>dev-rollabck:<br>  &lt;&lt;: *k8s-rollback-body-template-dev-vars<br>  &lt;&lt;: *k8s-rollback-body-template-dev-script</pre><p>This GitLab CI/CD template is designed for building and deploying applications using Docker and Kubernetes. Here’s a brief explanation of its components:</p><h4>General Structure</h4><ul><li><strong>YAML Anchors and Aliases:</strong> The template uses anchors (&amp;) and aliases (&lt;&lt;) to avoid repetition. Common configurations are defined once and reused.</li><li><strong>Stages:</strong> Defined stages include package-build, image-build, update-helm-and-deploy-dev, deploy-dev-hc, and dev-rollback.</li></ul><h4>Key Sections</h4><ol><li><strong>Global Variables and Settings:</strong></li></ol><ul><li>Docker in Docker (dind) is used for building Docker images.</li><li>Variables like DEV_PROJECT_ID, DEV_CLUSTER_NAME, and DOCKER_REGISTRY are defined for use throughout the pipeline.</li></ul><p><strong>2. Stages and Jobs:</strong></p><ul><li><strong>.filter-tail:</strong> Specifies that jobs only run for branches matching the patterns feature-* or release-*.</li><li><strong>.maven3-build-script-template &amp; .maven3-build-vars:</strong> Define how to build the application using Maven.</li><li><strong>maven3-build:</strong> Combines the Maven build script and variables into a job.</li><li><strong>.docker-image-build-and-push-template &amp; .docker-image-build-and-push-vars:</strong> Define how to build and push Docker images.</li><li><strong>docker-image-build-push:</strong> Combines Docker image build and push script and variables into a job.</li><li><strong>.base-helm-chart-pull-and-update-template:</strong> Handles updating Helm charts and deploying to the development environment.</li><li><strong>update-helm-and-deploy-dev:</strong> Job for updating Helm charts and deploying to the development environment.</li><li><strong>.k8s-deployment-health-check-script:</strong> Script to perform health checks on the deployed application.</li><li><strong>dev-health-check:</strong> Job that runs the health check script.</li><li><strong>.k8s-rollback-body-template-dev-script:</strong> Script for rolling back deployments if the health check fails.</li><li><strong>dev-rollabck:</strong> Job for rolling back the deployment in case of failure.</li></ul><h4>Workflow Summary</h4><ol><li><strong>Build Application:</strong> Maven is used to build the application.</li><li><strong>Build and Push Docker Image:</strong> Docker image is built and pushed to a registry.</li><li><strong>Update Helm Charts and Deploy:</strong> Helm charts are updated and the application is deployed to a Kubernetes cluster.</li><li><strong>Health Check:</strong> A health check script ensures the deployment is successful.</li><li><strong>Rollback:</strong> If the health check fails, the deployment is rolled back to the previous version.</li></ol><p>This template is designed to automate the CI/CD process for a cloud-based application, ensuring efficient build, deployment, and rollback capabilities.</p><h3><strong>2. D</strong>efines gitLab CI template set of rules:</h3><p>In your GitLab repository, create a .gitlab-ci-basic-rules.yml file:</p><p>This section of the GitLab CI template defines a set of rules for when jobs should be executed. Here’s a breakdown of each rule and its conditions:</p><h4>Rules Breakdown</h4><ol><li><strong>Pipeline Source Web:</strong></li></ol><pre>- if: $CI_PIPELINE_SOURCE == &quot;web&quot;   <br>  when: manual</pre><p>If the pipeline is triggered via the web interface (e.g., manually triggered through GitLab’s UI), the job will be executed manually.</p><p><strong>2. Pipeline Source Not Push:</strong></p><pre>- if: $CI_PIPELINE_SOURCE != &quot;push&quot;<br>  when: never</pre><p>The job will never run if the pipeline source is not a push event (e.g., a merge request or schedule).</p><p><strong>3. Commit Branch with Changes:</strong></p><pre>- if: $CI_COMMIT_BRANCH<br>  changes:<br>    - $MODULE/**/*.{$EXTENSIONS_TO_CHECK}<br>    - &quot;pom.xml&quot;<br>    - &quot;.gitlab-ci.yml&quot;<br>    - &quot;Dockerfile&quot;<br>  when: always</pre><p>If there is a commit to any branch and the changes include any files matching the specified patterns ($MODULE/**/*.{$EXTENSIONS_TO_CHECK}, pom.xml, .gitlab-ci.yml, Dockerfile), the job will always run.</p><p><strong>4. Feature or Release Branch with Maven Build Type:</strong></p><pre>- if: (($CI_COMMIT_BRANCH =~ /feature-.*/ || $CI_COMMIT_BRANCH =~ /release-.*/) &amp;&amp; ($BUILD_TYPE == &quot;maven3&quot;))<br>  when: manual</pre><p>If the commit is to a branch that matches feature-* or release-* and the build type is maven3, the job will be executed manually.</p><p><strong>5. Default Manual with Allow Failure:</strong></p><pre>- when: manual   <br>  allow_failure: true</pre><p>By default, the job will be executed manually, and failure of the job is allowed without causing the entire pipeline to fail.</p><h3>Step 4 Trigger the Pipeline and Verify</h3><p>Push your changes to GitLab to trigger the CI/CD pipeline. The pipeline will:</p><ol><li>Build and package the Java services.</li><li>Build and push Docker images to GCR.</li><li>Deploy the services to GKE and configure Istio.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VTH-f_QPhDn29XK9aRREaA.png" /></figure><p>To verify the pods are running properly, run the below commands:</p><pre>kubectl get pods -n &lt;namespace&gt;<br>kubectl get svc -n &lt;namespace&gt;</pre><p>Access your services through the DNS records.</p><pre>http://shopfront-dev.*****.***/<br>http://productcatalogue-dev.*****.***/product<br>http://stockmanager-dev.*****.***/stocks</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8fYg5M8Xht0YFqa-1RxBOQ.png" /></figure><p>Configure Kubernetes health checks for your Java microservices to ensure stability:</p><ol><li><strong>Shopfront</strong>: Use /health for both livenessProbe and readinessProbe in shopfront-deployment.yaml.</li><li><strong>Product Catalogue</strong>: Use /healthcheck in productcatalogue-deployment.yaml.</li><li><strong>Stock Manager</strong>: Use /actuator/health in stockmanager-deployment.yaml.</li></ol><p>This ensures Kubernetes monitors and restarts non-responsive services while routing traffic only to healthy instances.</p><pre>http://shopfront-dev.*****.***/health<br>http://productcatalogue-dev.*****.***/healthcheck<br>http://stockmanager-dev.*****.***/actuator/health</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*49kBBS7M0fm98AZjQqD4uQ.png" /></figure><h3>Conclusion</h3><p>A well-orchestrated deployment pipeline ensures efficient management of Java microservices in a Kubernetes environment. Leveraging GKE for scalability, Istio for advanced traffic control, and GitLab for CI/CD results in a robust infrastructure that can easily handle complex deployments. This setup helps teams deliver faster, with better control and observability over their services, ensuring high availability and performance. Happy deploying!</p><p>We hope this guide has been useful and insightful in your journey to deploying Java monorepo applications on GKE using Istio and GitLab CI/CD. If you have any questions or feedback, feel free to share them in the comments below. Thank you for taking the time to read!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6b06d8c3495" width="1" height="1" alt=""><hr><p><a href="https://blog.thecloudside.com/deploying-monorepo-java-applications-in-gke-using-istio-and-gitlab-d6b06d8c3495">Deploying Monorepo Java Applications in GKE using Istio and Gitlab</a> was originally published in <a href="https://blog.thecloudside.com/">The Cloudside View</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting Up an HPC Slurm Cluster on GCP with RHEL 7]]></title>
            <link>https://blog.thecloudside.com/setting-up-an-hpc-slurm-cluster-on-gcp-with-rhel-7-3adcd1ea96e1?source=rss-32dbd15475a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/3adcd1ea96e1</guid>
            <category><![CDATA[slurm]]></category>
            <category><![CDATA[packers]]></category>
            <category><![CDATA[rhel7]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[google-cloud]]></category>
            <dc:creator><![CDATA[Tinkal Shakya]]></dc:creator>
            <pubDate>Tue, 16 Jul 2024 07:22:58 GMT</pubDate>
            <atom:updated>2024-07-16T07:23:16.417Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*n-sr6ilQt0rEFLOyoNVCCw.png" /></figure><h3>Overview</h3><p>We blogged previously on <a href="https://medium.com/cloudside/hpc-clusters-on-gcp-running-ls-dyna-jobs-on-slurm-using-intel-mpi-7e02e4410511">how to run LS-Dyna</a> jobs on a Slurm cluster on GCP. You can provision a Slurm cluster on GCP in multiple ways using <a href="https://github.com/SchedMD/slurm-gcp">SchedMD’s Terraform template</a> or <a href="https://cloud.google.com/hpc-toolkit/docs/overview">GCP’s HPC toolkit</a>. However, neither supports deploying the Slurm nodes with a custom/hardened image with a different OS like RHEL. One of the large enterprise clients we are currently working with had a requirement to build the Slurm clusters with an IT-approved, hardened RHEL image. In this post, we explain how to deploy the Slurm cluster using Packer and Ansible.</p><h4>Why Use Ansible and Packer?</h4><p>Ansible and Packer are powerful automation tools that can streamline the creation of custom images. Here’s how they work together to create a RHEL image with Slurm configuration:</p><h3>Ansible</h3><p>Ansible is an open-source tool for configuration management and application deployment. It uses playbooks to automate tasks like installing packages, setting up Slurm nodes, and configuring networks on RHEL.</p><ul><li><strong>Ansible Playbooks</strong>: These scripts automate the installation and configuration of Slurm on RHEL. They can handle tasks such as installing necessary packages, configuring Slurm control and compute nodes, setting up user accounts, and configuring network settings.</li><li><strong>Roles</strong>: Ansible roles encapsulate complex sets of tasks and variables, promoting modularity and reuse of configuration scripts. They make it easier to manage and apply consistent configurations across different environments.</li></ul><h3>Packer</h3><p>Packer is an open-source tool for building identical machine images for multiple platforms. It uses builders, provisioners, and post-processors to create custom images.</p><ul><li><strong>Builders</strong>: These define the type of machine image you are creating and the platform it will run on. For example, you can use a GCP Virtual Machine builder to create a disk image.</li><li><strong>Provisioners</strong>: After starting a VM instance based on a basic RHEL image, Packer uses Ansible to install and configure Slurm by running Ansible playbooks within the Packer build process.</li><li><strong>Post-processors</strong>: Once the image is created, post-processors handle tasks like compressing it, uploading it to cloud storage, or adding metadata.</li></ul><h3>Supported Published Image Family</h3><p>You&#39;ll find various available images when searching for supported published image families for Slurm HPC clusters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/0*0mPxt6xcXg6GspPn" /></figure><p>However, there are currently no RHEL (Red Hat Enterprise Linux)-related images included in the list. As a result, organizations needing to use RHEL for their Slurm HPC environments will have to create a custom disk image to meet their specific requirements.</p><h3>Custom Image</h3><p>To create slurm cluster-compliant images yourself, a custom Slurm image can be created. Packer and Ansible are used to orchestrate custom image creation.</p><p>Custom images can be built from a supported private or public image (e.g. rhel7, centos-7). Additionally, ansible roles or scripts can be added to the provisioning process to install custom software and configure the custom Slurm image. In the next few steps, we will look at creating a custom image with RHEL and slurm configurations using packer and ansibe.</p><h3>Prerequisites</h3><p><strong>1. Install packer</strong></p><pre>sudo apt install packer<br>                                  <br>                              OR<br><br># Download the latest Packer binary<br>wget https://releases.hashicorp.com/packer/1.8.0/packer_1.8.0_linux_amd64.zip<br># Unzip the downloaded file<br>unzip packer_1.8.0_linux_amd64.zip<br># Move the packer binary to /usr/local/bin<br>sudo mv packer /usr/local/bin/</pre><p><strong>2. Install ansible</strong></p><pre>sudo apt-add-repository ppa:ansible/ansible<br>sudo apt update<br>sudo apt install ansible</pre><h3>Create image</h3><p>Install software dependencies and build images from the configuration. Clone the <a href="https://github.com/GoogleCloudPlatform">GoogleCloudPlatform</a>/<a href="https://github.com/GoogleCloudPlatform/slurm-gcp">slurm-gcp</a> repository. This repo contains slurm, packer configuration for building an image and terraform code for deploy the slurm cluster VMs</p><pre>git clone https://github.com/GoogleCloudPlatform/slurm-gcp.git</pre><h4>Need for Customizations</h4><p>Before building images with Packer, you can customize the process by modifying the slurm-gcp/packer/example.pkrvars.hcl file to include necessary and preferred configurations. This flexibility allows for the addition of custom packages and other specific settings, and these methods can be combined as needed to meet exact requirements.</p><p><strong>Note: You need to change the configuration under the image of these variable values. soruce_image_family is mandatory.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/0*zjJcv6dih0jD7fzq" /></figure><p>Then perform the following commands on the project root directory:</p><pre>cd slurm-gcp/packer<br>packer init . #to get the plugins<br>packer validate -var-file=example.pkrvars.hcl . #to validate the configuration<br>packer build -var-file=example.pkrvars.hcl . #to run the image build process</pre><p>Building an image with Packer might take approximately 15–20 minutes. Once the command executes successfully, the resultant image will appear as specified in the configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*SefpRMx-pxAP3xkvw31c4w.png" /></figure><h3>Deploy the HPC cluster using a custom Slurm image</h3><p>To deploy an HPC cluster using the previously created image, this example sets up a Slurm cluster, which is highly configurable via .tfvars files. Modify the <strong>slurm-gcp/terraform/slurm_cluster/examples/slurm_cluster/test_cluster/example.tfvars </strong>with the required and desired values to tailor the cluster according to specific needs. Use the image crafted in the earlier steps and update the variables as outlined to ensure the cluster is configured correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Kr8PEuDHvR1ILxcT" /></figure><p><strong>Note:</strong> The variables mentioned are found in multiple sections within the <strong>slurm-gcp/terraform/slurm_cluster/examples/slurm_cluster/test_cluster/example.tfvars</strong> file. Please ensure that all variables are updated as indicated across all relevant sections to avoid configuration discrepancies. Need to update the actual values instead of &lt;subnet_name&gt;, &lt;region_name&gt;,&lt;zone_name&gt;, &lt;project_id&gt;, &lt;image_project_id&gt; ,&lt;image_family&gt;</p><p>Now execute the following commands on this <a href="https://github.com/GoogleCloudPlatform/slurm-gcp/blob/master/docs/glossary.md#terraform-project">terraform project</a> root directory to reach the test_cluster folder.</p><pre>cd slurm-gcp/terraform/slurm_cluster/examples/slurm_cluster/test_cluster<br>terraform init #to get the plugins<br>terraform validate #to validate the configuration<br>terraform plan -var-file=example.tfvars #to see the infrastructure plan<br>terraform apply -var-file=example.tfvars #to apply the infrastructure build</pre><p>This process will create Slurm cluster VMs on Google Cloud Platform (GCP) using the custom image we previously created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DWtbnAQEY5Qu6jBe" /></figure><p>After logging into the VMs, you can identify that one of the VMs is the controller, and another is the login server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*lX8BJvfi4uIbZDuC6FvBgQ.png" /></figure><p>To run a job on either of the VMs in the cluster, you need to create a script to provide load to the cluster. This will allow you to observe how the cluster is handling the load.</p><p>Create a bash file</p><pre>vim test-job.sh<br>#!/bin/bash<br>## Resource Request<br>#SBATCH - job-name=TestJob<br>#SBATCH - output=TestJob.out<br>#SBATCH - time=1–00:10:00<br>#SBATCH - ntasks=1<br>#SBATCH - cpus-per-task=1<br>#SBATCH - mem-per-cpu=500M<br>## Job Steps<br>srun echo &quot;`Start process`&quot;<br>srun hostname<br>srun sleep 30<br>srun echo &quot;`End process`&quot;</pre><p>Now run the bash file using the following command to run a job</p><p><strong>sbatch test-job.sh</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*VCGkNHCh47Nht2SLIdTC3Q.png" /></figure><p>Using the <strong>sinfo</strong> command, you find the information related to the nodes created after the job is run. You can see the detailed information of running the new job in the above screenshot. The new job is running in the node basic-c2s4–0.</p><p>We hope that this guide has been informative and helpful in your journey towards building scalable and resilient applications. If you have any questions or comments, please feel free to leave them below. Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3adcd1ea96e1" width="1" height="1" alt=""><hr><p><a href="https://blog.thecloudside.com/setting-up-an-hpc-slurm-cluster-on-gcp-with-rhel-7-3adcd1ea96e1">Setting Up an HPC Slurm Cluster on GCP with RHEL 7</a> was originally published in <a href="https://blog.thecloudside.com/">The Cloudside View</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MongoDB Full and Incremental Backup using MongoDB dump]]></title>
            <link>https://blog.thecloudside.com/mongodb-full-and-incremental-backup-using-mongodb-dump-6ce7fb03e381?source=rss-32dbd15475a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ce7fb03e381</guid>
            <category><![CDATA[mongodb-replication]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[mongodump]]></category>
            <dc:creator><![CDATA[Tinkal Shakya]]></dc:creator>
            <pubDate>Fri, 07 Jul 2023 13:30:06 GMT</pubDate>
            <atom:updated>2024-07-10T09:40:22.690Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1RHrSROtbQm0DtrEa1FEDw.png" /></figure><p>We are going to document how to do full and incremental backups using the native MongoDB dump tool, mongodbdump let’s jump right in.</p><h4>Now, we will start taking MongoDB Backup</h4><h3>Step 1: Install MongoDB in the VM</h3><p>Firstly, let’s install MongoDB on a VM running Ubuntu 20.04 on the Google Cloud Platform (GCP). Open the terminal and execute the following commands:</p><pre>sudo apt update<br>sudo apt install -y wget curl gnupg2 software-properties-common apt-transport-https ca-certificates lsb-release<br>curl -fsSL https://www.mongodb.org/static/pgp/server-5.0.asc|sudo gpg - dearmor -o /etc/apt/trusted.gpg.d/mongodb-5.gpg<br>wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -<br>echo &quot;deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu $( lsb_release -cs)/mongodb-org/5.0 multiverse&quot; | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list<br>sudo apt update<br>sudo apt install -y mongodb-org<br>sudo systemctl enable - now mongod<br>mongod - version</pre><h3>Step 2: Configure MongoDB for Replication</h3><p>Next, we need to configure MongoDB for replication. Open the MongoDB configuration file:</p><pre>sudo vim /etc/mongod.conf</pre><pre>. . .<br># network interfaces<br>net:<br>  port: 27017<br>  bindIp: 127.0.0.1<br>. . .<br>replication:<br>  replSetName: &quot;rs0&quot;<br>  oplogSizeMB: 1024<br>. . .</pre><p>Save and exit the file, then restart the mongod service in all the VMs.</p><pre>sudo systemctl restart mongod</pre><h3>Step 3: Initialize Replica Set</h3><p>Now, let’s initialize the replica set. Open the MongoDB shell:</p><pre>mongosh</pre><p>Inside the MongoDB shell, run the following commands:</p><pre>rs.initiate(<br>… {<br>… _id: &quot;rs0&quot;,<br>… members: [<br>… { _id: 0, host: &quot;localhost&quot;},<br>… ]<br>… })<br>rs0:OTHER&gt;</pre><p>You should see rs0:OTHER&gt; as the prompt. To verify the replica set status, run rs.status():</p><pre>rs0:OTHER&gt;rs.status()</pre><p>Now the VM should be a primary replica.</p><pre>rs0:PRIMARY&gt;</pre><p>exit from the Mongo shell.</p><h3>Step 4: Create a Base Backup</h3><p>Now we create a simple <strong>query.js</strong> file and add the following strings. Here <strong>1684485444 is </strong>the current timestamp. You can get the current timestamp by using the following command.</p><pre>date +%s</pre><p>create a query.js file</p><pre>vim query.js</pre><p>Copy the given below content in the query.js file and replace the timestamp with the old timestamp as shown below.</p><pre>{&quot;ts&quot;:{&quot;$gt&quot;:{&quot;$timestamp&quot;:{&quot;t&quot;:1684485444,&quot;i&quot;:1}}}}</pre><p>Now you can make changes in Mongo shell to add databases, collections, and documents in the database then we can take backups.</p><h3>To create a base backup:</h3><p><strong>I. Full (base) Backup using mongodump:</strong></p><p>In the above, we learned about the importance of taking a base (full) backup before performing incremental backups in MongoDB. This step will guide you through the process of creating a base backup using the mongodump tool. Additionally, we will update the query.js file with the current timestamp to ensure proper synchronization with the incremental backups.</p><p>1. Set Up the Base Backup Script To begin, we’ll create a script named base_backup.sh that automates the base backup process. Open a text editor and enter the following content:</p><pre>#!/bin/bash<br><br>mongodump -h localhost --port 27017 -o backups/base<br>New_DATE=$(date +%s)<br>Old_DATE=$(cat query.js | awk -F: &#39;{print $5}&#39; | cut -c1-10)<br>sed -i &quot;s|$Old_DATE|$New_DATE|g&quot; query.js</pre><p>Explanation:</p><ul><li>The script starts with the shebang (#!/bin/bash) to indicate it should be executed using the Bash shell.</li><li>The “mongodump” command connects to the MongoDB instance running on localhost at port 27017 and performs a full backup. The backup files are stored in the “backups/base” directory.</li><li>We capture the current timestamp using the “date +%s” command and store it in the variable “New_DATE”.</li><li>The variable “Old_DATE” extracts the previous timestamp from the query.js file, assuming it is located after the fourth colon (:). The awk and cut commands are used for this extraction.</li><li>Finally, we use the “sed” command to replace the old timestamp in query.js with the new timestamp.</li></ul><p>2. Save the script and make it executable:</p><pre>chmod +x base_backup.sh</pre><p>3. Run the script to perform the base backup:</p><pre>./base_backup.sh</pre><p><strong>Note- The base backup is stored in backups/base.</strong></p><h3>Step 5: Create an Incremental backup:</h3><p>An incremental backup captures only the changes made to the database since the last backup, reducing the backup time and storage requirements. However, MongoDB does not natively support incremental backups with mongodump.</p><p>To create an incremental backup using mongodump, follow these steps:</p><ol><li>Create a script named incr_backup.sh and add the following content:</li></ol><pre>#!/bin/bash<br><br>DATE=$(date +%Y-%m-%d_%H-%M-%S)<br>mkdir -p backups/incremental/$DATE<br>mongodump -h localhost -d local -c oplog.rs --queryFile query.js --port 27017 -o - &gt; backups/incremental/$DATE/oplog.bson<br>New_DATE=$(date +%s)<br>Old_DATE=$(cat query.js | awk -F: &#39;{print $5}&#39; | cut -c1–10)<br>sed -i &quot;s|$Old_DATE|$New_DATE|g&quot; query.js</pre><p>The following script takes incremental backup from the previous timestamp provided in the query file. It then stores the current timestamp in the <strong>query.js</strong> file. The next incremental backup will take oplogs from this timestamp(time). The backups are stored in the <strong>$DATE</strong> format for identification.</p><p>2. Save the script and make it executable</p><pre>chmod +x incr_backup.sh</pre><p>3. Run the script to perform the incremental backup:</p><pre>./incr_backup.sh</pre><p>The incremental backup (oplogs) will be stored in the backups/incremental/$DATE/oplog.bson file, where $DATE represents the current timestamp.</p><h3>Step 6: Restore a MongoDB Backup:</h3><p>Once you have a backup, it’s crucial to know how to restore it when needed. The mongorestore tool is used to restore MongoDB backups created with mongodump. Here&#39;s how you can restore a backup:</p><p>Now that you have the oplog files, you can restore in any other VM with mongoDB with the same version using the following command-</p><pre>mongorestore -h localhost --oplogReplay --port 27017 --oplogFile=backups/incremental/2023–05–19_14–07–24/oplog.bson --dir backups/base</pre><p>Make sure to replace backups/incremental/2023-05-19_14-07-24/oplog.bson with the actual path to your oplog file.</p><p>2. If you are restoring the same database, you need to empty the database as it already contains the data you need to restore. If you are using a new VM with MongoDB database, you have to restore all the backups serially.</p><p>The mongorestore the command includes the following options:</p><p><strong>-h: </strong>Hostname</p><p><strong>oplogReplay:</strong> This option instructs mongorestore to apply the oplog operations from the specified oplog file. The oplog contains the incremental changes made to the database since the last backup.</p><p><strong>--port: </strong>MongoDB port number</p><p><strong>--oplogFile:</strong> Specifies the path to replaying the oplog file. This file contains the oplog entries generated by MongoDB, capturing the incremental changes. This is specified when taking an incremental backup</p><p><strong>--dir: </strong>Specifies the directory where the base backup files are located. This directory should contain the BSON and metadata files generated by the mongodump command, representing a complete dump of the database. The location is specified while creating a base and incremental backup.</p><p>That’s it! You now have a solid understanding of how to perform full and incremental backups using mongodump in MongoDB. By following these steps, you can ensure the safety of your data and easily restore it in case of data loss or system failures.</p><p><strong>Please note that the scripts and commands provided in this blog post are meant for instructional purposes and may need to be modified according to your specific setup and requirements.</strong></p><p>There are multiple ways of taking base and incremental backup for mongoDB. One of the way is to use a managed service like Percona backup for MongoDB. As it is a free service it is an easy and pocket friendly way to for base and incremental backup. You can refer to the blog- <a href="https://blog.thecloudside.com/percona-backup-for-mongodb-75b34501f1cd">Percona backup for Mongodb</a> by <a href="https://medium.com/u/94864c7683da">Writtick Sengupta</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ce7fb03e381" width="1" height="1" alt=""><hr><p><a href="https://blog.thecloudside.com/mongodb-full-and-incremental-backup-using-mongodb-dump-6ce7fb03e381">MongoDB Full and Incremental Backup using MongoDB dump</a> was originally published in <a href="https://blog.thecloudside.com/">The Cloudside View</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Highly Available MongoDB Replication with Primary Replica on GCP and Secondary Replica…]]></title>
            <link>https://blog.thecloudside.com/building-a-highly-available-mongodb-replication-with-primary-replica-on-gcp-and-secondary-replica-5d32bac8121b?source=rss-32dbd15475a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d32bac8121b</guid>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[mongodb-replication]]></category>
            <dc:creator><![CDATA[Tinkal Shakya]]></dc:creator>
            <pubDate>Wed, 15 Mar 2023 11:44:31 GMT</pubDate>
            <atom:updated>2023-07-11T20:37:04.347Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Highly Available MongoDB Replication with Primary Replica on GCP and Secondary Replica on AWS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pjui-21y9pJmm4S87Ns-ow.png" /></figure><p>In this article, we will walk you through how to set up MongoDB replication with a primary replica in Google Cloud Platform (GCP) and a secondary replica in Amazon Web Services (AWS) as a part of a Hybrid Cloud Environment.</p><h3><strong>Pre-requisites-</strong></h3><p>We will start by creating an HA-VPN tunnel between GCP and AWS</p><p><strong>Link:</strong> <a href="https://medium.com/peek-travel/connecting-an-aws-and-gcp-vpc-using-an-ipsec-vpn-tunnel-with-bgp-f332c2885975">VPN setup between AWS &amp; GCP</a></p><p><strong>Setup in AWS Side</strong></p><ol><li>Create a custom VPC with a subnet (172.31.0.0/24)</li><li>Create two Customer GW (to accommodate the GCP side of details)</li><li>Create a VPG (Virtual Private Gateway) and Attach a VPG to create VPC</li><li>Create two Site to Site VPNs (4 tunnels)</li><li>Update security group and routes to allow traffic from GCP</li></ol><p><strong>Setup in GCP Side of Steps</strong></p><ol><li>Create a custom VPC with a subnet(say 10.20.0.0/24)</li><li>Setup/Create a Cloud router</li><li>Create an HA-VPN and set up Cloud VPN Gateway.</li><li>Set up Peer VPN Gateway</li><li>Set up Cloud VPN tunnels</li><li>Set up a BGP session</li><li>Update firewall rules for custom VPC to allow traffic from AWS.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Xas9xGw49OoJulLd" /><figcaption>Established the BGP Session</figcaption></figure><p>To set up MongoDB replication with the primary replica in GCP and the secondary replica in AWS, we will follow these steps:</p><p><strong>Step 1-</strong> Create two Vms using Ubuntu(20.04 LTS) Boot Disk image with names tw-mongo-primary(GCP), tw-mongo-1(AWS). Here the Primary database will be in GCP and the Secondary replica will be in AWS.</p><p><strong>Step 2-</strong> SSH into all the VMs and install mongo DB. Keep the SSH windows of all the Vms open as we will work on them parallelly. We have installed MongoDB version 4.4 as we wanted to demonstrate the perks of using the old version. Using the latest version can reduce multiple steps in the following task.</p><pre>wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -<br>echo &quot;deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/5.0 multiverse&quot; | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list<br>sudo apt-get update<br>sudo apt-get install -y mongodb-org<br>sudo systemctl start mongod<br>sudo systemctl status mongod</pre><p><strong>Step 3-</strong> <strong>Configuring DNS Resolution</strong></p><p><strong>/etc/hosts</strong> is a special file that allows you to assign human-readable hostnames to numerical IP addresses. This means that if the IP address of any of your servers ever changes, you’ll only have to update the<strong> /etc/hosts</strong> file on all servers instead of reconfiguring the replica set.</p><pre>sudo vim /etc/hosts</pre><p>After the first line add the private IP and name of the host (tw-mongo-primary and replicas)</p><pre>127.0.0.1 localhost<br>10.20.0.4 tw-mongo-primary<br>172.31.59.28 tw-mongo-1</pre><p><strong>Note: Make these changes in all the Vms. All the host files will look identical after you make the changes</strong></p><p><strong>Step 4-</strong> <strong>Updating Each Server’s Firewall Configurations with UFW</strong></p><p>You will have set up a firewall on each of the servers on which you’ve installed MongoDB and enabled access for the OpenSSH UFW profile. This is an important security measure, as these firewalls currently block connections to any port on your servers, save for ssh connections that present keys that align with those in each server’s respective <strong>authorized_keys</strong> file.</p><p>However, these firewalls will also block the MongoDB instances on each server from communicating with one another, preventing you from initiating the replica set. To correct this, you’ll need to add new firewall rules to allow each server access to the port on the other two servers on which MongoDB is listening for connections.</p><p><strong>SSH into tw-mongo-primary VM and add the firewall rules</strong></p><pre>sudo ufw allow from tw-mongo-1_pvt_IP to any port 27017</pre><p><strong>SSH into the tw-mongo-1 VM and add the firewall rules</strong></p><pre>sudo ufw allow from tw-mongo-primary_pvt_IP to any port 27017</pre><p><strong>Step 5- Enabling Replication in Each Server’s MongoDB Configuration File</strong></p><p>At this point, you’ve edited your servers’ /etc/hosts files to configure hostnames which will resolve to each one’s IP address. You’ve also opened up each of your servers’ firewalls to allow the other two servers access to the default MongoDB port, 27107. Even though you’ve opened up each server’s firewall to allow the other servers access to port 27017, MongoDB is currently bound to 127.0.0.1, the local loopback network interface. This means that MongoDB is only able to accept connections that originate on the server where it’s installed.</p><p>To allow remote connections, you must bind MongoDB to your servers’ publicly-routable IP addresses in addition to 127.0.0.1. This way, your MongoDB installation will be able to listen to connections made to your MongoDB server from remote machines.</p><p>In the tw-mongo-primary VM, make the following changes in the mongod.conf file</p><pre>sudo vim /etc/mongod.conf</pre><pre>. . .<br># network interfaces<br>net:<br>  port: 27017<br>  bindIp: 127.0.0.1,tw-mongo-primary<br>. . .<br>replication:<br>  replSetName: &quot;rs0&quot;<br>. . .</pre><p>In the AWS (tw-mongo-1) VM, make the following changes in the mongod.conf file</p><pre>sudo vim /etc/mongod.conf</pre><pre>. . .<br># network interfaces<br>net:<br>  port: 27017<br>  bindIp: 127.0.0.1,tw-mongo-1<br>. . .<br>replication:<br>  replSetName: &quot;rs0&quot;<br>  oplogSizeMB: 1024<br>. . .</pre><p>Restart the mongod service in all the VMs.</p><pre>sudo systemctl restart mongod</pre><p>You can test the connection between tw-mongo-primary, and tw-mongo-1.</p><p>Go to tw-mongo-1 VM and check the connection between tw-mongo-1 and tw-mongo-primary by using the following command.</p><pre>nc -zv tw-mongo-primary 27017</pre><p><strong>Step 6 </strong>— <strong>Starting the Replica Set and adding Members</strong></p><p>Now that you’ve configured each of your three MongoDB installations, you can open up a MongoDB shell to initiate replication and add each VM (host) as a member.</p><p>Go to the GCP (tw-mongo-primary) VM and type <strong>mongo </strong>in the CLI.</p><p><strong>NOTE- As our MongoDB version is 4.4, we will use mongo. For later versions, we use <em>mongosh</em>. I would recommend using the latest version!</strong></p><p>From the prompt, you can initiate a replica set from the mongo shell by running the rs.initiate() method. However, running this method by itself would only initiate replication for the machine on which you run the method, and you’d then need to add your other Mongo instances by issuing an <strong>rs.add()</strong> method for each member.</p><p>To do this, begin an rs.initiate() method by typing the following.</p><pre>rs.initiate({_id: &quot;rs0&quot;,members: [{ _id: 0, host: &quot;tw-mongo-primary&quot; },{ _id: 1,host: &quot;tw-mongo-1&quot; },]})</pre><p>In this case you have created a tw-mongo-primary and a secondary replica.</p><p>If the replica set was initiated as expected, you’ll notice that the MongoDB client’s prompt will change from just a greater-than sign (&gt;) to the following:</p><pre>rs0 [direct: secondary] test &gt;</pre><p>Next, run the command rs.help()</p><pre>rs0 [direct: secondary] test &gt; rs.help()</pre><p>This should provide the following output</p><p>Output</p><pre> rs.status() { replSetGetStatus : 1 } checks repl set status<br> rs.initiate() { replSetInitiate : null } initiates set with default settings<br> rs.initiate(cfg) { replSetInitiate : cfg } initiates set with configuration cfg<br> rs.conf() get the current configuration object from local.system.replset<br> rs.reconfig(cfg) updates the configuration of a running replica set with cfg (disconnects)<br> rs.add(hostportstr) add a new member to the set with default attributes (disconnects)<br> rs.add(membercfgobj) add a new member to the set with extra attributes (disconnects)<br> rs.addArb(hostportstr) add a new member which is arbiterOnly:true (disconnects)<br> rs.stepDown([stepdownSecs, catchUpSecs]) step down as tw-mongo-primary (disconnects)<br> rs.syncFrom(hostportstr) make a secondary sync from the given member<br> rs.freeze(secs) make a node ineligible to become tw-mongo-primary for the time specified<br> rs.remove(hostportstr) remove a host from the replica set (disconnects)<br> rs.secondaryOk() allow queries on secondary nodesrs.printReplicationInfo() check oplog size and time range<br> rs.printSecondaryReplicationInfo() check replica set members and replication lag<br> db.isMaster() check who is tw-mongo-primary<br> db.hello() check who is tw-mongo-primary<br><br>reconfiguration helpers disconnect from the database so the shell will display<br> an error, even if the command succeeds.<br></pre><p>After running rs.help() or another one of these methods, you may see the client prompt change again to tw-mongo-primary</p><pre>rs0 [direct: primary] test &gt;</pre><p>This means that the MongoDB instance that you’re connected to was elected to serve as the tw-mongo-primary set member.</p><p><strong>NOTE-</strong> If you have additional nodes that you’d like to add to the replica set in the future, you can do so with the <strong>rs.add()</strong> method. Make sure the configuration is done for the new tw-mongo-2 as shown in above steps.</p><pre>rs.add( &quot;tw-mongo-2&quot; )</pre><p>Now when you type mongosh in the VM, You can see one VM as tw-mongo-primary and other two VM as secondary. Considering you have updated the host file, firewalls, mongod.conf file correctly.</p><p>Now the tw-mongo-primary is used for Read/Write and the secondaries are used for Read only. If the tw-mongo-primary fails, one of the secondary will become the tw-mongo-primary automatically. This feature is called Automatic failover.</p><p><strong>TESTING REPLICATION</strong></p><p><strong>Step 7-</strong> Create a database and collection in tw-mongo-primary VM</p><pre>rs0 [direct: primary] test &gt;use db-tw<br>rs0 [direct: primary] db-tw &gt; db.createCollection(&quot;tw-test-1&quot;)</pre><p>Now if you try to see if the database and collection have been updated in the secondary VM, you will get the output</p><pre>rs0 [direct: secondary] test &gt;use db-tw<br>rs0 [direct: secondary] db-tw &gt; show dbs<br>rs0 [direct: secondary] db-tw &gt; show collections</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*Unng0cAXlCKUtGjHw7tEsw.png" /></figure><p>This shows that replication is working as expected.</p><p><strong>There are several reasons why using a hybrid cloud approach for MongoDB replication can be beneficial.</strong></p><ul><li>Improved Availability: By using two separate cloud providers, you can ensure that your MongoDB deployment is highly available even in the event of a cloud provider outage. If one cloud provider experiences downtime, your deployment will still be available on the other cloud provider.</li><li>Cost-Effective: By leveraging the strengths of different cloud providers, you can reduce the costs associated with deploying MongoDB. For example, you can use GCP’s high-performance VMs for your primary replica set node and AWS’s cost-effective storage options for your secondary replica set node.</li><li>Scalability: A hybrid cloud approach allows you to scale your MongoDB deployment more efficiently by leveraging the strengths of different cloud providers. You can use GCP’s auto-scaling capabilities to scale up your primary replica set node to handle write-heavy workloads and AWS’s auto-scaling capabilities to scale up your secondary replica set node to handle read-heavy workloads.</li><li>Compliance: In some cases, regulatory or security requirements may necessitate the use of multiple cloud providers. A hybrid cloud approach allows you to comply with these requirements while still enjoying the benefits of MongoDB replication.</li></ul><p>Overall, a hybrid cloud approach to MongoDB replication can provide improved availability, cost savings, scalability, and compliance with regulatory requirements.</p><p>We hope that this guide has been informative and helpful in your journey towards building scalable and resilient applications. If you have any questions or comments, please feel free to leave them below. Thank you for reading!</p><p>A few more blog posts about <a href="https://medium.com/u/db5cd12199bd">MongoDB</a> on <a href="https://blog.thecloudside.com/">the Cloudside view</a></p><ol><li><a href="https://blog.thecloudside.com/setting-up-a-fault-tolerant-mongodb-replica-set-on-google-kubernetes-engine-gke-a48cb0bebd6">Setting Up a Fault-Tolerant MongoDB Replica Set on Google Kubernetes Engine (GKE) </a>by <a href="https://medium.com/u/94864c7683da">Writtick Sengupta</a></li><li><a href="https://blog.thecloudside.com/how-to-set-up-mongodb-replication-in-gcp-vms-bc7876374104">Setting up MongoDB replication on Google Cloud Platform(GCP) Virtual Machines(VMs)</a> by <a href="https://medium.com/u/32dbd15475a5">Tinkal Shakya</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d32bac8121b" width="1" height="1" alt=""><hr><p><a href="https://blog.thecloudside.com/building-a-highly-available-mongodb-replication-with-primary-replica-on-gcp-and-secondary-replica-5d32bac8121b">Building a Highly Available MongoDB Replication with Primary Replica on GCP and Secondary Replica…</a> was originally published in <a href="https://blog.thecloudside.com/">The Cloudside View</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting Up MongoDB Replication on Google Cloud Platform (GCP) Virtual Machines (VMs)]]></title>
            <link>https://blog.thecloudside.com/how-to-set-up-mongodb-replication-in-gcp-vms-bc7876374104?source=rss-32dbd15475a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc7876374104</guid>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[google-compute-engine]]></category>
            <category><![CDATA[replication]]></category>
            <category><![CDATA[google-cloud]]></category>
            <category><![CDATA[database-replication]]></category>
            <dc:creator><![CDATA[Tinkal Shakya]]></dc:creator>
            <pubDate>Fri, 24 Feb 2023 12:47:47 GMT</pubDate>
            <atom:updated>2023-05-30T12:27:53.145Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*o3CezywGN-4bM0ydtpGS7Q.png" /></figure><p><a href="https://medium.com/u/db5cd12199bd">MongoDB</a> is a popular NoSQL database that is widely used for its scalability, high availability, and flexibility. One of the key features of MongoDB is replication, which allows you to create a redundant copy of your data to ensure high availability and data durability. In this blog post, we will discuss how to set up MongoDB replication in GCP VMs.</p><p>Before we begin, let’s first understand the basic concepts of MongoDB replication. MongoDB replication consists of a primary and one or more secondary replicas. The primary replica is responsible for accepting write operations and propagating the changes to the secondary replicas. The secondary replicas are read-only copies of the data that can be used for scaling read operations and providing high availability.</p><p>To set up MongoDB replication in GCP VMs, we will follow these steps:</p><p><strong>Step 1-</strong> Create 3 VMs using Ubuntu(20.04 LTS) Boot Disk image with names primary,replica1,replica2.</p><p><strong>Step 2-</strong> SSH into all the VMs and install mongo DB. Keep the SSH windows of all the Vms open as we will work on them parallelly. We have installed MongoDB version 4.4 as we wanted to demonstrate the perks of using the old version. Using the latest version can reduce multiple steps in the following task.</p><pre>curl -fsSL https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -<br>apt-key list<br>echo &quot;deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse&quot; | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list<br>sudo apt update<br>sudo apt install mongodb-org<br>sudo systemctl start mongod.service<br>sudo systemctl status mongod<br>sudo systemctl enable mongod</pre><p><strong>Step3-</strong> <strong>Configuring DNS Resolution</strong></p><p><strong>/etc/hosts</strong> is a special file that allows you to assign human-readable hostnames to numerical IP addresses. This means that if the IP address of any of your servers ever changes, you’ll only have to update the <strong>/etc/hosts</strong> file on the three servers instead of reconfiguring the replica set.</p><pre>sudo vim /etc/hosts</pre><p>After the first line add the private IP and name of the host (primary and replicas)</p><pre>127.0.0.1 localhost<br>203.0.113.0 primary<br>203.0.113.1 replica1<br>203.0.113.2 replica2</pre><p><strong>Step4-</strong> <strong>Updating Each Server’s Firewall Configurations with UFW</strong></p><p>You will have set up a firewall on each of the servers on which you’ve installed MongoDB and enabled access for the OpenSSH UFW profile. This is an important security measure, as these firewalls currently block connections to any port on your servers, save for ssh connections that present keys which align with those in each server’s respective <strong>authorized_keys</strong> file.</p><p>However, these firewalls will also block the MongoDB instances on each server from communicating with one another, preventing you from initiating the replica set. To correct this, you’ll need to add new firewall rules to allow each server access to the port on the other two servers on which MongoDB is listening for connections.</p><p>SSH into primary VM and add the firewall rules</p><pre>sudo ufw allow from replica1_pvt_IP to any port 27017<br>sudo ufw allow from replica2_pvt_IP to any port 27017</pre><p>SSH into the replica 1 VM and add the firewall rules</p><pre>sudo ufw allow from primary_pvt_IP to any port 27017<br>sudo ufw allow from replica2_pvt_IP to any port 27017</pre><p>SSH into the replica 2 VM and add the firewall rules</p><pre>sudo ufw allow from primary_pvt_IP to any port 27017<br>sudo ufw allow from replica1_pvt_IP to any port 27017</pre><p><strong>Step5- Enabling Replication in Each Server’s MongoDB Configuration File</strong></p><p>At this point, you’ve edited your servers’ /etc/hosts files to configure hostnames which will resolve to each one’s IP address. You’ve also opened up each of your servers’ firewalls to allow the other two servers access to the default MongoDB port, 27107. Even though you’ve opened up each server’s firewall to allow the other servers access to port 27017, MongoDB is currently bound to 127.0.0.1, the local loopback network interface. This means that MongoDB is only able to accept connections that originate on the server where it’s installed.</p><p>To allow remote connections, you must bind MongoDB to your servers’ publicly-routable IP addresses in addition to 127.0.0.1. This way, your MongoDB installation will be able to listen to connections made to your MongoDB server from remote machines.</p><p>In the primary VM, make the following changes in the mongod.conf file</p><pre>sudo vim /etc/mongod.conf</pre><pre>. . .<br># network interfaces<br>net:<br>  port: 27017<br>  bindIp: 127.0.0.1,primary<br>. . .<br>replication:<br>  replSetName: &quot;rs0&quot;<br>. . .</pre><p>In the replica1 VM, make the following changes in the mongod.conf file</p><pre>. . .<br># network interfaces<br>net:<br>  port: 27017<br>  bindIp: 127.0.0.1,replica1<br>. . .<br>replication:<br>  replSetName: &quot;rs0&quot;<br>. . .</pre><p>In the replica2 VM, make the following changes in the mongod.conf file</p><pre>. . .<br># network interfaces<br>net:<br>  port: 27017<br>  bindIp: 127.0.0.1,replica2<br>. . .<br>replication:<br>  replSetName: &quot;rs0&quot;<br>. . .</pre><p>Restart the mongod service in all the VMs.</p><pre>sudo systemctl restart mongod</pre><p>You can test the connection between primary,replica1,replica2</p><p>Go to replica1 vm and check connecting between replica1 and primary by using the following command.</p><pre>nc -zv primary 27017</pre><p><strong>Step6 </strong>— <strong>Starting the Replica Set and adding Members</strong></p><p>Now that you’ve configured each of your three MongoDB installations, you can open up a MongoDB shell to initiate replication and add each vm (host) as a member.</p><p>Go to the primary VM and type <strong>mongo </strong>in the CLI.</p><p><strong>NOTE- As our MongoDB version is 4.4, we will use mongo. For later versions, we use mongosh. I would recommend using the latest version!</strong></p><p>From the prompt, you can initiate a replica set from the mongo shell by running the rs.initiate() method. However, running this method by itself would only initiate replication for the machine on which you run the method, and you’d then need to add your other Mongo instances by issuing an <strong>rs.add()</strong> method for each member.</p><p>To do this, begin an rs.initiate() method by typing the following.</p><pre>rs.initiate({_id: &quot;rs0&quot;,members: [{ _id: 0, host: &quot;primary&quot; },{ _id: 1, host: &quot;replica1&quot; },]})</pre><p>In this case you have created a primary and a secondary replica.</p><p>If the replica set was initiated as expected, you’ll notice that the MongoDB client’s prompt will change from just a greater-than sign (&gt;) to the following:</p><pre>rs0:SECONDARY&gt;</pre><p>Next, run the command rs.help()</p><pre>rs0:SECONDARY&gt;rs.help()</pre><p>This should provide the following output</p><p>Output</p><pre> rs.status() { replSetGetStatus : 1 } checks repl set status<br> rs.initiate() { replSetInitiate : null } initiates set with default settings<br> rs.initiate(cfg) { replSetInitiate : cfg } initiates set with configuration cfg<br> rs.conf() get the current configuration object from local.system.replset<br> rs.reconfig(cfg) updates the configuration of a running replica set with cfg (disconnects)<br> rs.add(hostportstr) add a new member to the set with default attributes (disconnects)<br> rs.add(membercfgobj) add a new member to the set with extra attributes (disconnects)<br> rs.addArb(hostportstr) add a new member which is arbiterOnly:true (disconnects)<br> rs.stepDown([stepdownSecs, catchUpSecs]) step down as primary (disconnects)<br> rs.syncFrom(hostportstr) make a secondary sync from the given member<br> rs.freeze(secs) make a node ineligible to become primary for the time specified<br> rs.remove(hostportstr) remove a host from the replica set (disconnects)<br> rs.secondaryOk() allow queries on secondary nodes<br> rs.printReplicationInfo() check oplog size and time range<br> rs.printSecondaryReplicationInfo() check replica set members and replication lag<br> db.isMaster() check who is primary<br> db.hello() check who is primary<br> reconfiguration helpers disconnect from the database so the shell will display<br> an error, even if the command succeeds.</pre><p>After running rs.help() or another one of these methods, you may see the client prompt change again to Primary</p><pre>rs0:PRIMARY&gt;</pre><p>This means that the MongoDB instance that you’re connected to was elected to serve as the primary set member.</p><p>NOTE- If you have additional nodes that you’d like to add to the replica set in the future, you can do so with the <strong>rs.add()</strong> method. Make sure the configuration is done for the new replica2 as shown in above steps.</p><pre>rs.add( &quot;replica2&quot; )</pre><p>Now when you type mongo in the VM, You can see one VM as primary and other two VM as secondary. Considering you have updated the host file, firewalls, mongod.conf file correctly.</p><p>Now the Primary is used for Read/Write and the secondaries are used for Read only. If the primary fails, one of the secondary will become the primary automatically. This feature is called Automatic failover.</p><p><strong>TESTING REPLICATION-</strong></p><p><strong>Step7-</strong> Create a database and collection in primary VM</p><pre>rs0:PRIMARY&gt;use db-test<br>rs0:PRIMARY&gt;db.createCollection(&quot;MyCollection&quot;)</pre><p>Now if you try to see if the database and collection has been updated in the secondary vm, you will get the following error.</p><pre>rs0:SECONDARY&gt; show dbs<br>uncaught exception: Error: listDatabases failed:{<br> &quot;topologyVersion&quot; : {<br> &quot;processId&quot; : ObjectId(&quot;63eca5eceb24e987ddbda722&quot;),<br> &quot;counter&quot; : NumberLong(3)<br> },<br> &quot;operationTime&quot; : Timestamp(1676454300, 1),<br> &quot;ok&quot; : 0,<br> &quot;errmsg&quot; : &quot;not master and slaveOk=false&quot;,<br> &quot;code&quot; : 13435,<br> &quot;codeName&quot; : &quot;NotPrimaryNoSecondaryOk&quot;,<br> &quot;$clusterTime&quot; : {<br> &quot;clusterTime&quot; : Timestamp(1676454300, 1),<br> &quot;signature&quot; : {<br> &quot;hash&quot; : BinData(0,&quot;AAAAAAAAAAAAAAAAAAAAAAAAAAA=&quot;),<br> &quot;keyId&quot; : NumberLong(0)<br> }<br> }<br>} :<br>_getErrorWithCode@src/mongo/shell/utils.js:25:13<br>Mongo.prototype.getDBs/&lt;@src/mongo/shell/mongo.js:147:19<br>Mongo.prototype.getDBs@src/mongo/shell/mongo.js:99:12<br>shellHelper.show@src/mongo/shell/utils.js:937:13<br>shellHelper@src/mongo/shell/utils.js:819:15<br>@(shellhelp2):1:1<br><br>rs0:SECONDARY&gt;<br></pre><p>For replicas to start replicating, you have to run the following command on all the replicas.</p><pre>rs0:SECONDARY&gt;rs.secondaryOk()</pre><p>But every time you exit the mongo shell, you have to apply the command again on all the replicas. The solution is to create a file called <strong>mongorc.js</strong> in <strong>/etc/mongorc.js</strong>.</p><pre>Vim /etc/mongorc.js<br>rs.secondaryOk()</pre><p>Save and quit by entering-</p><p>Esc → :wq → enter</p><p>Now every time you enter the mongo shell, replication starts immediately</p><p><strong>NOTE- If you use MongoDB version 4.4, you will have to add rs.secondaryOk() in the /etc/mongo.js file. This has been deprecated in versions greater than 4.4. So I would strongly suggest using the latest MongoDB version. For the next section, we will be using MongoDB latest version when deploying in GKE. Hence, we don’t need rs.secondaryOk().</strong></p><p>Thank you for taking the time to read this post.</p><p>A few more blog posts about <a href="https://medium.com/u/db5cd12199bd?source=post_page-----5d32bac8121b--------------------------------">MongoDB</a> on <a href="https://blog.thecloudside.com/">the Cloudside view</a></p><ol><li><a href="https://blog.thecloudside.com/setting-up-a-fault-tolerant-mongodb-replica-set-on-google-kubernetes-engine-gke-a48cb0bebd6">Setting Up a Fault-Tolerant MongoDB Replica Set on Google Kubernetes Engine (GKE) </a>by <a href="https://medium.com/u/94864c7683da">Writtick Sengupta</a></li><li><a href="https://blog.thecloudside.com/building-a-highly-available-mongodb-replication-with-primary-replica-on-gcp-and-secondary-replica-5d32bac8121b">Building a Highly Available MongoDB Replication with Primary Replica on GCP and Secondary Replica on AWS</a> by <a href="https://medium.com/u/32dbd15475a5">Tinkal Shakya</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc7876374104" width="1" height="1" alt=""><hr><p><a href="https://blog.thecloudside.com/how-to-set-up-mongodb-replication-in-gcp-vms-bc7876374104">Setting Up MongoDB Replication on Google Cloud Platform (GCP) Virtual Machines (VMs)</a> was originally published in <a href="https://blog.thecloudside.com/">The Cloudside View</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrate AWS EC2 to GCP Compute Engine using ‘Migrate to VM’]]></title>
            <link>https://blog.thecloudside.com/migrate-aws-instance-to-google-cloud-compute-engine-vm-9659c35aeb30?source=rss-32dbd15475a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/9659c35aeb30</guid>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[gcp-compute-engine]]></category>
            <category><![CDATA[site-to-site-vpn]]></category>
            <category><![CDATA[migration]]></category>
            <dc:creator><![CDATA[Tinkal Shakya]]></dc:creator>
            <pubDate>Tue, 06 Dec 2022 14:19:43 GMT</pubDate>
            <atom:updated>2023-04-25T10:16:19.960Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WFu9mFw3pmpVFQ9P9jOHog.png" /></figure><p>In recent times, I came across several projects where I needed to migrate a VM from On-premises or from other cloud platforms to Google Cloud. I often wondered about the best possible way for migrating, considering there are several ways to do it. We have third-party tools that can be used for VM migration between clouds/On-prem, I wanted to use something managed by Cloud Provider — meet <a href="https://cloud.google.com/migrate/virtual-machines">Migrate to Virtual Machines</a></p><p>GCP offers an astounding service called Migrate to VM to achieve the goal. To provide a brief explanation of the task. There are two cloud platforms — AWS and GCP. Each cloud platform contains Compute Engine VM and both the cloud platform are connected via a VPN tunnel. Cloud VPN provides several advantages -</p><ul><li>Secure peer-to-peer connection using an IPsec VPN tunnel.</li><li>Traffic is encrypted and travels between the two networks over the public internet.</li><li>Cloud VPN is useful for low-volume data connections.</li><li>Cheaper than direct interconnect and supports high availability.</li></ul><p>We will deploy the application in Amazon EC2 VM. If you want to deploy the application in Google Compute Engine VM with the same disk data, you need to migrate the VM which is considered to be very favorable.</p><h4>Let’s begin the setup!</h4><h3>Pre-requisites</h3><p><strong><em>Setup in AWS Side</em></strong></p><ol><li><em>Create a custom VPC with a subnet( 10.10.0.0/24)</em></li><li><em>Create two Customer GW (to accommodate the GCP side of details)</em></li><li><em>Create a VPG (Virtual Private Gateway) and Attach VPG to created VPC</em></li><li><em>Create two Site to Site VPN(4 tunnels)</em></li><li><em>Update security group and routes to allow traffic from GCP</em></li></ol><p><strong><em>Setup in GCP Side of Steps</em></strong></p><ol><li><em>Create a custom VPC with a subnet(say 10.20.0.0/24)</em></li><li><em>Setup/Create a Cloud router</em></li><li><em>Create a HA-VPN and set up Cloud VPN Gateway.</em></li><li><em>Set up Peer VPN Gateway</em></li><li><em>Set up Cloud VPN tunnels</em></li><li>Set up BGP session</li><li><em>Update firewall rules for custom VPC to allow traffic from AWS.</em></li></ol><blockquote><strong>Note :- </strong>If you don’t know how to set up the VPN, follow the below doc, in which you’ll find step-by-step instructions.</blockquote><blockquote><strong>Link:</strong> <a href="https://medium.com/peek-travel/connecting-an-aws-and-gcp-vpc-using-an-ipsec-vpn-tunnel-with-bgp-f332c2885975">VPN setup between AWS &amp; GCP</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bggtyaQemhPMYQ7PLs-k0w.png" /><figcaption>Established the BGP Session</figcaption></figure><p>After Setup the VPN and establishing the BGP Session. We move to the next step.</p><h3><strong>M</strong><em>igrate AWS Instance to GCP VM</em></h3><ol><li>In Google Cloud Console, Go to the <strong>Compute Engine</strong> -&gt; <strong>Migrate to Virtual Machine</strong> and select the source section then click on <strong>Add Source</strong> -&gt; <strong>+Add AWS Source</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aTQUAOveuwDUbc7I" /></figure><p>Provide the AWS Access Key ID and Secret access key and Click create. And Wating for a few minutes when the source is active.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/0*TUCkfJx1qiyE1ELj" /></figure><p>Wait for a few minutes. until the source status becomes active. And then you will see AWS EC2 Instance in GCP.</p><p>In my case, I saw two VMs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9gjRKgkjppc-1RI53jJrjw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9gjRKgkjppc-1RI53jJrjw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/0*Scc9ex_3IFKMFl_m" /></figure><p>3. Go to the <strong>Migration </strong>Section. Here you see the Migration VM and select the source VM and then Click on <strong>Edit Target Details</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/0*k_pPRUCSELnlYBk6" /></figure><p>Provide the 7 required details <strong>for creating the GCP VM</strong> like — Instance Name, Project, Zone, machine type series, machine type, network, subnetwork</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ewjygQ7DOEWI9ZN7" /></figure><p>Click<strong> Machine Configuration</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a93Y-3AATy_JHUBo" /></figure><p>In the Last set, the<strong> Network Configuration </strong>and Click on save</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qObUz3X0hD0dngnN" /></figure><p>Select Migration and Start the replication. Wait for few minutes….</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/0*Ph78nAQVWMRBATZp" /></figure><p>Whenever It’s Active mode click <strong>CUT-OVER AND TEST-CLONE </strong>and run the test clone</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6wKE1cqUP8qFXskn" /></figure><blockquote><strong>Note-</strong> Please ensure that your AWS EC2 instance does not use an image that GCP does not support. Like- Amazon Linux</blockquote><p>Verified the <strong>Test Clone</strong> is Completed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FAuNiA1mtyz97n9QkrsLnQ.png" /></figure><p>Now Your <strong>Migrated VM</strong> is Ready</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*INJ8VnStiiAssgsT6OFzTw.png" /></figure><p><strong>AWS EC2 instance to GCP VM Migration Completed.</strong></p><p>To summarize, we migrated an EC2 instance from Amazon to the Google Cloud platform using a service called migrate to VM.</p><p>Hopefully, this article helped you in some way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9659c35aeb30" width="1" height="1" alt=""><hr><p><a href="https://blog.thecloudside.com/migrate-aws-instance-to-google-cloud-compute-engine-vm-9659c35aeb30">Migrate AWS EC2 to GCP Compute Engine using ‘Migrate to VM’</a> was originally published in <a href="https://blog.thecloudside.com/">The Cloudside View</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>