<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rubaiyat Rahim on Medium]]></title>
        <description><![CDATA[Stories by Rubaiyat Rahim on Medium]]></description>
        <link>https://medium.com/@rubaiyat.rahim?source=rss-86debe563139------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*PpsMW1BvK3uZiGKt</url>
            <title>Stories by Rubaiyat Rahim on Medium</title>
            <link>https://medium.com/@rubaiyat.rahim?source=rss-86debe563139------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 17:06:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rubaiyat.rahim/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Django Starter 6 — Main Index]]></title>
            <link>https://medium.com/@rubaiyat.rahim/django-starter-6-main-index-21dcd41e7f38?source=rss-86debe563139------2</link>
            <guid isPermaLink="false">https://medium.com/p/21dcd41e7f38</guid>
            <category><![CDATA[main]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[index]]></category>
            <dc:creator><![CDATA[Rubaiyat Rahim]]></dc:creator>
            <pubDate>Sun, 26 May 2024 17:49:30 GMT</pubDate>
            <atom:updated>2024-05-26T17:54:25.928Z</atom:updated>
            <content:encoded><![CDATA[<h3>Django Starter 6 — Main Index</h3><p>Creating the main index page of the site.</p><p>Other parts of this series: <a href="https://medium.com/@rubaiyat.rahim/django-starter-part-1-82940a2a0e82">Part 1</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-part-2-9a279df4d6ec">Part 2</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-3-database-admin-7dff33218f93">Part 3</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-4-showing-table-data-255788280ee1">Part 4</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-5-master-template-cd5bca8d8933">Part 5</a></p><h3>Create Main Template</h3><ul><li>Create the main template (<em>myproject\players\templates\main.html</em>) as follows:</li></ul><pre>{% extends &quot;master.html&quot; %}<br><br>{% block title %}<br>  Chelsea Football Club<br>{% endblock %}<br><br><br>{% block content %}<br>  &lt;h1&gt;Chelsea Football Club&lt;/h1&gt;<br><br>  &lt;h3&gt;Players&lt;/h3&gt;<br>  <br>  &lt;p&gt;Check out all the &lt;a href=&quot;players/&quot;&gt;Players&lt;/a&gt;&lt;/p&gt;<br>  <br>{% endblock %}</pre><h3>Create Main View</h3><ul><li>Create the main view <em>myproject\players\views.py</em> in as follows:</li></ul><pre>from django.http import HttpResponse<br>from django.template import loader<br>from .models import Player<br><br>def players(request):<br>  allplayers = Player.objects.all().values()<br>  template = loader.get_template(&#39;all_players.html&#39;)<br>  context = {<br>    &#39;allplayers&#39;: allplayers,<br>  }<br>  return HttpResponse(template.render(context, request))<br><br>def details(request, id):<br>  theplayer = Player.objects.get(id=id)<br>  template = loader.get_template(&#39;details.html&#39;)<br>  context = {<br>    &#39;theplayer&#39;: theplayer,<br>  }<br>  return HttpResponse(template.render(context, request))<br><br>def main(request):<br>  template = loader.get_template(&#39;main.html&#39;)<br>  return HttpResponse(template.render())</pre><h3>Add URL</h3><ul><li>Add URL by putting the entry <em>path(‘’, views.main, name=’main’)</em> in the urlpatterns in <em>myproject\players\urls.py</em> as follows:</li></ul><pre>from django.urls import path<br>from . import views<br><br>urlpatterns = [<br>    path(&#39;&#39;, views.main, name=&#39;main&#39;),<br>    path(&#39;players/&#39;, views.players, name=&#39;players&#39;),<br>    path(&#39;players/details/&lt;int:id&gt;&#39;, views.details, name=&#39;details&#39;),<br><br>]</pre><h3>Add Link back to Main Index</h3><ul><li>Add a link (<em>&lt;a href=”/”&gt;HOME&lt;/a&gt;</em>) back to the main index page in the list of Players page (<em>myproject\players\templates\all_players.html</em>) as follows:</li></ul><pre>{% extends &quot;master.html&quot; %}<br><br>{% block title %}<br>  Chelsea Football Club - List of all Players<br>{% endblock %}<br><br><br>{% block content %}<br><br>  &lt;p&gt;&lt;a href=&quot;/&quot;&gt;HOME&lt;/a&gt;&lt;/p&gt;<br><br>  &lt;h1&gt;Players&lt;/h1&gt;<br>  <br>  &lt;ul&gt;<br>    {% for x in allplayers %}<br>      &lt;li&gt;&lt;a href=&quot;details/{{ x.id }}&quot;&gt;{{ x.firstname }} {{ x.lastname }}&lt;/a&gt;&lt;/li&gt;<br>    {% endfor %}<br>  &lt;/ul&gt;<br>{% endblock %}</pre><ul><li>The list of players page now has a link back to the main index page of the site as follows:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*_JhZIw1jn4Ucr-jgRYlJGw.png" /><figcaption>Fig: List of Players with a link back to the main index page of the site.</figcaption></figure><h3>The Index Page</h3><ul><li>Finally the main index page of the site looks like as follows:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*co3hV5xTN3imHK9exdDnSQ.png" /><figcaption>Fig: The main index page of the site.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21dcd41e7f38" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django Starter 5 — Master Template]]></title>
            <link>https://medium.com/@rubaiyat.rahim/django-starter-5-master-template-cd5bca8d8933?source=rss-86debe563139------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd5bca8d8933</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[master-template]]></category>
            <dc:creator><![CDATA[Rubaiyat Rahim]]></dc:creator>
            <pubDate>Sun, 26 May 2024 17:27:35 GMT</pubDate>
            <atom:updated>2024-05-26T17:55:36.508Z</atom:updated>
            <content:encoded><![CDATA[<h3>Django Starter 5 — Master Template</h3><p>Using a master template to reuse common items in multiple pages.</p><p>Other parts of this series: <a href="https://medium.com/@rubaiyat.rahim/django-starter-part-1-82940a2a0e82">Part 1</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-part-2-9a279df4d6ec">Part 2</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-3-database-admin-7dff33218f93">Part 3</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-4-showing-table-data-255788280ee1">Part 4</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-6-main-index-21dcd41e7f38">Part 6</a></p><h3>Create Master Template</h3><ul><li>Create the master template (<em>myproject\players\templates\master.html</em>) as follows:</li></ul><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>  &lt;title&gt;{% block title %}{% endblock %}&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br><br>{% block content %}<br>{% endblock %}<br><br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h3>Change Templates to use the Master Template</h3><h4>Changing All Players Template</h4><ul><li>Change the list of all players template (<em>myproject\players\templates\all_players.html</em>) as follows:</li></ul><pre>{% extends &quot;master.html&quot; %}<br><br>{% block title %}<br>  Chelsea Football Club - List of all Players<br>{% endblock %}<br><br><br>{% block content %}<br>  &lt;h1&gt;Players&lt;/h1&gt;<br>  <br>  &lt;ul&gt;<br>    {% for x in allplayers %}<br>      &lt;li&gt;&lt;a href=&quot;details/{{ x.id }}&quot;&gt;{{ x.firstname }} {{ x.lastname }}&lt;/a&gt;&lt;/li&gt;<br>    {% endfor %}<br>  &lt;/ul&gt;<br>{% endblock %}</pre><h4>Changing Players Detail Template</h4><ul><li>Change the Players Detail template (<em>myproject\players\templates\details.html</em>) as follows:</li></ul><pre>{% extends &quot;master.html&quot; %}<br><br>{% block title %}<br>  Player Details of {{ theplayer.firstname }} {{ theplayer.lastname }}<br>{% endblock %}<br><br><br>{% block content %}<br>  &lt;h1&gt;{{ theplayer.firstname }} {{ theplayer.lastname }}&lt;/h1&gt;<br>  <br>  &lt;p&gt;Phone {{ theplayer.phone }}&lt;/p&gt;<br>  &lt;p&gt;Date of Birth: {{ theplayer.dateofbirth }}&lt;/p&gt;<br>  <br>  &lt;p&gt;Back to &lt;a href=&quot;/players&quot;&gt;Players&lt;/a&gt;&lt;/p&gt;<br>  <br>{% endblock %}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd5bca8d8933" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django Starter 4 — Showing Table Data]]></title>
            <link>https://medium.com/@rubaiyat.rahim/django-starter-4-showing-table-data-255788280ee1?source=rss-86debe563139------2</link>
            <guid isPermaLink="false">https://medium.com/p/255788280ee1</guid>
            <category><![CDATA[django-database]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Rubaiyat Rahim]]></dc:creator>
            <pubDate>Sat, 25 May 2024 14:53:29 GMT</pubDate>
            <atom:updated>2024-05-26T17:57:17.367Z</atom:updated>
            <content:encoded><![CDATA[<h3>Django Starter 4 — Showing Table Data</h3><p>Showing database table data without using Admin panel.</p><p>Other parts of this series: <a href="https://medium.com/@rubaiyat.rahim/django-starter-part-1-82940a2a0e82">Part 1</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-part-2-9a279df4d6ec">Part 2</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-3-database-admin-7dff33218f93">Part 3</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-5-master-template-cd5bca8d8933">Part 5</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-6-main-index-21dcd41e7f38">Part 6</a></p><h3>Adding a List Page</h3><h4>Create Table/Model</h4><ul><li>Create the model class (<em>Player</em>) in models.py in the app folder (<em>myproject\players\models.py</em>) as follows:</li></ul><pre>from django.db import models<br><br>class Player(models.Model):<br>    firstname = models.CharField(max_length=100)<br>    lastname = models.CharField(max_length=100)<br>    dateofbirth = models.DateField(null=True)<br>    phonenumber = models.CharField(max_length=50)</pre><ul><li>Create migration, then migrate.</li></ul><pre>py manage.py makemigrations<br>py manage.py migrate</pre><h4>Create Template</h4><ul><li>Create the template file <em>all_players.html</em> in the <em>templates</em> folder as (<em>myproject\players\templates\all_players.html</em>) to show all the <em>Player</em> objects from the <em>Players</em> table as follows:</li></ul><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;body&gt;<br><br>&lt;h1&gt;Players&lt;/h1&gt;<br>  <br>&lt;ul&gt;<br>  {% for x in allplayers %}<br>    &lt;li&gt;{{ x.firstname }} {{ x.lastname }}&lt;/li&gt;<br>  {% endfor %}<br>&lt;/ul&gt;<br><br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h4>Create View</h4><ul><li>Create the <em>Players</em> view in the <em>players</em> folder (<em>myproject\players\views.py</em>) as follows:</li></ul><pre>from django.http import HttpResponse<br>from django.template import loader<br>from .models import Player<br><br>def players(request):<br>  allplayers = Player.objects.all().values()<br>  template = loader.get_template(&#39;all_players.html&#39;)<br>  context = {<br>    &#39;allplayers&#39;: allplayers,<br>  }<br>  return HttpResponse(template.render(context, request))</pre><ul><li>List of Players will be shown as follows:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*3XnveShi4ol1C5R7rWff_g.png" /><figcaption>Fig: List of Players.</figcaption></figure><h3>Adding a Detail Page</h3><h4>Create Template</h4><ul><li>Create the template file <em>details.html</em> in the <em>templates</em> folder (<em>myproject\players\templates\details.html</em>) as follows:</li></ul><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br><br>&lt;body&gt;<br><br>&lt;h1&gt;{{ theplayer.firstname }} {{ theplayer.lastname }}&lt;/h1&gt;<br>  <br>&lt;p&gt;Phone: {{ theplayer.phonenumber }}&lt;/p&gt;<br>&lt;p&gt;Date of Birth: {{ theplayer.dateofbirth }}&lt;/p&gt;<br><br>&lt;p&gt;Back to &lt;a href=&quot;/players&quot;&gt;Players&lt;/a&gt;&lt;/p&gt;<br><br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h4>Add Link in List Page</h4><ul><li>Insert a link in the list of all players (<em>myproject\players\templates\all_players.html</em>) as follows:</li></ul><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;body&gt;<br><br>&lt;h1&gt;Players&lt;/h1&gt;<br>  <br>&lt;ul&gt;<br>  {% for x in allplayers %}<br>    &lt;li&gt;&lt;a href=&quot;details/{{ x.id }}&quot;&gt;{{ x.firstname }} {{ x.lastname }}&lt;/a&gt;&lt;/li&gt;<br>  {% endfor %}<br>&lt;/ul&gt;<br><br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h4>Create View</h4><ul><li>Add a <em>details</em> view function in the <em>views.py</em> (<em>myproject\players\views.py</em>) as follows:</li></ul><pre>from django.http import HttpResponse<br>from django.template import loader<br>from .models import Player<br><br>def players(request):<br>  allplayers = Player.objects.all().values()<br>  template = loader.get_template(&#39;all_players.html&#39;)<br>  context = {<br>    &#39;allplayers&#39;: allplayers,<br>  }<br>  return HttpResponse(template.render(context, request))<br><br>def details(request, id):<br>  theplayer = Player.objects.get(id=id)<br>  template = loader.get_template(&#39;details.html&#39;)<br>  context = {<br>    &#39;theplayer&#39;: theplayer,<br>  }<br>  return HttpResponse(template.render(context, request))</pre><h4>Add URL</h4><ul><li>Add the url in <em>myproject\players\urls.py</em> as follows:</li></ul><pre>from django.urls import path<br>from . import views<br><br>urlpatterns = [<br>    path(&#39;players/&#39;, views.players, name=&#39;players&#39;),<br>    path(&#39;players/details/&lt;int:id&gt;&#39;, views.details, name=&#39;details&#39;),<br><br>]</pre><ul><li>List of Players is now being shown with link to the Players details page as follows:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*IxHaHkzul22lA2cyGIz5Gw.png" /><figcaption>Fig: List of Players with Details link.</figcaption></figure><ul><li>When the Details link of Players are clicked, details of that Player is being shown as follows:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*La7k_Zl-1cEfHHCSp8Dquw.png" /><figcaption>Fig: Details of Players.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=255788280ee1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django Starter 3 — Database Admin]]></title>
            <link>https://medium.com/@rubaiyat.rahim/django-starter-3-database-admin-7dff33218f93?source=rss-86debe563139------2</link>
            <guid isPermaLink="false">https://medium.com/p/7dff33218f93</guid>
            <category><![CDATA[superuser]]></category>
            <category><![CDATA[django-admin]]></category>
            <category><![CDATA[model]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Rubaiyat Rahim]]></dc:creator>
            <pubDate>Wed, 22 May 2024 15:31:19 GMT</pubDate>
            <atom:updated>2024-05-26T17:59:15.533Z</atom:updated>
            <content:encoded><![CDATA[<h3>Django Starter 3 — Database Admin Panel</h3><p>Working with databases and tables using Admin panel.</p><p>Other parts of this series: <a href="https://medium.com/@rubaiyat.rahim/django-starter-part-1-82940a2a0e82">Part 1</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-part-2-9a279df4d6ec">Part 2</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-4-showing-table-data-255788280ee1">Part 4</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-5-master-template-cd5bca8d8933">Part 5</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-6-main-index-21dcd41e7f38">Part 6</a></p><h4>Create User and Login as Admin</h4><pre># Make migrations to introduce in the database<br>py manage.py makemigrations<br><br># Implement the migrations<br>py manage.py migrate<br><br># Create a super user<br>py manage.py createsuperuser<br><br># Run the server<br>py manage.py runserver<br><br># Go to the page http://127.0.0.1:8000/admin <br># and login using the user just created</pre><h4>Create Table/Model</h4><ul><li>Create the model class (<em>Player</em>) in models.py in the app folder (<em>myproject\players\models.py</em>) as follows:</li></ul><pre>from django.db import models<br><br>class Player(models.Model):<br>    firstname = models.CharField(max_length=100)<br>    lastname = models.CharField(max_length=100)<br>    dateofbirth = models.DateField(null=True)<br>    phonenumber = models.CharField(max_length=50)</pre><ul><li>Include the <em>Player</em> class in the admin interface (<em>myproject\players\admin.py</em>) as follows:</li></ul><pre>from django.contrib import admin<br>from .models import Player<br><br># Register your models here.<br>admin.site.register(Player)</pre><ul><li>Create migration, then migrate, and then run the server.</li></ul><pre>py manage.py makemigrations<br>py manage.py migrate<br>py manage.py runserver</pre><ul><li>The <em>Player</em> model/table is shown now in the admin panel as follows:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hxApk_SOenrq8xDcKgI1IA.png" /><figcaption>Fig: Model shown in admin panel.</figcaption></figure><h4>Setting the List Fields</h4><ul><li>Set display label for the list of Players to be seen in the admin panel by setting the string representation of the Players in (<em>myproject\players\models.py</em>) as follows:</li></ul><pre>from django.db import models<br><br># Create your models here.<br>class Player(models.Model):<br>    firstname = models.CharField(max_length=100)<br>    lastname = models.CharField(max_length=100)<br>    dateofbirth = models.DateField(null=True)<br>    phonenumber = models.CharField(max_length=50)<br><br>    def __str__(self):<br>        return f&quot;{self.firstname} {self.lastname}&quot;</pre><p>The list is now being shown as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9caw3ZXWL8-MD63R2xzcXg.png" /><figcaption>Fig: First name and last name being shown in the list of Players.</figcaption></figure><ul><li>Fields to be displayed in the Players admin panel can be defined by a tuple also. Create a ModelAdmin class and supply the <em>list_display</em> tuple in the model registration call in (<em>myproject\players\admin.py</em>) as follows:</li></ul><pre>from django.contrib import admin<br>from .models import Player<br><br># Register your models here.<br><br>class PlayerAdmin(admin.ModelAdmin):<br>    list_display = (&quot;firstname&quot;, &quot;lastname&quot;, &quot;dateofbirth&quot;,)<br><br>admin.site.register(Player, PlayerAdmin)</pre><p>The list is now being shown as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VSqFt4NfyOa49zHZLwGw4w.png" /><figcaption>Fig: Several fields being shown in the list of Players.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7dff33218f93" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django Starter 2 — Create App]]></title>
            <link>https://medium.com/@rubaiyat.rahim/django-starter-part-2-9a279df4d6ec?source=rss-86debe563139------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a279df4d6ec</guid>
            <category><![CDATA[django-app]]></category>
            <category><![CDATA[template]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[vıew]]></category>
            <dc:creator><![CDATA[Rubaiyat Rahim]]></dc:creator>
            <pubDate>Mon, 20 May 2024 16:38:11 GMT</pubDate>
            <atom:updated>2024-05-26T18:00:10.887Z</atom:updated>
            <content:encoded><![CDATA[<h3>Django Starter 2 — Create App</h3><p>Creating a basic app in an existing Django project and adding basic views in it.</p><p>Other parts of this series: <a href="https://medium.com/@rubaiyat.rahim/django-starter-part-1-82940a2a0e82">Part 1</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-3-database-admin-7dff33218f93">Part 3</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-4-showing-table-data-255788280ee1">Part 4</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-5-master-template-cd5bca8d8933">Part 5</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-6-main-index-21dcd41e7f38">Part 6</a></p><h4>Creating the App</h4><pre># Navigate to the project folder and create the app<br>cd myproject<br>py manage.py startapp players</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/235/1*udFZt1R197huceU-yW8M6g.png" /><figcaption>File system contents in the app folder (<em>projectroot/myproject/players).</em></figcaption></figure><h4>Registering the new App</h4><p>Add the name of the app in the INSTALLED_APPS list in <em>projectroot/myproject/settings.py</em> file as follows:</p><pre>...<br><br>INSTALLED_APPS = [<br>    &#39;django.contrib.admin&#39;,<br>    &#39;django.contrib.auth&#39;,<br>    &#39;django.contrib.contenttypes&#39;,<br>    &#39;django.contrib.sessions&#39;,<br>    &#39;django.contrib.messages&#39;,<br>    &#39;django.contrib.staticfiles&#39;,<br><br>    &#39;players&#39;,<br>]<br><br>...</pre><h4>Creating a basic Hello World View</h4><ul><li>Add the view in <em>projectroot/myproject/players/views.py</em> as follows:</li></ul><pre>from django.shortcuts import render<br>from django.http import HttpResponse<br><br>def players(request):<br>    return HttpResponse(&quot;Hello world!!!&quot;)</pre><ul><li>Set the URL in the app folder by creating a new file urls.py there as follows: (<em>projectroot/myproject/players/urls.py</em>)</li></ul><pre>from django.urls import path<br>from . import views<br><br>urlpatterns = [<br>    path(&#39;players/&#39;, views.players, name=&#39;players&#39;),<br>]</pre><ul><li>Set the URL in the project folder as follows: (<em>projectroot/myproject/urls.py</em>)</li></ul><pre>from django.contrib import admin<br>from django.urls import include, path<br><br>urlpatterns = [<br>    path(&#39;&#39;, include(&#39;players.urls&#39;)),<br>    path(&#39;admin/&#39;, admin.site.urls),<br>]</pre><ul><li>Following message shown at <a href="http://127.0.0.1:8000/players/">http://127.0.0.1:8000/players/</a> if everything is alright:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*zKIkVPqVhswUiEjihl7UFg.png" /><figcaption>Output of the basic Hello World view.</figcaption></figure><h4>Creating a basic View using Template</h4><ul><li>Create a folder named <em>templates</em> and an html file (<em>basic.html</em>) for the template as follows:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*aR3I4_L_JfF7x8gCXWLaOw.png" /><figcaption>The basic template file in the (app)/templates folder.</figcaption></figure><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;body&gt;<br><br>&lt;h1&gt;Hello World!!!&lt;/h1&gt;<br>&lt;p&gt;This is a very basic template example.&lt;/p&gt;<br><br>&lt;/body&gt;<br>&lt;/html&gt;</pre><ul><li>Following message shown at <a href="http://127.0.0.1:8000/players/">http://127.0.0.1:8000/players/</a> if everything is alright:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*oXidKBgahoWasqrZv_GYUQ.png" /><figcaption>Output of the basic template view.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a279df4d6ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django Starter 1 — Create Project]]></title>
            <link>https://medium.com/@rubaiyat.rahim/django-starter-part-1-82940a2a0e82?source=rss-86debe563139------2</link>
            <guid isPermaLink="false">https://medium.com/p/82940a2a0e82</guid>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Rubaiyat Rahim]]></dc:creator>
            <pubDate>Mon, 20 May 2024 15:46:08 GMT</pubDate>
            <atom:updated>2024-05-26T18:01:09.104Z</atom:updated>
            <content:encoded><![CDATA[<h3>Django Starter 1 — Create Project</h3><p>Creating a basic Django project.</p><p>Other parts of this series: <a href="https://medium.com/@rubaiyat.rahim/django-starter-part-2-9a279df4d6ec">Part 2</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-3-database-admin-7dff33218f93">Part 3</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-4-showing-table-data-255788280ee1">Part 4</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-5-master-template-cd5bca8d8933">Part 5</a> | <a href="https://medium.com/@rubaiyat.rahim/django-starter-6-main-index-21dcd41e7f38">Part 6</a></p><h4>Prepare the Environment</h4><pre># Create the project root folder.<br>mkdir projectroot<br><br># Open the folder in VS Code.<br>code .<br><br># Open new terminal in VS Code.<br><br># Create a new virtual environment and activate.<br>py -m venv env<br>.\env\Scripts\activate<br><br># In VS Code IDE, go to <br># View <br># → Command Palette <br># → Python: Select Interpreter <br># → Select the python in the virtual environment just created.<br><br># Check version of python and pip, upgrade pip.<br>py --version<br>py -m pip install --upgrade pip<br>pip --version<br><br># Install Django and check version.<br>py -m pip install django<br>django-admin --version</pre><h4>Create the Project</h4><pre># Create the Django project.<br>django-admin startproject myproject</pre><h4>Test the Project</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*KJ1dbdoVQx3NIJHzoTQjtQ.png" /><figcaption>File system contents in the project root folder.</figcaption></figure><pre># Navigate to the project folder and run the project.<br>cd myproject<br>py manage.py runserver<br><br># Project creation succeeded <br># if the following is shown at http://127.0.0.1:8000/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dD8FWVtrX9lSkB92mKyc7A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82940a2a0e82" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing Kubernetes in Ubuntu — Setting It Up]]></title>
            <link>https://medium.com/@rubaiyat.rahim/installing-kubernetes-in-ubuntu-setting-it-up-3e3b50515b05?source=rss-86debe563139------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e3b50515b05</guid>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[kubeadm]]></category>
            <dc:creator><![CDATA[Rubaiyat Rahim]]></dc:creator>
            <pubDate>Wed, 17 Jan 2024 03:51:07 GMT</pubDate>
            <atom:updated>2024-01-21T16:01:17.511Z</atom:updated>
            <content:encoded><![CDATA[<h3>Installing Kubernetes in Ubuntu — Setting It Up</h3><p>This is part two of a two-part series where steps taken while installing Kubernetes in an Ubuntu VM in windows machine will be briefly discussed.</p><h3>Create Installation Scripts</h3><h4>Create Script to Install Docker</h4><ul><li>Create a file named <strong>install_docker.sh</strong> with following content at a convenient location:</li></ul><pre>#!/bin/bash <br><br># --------------------------------------------------<br># Install docker: <br># --------------------------------------------------<br><br># Function to print something<br>print() {<br>  echo<br>  echo &quot;==================================================================&quot;<br>  echo $1<br>  echo &quot;==================================================================&quot;<br>  echo<br>}<br><br><br># --------------------------------------------------<br>print &quot;Uninstalling old docker ...&quot;<br><br># uninastall old docker<br>for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done<br><br># --------------------------------------------------<br>print &quot;Add Docker&#39;&#39;s official GPG key ...&quot;<br><br># install using apt repository<br># Set up Docker&#39;s apt repository.<br># Add Docker&#39;s official GPG key:<br>sudo apt-get update<br>sudo apt-get install ca-certificates curl gnupg<br>sudo install -m 0755 -d /etc/apt/keyrings<br>curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg<br>sudo chmod a+r /etc/apt/keyrings/docker.gpg<br><br># --------------------------------------------------<br>print &quot;Add the repository to Apt sources ...&quot;<br><br># Add the repository to Apt sources:<br>echo \<br>  &quot;deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \<br>  $(. /etc/os-release &amp;&amp; echo &quot;$VERSION_CODENAME&quot;) stable&quot; | \<br>  sudo tee /etc/apt/sources.list.d/docker.list &gt; /dev/null<br>sudo apt-get update<br><br># --------------------------------------------------<br><br>print &quot;Install the Docker packages ...&quot;<br># Install the Docker packages.<br>sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin<br><br># --------------------------------------------------<br><br>print &quot;Verify that the Docker Engine installation is successful ...&quot;<br><br># Verify that the Docker Engine installation is successful by running the hello-world image.<br>sudo docker run hello-world</pre><ul><li>Change the permission of the script file to execute as follows:</li></ul><pre>chmod +x install_docker.sh</pre><h4>Create Common Script to install Kubernetes in Master and Worker</h4><ul><li>Create a file named <strong>install_k8s_common.sh</strong> with following content at a convenient location:</li></ul><pre>#!/bin/bash<br><br># Function to print something<br>print() {<br>  echo<br>  echo &quot;==================================================================&quot;<br>  echo $1<br>  echo &quot;==================================================================&quot;<br>  echo<br>}<br><br># --------------------------------------------------<br><br>print &quot;Update and upgrade ubuntu ...&quot;<br>read -r -s -p $&#39;Press ENTER to continue...\n&#39;<br><br>sudo apt update<br>sudo apt upgrade<br><br># --------------------------------------------------<br><br>print &quot;Disable swap ...&quot;<br>read -r -s -p $&#39;Press ENTER to continue...\n&#39;<br><br>sudo swapoff -a<br>sudo sed -i &#39;/ swap / s/^\(.*\)$/#\1/g&#39; /etc/fstab<br><br># --------------------------------------------------<br><br>print &quot;Check if swap is zero ...&quot;<br># check if swap is zero<br>free -h<br><br># --------------------------------------------------<br><br>print &quot;Add Kernel Parameters ...&quot;<br>read -r -s -p $&#39;Press ENTER to continue...\n&#39;<br><br># Load the required kernel modules on all nodes:<br>sudo tee /etc/modules-load.d/containerd.conf &lt;&lt;EOF<br>overlay<br>br_netfilter<br>EOF<br>sudo modprobe overlay<br>sudo modprobe br_netfilter<br><br># Configure the critical kernel parameters for Kubernetes using the following:<br>sudo tee /etc/sysctl.d/kubernetes.conf &lt;&lt;EOF<br>net.bridge.bridge-nf-call-ip6tables = 1<br>net.bridge.bridge-nf-call-iptables = 1<br>net.ipv4.ip_forward = 1<br>EOF<br><br># Then, reload the changes:<br>sudo sysctl --system<br><br># --------------------------------------------------<br><br>print &quot;Install Containerd Runtime ...&quot;<br>read -r -s -p $&#39;Press ENTER to continue...\n&#39;<br><br># Install containerd and its dependencies with the following commands:<br>sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates<br><br># Enable the Docker repository:<br>sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/docker.gpg<br>sudo add-apt-repository &quot;deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable&quot;<br><br># Update the package list and install containerd:<br>sudo apt update<br>sudo apt install -y containerd.io<br><br># Configure containerd to start using systemd as cgroup:<br>containerd config default | sudo tee /etc/containerd/config.toml &gt;/dev/null 2&gt;&amp;1<br>sudo sed -i &#39;s/SystemdCgroup \= false/SystemdCgroup \= true/g&#39; /etc/containerd/config.toml<br><br># Restart and enable the containerd service:<br>sudo systemctl restart containerd<br>sudo systemctl enable containerd<br><br># --------------------------------------------------<br><br>print &quot;Add Apt Repository for Kubernetes ...&quot;<br>read -r -s -p $&#39;Press ENTER to continue...\n&#39;<br><br>curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/kubernetes-xenial.gpg<br>sudo apt-add-repository &quot;deb http://apt.kubernetes.io/ kubernetes-xenial main&quot;<br><br># --------------------------------------------------<br><br>print &quot;Install Kubectl, Kubeadm, and Kubelet ...&quot;<br>read -r -s -p $&#39;Press ENTER to continue...\n&#39;<br><br>sudo apt update<br>sudo apt install -y kubelet kubeadm kubectl<br>sudo apt-mark hold kubelet kubeadm kubectl<br><br>print &quot;Common script to install Kubernetes completed.&quot;<br>exit</pre><ul><li>Change the permission of the script file to execute as follows:</li></ul><pre>chmod +x install_k8s_common.sh</pre><h4>Create Script to install Kubernetes in Master</h4><ul><li>Create a file named <strong>install_k8s_master.sh</strong> with following content at a convenient location:</li></ul><pre>#!/bin/bash<br><br># Function to print something<br>print() {<br>  echo<br>  echo &quot;==================================================================&quot;<br>  echo $1<br>  echo &quot;==================================================================&quot;<br>  echo<br>}<br><br># --------------------------------------------------<br><br>print &quot;Initialize Kubernetes Cluster with Kubeadm ...&quot;<br>read -r -s -p $&#39;Press ENTER to continue...\n&#39;<br><br>sudo kubeadm init<br>mkdir -p $HOME/.kube<br>sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config<br>sudo chown $(id -u):$(id -g) $HOME/.kube/config<br><br># --------------------------------------------------<br><br>print &quot;Install Kubernetes Network Plugin ...&quot;<br>read -r -s -p $&#39;Press ENTER to continue...\n&#39;<br><br>kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/calico.yaml<br><br># --------------------------------------------------<br><br>print &quot;Verify ...&quot;<br>read -r -s -p $&#39;Press ENTER to continue...\n&#39;<br><br>kubectl get nodes<br>kubectl get pods -n kube-system</pre><ul><li>Change the permission of the script file to execute as follows:</li></ul><pre>chmod +x install_k8s_master.sh</pre><h3>Execute Setup Scripts in Hosts</h3><h4>Setup Master and Worker Nodes</h4><pre># --------------------------------------------------------<br># install docker<br># --------------------------------------------------------<br>./install_docker.sh<br><br># check docker version<br>docker version<br><br># if server version not shown, run the following command and re-login<br>sudo usermod -aG docker $USER<br><br># check docker version again to see if server version is shown.<br># if still not shown, run the following command:<br>sudo setfacl -m user:$USER:rw /var/run/docker.sock<br><br># --------------------------------------------------------<br># install kubernetes<br># --------------------------------------------------------<br>./install_k8s_common.sh</pre><h4>Initialize the Cluster in Master Node</h4><pre># initialize cluster<br>./install_k8s_master.sh<br><br># verify<br>kubectl get nodes<br>kubectl get pods -n kube-system</pre><h3>Add Workers to the Master</h3><pre># --------------------------------------------------------<br># Execute kubeadm join ... command that was recommended<br># in the output of kubeadm init <br># that was run while setting up the master<br># --------------------------------------------------------<br># sudo kubeadm join 192.168.102.16:6443 --token mafqxg.jut5swaq0c37252k --discovery-token-ca-cert-hash sha256:e138a10b695302eca2416b56537fbab871594b7ff85886ac9baf27a4a1d37fc7<br><br># --------------------------------------------------------<br># If the kubeadm join ... command is missing somehow,<br># get the join command to add worker nodes <br># to the cluster by running the following command <br># in the master<br># --------------------------------------------------------<br># kubeadm token create --print-join-command<br><br># --------------------------------------------------------<br># verify the nodes by running following commands <br># in the master node<br># --------------------------------------------------------<br>kubectl get nodes<br>kubectl get pods -n kube-system<br><br># --------------------------------------------------------<br># if join fails, disable firewalls in master and worker<br># --------------------------------------------------------<br># sudo ufw disable<br># sudo ufw status</pre><h4>Reference:</h4><ul><li><a href="https://hbayraktar.medium.com/how-to-install-kubernetes-cluster-on-ubuntu-22-04-step-by-step-guide-7dbf7e8f5f99">How to Install Kubernetes Cluster on Ubuntu 22.04 (Step-by-Step Guide) | by Hakan Bayraktar | Medium</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e3b50515b05" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing Docker in Ubuntu]]></title>
            <link>https://medium.com/@rubaiyat.rahim/installing-docker-in-ubuntu-400968e43bc0?source=rss-86debe563139------2</link>
            <guid isPermaLink="false">https://medium.com/p/400968e43bc0</guid>
            <category><![CDATA[ubuntu-22-04]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Rubaiyat Rahim]]></dc:creator>
            <pubDate>Mon, 01 Jan 2024 16:19:00 GMT</pubDate>
            <atom:updated>2024-01-01T16:19:00.063Z</atom:updated>
            <content:encoded><![CDATA[<p>Step-by-step illustration of installing Docker in Ubuntu 22.04.</p><h3>Uninstall Existing Docker</h3><pre># remove previous installation<br>for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done<br><br># remove docker engine<br>sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras<br><br># remove all images, containers, and volumes<br>sudo rm -rf /var/lib/docker<br>sudo rm -rf /var/lib/containerd</pre><h3>Install Docker Using apt Repository</h3><pre># Set up Docker&#39;s apt repository<br># Add Docker&#39;s official GPG key:<br>sudo apt-get update<br>sudo apt-get install ca-certificates curl gnupg<br>sudo install -m 0755 -d /etc/apt/keyrings<br>curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg<br>sudo chmod a+r /etc/apt/keyrings/docker.gpg<br><br># Add the repository to Apt sources:<br>echo \<br>  &quot;deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \<br>  $(. /etc/os-release &amp;&amp; echo &quot;$VERSION_CODENAME&quot;) stable&quot; | \<br>  sudo tee /etc/apt/sources.list.d/docker.list &gt; /dev/null<br>sudo apt-get update<br><br># install the latest version<br>sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin<br><br># verify<br>sudo docker run hello-world<br><br># check version<br>docker version<br># if server version not shown, run the following command and re-login<br>sudo usermod -aG docker $USER<br># if problem still persists<br>sudo setfacl -m user:$USER:rw /var/run/docker.sock</pre><h4>Reference:</h4><p><a href="https://docs.docker.com/engine/install/ubuntu/#uninstall-docker-engine">Install Docker Engine on Ubuntu | Docker Docs</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=400968e43bc0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing Kubernetes in Ubuntu — Preparing VM]]></title>
            <link>https://medium.com/@rubaiyat.rahim/installing-kubernetes-in-ubuntu-preparing-vm-9a9bcea0981a?source=rss-86debe563139------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a9bcea0981a</guid>
            <category><![CDATA[virtualbox]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Rubaiyat Rahim]]></dc:creator>
            <pubDate>Sun, 17 Dec 2023 16:49:43 GMT</pubDate>
            <atom:updated>2024-01-02T15:36:34.879Z</atom:updated>
            <content:encoded><![CDATA[<h3>Installing Kubernetes in Ubuntu — Preparing VM</h3><p>This is part one of a two-part series where steps taken while installing Kubernetes in an Ubuntu VM in windows machine will be briefly discussed.</p><h3>Virtual Box</h3><p>The virtual machine will be managed by Oracle VM VirtualBox.</p><ul><li>Download VirtualBox from <a href="https://www.virtualbox.org/">Oracle VM VirtualBox</a>.</li><li>Install by executing the downloaded installer.</li><li>Leave all default options as they are.</li></ul><h3>Ubuntu</h3><p>The host operating software will be Ubuntu 22.04.</p><ul><li>Go to website <a href="https://ubuntu.com/">Enterprise Open Source and Linux | Ubuntu</a> to download the image.</li><li>Go to the site menu → Download → Ubuntu Desktop.</li><li>Download Ubuntu 22.04.3 LTS.</li></ul><h3>Preparing VM for Kubernetes Installation</h3><h4>Create VM in VirtualBox</h4><ul><li>Open VirtualBox.</li><li>Click the New icon to create a new Virtual Machine.</li><li>Provide hostname.</li><li>Don’t provide the ISO file just yet.</li><li>Set RAM as 3 GB, CPU 2, and Disk size 50GB.</li><li>From the Settings tab, provide the ISO location in storage.</li><li>Start installation.</li></ul><h4>Post Ubuntu-Installation Tasks</h4><ul><li><strong>Add user to sudoers group.</strong></li></ul><pre># log in as root<br>su root</pre><pre># insert username below root<br>nano /etc/sudoers<br>...<br># User privilege specification<br>root ALL=(ALL:ALL) ALL<br>username  ALL=(ALL:ALL) ALL<br>...</pre><pre># add to the sudoers group<br>usermod -aG sudo username</pre><ul><li><strong>Fix the GUI-not-maximized issue.</strong></li></ul><pre>sudo apt update<br>sudo apt install -y build-essential linux-headers-$(uname -r)<br><br># Go to virtual box -&gt; Devices -&gt; Insert Guest Edition CD Image<br># Double click the cd icon in the side bar. Autorun should run automatically.<br># If not run, open a terminal in the mounted cd location and run ./autorun.sh</pre><ul><li><strong>Install net-tools.</strong></li></ul><pre>sudo apt install net-tools</pre><ul><li><strong>Install curl.</strong></li></ul><pre>sudo apt install curl</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a9bcea0981a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker Kubernetes Service — Storage with Persistent Volume]]></title>
            <link>https://medium.com/@rubaiyat.rahim/docker-kubernetes-service-storage-with-persistent-volume-b7bf5273d239?source=rss-86debe563139------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7bf5273d239</guid>
            <category><![CDATA[recycle-reclaim-policy]]></category>
            <category><![CDATA[delete-reclaim-policy]]></category>
            <category><![CDATA[persistent-volume]]></category>
            <category><![CDATA[retain-reclaim-policy]]></category>
            <category><![CDATA[persistent-volume-claim]]></category>
            <dc:creator><![CDATA[Rubaiyat Rahim]]></dc:creator>
            <pubDate>Thu, 31 Aug 2023 16:40:31 GMT</pubDate>
            <atom:updated>2023-08-31T16:40:31.374Z</atom:updated>
            <content:encoded><![CDATA[<h3>Docker Kubernetes Service — Storage with Persistent Volume</h3><p>Notes taken from A Cloud Guru course titled “Docker Certified Associate (DCA)” by Will Boyd.</p><h3>Persistent Volume</h3><ul><li>Allow to manage storage resources in an abstract fashion.</li><li>Allow to define a set of available storage resources as a Kubernetes object, then later claim those storage resources for usages in pods.</li></ul><h3>Persistent Volume Claim</h3><ul><li>Defines a specific request for storage resources that can be mounted to a pod’s containers.</li><li>Persistent Volume is an abstract storage resource, and a persistent volume claim is an actual instance of usage for that storage resource.</li></ul><h3>Reclaim Policy</h3><ul><li>A Persistent Volume has a reclaim policy.</li><li>Determines what happens when a persistent volume’s associated claims are deleted.</li><li>There are 3 reclaim policies: Retain, Delete, and Recycle.</li></ul><h4><strong>Retain</strong></h4><ul><li>Keeps the volume and its data.</li><li>Allows an administrator to manually reclaim that storage and set up that storage resource to be used again in future.</li><li>Admin is responsible for cleaning up existing data.</li></ul><h4>Delete</h4><ul><li>Deletes both the persistent volume and its underlying storage infrastructure (such as cloud storage object).</li><li>Mainly used on cloud platforms.</li></ul><h4>Recycle</h4><ul><li>Deletes the data contained in the volume and allows it to be used again.</li><li>Unlike retain policy, it does not require an administrator to manually clean up the data.</li></ul><h3>Expanding a PVC</h3><ul><li>A persistent volume claim can be expanded by simply editing the object to have a larger size.</li><li>For this to work, the storage class must support volume expansion.</li><li>In that case, the storage class’s <strong>allowVolumeExpansion</strong> field will be set to true.</li></ul><h3>Working with PVC in UCP</h3><ul><li>Access UCP in a browser at https://&lt;UCP_SERVER_PUBLIC_IP&gt;.</li><li>We can create Kubernetes objects in UCP by navigating to <strong>Kubernetes → + Create</strong>. Make sure to use the <strong>default </strong>namespace.</li><li>Make sure to view the default namespace (<strong>Kubernetes → Namespaces</strong>, then click Set Context next to <strong>default</strong>).</li></ul><h4>Create a StorageClass and PersistentVolume</h4><ul><li>Create a StorageClass that supports volume expansion.</li></ul><pre>apiVersion: storage.k8s.io/v1<br>kind: StorageClass<br>metadata:<br>  name: localdisk<br>provisioner: kubernetes.io/no-provisioner<br>allowVolumeExpansion: true</pre><ul><li>Create a PersistentVolume.</li></ul><pre>kind: PersistentVolume<br>apiVersion: v1<br>metadata:<br>  name: my-pv<br>spec:<br>  storageClassName: localdisk<br>  persistentVolumeReclaimPolicy: Recycle<br>  capacity:<br>    storage: 1Gi<br>  accessModes:<br>    - ReadWriteOnce<br>  hostPath:<br>    path: /tmp/pvoutput</pre><h4>Create a PersistentVolumeClaim</h4><ul><li>Create a PersistentVolumeClaim.</li></ul><pre>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: my-pvc<br>spec:<br>  storageClassName: localdisk<br>  accessModes:<br>    - ReadWriteOnce<br>  resources:<br>    requests:<br>      storage: 100Mi</pre><ul><li>Check the claim’s status to make sure it is Bound to the PersistentVolume.</li></ul><h4>Create the Pod</h4><ul><li>Create a pod that uses the PersistentVolumeClaim and writes some data to it.</li></ul><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: pvc-pod<br>spec:<br>  containers:<br>  - name: busybox<br>    image: busybox<br>    command: [&#39;sh&#39;, &#39;-c&#39;, &#39;while true; do echo &quot;Successfully written to log.&quot; &gt;&gt; /output/output.log; sleep 10; done&#39;<br>    volumeMounts:<br>    - name: pv-storage<br>      mountPath: /output<br>  volumes:<br>  - name: pv-storage<br>    persistentVolumeClaim:<br>      claimName: my-pvc</pre><ul><li>Verify the pod can start up.</li><li>Take note of which node the pod is running on and log in to that node via SSH.</li><li>Check the output data from the pod.</li></ul><pre>ls /tmp/pvoutput<br>cat /tmp/pvoutput/output.log</pre><h4>Recycle the Persistent Storage</h4><ul><li>In the UCP interface, navigate to <strong>Kubernetes → Pods</strong>, and use the three-dot menu for the <strong>pvc-pod</strong> pod to delete the pod.</li></ul><blockquote>Note: <strong>Force Remove</strong> is faster and is okay to use here since we are just testing and do not need the pod to shut down gracefully.</blockquote><ul><li>Navigate to <strong>Kubernetes → Storage</strong>, and use the three-dot menu for the <strong>my-pvc</strong> PersistentVolumeClaim to delete the PersistentVolumeClaim.</li><li>We should see the status for the <strong>my-pv </strong>PersistentVolume return to Available.</li><li>Create a new PersistentVolumeClaim.</li></ul><pre>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: my-new-pvc<br>spec:<br>  storageClassName: localdisk<br>  accessModes:<br>    - ReadWriteOnce<br>  resources:<br>    requests:<br>      storage: 100Mi</pre><ul><li>We should see both the PersistentVolume and PersistentVolumeClaim return their status to Bound.</li></ul><h4>Expand the PersistentVolumeClaim</h4><ul><li>Navigate to <strong>Kubernetes → Storage → my-new-pvc</strong>. Click the gear icon to edit the PersistentVolumeClaim.</li><li>Find the line that says <strong><em>storage: 100Mi</em></strong> and change it to increase the claim size:</li></ul><pre>spec:<br>  ...<br>  resources:<br>    requests:<br>      storage: 200Mi</pre><ul><li>Click Save.</li></ul><h4>Further Reads</h4><ol><li><a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/">Persistent Volumes | Kubernetes</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7bf5273d239" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>