<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Otuekong Arthur</title>
    <description>The latest articles on Forem by Otuekong Arthur (@fizy_hector).</description>
    <link>https://forem.com/fizy_hector</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1054506%2F92e90d4f-0ebb-4eda-b88c-804412d83783.jpg</url>
      <title>Forem: Otuekong Arthur</title>
      <link>https://forem.com/fizy_hector</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/fizy_hector"/>
    <language>en</language>
    <item>
      <title>Running A Headless Raspberry Pi</title>
      <dc:creator>Otuekong Arthur</dc:creator>
      <pubDate>Sun, 31 Dec 2023 19:53:00 +0000</pubDate>
      <link>https://forem.com/fizy_hector/running-a-headless-raspberry-pi-1ljl</link>
      <guid>https://forem.com/fizy_hector/running-a-headless-raspberry-pi-1ljl</guid>
      <description>&lt;p&gt;Imagine having a Raspberry Pi, a tiny computer that fits in your palm, running smoothly without the need for a monitor, keyboard, or mouse. This is what we call running a headless Raspberry Pi: a setup where the Pi operates without a traditional display and input devices. It might sound a bit techy, but it's simpler than you think.&lt;br&gt;
In this article, we'll walk through the basics of running your Raspberry Pi headlessly, unlocking its potential without the clutter of additional peripherals.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Aside&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I recently got a Raspberry Pi from a friend and many things have been flooding my mind on what to use it for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Perhaps If I add another Raspberry Pi I could run a Kubernetes Cluster&lt;/li&gt;
&lt;li&gt;Practice my Linux skills&lt;/li&gt;
&lt;li&gt;Use it for some home automation ideas in the future.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even though I have Ubuntu Linux running on my Windows machine, I still need the feel of a standalone Linux machine and my tiny raspberry pi cuts it for me.&lt;br&gt;
Anyway, let's get to it.&lt;br&gt;
These are the list of things I will be working with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Raspberry Pi 3 Model B&lt;/li&gt;
&lt;li&gt;SD card&lt;/li&gt;
&lt;li&gt;A private Wifi network&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.raspberrypi.com/software/"&gt;Raspberry Pi Imager&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.realvnc.com/en/connect/download/viewer"&gt;RealVNC viewer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html"&gt;Putty&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;:&lt;br&gt;
I recommend you install the recommended software on your machine before we start.&lt;/p&gt;
&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;In summary, we are going to perform 9 steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Insert Or connect our SD card to our computer&lt;/li&gt;
&lt;li&gt;Format the SD  card&lt;/li&gt;
&lt;li&gt;Selecting the Device and operating system in the Raspberry Pi Imager&lt;/li&gt;
&lt;li&gt;Configure settings for our Raspberry Pi Os&lt;/li&gt;
&lt;li&gt;Download Raspberry PI OS to our SD card&lt;/li&gt;
&lt;li&gt;Insert Our Sd card into the Raspberry PI&lt;/li&gt;
&lt;li&gt;Connect the Raspberry Pi to a power source&lt;/li&gt;
&lt;li&gt;Remotely SSH into the Raspberry PI over a Wi-Fi network&lt;/li&gt;
&lt;li&gt;Use RealVNC viewer to Remotely access the Raspberry PI over a Wi-Fi network&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  About Raspberry PI
&lt;/h2&gt;

&lt;p&gt;According to &lt;a href="https://en.wikipedia.org/wiki/Raspberry_Pi"&gt;Wikipedia&lt;/a&gt;, Raspberry Pi is a series of small single-board computers (SBCs) developed in the United Kingdom by the Raspberry Pi Foundation in association with Broadcom.&lt;br&gt;
In summary, they say that a Raspberry Pi is a small computer that has all the Storage and memory (RAM) on a single and small board.&lt;br&gt;
As earlier stated, I will be using a Raspberry Pi 3 model B with 1 gigabyte of Random Access Memory(RAM) and 8 gigabytes SD card for storage&lt;br&gt;
First connect your SD card to your computer, if your machine has an SD card slot like mine then you may just slide it in else you should get an SD card adapter.&lt;br&gt;
Launch the Raspberry Pi Imager and you’ll get to see the below screen:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3LnM7ufE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jh655uqsw1c1bkvpslur.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3LnM7ufE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jh655uqsw1c1bkvpslur.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, you will get to choose your Raspberry Pi device, go ahead and choose your device&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F9PeH0Sd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yogpfzgbcmbew6nlkrv9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F9PeH0Sd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yogpfzgbcmbew6nlkrv9.png" alt="Image description" width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my case, I selected Raspberry Pi 3 as my option. You can see that it has all the submodels under it.&lt;br&gt;
Go ahead and choose the Operating system(OS)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dL79D7hx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wyhn4w9oetn5jgdsg3hq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dL79D7hx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wyhn4w9oetn5jgdsg3hq.png" alt="Image description" width="800" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, click on Choose Storage and select your SD card as the storage&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UhlHHPyP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p7aoihvc7p499c5lf5uk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UhlHHPyP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p7aoihvc7p499c5lf5uk.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may now click on the Next button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_mNe2q4z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mpk34fl23a7n3d30eyvr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_mNe2q4z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mpk34fl23a7n3d30eyvr.png" alt="Image description" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At the click of the Next button, you’ll be prompted  with the OS Customisation menu as below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uNdWuvbo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x41bavyhgc3cxcpm6f5f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uNdWuvbo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x41bavyhgc3cxcpm6f5f.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Under the OS customization menu are 3 tabs&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;General&lt;/li&gt;
&lt;li&gt;Services&lt;/li&gt;
&lt;li&gt;Options&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;First, the General tab provides a way to set our hostname for the Raspberry Pi and set username and password. Under Configure wireless LAN, Add your Wifi network name and password. Also choose your country under Wireless LAN country, in my case, I selected NG which is the symbol for Nigeria.&lt;br&gt;
Next, under Set locale settings, choose your timezone and keyboard layout.&lt;br&gt;
Move to the services tab:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--16GlCNU2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t9xomt0mitd5xinrw3qo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--16GlCNU2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t9xomt0mitd5xinrw3qo.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Under the services tab, enable SSH(Secure Shell). This is very important as it will allow us to communicate with this device over the Wifi network through the terminal. Also, choose password authentication.&lt;br&gt;
Done with the services tab, move to the Options tab:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HoRaHrGV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hbl9phgsq8m71xvpwqd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HoRaHrGV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hbl9phgsq8m71xvpwqd.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just as the name suggests, The Options tab is optional, but for me, I need my machine to play sound when it is finished downloading the OS. I also need it to automatically eject the SD card when completed and also enable telemetry which provides  OS downloads data to Raspberry.&lt;br&gt;
When done, click on the Save button and you will be presented with the confirmation screen below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jRtlrGf2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ow4io11rsppse2wkjcaj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jRtlrGf2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ow4io11rsppse2wkjcaj.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click Yes.&lt;/p&gt;

&lt;p&gt;You’ll then be prompted to confirm if you want to do this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x3e_2wWd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8pu12zqybkh2c7sd81xf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x3e_2wWd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8pu12zqybkh2c7sd81xf.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since you are sure of what you are doing, click Yes.&lt;/p&gt;

&lt;p&gt;If everything goes well, you should see the below output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MgF3xvIH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/39jc9xl20xgr4m3m2bl4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MgF3xvIH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/39jc9xl20xgr4m3m2bl4.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are getting the “Please insert a disk into ..” error like the below output&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v8JRdc4G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mfx1mtjfu4fzabu0kjuh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v8JRdc4G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mfx1mtjfu4fzabu0kjuh.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This little &lt;a href="https://www.sdcard.org/downloads/formatter/"&gt;&lt;strong&gt;SD formatter tool&lt;/strong&gt;&lt;/a&gt; should fix the issue.&lt;/p&gt;

&lt;p&gt;After some time, the download will start:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9rNzJuXu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/co8frfuu7w9ru3tyv03r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9rNzJuXu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/co8frfuu7w9ru3tyv03r.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you chose the Eject media option, your SD card will be automatically ejected when installation is completed. If you did not, you will have to eject it yourself manually.&lt;br&gt;
Next, we will run the Raspberry OS on our Raspberry PI.&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting Raspberry Pi Running
&lt;/h2&gt;

&lt;p&gt;Insert the SD card card into your Raspberry PI and plug in the power cable.&lt;br&gt;
After some seconds your Raspberry PI should be up and running.&lt;br&gt;
We need to find a way to communicate with this device.&lt;br&gt;
Remember we had a wifi network as one of the things you’ll need in this tutorial? &lt;br&gt;
Get your Raspberry Pi and your machine on the same Wifi network you configured in Os customization for the Raspberry Pi.&lt;br&gt;
After you have them both connected to the same network, under &lt;br&gt;
This is the time that we bring in one Putty. Putty is an SSH client that will let us communicate with our Raspberry Pi on the Wifi network using its IP address.&lt;br&gt;
Open your Wifi router menu and copy the IP address of the Raspberry Pi on the network. Open Putty and paste the IP address like so:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4rr87gJe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gt49nigke485706l3juf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4rr87gJe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gt49nigke485706l3juf.png" alt="Image description" width="800" height="443"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on open.&lt;/p&gt;

&lt;p&gt;You will be prompted to enter your username and password. If the login is successful, you should see a screen similar to below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hBqcVSzq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c4yhqzb1bd2e58di44ul.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hBqcVSzq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c4yhqzb1bd2e58di44ul.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hurray, we are in.&lt;br&gt;
We can use our tiny computer from here(command line) or even take it further and get a graphical user interface(GUI) from it.&lt;br&gt;
To achieve this we need &lt;a href="https://web.mit.edu/cdsdev/src/howitworks.html"&gt;&lt;strong&gt;Virtual Network Computing&lt;/strong&gt;&lt;/a&gt;(VNC) software. VNC is a remote access technology that enables computers to access and take control of another computer.&lt;br&gt;
In this tutorial, we will be using a type of VNC called RealVNC viewer. &lt;br&gt;
RealVNC comes in 2 parts: RealVNC viewer that we have installed on our machine and RealVNC Server that talks to us from the computer we want to access.&lt;br&gt;
We have to get into our tiny machine and enable the RealVNC Server.&lt;br&gt;
In the Putty terminal run the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;raspi-config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On running the above command, you’ll be shown the screen below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UDjQWpJ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5v1hqgv6w4fiuoerq7al.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UDjQWpJ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5v1hqgv6w4fiuoerq7al.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What is of particular interest to us is the Interface Options. Navigate to the Interface Options using the arrow down key and press enter when you are there.&lt;br&gt;
This gets you to the screen below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SgsNUPY3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n83rzzslt16rcsxvc4fu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SgsNUPY3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n83rzzslt16rcsxvc4fu.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use the down arrow key to scroll to VNC and hit enter&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wsyQ9rhL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7iqm4is5kij7ga08yg6k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wsyQ9rhL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7iqm4is5kij7ga08yg6k.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use the left and right arrow keys to toggle between Yes and No. Toggle it to Yes and press the enter key.&lt;br&gt;
It shows that the RealVNC server is enabled by showing the following output&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Cb2bP6MZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c9n54jfw80m72ip66xgy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Cb2bP6MZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c9n54jfw80m72ip66xgy.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on enter and use the right arrow key to navigate to finish. Then press enter.&lt;br&gt;
RealVNC Server is now ready to talk to our machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessing Raspberry Pi through RealVNC viewer(Desktop)
&lt;/h2&gt;

&lt;p&gt;Open RealVNC viewer, click on the file tab then “new connection”.&lt;br&gt;
The below output is what you should see next.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ma67Gy17--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n1i427f3x70ix8exa68f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ma67Gy17--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n1i427f3x70ix8exa68f.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy and paste the Raspberry Pi IP address to the “VNC Server” then click OK.&lt;br&gt;
Right-click on the monitor icon and click connect&lt;br&gt;
It will ask for your RealVNC username and password, supply it and &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ry818so_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2rnjpkbizk18ivtea67a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ry818so_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2rnjpkbizk18ivtea67a.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click Ok&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PoF5z5x5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9tgqbffwf72i1ufs0hhn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PoF5z5x5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9tgqbffwf72i1ufs0hhn.png" alt="Image description" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may play around with it, ensure you shut it down before you unplug the power cable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g5piM5vs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6p111lmp05302efh7srv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g5piM5vs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6p111lmp05302efh7srv.png" alt="Image description" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessing Raspberry Pi through RVNC viewer(Mobile)
&lt;/h2&gt;

&lt;p&gt;It is also possible to remotely access the Raspberry Pi with your smartphone.&lt;br&gt;
To achieve this, search and install RVNC viewer on Google Play Store for Android or App Store for iOS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qKTmwzOh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g9qfe0toqaz7ebde8cov.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qKTmwzOh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g9qfe0toqaz7ebde8cov.jpg" alt="Image description" width="720" height="1640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the &lt;strong&gt;+&lt;/strong&gt; button &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kCqotAek--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x7usi6hss4u3jrhn2z3o.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kCqotAek--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x7usi6hss4u3jrhn2z3o.jpg" alt="Image description" width="720" height="1640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, input your Raspberry Pi IP address and click Create.&lt;br&gt;
You will be presented with the below screen&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N2QtL60q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bzqv4o4h7z6x0eb5oe8e.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N2QtL60q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bzqv4o4h7z6x0eb5oe8e.jpg" alt="Image description" width="720" height="1640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on “Connect” &lt;br&gt;
Add your username and password and click “Continue”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yqYRw_wv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mwhv48mmxxtumyvxbw3l.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yqYRw_wv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mwhv48mmxxtumyvxbw3l.jpg" alt="Image description" width="720" height="1640"&gt;&lt;/a&gt;&lt;br&gt;
Behold your Raspberry PI on mobile&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DvsbtXVc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w1uru8iochg8ylsvetzf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DvsbtXVc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w1uru8iochg8ylsvetzf.jpg" alt="Image description" width="720" height="1640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Running a headless Raspberry Pi offers an efficient way to use this versatile mini-computer. By eliminating the need for monitor and input devices, you not only save space but also open up possibilities for various projects and applications.&lt;/p&gt;

</description>
      <category>raspberrypi</category>
      <category>tutorial</category>
      <category>linux</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Introduction to YAML for Kubernetes</title>
      <dc:creator>Otuekong Arthur</dc:creator>
      <pubDate>Sat, 16 Dec 2023 21:47:52 +0000</pubDate>
      <link>https://forem.com/fizy_hector/introduction-to-yaml-for-kubernetes-1dfa</link>
      <guid>https://forem.com/fizy_hector/introduction-to-yaml-for-kubernetes-1dfa</guid>
      <description>&lt;p&gt;Welcome as we go through the basics of YAML, the go-to configuration language for Kubernetes. No tech jargon or complex terms here, just straightforward insights to help you understand  YAML. &lt;br&gt;
In this article, we will check out YAML as it pertains to Kubernetes. &lt;/p&gt;
&lt;h2&gt;
  
  
  YAML?
&lt;/h2&gt;

&lt;p&gt;YAML, short for YAML Ain’t Markup Language, is a file format for making configurations. It is a data serialization language for all programming languages, which means it acts as a middleman to let programming languages talk to each other. Although Kubernetes files can be written in JSON and XML, YAML is the most preferred for this. &lt;br&gt;
Among the benefits of YAML are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Human readable&lt;/li&gt;
&lt;li&gt;Intuitive Structure&lt;/li&gt;
&lt;li&gt;Easy to Learn and Write&lt;/li&gt;
&lt;li&gt;Versatility in Configuration&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Assumptions:
&lt;/h2&gt;

&lt;p&gt;I assume that you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Know what Kubernetes is&lt;/li&gt;
&lt;li&gt;Know what Kubernetes config files are.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you know the above, let's jump right into it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Understanding YAML
&lt;/h2&gt;

&lt;p&gt;It will be nice to get some understanding of YAML.&lt;br&gt;
Let's start with indentation.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Indentation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;YAML uses indentation to represent the structure of data. Think of it like an organized to-do list. Each task (or data element) is neatly indented to show its relationship to the broader category. Indentation signifies the hierarchy and relationship between different components in a YAML file.&lt;br&gt;
Notice how in the first countries list, the countries are all aligned, while in the second countries list the fact that the countries are not all aligned makes it invalid YAML.&lt;br&gt;
YAML takes indentation very seriously.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;#valid yaml&lt;/span&gt;
&lt;span class="na"&gt;countries&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="s"&gt;-Nigeria&lt;/span&gt;
  &lt;span class="s"&gt;-India&lt;/span&gt;
  &lt;span class="s"&gt;-USA&lt;/span&gt;
  &lt;span class="s"&gt;-Germany&lt;/span&gt;

&lt;span class="c1"&gt;#invalid yaml&lt;/span&gt;
&lt;span class="na"&gt;countries&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="s"&gt;-Nigeria&lt;/span&gt;
&lt;span class="s"&gt;-India&lt;/span&gt;
  &lt;span class="s"&gt;-USA&lt;/span&gt;
  &lt;span class="s"&gt;-Germany&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Key-Value Pairs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;It uses a key-value pair structure. Let's look at how this key-value setup works.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Otuekong&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the colon separates the key from the value, with the name being the key and &lt;code&gt;Otuekong&lt;/code&gt; being the value.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Sequence/Lists&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Sequence/List offers a way to group related data in YAML.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;countries&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="s"&gt;-Nigeria&lt;/span&gt;
  &lt;span class="s"&gt;-India&lt;/span&gt;
  &lt;span class="s"&gt;-USA&lt;/span&gt;
  &lt;span class="s"&gt;-Germany&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the &lt;code&gt;countries&lt;/code&gt; key has a list of strings representing different countries.&lt;/p&gt;

&lt;p&gt;The above may also be written as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;countries&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;Nigeria&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;India&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;USA&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;Germany&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are nested lists too in YAML. See it as a list inside a list or lists inside a list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;nested_list&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;list1&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;list2&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="s"&gt;-sublist1&lt;/span&gt;
      &lt;span class="s"&gt;-sublist2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the preceding example, the &lt;code&gt;nested_list&lt;/code&gt; key has &lt;code&gt;list1&lt;/code&gt; and &lt;code&gt;list2&lt;/code&gt; under it.&lt;code&gt;list2&lt;/code&gt; holds &lt;code&gt;sublist1&lt;/code&gt; and &lt;code&gt;sublist2&lt;/code&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Scalars&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A scalar is a single piece of information, such as a number or some text. It's like a basic building block for data, like a single Lego piece instead of the whole Lego set. Scalars in YAML are simple, just like writing a single number or a short sentence. They help you express simple stuff without getting too fancy or complicated.&lt;br&gt;
There are 4 scalar types in YAML:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Strings&lt;/li&gt;
&lt;li&gt;Numbers&lt;/li&gt;
&lt;li&gt;Booleans&lt;/li&gt;
&lt;li&gt;Null&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s go a little deeper into the scalar types.&lt;br&gt;
&lt;strong&gt;Strings&lt;/strong&gt;&lt;br&gt;
Unlike Javascript-Object Notation(JSON), Yaml accepts strings with or without quotation marks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;
&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Hector&lt;/span&gt; &lt;span class="c1"&gt;#string without quotation marks&lt;/span&gt;

&lt;span class="na"&gt;name2&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Hector'&lt;/span&gt; &lt;span class="c1"&gt;#string with quotation marks&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above demonstrates the two ways of declaring a string in YAML and they are both valid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Numbers&lt;/strong&gt;&lt;br&gt;
When it comes to numbers, it can be represented in YAML as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Integers&lt;/li&gt;
&lt;li&gt;Floating-point numbers&lt;/li&gt;
&lt;li&gt;Scientific notation (exponential notation)&lt;/li&gt;
&lt;li&gt;Hexadecimal and octal notation (using &lt;code&gt;0x&lt;/code&gt; and &lt;code&gt;0o&lt;/code&gt; prefixes)&lt;/li&gt;
&lt;li&gt;Numeric strings
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50&lt;/span&gt; &lt;span class="c1"&gt;#I am an integer&lt;/span&gt;
&lt;span class="na"&gt;temperature&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;23.5&lt;/span&gt; &lt;span class="c1"&gt;#I am a floating-point&lt;/span&gt;
&lt;span class="na"&gt;large_number&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;4.022e23&lt;/span&gt; &lt;span class="c1"&gt;#I am a scientific notation&lt;/span&gt;
&lt;span class="na"&gt;hex_value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;0xFF&lt;/span&gt; &lt;span class="c1"&gt;#I am a hex value&lt;/span&gt;
&lt;span class="na"&gt;octal_value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;0o12&lt;/span&gt; &lt;span class="c1"&gt;#I am an octal value&lt;/span&gt;
&lt;span class="na"&gt;numeric_string&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;007"&lt;/span&gt; &lt;span class="c1"&gt;#I am a numeric string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Booleans&lt;/strong&gt;&lt;br&gt;
In YAML, on, true, and yes represent true while off, false, and no represent false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;#These are all true values&lt;/span&gt;
&lt;span class="na"&gt;christmas&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;on&lt;/span&gt;
&lt;span class="na"&gt;harmattan&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; 
&lt;span class="na"&gt;holiday&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;yes&lt;/span&gt; 

&lt;span class="c1"&gt;#These are all falsy values&lt;/span&gt;
&lt;span class="na"&gt;rains&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;off&lt;/span&gt;
&lt;span class="na"&gt;travel&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="na"&gt;something&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;no&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Null&lt;/strong&gt;&lt;br&gt;
Null represents the absence of a value. It can be represented with the string &lt;code&gt;null&lt;/code&gt; or the tilde sign (~) which on most keyboards is located on the top-left corner of the keyboard, to the left of the number 1 key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;christmasHamper&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; 
&lt;span class="na"&gt;reason&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;~&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above snippet demonstrates the usage of null.&lt;/p&gt;

&lt;h3&gt;
  
  
  Maps
&lt;/h3&gt;

&lt;p&gt;A map is like a dictionary where you have a key (the word) and a value (the definition). Maps in YAML help organize data in a clear and easy-to-read way.&lt;br&gt;
The snippet below represents a simple map under the key scores. Each entry within the scores map consists of a name (key) and a corresponding score (value).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;scores&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;Williams&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;45&lt;/span&gt;
  &lt;span class="na"&gt;Francis&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;13&lt;/span&gt;
  &lt;span class="na"&gt;Charles&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;65&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Comments&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Comments are like little notes you can add to explain things. You put a # (hash symbol) and then write whatever you want next to it. YAML ignores it as it's just for you and others to understand what's going on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;desserts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;Cupcakes&lt;/span&gt; &lt;span class="c1"&gt;#This is a comment&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;Chocolate Chip Cookies&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;Brownies&lt;/span&gt;

&lt;span class="c1"&gt;#This is also a comment&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  YAML in Kubernetes
&lt;/h2&gt;

&lt;p&gt;It is possible to imperatively manage Kubernetes resources by directly giving Kubernetes the instructions to manage your resources but soon enough this will get tiring and complicated to manage. Then comes the declarative way. Using YAML configuration files. With this, you just write what you want Kubernetes to do in a YAML file, point Kubernetes to the file, and let it handle the rest. Let's relate what we learned up there to Kubernetes.&lt;br&gt;
We will need a Kubernetes config file. For this, let's go with a Pod file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Pod&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;merry_christmas&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx-container&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx:stable-alpine-slim&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;containerPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
  &lt;span class="na"&gt;restartPolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Always&lt;/span&gt;
  &lt;span class="na"&gt;nodeSelector&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;gpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
      &lt;span class="s"&gt;activeDeadlineSeconds&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s break down the content of the above file.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;apiVersion&lt;/strong&gt;: This is a string scalar that Specifies the Kubernetes API version used.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;kind&lt;/strong&gt;: This is still another string scalar that Indicates the type of Kubernetes resource in this case Pod.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;metadata&lt;/strong&gt;: It is a map that Contains metadata about the Pod. In this case, It contains the name of the pod.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;spec&lt;/strong&gt;: This is a map that Describes the desired state of the Pod. This contains a map of:&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;containers&lt;/strong&gt;: Specifies a list of containers within the Pod.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;name&lt;/strong&gt;: This is a string scalar inside containers stating the name of the container. &lt;/li&gt;
&lt;li&gt;image: This is also a  string scalar inside containers specifying the Docker image to use.
8.ports: This contains a list of ports for the container.
9.containerPort: This is a scalar integer and indicates to Kubernetes the port to open on the container in this case port 80. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;restartPolicy&lt;/strong&gt;: It is a  string scalar that sets the restart policy for the Pod.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;nodeSelector&lt;/strong&gt;: This is a map that specifies node selection criteria for the Pod.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;gpu&lt;/strong&gt;: This is a  boolean scalar indicating whether the node should have a &lt;strong&gt;&lt;em&gt;graphics processing unit&lt;/em&gt;&lt;/strong&gt;(GPU). Here it is set to true. It could also take yes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;activeDeadlineSeconds&lt;/strong&gt;: Specifies the maximum time (in seconds) for the Pod to run. It's set to &lt;strong&gt;&lt;code&gt;null&lt;/code&gt; scalar&lt;/strong&gt;, indicating an undefined value.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Three things are worthy of note here. They are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;scalars represent single values which could be numbers, strings, booleans, and null.&lt;/li&gt;
&lt;li&gt;Mappings represent key-value pairs.&lt;/li&gt;
&lt;li&gt;Sequences represent lists of items.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understand the above and throw in indentation and you are on your way to conquer YAML.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Understanding YAML  is essential for anyone working with Kubernetes. In this article, we went into the basics of YAML, looking at indentation, scalars, maps, and sequences. We finally connected the dots and made sense of the pieces that make up YAML. I hope this article made YAML more approachable and in a way simplified your Kubernetes operations.&lt;br&gt;
Thanks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resource
&lt;/h3&gt;

&lt;p&gt;If you are looking to advance your understanding of YAML, I recommend this article.&lt;br&gt;
&lt;a href="https://spacelift.io/blog/yaml"&gt;YAML Tutorial: A Complete Language Guide with Examples&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>kubernetes</category>
      <category>cloud</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Getting Started With Kubectl: A Guide To Kubernetes</title>
      <dc:creator>Otuekong Arthur</dc:creator>
      <pubDate>Tue, 12 Dec 2023 15:56:12 +0000</pubDate>
      <link>https://forem.com/fizy_hector/getting-started-with-kubectl-a-guide-to-kubernetes-2e7n</link>
      <guid>https://forem.com/fizy_hector/getting-started-with-kubectl-a-guide-to-kubernetes-2e7n</guid>
      <description>&lt;p&gt;Kubernetes features and scalability make it a preferred choice for managing containerized applications. However, harnessing the full power of Kubernetes requires proficiency in various tools and one of the most essential among them is Kubectl.&lt;/p&gt;

&lt;p&gt;In this guide, we will get into the heart of Kubernetes management, offering a guide to mastering Kubectl. This guide will equip you with the knowledge and skills needed to streamline your Kubernetes workflow. Let's navigate the complexities of Kubectl together and unlock the potential of seamless Kubernetes administration.&lt;/p&gt;

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

&lt;p&gt;Before we begin, ensure you have the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Package manager, on macOS, you can use Homebrew, on Linux, you can use Snap, and on Windows, you can use a package manager like Chocolatey.&lt;/li&gt;
&lt;li&gt;A Kubernetes Cluster: You need a working Kubernetes cluster. If you don't have one, you can set up a local cluster using tools like Minikube, Kind or use a cloud-based Kubernetes service like Google Kubernetes Engine (GKE) or Amazon EKS.  In this article, I will be using Minikube.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Notes:&lt;br&gt;
 -Due to lengthy outputs, some screenshots may be cut off.&lt;br&gt;
 -If you are using Minikube,kubectl comes bundled with it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I will be working from a folder I created on my desktop called kubectl_practice.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Kubectl?
&lt;/h2&gt;

&lt;p&gt;Kubectl is a command-line utility designed for communication with Kubernetes clusters. It enables users to deploy and oversee applications, inspect and manage cluster resources, and examine logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Kubectl Installation
&lt;/h2&gt;

&lt;p&gt;We will be looking at ways of installing Kubectl on Windows, Mac, and Linux.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;On Windows&lt;/strong&gt;, open Command Prompt or PowerShell as an administrator and run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;choco install kubernetes-cli&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;On MacOS&lt;/strong&gt; If you have Homebrew installed, run the following:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;brew install kubectl&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;On Linux&lt;/strong&gt; For uniformity of installation,I will be using Snap, a package manager that comes bundled in most Linux distributions.&lt;br&gt;
First check if you have Snap installed by running:&lt;br&gt;
&lt;code&gt;snap --version&lt;/code&gt;&lt;br&gt;
You should get the output below if you have Snap installed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnh8v0ha0evkxxjcnslp7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnh8v0ha0evkxxjcnslp7.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
If you don't have Snap installed, on Ubuntu-based systems you can do so by running&lt;br&gt;
&lt;code&gt;sudo apt-get install snapd -y&lt;/code&gt;&lt;br&gt;
while on Red-hat-based distribution, you will first have to install the &lt;a href="https://docs.fedoraproject.org/en-US/epel/epel-about/" rel="noopener noreferrer"&gt;Epel&lt;/a&gt; repository with:&lt;br&gt;
&lt;code&gt;sudo dnf install epel-release -y&lt;/code&gt;&lt;br&gt;
Then, update dnf with:&lt;br&gt;
&lt;code&gt;sudo dnf upgrade&lt;/code&gt;&lt;br&gt;
Finally, install Snap with:&lt;br&gt;
&lt;code&gt;sudo dnf install snap -y&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When you are done with the above steps, just run:&lt;br&gt;
&lt;code&gt;sudo snap install kubectl --classic&lt;/code&gt;&lt;br&gt;
And you are in!&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7cv0sr2ttpn1w48d3l3v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7cv0sr2ttpn1w48d3l3v.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Verifying the Installation
&lt;/h2&gt;

&lt;p&gt;After installation, verify that &lt;strong&gt;&lt;code&gt;kubectl&lt;/code&gt;&lt;/strong&gt; is working by running the command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl version&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;If you are using a cloud-based Kubernetes cluster, there are extra things you need to get Kubectl up and running.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuring Kubectl for cloud-based Kubernetes cluster
&lt;/h2&gt;

&lt;p&gt;You need the cluster configuration details to connect &lt;strong&gt;&lt;code&gt;kubectl&lt;/code&gt;&lt;/strong&gt; to your cluster. These details typically include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cluster API Server: The endpoint where your cluster is running.&lt;/li&gt;
&lt;li&gt;Cluster Certificate Authority: The certificate authority data for your cluster.&lt;/li&gt;
&lt;li&gt;Authentication Token: A token for authenticating with the cluster (used in some configurations).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are 2 ways of achieving this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using &lt;code&gt;kubectl config&lt;/code&gt; command&lt;/li&gt;
&lt;li&gt;Kubeconfig File&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using kubectl config command: To set cluster configuration  using the kubectl config command, open a terminal and paste the following commands&lt;/p&gt;

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

kubectl config set-cluster my-cluster-name --server=https://cluster-api-server-address --certificate-authority=path/to/certificate-authority
kubectl config set-credentials my-cluster-cred --token=your-auth-token
kubectl config set-context my-cluster-context --cluster=my-cluster-name --user=my-cluster-


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

&lt;/div&gt;

&lt;p&gt;Replace &lt;strong&gt;&lt;code&gt;my-cluster-name&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;https://cluster-api-server-address&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;path/to/certificate-authority&lt;/code&gt;&lt;/strong&gt;, and &lt;strong&gt;&lt;code&gt;your-auth-token&lt;/code&gt;&lt;/strong&gt; with your specific cluster details.&lt;/p&gt;

&lt;p&gt;Using kubeconfig file: You can directly edit the &lt;strong&gt;&lt;code&gt;kubeconfig&lt;/code&gt;&lt;/strong&gt; file (usually located at &lt;strong&gt;&lt;code&gt;~/.kube/config&lt;/code&gt;&lt;/strong&gt;) to add multiple clusters. Manually add your cluster details in the &lt;strong&gt;&lt;code&gt;clusters&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;users&lt;/code&gt;&lt;/strong&gt;, and &lt;strong&gt;&lt;code&gt;contexts&lt;/code&gt;&lt;/strong&gt; sections.&lt;/p&gt;

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

&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;clusters&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;cluster&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;certificate-authority-data&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;certificate-authority-data&amp;gt;&lt;/span&gt;
    &lt;span class="na"&gt;server&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://cluster-api-server-address&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-cluster-name&lt;/span&gt;
&lt;span class="na"&gt;contexts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;cluster&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-cluster-name&lt;/span&gt;
    &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-cluster-cred&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-cluster-context&lt;/span&gt;
&lt;span class="na"&gt;current-context&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-cluster-context&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Config&lt;/span&gt;
&lt;span class="na"&gt;preferences&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{}&lt;/span&gt;
&lt;span class="na"&gt;users&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-cluster-cred&lt;/span&gt;
  &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;your-auth-token&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Once you've configured &lt;code&gt;kubectl&lt;/code&gt;, you can test the connection by running: &lt;/p&gt;

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

&lt;span class="s"&gt;kubectl cluster-info&lt;/span&gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Getting Minikube Ready
&lt;/h2&gt;

&lt;p&gt;I will use Minikube to set up a Kubernetes cluster on my local machine.&lt;/p&gt;

&lt;p&gt;For this guide, I will be using the bash terminal on Windows but command prompt or PowerShell will work fine. Let’s start a Minikube cluster of 3 nodes. Open the terminal and type:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;

&lt;span class="s"&gt;minikube start --nodes &lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;When Minikube is done starting, you will be presented with the below output&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4gbvwn9e4xdecrtpm7um.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4gbvwn9e4xdecrtpm7um.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
All good, we now have our Minikube cluster running.&lt;/p&gt;

&lt;p&gt;Now let us get into business.&lt;/p&gt;

&lt;p&gt;In this article, we will not be looking at all the commands that are available in Kubectl.To get you up and running, we will check out Kubectl commands as they pertain to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node and Cluster Management&lt;/li&gt;
&lt;li&gt;Application Management&lt;/li&gt;
&lt;li&gt;Updating and Deleting Application&lt;/li&gt;
&lt;li&gt;Debugging Application&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a comprehensive list of all Kubectl commands please check the &lt;a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands" rel="noopener noreferrer"&gt;Kubectl documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Below is a table of commands we will be looking at in this guide. &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Commands&lt;/th&gt;
&lt;th&gt;Uses&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;kubectl get&lt;/td&gt;
&lt;td&gt;Retrieving information about Kubernetes resources&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;kubectl describe&lt;/td&gt;
&lt;td&gt;Detailed information about a specific resource&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;kubectl logs&lt;/td&gt;
&lt;td&gt;Accessing container logs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;kubectl create&lt;/td&gt;
&lt;td&gt;Creating  resources&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;kubectl apply&lt;/td&gt;
&lt;td&gt;Updating resources&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;kubectl delete&lt;/td&gt;
&lt;td&gt;Removing resources from the cluster&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;kubectl exec&lt;/td&gt;
&lt;td&gt;Running commands inside containers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;kubectl cordon&lt;/td&gt;
&lt;td&gt;Marks a node as unschedulable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;kubectl uncordon&lt;/td&gt;
&lt;td&gt;Unmarks a node as unschedulable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;kubectl drain&lt;/td&gt;
&lt;td&gt;Gracefully moves all pods off a node&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;kubectl set image deployment&lt;/td&gt;
&lt;td&gt;Updating the container image in a specific deployment&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;kubectl api-versions&lt;/td&gt;
&lt;td&gt;Lists the API groups and their versions understood by the Kubernetes API server.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;kubectl api-resources&lt;/td&gt;
&lt;td&gt;Display the available API resources&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Node and Cluster Management
&lt;/h2&gt;

&lt;p&gt;As a Kubernetes user, among the things you will be doing is working with nodes and clusters. This section will guide you on using kubectl to operate Kubernetes node and cluster.&lt;/p&gt;

&lt;h3&gt;
  
  
  Get Nodes
&lt;/h3&gt;

&lt;p&gt;Do you still remember the cluster we created? Let’s now put it to use.&lt;/p&gt;

&lt;p&gt;First, let’s get some information about the minikube cluster. In your terminal, type:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl get nodes&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command gets information about the nodes in our minikube cluster and  presents us with the below output:&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Describe Nodes
&lt;/h3&gt;

&lt;p&gt;Let’s go further and get detailed information about the nodes.&lt;/p&gt;

&lt;p&gt;Type &lt;code&gt;kubectl describe nodes&lt;/code&gt; and you will be presented with descriptions of all the nodes on your cluster.&lt;/p&gt;

&lt;p&gt;Let’s narrow our command and get a description of our minikube control-plane node.&lt;/p&gt;

&lt;p&gt;Type &lt;code&gt;kubectl describe node minikube&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Kubernetes returns an output stating details about the minikube node.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnyflpwkfe8y7yfd0mt22.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnyflpwkfe8y7yfd0mt22.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Before we move on, let's get information about our minikube-m02 node.&lt;/p&gt;

&lt;p&gt;In the terminal, type: &lt;code&gt;kubectl describe node minikube-m02&lt;/code&gt;      &lt;/p&gt;

&lt;p&gt;The above command  displays a description of our minikube-m02 node below:&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Cordon Nodes
&lt;/h3&gt;

&lt;p&gt;Imagine you have a team of workers doing their tasks in an office. Now, let's say you need to do some maintenance on a particular desk and don't want anyone to start new tasks there until you're done. In Kubernetes, kubectl cordon is like putting a Do Not Disturb sign on that desk. It tells Kubernetes not to schedule any new work on a specific worker node so you can conduct maintenance on it.&lt;/p&gt;

&lt;p&gt;Let us demonstrate this with our minikube-m02 node.&lt;/p&gt;

&lt;p&gt;On the terminal,type &lt;code&gt;kubectl cordon minikube-m02&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;Now our minikube-m02 node is restricted from having new pods scheduled on it.&lt;/p&gt;

&lt;p&gt;Use &lt;code&gt;kubectl describe node minikube-m02&lt;/code&gt; to check if this is true.&lt;/p&gt;

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

&lt;p&gt;Pay attention to the output,unshedulable now says true.&lt;/p&gt;

&lt;p&gt;Get it to run new pods by executing &lt;code&gt;kubectl uncordon minikube-m02&lt;/code&gt;&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Drain Nodes
&lt;/h3&gt;

&lt;p&gt;Next on our lineup is kubectl  drain. If you ever need to remove all pods from a node, then kubectl drain is the man for the job.&lt;/p&gt;

&lt;p&gt;It helps you prepare a node for maintenance by moving all the tasks and applications to other nodes. Let us see it in action.&lt;/p&gt;

&lt;p&gt;In your terminal, type &lt;code&gt;kubectl drain minikube-m03 --ignore-daemonsets --force&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Before we press enter, let me explain what the above command does.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;kubectl drain is the main command that tells Kubernetes to prepare a particular node for maintenance.&lt;/li&gt;
&lt;li&gt;minikube-m03 is our particular node for maintenance.&lt;/li&gt;
&lt;li&gt;--ignore-daemonsets : this tells Kubernetes not to move certain essential tasks called daemonsets to other nodes.&lt;/li&gt;
&lt;li&gt;--force : the force flag tells Kubernetes not to wait for resources to terminate gracefully.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now hit enter.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw4kdqv8oq1fvjr68hieg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw4kdqv8oq1fvjr68hieg.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the above output, we can see that the drain command does 2 things. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It cordons or stops the node from having new pods scheduled on it.&lt;/li&gt;
&lt;li&gt;It then drains the node of existing pods.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Delete Nodes
&lt;/h3&gt;

&lt;p&gt;With our minikube-m03 node drained, we are now ready to delete the node. Run this command &lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl delete node minikube-m03&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The screenshot below shows us that our minikube-m03 node has been deleted.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Cluster Management
&lt;/h3&gt;

&lt;p&gt;It is advisable to regularly inspect the cluster API versions, as each new release of Kubernetes introduces new API versions and may eliminate older ones. To obtain a list of available APIs, execute the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl api-versions&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ke2n0f7cc27py8mpxwt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ke2n0f7cc27py8mpxwt.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
The above output returns a list of API versions available that we can make use of.&lt;/p&gt;

&lt;p&gt;Kubectl also provides a way to check the API resource list.&lt;/p&gt;

&lt;p&gt;To get the available API resource list  run &lt;code&gt;kubectl api-resources&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcs9g5ccadp3ky9uuj1d5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcs9g5ccadp3ky9uuj1d5.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our command returns the accessible resources, their short names, the API group to which a resource is affiliated, whether it is namespace-specific or not, and the specific KIND type.&lt;/p&gt;

&lt;h2&gt;
  
  
  Application Management
&lt;/h2&gt;

&lt;p&gt;In this section, we will look at application management with Kubectl. Navigate to the kubectl_practice folder.&lt;/p&gt;

&lt;p&gt;Let’s start with creating a deployment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create Deployment
&lt;/h3&gt;

&lt;p&gt;In the &lt;strong&gt;&lt;code&gt;kubectl_practice&lt;/code&gt;&lt;/strong&gt; folder, create a file named &lt;strong&gt;&lt;code&gt;practice-deployment.yaml&lt;/code&gt;&lt;/strong&gt; with the provided content.&lt;/p&gt;

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

&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;apps/v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deployment&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-deployment&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;replicas&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;matchLabels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-app&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-app&lt;/span&gt;
    &lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-container&lt;/span&gt;
        &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx:latest&lt;/span&gt;
        &lt;span class="na"&gt;resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;limits&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;0.5"&lt;/span&gt; 
            &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;512Mi"&lt;/span&gt;  
          &lt;span class="na"&gt;requests&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;0.2"&lt;/span&gt;  
            &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;256Mi"&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Run &lt;code&gt;kubectl apply -f practice-deployment.yaml&lt;/code&gt; to deploy using the configuration in the practice-deployment.yaml file.&lt;/p&gt;

&lt;p&gt;The above command will present you with the console output below :&lt;/p&gt;

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

&lt;p&gt;Let's check the status of our deployment by running &lt;code&gt;kubectl get deployments&lt;/code&gt;&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Create A Service
&lt;/h3&gt;

&lt;p&gt;Services expose Pods to the network within or outside the cluster. Let’s check out how to create services with Kubectl .&lt;/p&gt;

&lt;p&gt;I will create  a file in kubectl_practice folder and name it practice-service.yaml with the below as the content of this file:&lt;/p&gt;

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

&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Service&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-service&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-app&lt;/span&gt;
  &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;protocol&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;TCP&lt;/span&gt;
      &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
      &lt;span class="na"&gt;targetPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ClusterIP&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Next, let's apply the configuration. &lt;/p&gt;

&lt;p&gt;Type &lt;code&gt;kubectl apply -f practice-service.yaml&lt;/code&gt; in your terminal and hit the enter key.&lt;/p&gt;

&lt;p&gt;The screenshot below shows that our service was created.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi43180hjj9x9tj163pub.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi43180hjj9x9tj163pub.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
You may check the status of the service by running &lt;code&gt;kubectl get services&lt;/code&gt;  which displays the output below &lt;/p&gt;

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

&lt;p&gt;Nice, our service is running.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create Pods
&lt;/h3&gt;

&lt;p&gt;Creating pods directly in Kubernetes seems convenient but brings challenges in scalability, resilience, updates, and resource management. Using higher-level abstractions like Deployments and ReplicaSets ensures easier management, automatic healing, streamlined updates, and optimized resource use for a more efficient Kubernetes experience. For the above, avoid creating pods directly in Kubernetes but instead, use deployments.&lt;/p&gt;

&lt;p&gt;In the kubectl_practice folder, create a file named practice-pod.yaml with the following content:&lt;/p&gt;

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

&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Pod&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;practice-pod-1&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-container&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx:latest&lt;/span&gt;
    &lt;span class="na"&gt;resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;limits&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;200Mi"&lt;/span&gt;
        &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;500m"&lt;/span&gt;   
      &lt;span class="na"&gt;requests&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;120Mi"&lt;/span&gt;
        &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;250m"&lt;/span&gt;

&lt;span class="nn"&gt;---&lt;/span&gt;

&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Pod&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;practice-pod-2&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;container-1&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx:latest&lt;/span&gt;
    &lt;span class="na"&gt;resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;limits&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;150Mi"&lt;/span&gt;
        &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;300m"&lt;/span&gt;   
      &lt;span class="na"&gt;requests&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;100Mi"&lt;/span&gt;
        &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;200m"&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Now  run this command &lt;code&gt;kubectl apply -f practice-pod.yaml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you follow everything correctly, the screenshot below should be the output on your terminal.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F23v89abav4vrt66iwer2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F23v89abav4vrt66iwer2.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With our practice-pod.yaml file we created 2 pods. Let’s confirm this by running &lt;code&gt;kubectl get pods&lt;/code&gt; &lt;/p&gt;

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

&lt;p&gt;Get rid of these pods by running  &lt;code&gt;kubectl delete pods practice-pod-1 practice-pod-2&lt;/code&gt;&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Updating And Deleting Application
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Updating
&lt;/h3&gt;

&lt;p&gt;There are many methods to deploy a new application version. Here, we will be focusing on two methods:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;kubectl apply&lt;/li&gt;
&lt;li&gt;kubectl set image&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Open the practice-deployment.yaml file and change the docker image from &lt;code&gt;nginx:latest&lt;/code&gt; to &lt;code&gt;nginx:stable-perl&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Save the file and run the following command &lt;code&gt;kubectl apply -f practice-deployment.yaml&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;Let’s run a quick command to get a description of our deployment. &lt;/p&gt;

&lt;p&gt;In your terminal, type &lt;code&gt;kubectl describe deployment my-deployment&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;In the above screenshot, did you notice that the container image changed from nginx:latest tag to nginx:stable-perl? &lt;/p&gt;

&lt;p&gt;Let's use &lt;code&gt;kubectl set image&lt;/code&gt; to change the container image tag to another version. Jump back into the terminal and type:  ****&lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl set image deployment my-deployment my-container=nginx:mainline&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;Get the description of our deployment by running &lt;code&gt;kubectl describe deployment my-deployment&lt;/code&gt;&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Exposing Application To The Internet
&lt;/h3&gt;

&lt;p&gt;To make your application available on the internet, go into the practice-service.yaml file and change the type from clusterIP to LoadBalancer.&lt;/p&gt;

&lt;p&gt;Apply the changes by running &lt;code&gt;kubectl apply -f practice-service.yaml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then run the get service command by typing &lt;code&gt;kubectl get service&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The below screenshot should be similar to the output on your console.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F97rh564vhdtjcxgrfgl9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F97rh564vhdtjcxgrfgl9.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are using a cloud-based Kubernetes cluster, It might take minutes for your cloud provider to set you up. If you are using Minikube, you will need to start the Minikube tunnel to expose the External-IP.&lt;/p&gt;

&lt;p&gt;On a separate terminal, run  &lt;code&gt;minikube tunnel&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Then get back and run &lt;code&gt;kubectl get service&lt;/code&gt;    &lt;/p&gt;

&lt;p&gt;By now the external IP status should change from pending to showing an external IP like so.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdzi6tmu7ryoru8hajj0f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdzi6tmu7ryoru8hajj0f.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the EXTERNAL-IP, and open it in a browser.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faxx9gb511x6p9gk10zeh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faxx9gb511x6p9gk10zeh.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You have successfully exposed your application to the internet. Great job.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deleting Application
&lt;/h3&gt;

&lt;p&gt;Let us get information about our deployment and our service. &lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;kubectl get service&lt;/code&gt; command to get our service.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvmnco2kezgwmkrlaaubf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvmnco2kezgwmkrlaaubf.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Let’s delete my-service with  &lt;code&gt;kubectl delete service my-service&lt;/code&gt; &lt;/p&gt;

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

&lt;p&gt;Try to get my-service with &lt;code&gt;kubectl get service&lt;/code&gt; and you will notice it is no longer there.&lt;/p&gt;

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

&lt;p&gt;Get the name of our deployment with &lt;code&gt;kubectl get deployments&lt;/code&gt; and run &lt;code&gt;kubectl delete deployment my-deployment&lt;/code&gt;.&lt;/p&gt;

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

&lt;p&gt;Try to get our deployment with &lt;code&gt;kubectl get deployments&lt;/code&gt; and you will get the below output:&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Debugging Application
&lt;/h2&gt;

&lt;p&gt;Sometimes things might not go as planned and you have to get into the pods to fix things. To demonstrate this, let’s create a fresh deployment.&lt;/p&gt;

&lt;p&gt;In the kubectl_practice folder, create a file called myDatabase-deployment.yaml and paste the below content.&lt;/p&gt;

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

&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;apps/v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deployment&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-database&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;replicas&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;matchLabels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-app&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-app&lt;/span&gt;
    &lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-sql&lt;/span&gt;
        &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mysql:oracle&lt;/span&gt;
        &lt;span class="c1"&gt;#env goes here&lt;/span&gt;
        &lt;span class="na"&gt;resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;requests&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;0.4"&lt;/span&gt;
            &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;800Mi"&lt;/span&gt;
          &lt;span class="na"&gt;limits&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;0.8"&lt;/span&gt;
            &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;900Mi"&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Get into the terminal and type &lt;code&gt;kubectl apply -f myDatabase-deployment.yaml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The above command gives the output below.&lt;/p&gt;

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

&lt;p&gt;Try to get our deployment with &lt;code&gt;kubectl get deployments&lt;/code&gt; and you will be presented with the output below.&lt;/p&gt;

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

&lt;p&gt;For some reason,my-database deployment is not ready. Let’s get the pods in our deployment&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;kubectl get pods&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;From the above output, we can see that my-database— pod has the status of CrashLoopBackOff.What could this be?&lt;/p&gt;

&lt;p&gt;Let's get a log of the pods, run &lt;code&gt;kubectl logs my-database-7c44d9bcb4-h9h54&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhrlticiiaboquaq9jmn7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhrlticiiaboquaq9jmn7.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The preceding command shows a log of the pods. Line 3 of the logs is of concern to us where it displays that "Database is uninitialized and password option is not specified You need to specify one of the following as an environment variable:"&lt;br&gt;
This means that we need to set a password for the database. To fix this, get into myDatabase-deployment.yaml file, under containers, add the below content:&lt;/p&gt;

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

&lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
         &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;MYSQL_ROOT_PASSWORD&lt;/span&gt;
           &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;secret-password&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Next, get back to the terminal and run &lt;code&gt;kubectl apply -f myDatabase-deployment.yaml&lt;/code&gt;&lt;br&gt;
Confirm if our pod is running by executing &lt;code&gt;kubectl get pods&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;Awesome our pods are running.&lt;br&gt;
Finally, let's show how to use &lt;code&gt;kubectl exec&lt;/code&gt; to run a terminal inside a container. I will be using Windows Powershell to demonstrate this.&lt;br&gt;
If you are using Windows OS, open Powershell and navigate to our kubectl_practice folder.&lt;br&gt;
First I will run &lt;code&gt;kubectl get pods&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgthez1m0nozae2akiyiw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgthez1m0nozae2akiyiw.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Second  I will get the pod name and exec into the container with &lt;br&gt;
&lt;code&gt;kubectl exec -it my-database-7c8c774899-jdqth -- /bin/bash&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxqfexg5z2hzfayid204n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxqfexg5z2hzfayid204n.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Let's get a list of directories/folders inside the container by running &lt;code&gt;ls&lt;/code&gt; which stands for lists.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmoce8no7eegtp269ilev.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmoce8no7eegtp269ilev.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
The above output shows the Linux directory structure inside our my-sql container.&lt;br&gt;
Let's run &lt;code&gt;mysql -p&lt;/code&gt; which will prompt for the password to be entered.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftnswkpesl5swmkb0ogqy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftnswkpesl5swmkb0ogqy.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Remember we set the password to secret-password. Type it in and you will be presented with an output similar to this:&lt;/p&gt;

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

&lt;p&gt;You may leave the container by running &lt;code&gt;exit&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;And there you have it, your journey into the world of Kubectl. We covered node and cluster management, application management, and updating and deleting applications, and even went as far as debugging your applications. Remember, mastering Kubectl takes practice but every command you learn brings you a step closer to becoming a Kubernetes master.&lt;br&gt;
Keep this guide handy as you continue your Kubernetes exploration, and don't hesitate to experiment. The world of Kubernetes is dynamic and ever-expanding and Kubectl is your key to unlocking its full potential.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>kubernetes</category>
      <category>cloud</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Containerizing your full-stack node app using Docker Compose</title>
      <dc:creator>Otuekong Arthur</dc:creator>
      <pubDate>Sat, 04 Nov 2023 10:28:13 +0000</pubDate>
      <link>https://forem.com/fizy_hector/-containerizing-your-full-stack-node-app-using-docker-compose-4lnk</link>
      <guid>https://forem.com/fizy_hector/-containerizing-your-full-stack-node-app-using-docker-compose-4lnk</guid>
      <description>&lt;p&gt;Containerization, particularly with Docker, has revolutionized the way we develop, test, and deploy software. Docker Compose, an essential companion to Docker, simplifies the process of managing multi-container applications. In this article, we embark on a journey into the world of containerization, focusing on containerizing a full-stack Node.js application using Docker Compose. &lt;/p&gt;

&lt;p&gt;Whether you're a seasoned developer or just stepping into the world of containerization, this article will guide you through the process of Dockerizing a comprehensive application, from setting up your development environment to orchestrating multi-container setups effortlessly. By the end of this journey, you'll have a deep understanding of Docker Compose and the confidence to containerize your own full-stack Node.js applications, paving the way for efficient, scalable, and reliable software deployment. So, let's dive in and explore the transformative power of containerization in modern software development.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Prerequisite:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This article assumes that you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker Desktop&lt;/li&gt;
&lt;li&gt;Node and Npm&lt;/li&gt;
&lt;li&gt;Basic knowledge of react&lt;/li&gt;
&lt;li&gt;Basic knowledge of tailwind css&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To follow along, you will need the following already installed on your computer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker Desktop&lt;/li&gt;
&lt;li&gt;Node js&lt;/li&gt;
&lt;li&gt;And a code editor&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You will need tailwind CSS to get the styles I have used in this tutorial. Visit the &lt;a href="https://tailwindcss.com/docs/guides/vite" rel="noopener noreferrer"&gt;Tailwind CSS&lt;/a&gt; documentation to get Tailwind up and running.  &lt;/p&gt;

&lt;p&gt;Let’s create a folder for our project.&lt;br&gt;
Open the command line on Windows and terminal on Mac, navigate to your desktop or your desired directory, and create a folder with &lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkdir Docker_Compose&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Inside this folder &lt;/p&gt;

&lt;p&gt;navigate inside the folder you just created with &lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd Docker_Compose&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;inside the Docker_Compose folder, create two folders named frontend and backend with&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkdir frontend&lt;/code&gt; and  &lt;code&gt;mkdir backend&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Getting our backend ready&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;navigate inside the backend folder with&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd backend&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Initialize your express js backend package.json file with&lt;br&gt;
&lt;code&gt;npm init -y&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The above command will create a package.json file in the root of your server and this file contains details about your project and its dependencies&lt;/p&gt;

&lt;p&gt;Install Express.js using the following command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install express&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will download and install the Express.js package for your project.&lt;/p&gt;

&lt;p&gt;Before we get into creating our backend code, let’s create a script that starts up our server. In the root of our backend folder, open the package.json file and paste this command under scripts&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"start": "node server.js",&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Next, to avoid,cross-origin request issues from our backend, we’ll install cors npm package by running the following command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i cors&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Open the Docker_Compose folder in your text editor and navigate to the backend folder you created.&lt;/p&gt;

&lt;p&gt;Inside the backend folder, create a file called server.js, and paste the following code:&lt;/p&gt;

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

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cors&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;joke&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Why don't scientists trust atoms? Because they make up everything!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;joke&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I'm on a seafood diet. I see food and I eat it&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;joke&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I used to be a baker because I kneaded dough&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;joke&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Why don’t some couples go to the gym? Because some relationships don’t work out!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;joke&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I'm reading a book on anti-gravity. It's impossible to put down!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;joke&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Parallel lines have so much in common. It’s a shame they’ll never meet&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;joke&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Why did the scarecrow win an award? Because he was outstanding in his field!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;joke&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Why don't oysters donate to charity? Because they are shellfish!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;joke&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I'm on a whiskey diet. I've lost three days already&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;joke&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I used to play piano by ear, but now I use my hands&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Listening on port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Start your Express server using the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The above command will run your server on port 8000 on localhost, which you can access on &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:8000&lt;/a&gt; in your browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Getting our frontend ready&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;On our front end, we will be using Vite to initialize a React application.&lt;/p&gt;

&lt;p&gt;Navigate to the frontend folder and input the following command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm create vite@latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After you are done initializing the react app, delete the content of the App.js file and paste the following code &lt;/p&gt;

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

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setError&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;jokes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setJokes&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://localhost:8000&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
          &lt;span class="nf"&gt;setJokes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="nf"&gt;setError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error fetching data:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statusText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error fetching data:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;nav&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'bg-red-50 py-4'&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'font-light text-4xl text-red-400  px-20 '&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;jokesVille&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;nav&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'flex justify-center items-center px-6 py-10 bg-red-100'&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;
            &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;
              &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;flex&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hidden&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; h-full justify-center items-center text-center`&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
          &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'text-xl font-medium'&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
              So Sorry we could not find you jokes
              &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'img'&lt;/span&gt; &lt;span class="na"&gt;aria-label&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'dissapointed'&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'text-4xl'&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="ni"&gt;&amp;amp;#128542;&lt;/span&gt;
              &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 justify-center items-center gap-x-4 gap-y-3 text-center my-10 py-5'&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;jokes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;joke&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
              &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;
                &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;joke&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
                &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;' h-40 flex flex-col justify-center items-center bg-gray-50 rounded-md py-16 px-20'&lt;/span&gt;
              &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'img'&lt;/span&gt; &lt;span class="na"&gt;aria-label&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'laugh'&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                  &lt;span class="ni"&gt;&amp;amp;#128514;&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'text-gray-500'&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;joke&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;joke&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Now fire up the jokesVille app frontend by running &lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There we have our app running nice and shiny in our browser&lt;/p&gt;

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

&lt;p&gt;Frontend view in chrome&lt;/p&gt;

&lt;p&gt;To reap the benefits of docker we will need to go beyond directly running our app on the browser but through docker containers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Then comes Docker:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is Docker?
&lt;/h3&gt;

&lt;p&gt;Docker is an open-source platform that enables developers to automate the deployment of applications in lightweight, portable containers. These containers are a form of virtualization that packages an application and its dependencies together, creating a consistent and isolated environment for running software.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why do we need docker?
&lt;/h3&gt;

&lt;p&gt;1 &lt;strong&gt;Consistency Across Environments:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Developers often face the challenge of "it works on my machine" issues when deploying applications to different environments. Docker containers encapsulate applications and their dependencies, ensuring consistency across development, testing, and production environments. This consistency eliminates discrepancies between environments, leading to more reliable deployments.&lt;/p&gt;

&lt;p&gt;2 &lt;strong&gt;Isolation and Resource Efficiency:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Docker containers offer both process and file system separation, enabling applications to operate autonomously from the host system. This separation guarantees that applications operate in their own space, preventing any interference and creating a stable, secure environment. Moreover, Docker's lightweight design demands fewer resources in comparison to conventional virtual machines, enhancing efficiency in terms of both memory and processing capabilities.&lt;/p&gt;

&lt;p&gt;3 &lt;strong&gt;Microservices Architecture:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In contemporary software development, the microservices architecture is extensively utilized. Docker simplifies the creation and supervision of microservices by enabling each service to operate within its dedicated container. This method of development, which emphasizes modularity, improves scalability, fault tolerance, and simplifies maintenance.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Docker Compose?
&lt;/h3&gt;

&lt;p&gt;Docker Compose is a utility designed to define and oversee complex Docker applications with multiple containers. It allows the comprehensive description of an application setup, encompassing services, networks, and storage allocations, within a unified docker-compose.yml file. This file serves as a plan for your application, outlining the construction, configuration, and interconnections of diverse containers.&lt;/p&gt;

&lt;p&gt;To reap the above benefits, let’s get into running our app in Docker&lt;/p&gt;

&lt;p&gt;To ensure our front-end displays in the browser when we run it in a container, go into vite.config file and replace the contents of the file with the following&lt;/p&gt;

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

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;defineConfig&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;vite&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;react&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@vitejs/plugin-react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineConfig&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
 &lt;span class="na"&gt;base&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;react&lt;/span&gt;&lt;span class="p"&gt;()],&lt;/span&gt;
 &lt;span class="na"&gt;server&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;strictPort&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;



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

&lt;/div&gt;

&lt;p&gt;You may choose to keep the default port: 5173, in my case I went with port: 3000. If you decide to go with a different port, do remember to change it accordingly in the frontend Dockerfile.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Containerizing our Application&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To start, we have to create 2 docker files,1 in our frontend folder and 1 in our backend folder.&lt;br&gt;
First, navigate into the frontend folder and create a file named Dockerfile, then paste the following command into the file:&lt;/p&gt;

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

&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; node:20.9.0-alpine3.18&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /Docker_Compose/frontend&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; package.json .&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;
&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 3000&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["npm", "run", "dev"]&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Before we move on to creating our backend docker file, let’s take some time to explain the content of the above docker file and what they do:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;FROM node:20.9.0-alpine3.18&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This line defines the foundational image for the Docker container. It begins with a minimal Alpine Linux system (version 3.18) and then adds Node.js version 20.9.0 onto this base system.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;WORKDIR /Docker_Compose/frontend&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This sets the working directory within the container to &lt;code&gt;/Docker_Compose/frontend&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;COPY packag.json ./&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This line copies &lt;code&gt;package.json&lt;/code&gt; from the host machine to the current working directory in the container (&lt;code&gt;/Docker_Compose/frontend&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;RUN npm install&lt;/code&gt;`&lt;/p&gt;

&lt;p&gt;This command installs the Node.js dependencies specified in &lt;code&gt;package.json&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;COPY . .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command copies all files from the directory on the host machine where the Dockerfile is located to the active working directory within the container. This encompasses various items such as the application code and extra configuration files.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;EXPOSE 3000&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This informs Docker that the container will listen on port 3000 at runtime.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CMD ["npm","run","dev"]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This specifies the default command to run when the container starts. &lt;/p&gt;

&lt;p&gt;To create our backend docker file, navigate to the backend folder, create a file named Dockerfile, and paste in the following commands&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;docker&lt;br&gt;
FROM node:20.9.0-alpine3.18&lt;br&gt;
WORKDIR /Docker_Compose/backend&lt;br&gt;
COPY package.json .&lt;br&gt;
RUN npm install&lt;br&gt;
COPY . .&lt;br&gt;
EXPOSE 8000 &lt;br&gt;
CMD ["npm", "start"]&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Next, navigate to the root folder (Docker_Compose) and create a file named docker-compose.yaml, then paste the following text&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;yaml&lt;br&gt;
version: "3.8"&lt;br&gt;
services:&lt;br&gt;
  frontend:&lt;br&gt;
    build: ./frontend&lt;br&gt;
    container_name: jokesVille_client&lt;br&gt;
    ports:&lt;br&gt;
      - "3000:3000"&lt;br&gt;
  backend:&lt;br&gt;
    build: ./backend&lt;br&gt;
    container_name: jokesVille_server&lt;br&gt;
    ports:&lt;br&gt;
      - "8000:8000"&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In the root folder  (Docker_Compose), and with Docker Desktop running, run the below command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker-compose up --build&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you have been following the tutorial correctly, you should be greeted with a screen similar to this&lt;/p&gt;

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

&lt;p&gt;Open &lt;a href="http://localhost:8000/" rel="noopener noreferrer"&gt;http://localhost:8000/&lt;/a&gt; and view the jokesville backend&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftbbmhwimpnkgp74fbxqg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftbbmhwimpnkgp74fbxqg.png" alt="jokesville backend"&gt;&lt;/a&gt;&lt;br&gt;
Open &lt;a href="http://localhost:3000/" rel="noopener noreferrer"&gt;http://localhost:3000/&lt;/a&gt; on your browser and you’ll have our jokesville frontend nicely displayed and connected to the backend.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7it4sehpmmtrys16j5nd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7it4sehpmmtrys16j5nd.png" alt="jokesville frontend"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To shut down the docker containers, in the root folder run &lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker-compose down&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, you've learned the process of containerizing your full-stack web application with Docker Compose. Initially, we set up a backend Express server with Node.js and developed a front-end application using React.js. Following these stages, Dockerfiles were generated for both applications, alongside a docker-compose.yaml file.&lt;br&gt;
Using this docker-compose.yaml file, we built and launched the application containers.&lt;/p&gt;

</description>
      <category>node</category>
      <category>react</category>
      <category>docker</category>
      <category>devops</category>
    </item>
    <item>
      <title>Setting up environmental variables in React</title>
      <dc:creator>Otuekong Arthur</dc:creator>
      <pubDate>Mon, 21 Aug 2023 19:43:55 +0000</pubDate>
      <link>https://forem.com/fizy_hector/setting-up-env-variables-in-react-4aob</link>
      <guid>https://forem.com/fizy_hector/setting-up-env-variables-in-react-4aob</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Prerequisite:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This tutorial assumes that you have some knowledge of Html, CSS,Tailwind CSS,Javascript, and React.&lt;br&gt;
At the end of this tutorial, you should be able to create and use environmental variables in React.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Overview:&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;what are environmental variables&lt;/li&gt;
&lt;li&gt;Reason for environmental variables&lt;/li&gt;
&lt;li&gt;Setting up and accessing environmental variables in create-react-app&lt;/li&gt;
&lt;li&gt;Setting up and accessing environmental variables in Vite&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  What are environmental variables
&lt;/h3&gt;

&lt;p&gt;Environmental variables in React are special variables that store configuration settings or sensitive information outside of your application's source code.&lt;br&gt;
Environmental variables are typically stored in files named .env or .env.local at the root of your project.&lt;/p&gt;
&lt;h3&gt;
  
  
  Reasons for environmental variables
&lt;/h3&gt;

&lt;p&gt;Environmental variables are useful for storing sensitive information like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API keys&lt;/li&gt;
&lt;li&gt;API endpoints&lt;/li&gt;
&lt;li&gt;Database credentials&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Setting up environmental variables in create-react-app
&lt;/h3&gt;

&lt;p&gt;In React,environmental variables are declared  by creating a .env  file in  your project root folder and declaring the variable name in all uppercase,like so&lt;br&gt;
&lt;code&gt;REACT_APP_YOUR_VARIABLE_NAME=thisismyFirstENVvariablewithCreateReactApp&lt;br&gt;
&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MfiXttjN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/olmr4hwfh6cr0k1a80uy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MfiXttjN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/olmr4hwfh6cr0k1a80uy.png" alt="setting up environmental variable in create-react-app" width="800" height="140"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Accessing environmental variables in create-react-app
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;process.env.REACT_APP_YOUR_VARIABLE_NAME&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "./App.css";
import { useState } from "react";

export default function App() {
  const [jokes, setJokes] = useState();

  const url = "https://jokes-by-api-ninjas.p.rapidapi.com/v1/jokes?";
  const options = {
    method: "GET",
    headers: {
      "X-RapidAPI-Key": process.env.REACT_APP_API_KEY,
      "X-RapidAPI-Host": "jokes-by-api-ninjas.p.rapidapi.com",
    },
  };

  async function getJokes() {
    try {
      const response = await fetch(url, options);
      const result = await response.text();
      setJokes(result);
    } catch (error) {
      console.error(error);
    }
  }

  return (
    &amp;lt;div className='App w-full flex justify-center items-center mt-40 '&amp;gt;
      &amp;lt;div className=' w-[80%] lg:w-1/3 bg-gray-500 rounded-lg py-6 space-y-6 shadow-xl '&amp;gt;
        &amp;lt;p className='text-white text-lg font-semibold px-3'&amp;gt;{jokes}&amp;lt;/p&amp;gt;
        &amp;lt;button
          className='rounded-md bg-purple-400 text-white p-2 '
          onClick={() =&amp;gt; getJokes()}
        &amp;gt;
          Get Advice
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setting up environmental variables in Vite React
&lt;/h3&gt;

&lt;p&gt;Environmental variable in vite react starts with VITE_&lt;br&gt;
like so&lt;br&gt;
&lt;code&gt;VITE_YOUR_VARIABLE_NAME=thisismyfirstENVvariableinVite&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CbE97WO9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nf5pvf1xmzu55jlvvp3m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CbE97WO9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nf5pvf1xmzu55jlvvp3m.png" alt="setting up environmental variable in Vite-react" width="800" height="140"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Accessing environmental variables in Vite React
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;import.meta.env.VITE_YOUR_VARIABLE_NAME&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const options = {
    method: "GET",
    headers: {
      "X-RapidAPI-Key": import.meta.env.VITE_API_KEY,
      "X-RapidAPI-Host": "jokes-by-api-ninjas.p.rapidapi.com",
    },
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Environmental variables enhance security by keeping sensitive information, such as API keys or database passwords, out of source code. Storing these secrets as environmental variables helps protect them from accidental exposure and unauthorized access.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
