<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jayapriya Pai</title>
    <description>The latest articles on DEV Community by Jayapriya Pai (@slashpai).</description>
    <link>https://dev.to/slashpai</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%2F352120%2F45d11f47-ff13-48b5-9533-bf39c9be365b.png</url>
      <title>DEV Community: Jayapriya Pai</title>
      <link>https://dev.to/slashpai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/slashpai"/>
    <language>en</language>
    <item>
      <title>Rapid Web App Development in Ruby: Introduction</title>
      <dc:creator>Jayapriya Pai</dc:creator>
      <pubDate>Sun, 28 Jun 2020 07:16:15 +0000</pubDate>
      <link>https://dev.to/slashpai/rapid-web-app-development-in-ruby-3ppd</link>
      <guid>https://dev.to/slashpai/rapid-web-app-development-in-ruby-3ppd</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wK69-z4_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8zezxb0ql4fajc06zf3f.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wK69-z4_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8zezxb0ql4fajc06zf3f.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;Photo by &lt;a href="https://unsplash.com/@lincon_street?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Divyadarshi Acharya&lt;/a&gt; on &lt;a href="/s/photos/web-developement?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;In this blog series, I will be covering how to create a web app using ruby with minimal effort. Assuming you have ruby installed let's get started.&lt;/p&gt;

&lt;p&gt;I am going to use &lt;strong&gt;sinatra&lt;/strong&gt; framework here, so first step is to install sinatra gem.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;sinatra&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now create a new folder to store your app files. Since I am going to create a simple search app which has contact information, naming it as contacts. Open this folder in your editor now. I am using visual studio code.&lt;/p&gt;

&lt;p&gt;Create a file named &lt;code&gt;app.rb&lt;/code&gt; with the following contents&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# app.rb&lt;/span&gt;

&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'sinatra'&lt;/span&gt;

&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="s1"&gt;'Welcome to contacts app!'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now from your terminal, run &lt;code&gt;ruby app.rb&lt;/code&gt;, you will see a similar message on your screen now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;slashpai@pai  ~/contacts   ruby app.rb

&lt;span class="o"&gt;[&lt;/span&gt;2020-06-28 12:05:09] INFO  WEBrick 1.4.2
&lt;span class="o"&gt;[&lt;/span&gt;2020-06-28 12:05:09] INFO  ruby 2.6.6 &lt;span class="o"&gt;(&lt;/span&gt;2020-03-31&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;x86_64-linux]
&lt;span class="o"&gt;==&lt;/span&gt; Sinatra &lt;span class="o"&gt;(&lt;/span&gt;v2.0.8.1&lt;span class="o"&gt;)&lt;/span&gt; has taken the stage on 4567 &lt;span class="k"&gt;for &lt;/span&gt;development with backup from WEBrick
&lt;span class="o"&gt;[&lt;/span&gt;2020-06-28 12:05:09] INFO  WEBrick::HTTPServer#start: &lt;span class="nv"&gt;pid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;21875 &lt;span class="nv"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;4567

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

&lt;/div&gt;



&lt;p&gt;From your browser, go to &lt;a href="http://localhost:4567"&gt;localhost:4567&lt;/a&gt;, you should see the content on web page as &lt;em&gt;Welcome to contacts app!&lt;/em&gt;. That was easy right?&lt;/p&gt;

&lt;p&gt;Now let's understand how it worked. When you typed &lt;a href="http://localhost:4567"&gt;localhost:4567&lt;/a&gt; in your browser, it checked in &lt;code&gt;app.rb&lt;/code&gt; file if route for this url is defined, since this is root of website, it will look for route with &lt;code&gt;/&lt;/code&gt;. And that's what we have defined with &lt;code&gt;get&lt;/code&gt; method in app.rb file.&lt;/p&gt;

&lt;p&gt;In Sinatra, a route is an HTTP method paired with a URL pattern. Each route is associated with a block. Routes will be evaluated in the same order as they are defined. The first route that matched will be invoked.&lt;/p&gt;

&lt;p&gt;Now let's add more routes in &lt;code&gt;app.rb&lt;/code&gt; file and restart  app using &lt;code&gt;ruby app.rb&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# app.rb&lt;/span&gt;

&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'sinatra'&lt;/span&gt;

&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="s1"&gt;'Welcome to contacts app!'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/home'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="s1"&gt;'Home page'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/contacts'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="s1"&gt;'This page is under construction'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now visit &lt;a href="http://localhost:4567/home"&gt;home&lt;/a&gt; and &lt;a href="http://localhost:4567/contacts"&gt;contacts&lt;/a&gt; pages. You should see same messages as defined in routes.&lt;/p&gt;

&lt;p&gt;You might have noticed, you need to restart &lt;code&gt;app.rb&lt;/code&gt; everytime you make a change. How we can simplify this?&lt;/p&gt;

&lt;p&gt;We will use the gem 'sinatra-contrib' for this. Go ahead and install this gem now&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;gem&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;sinatra&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;contrib&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now in your &lt;code&gt;app.rb&lt;/code&gt; file, require the following library which comes as part of &lt;code&gt;sinatra-contrib&lt;/code&gt; gem&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'sinatra/reloader'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run your app now &lt;code&gt;ruby app.rb&lt;/code&gt;. While the app is running make any changes to the route messages to verify auto reload is working. The site will display updated content without needing the app restart.&lt;/p&gt;

&lt;p&gt;The complete app.rb file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# app.rb&lt;/span&gt;

&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'sinatra'&lt;/span&gt;
&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'sinatra/reloader'&lt;/span&gt;

&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="s1"&gt;'Welcome to contacts app!'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/home'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="s1"&gt;'Home page'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/contacts'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="s1"&gt;'This page is under construction'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Hope that was helpful, we will see more on Sinatra web development in next post!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Quickly creating kubernetes manifest files using kubectl</title>
      <dc:creator>Jayapriya Pai</dc:creator>
      <pubDate>Mon, 13 Apr 2020 16:52:32 +0000</pubDate>
      <link>https://dev.to/slashpai/quickly-creating-kubernetes-manifest-files-using-kubectl-2khj</link>
      <guid>https://dev.to/slashpai/quickly-creating-kubernetes-manifest-files-using-kubectl-2khj</guid>
      <description>&lt;p&gt;When someone is just starting with kubernetes, writing manifest files can be a bit difficult. In this post I will try to give some tips in writing manifest files easily.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pods
&lt;/h2&gt;

&lt;p&gt;Use the &lt;a href="https://kubernetes.io/docs/reference/kubectl/conventions/#generators"&gt;generator&lt;/a&gt; to create pods. Verify if the given entries are syntactically correct by doing a dry run.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl run &lt;span class="nt"&gt;--generator&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;run-pod/v1 &amp;lt;pod name&amp;gt; &lt;span class="nt"&gt;--image&lt;/span&gt; &amp;lt;image to use&amp;gt; &lt;span class="nt"&gt;--dry-run&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the pod definition to a yaml file for future changes as well as reference&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl run &lt;span class="nt"&gt;--generator&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;run-pod/v1 &amp;lt;pod name&amp;gt; &lt;span class="nt"&gt;--image&lt;/span&gt; &amp;lt;image to use&amp;gt; &lt;span class="nt"&gt;--dry-run&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; yaml &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; pod.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;slashpai@pai  ~  &lt;span class="o"&gt;(&lt;/span&gt;⎈ |kind-pai:default&lt;span class="o"&gt;)&lt;/span&gt; kubectl run &lt;span class="nt"&gt;--generator&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;run-pod/v1 nginx-pod &lt;span class="nt"&gt;--image&lt;/span&gt; nginx &lt;span class="nt"&gt;--dry-run&lt;/span&gt;        
pod/nginx-pod created &lt;span class="o"&gt;(&lt;/span&gt;dry run&lt;span class="o"&gt;)&lt;/span&gt;
slashpai@pai  ~  &lt;span class="o"&gt;(&lt;/span&gt;⎈ |kind-pai:default&lt;span class="o"&gt;)&lt;/span&gt; kubectl run &lt;span class="nt"&gt;--generator&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;run-pod/v1 nginx-pod &lt;span class="nt"&gt;--image&lt;/span&gt; nginx &lt;span class="nt"&gt;--dry-run&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; yaml &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; pod.yaml
slashpai@pai  ~  &lt;span class="o"&gt;(&lt;/span&gt;⎈ |kind-pai:default&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;cat &lt;/span&gt;pod.yaml 
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx-pod
  name: nginx-pod
spec:
  containers:
  - image: nginx
    name: nginx-pod
    resources: &lt;span class="o"&gt;{}&lt;/span&gt;
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: &lt;span class="o"&gt;{}&lt;/span&gt;
slashpai@pai  ~  &lt;span class="o"&gt;(&lt;/span&gt;⎈ |kind-pai:default&lt;span class="o"&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deployment
&lt;/h2&gt;

&lt;p&gt;Generator for deployment is deprecated so following way helps. Verify if given entries are syntactically correct by doing a dry run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl create deployment &amp;lt;deployment name&amp;gt; &lt;span class="nt"&gt;--image&lt;/span&gt; &amp;lt;image to use&amp;gt; &lt;span class="nt"&gt;--dry-run&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the deployment definition to a yaml file for future changes as well as reference&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl create deployment &amp;lt;deployment name&amp;gt; &lt;span class="nt"&gt;--image&lt;/span&gt; &amp;lt;image to use&amp;gt; &lt;span class="nt"&gt;--dry-run&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; yaml &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; deployment.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;slashpai@pai  ~  &lt;span class="o"&gt;(&lt;/span&gt;⎈ |kind-pai:default&lt;span class="o"&gt;)&lt;/span&gt; kubectl create deployment nginx-deployment &lt;span class="nt"&gt;--image&lt;/span&gt; nginx &lt;span class="nt"&gt;--dry-run&lt;/span&gt;
deployment.apps/nginx-deployment created &lt;span class="o"&gt;(&lt;/span&gt;dry run&lt;span class="o"&gt;)&lt;/span&gt;
slashpai@pai  ~  &lt;span class="o"&gt;(&lt;/span&gt;⎈ |kind-pai:default&lt;span class="o"&gt;)&lt;/span&gt; kubectl create deployment nginx-deployment &lt;span class="nt"&gt;--image&lt;/span&gt; nginx &lt;span class="nt"&gt;--dry-run&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; yaml &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; deployment.yaml
slashpai@pai  ~  &lt;span class="o"&gt;(&lt;/span&gt;⎈ |kind-pai:default&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;cat &lt;/span&gt;deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx-deployment
  name: nginx-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-deployment
  strategy: &lt;span class="o"&gt;{}&lt;/span&gt;
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx-deployment
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: &lt;span class="o"&gt;{}&lt;/span&gt;
status: &lt;span class="o"&gt;{}&lt;/span&gt;
slashpai@pai  ~  &lt;span class="o"&gt;(&lt;/span&gt;⎈ |kind-pai:default&lt;span class="o"&gt;)&lt;/span&gt; 

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  ReplicaSet
&lt;/h2&gt;

&lt;p&gt;There is no direct way I could find to create this from kubectl. I found this trick though till I could find a better way. Use the same way to create deployment and modify &lt;code&gt;kind&lt;/code&gt; to ReplicaSet in the yaml file and remove fields specific to deployment. I found this with trial and error, so this is the diff file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;slashpai@pai  ~  &lt;span class="o"&gt;(&lt;/span&gt;⎈ |kind-pai:default&lt;span class="o"&gt;)&lt;/span&gt; diff deployment.yaml replicaset.yaml 
2c2
&amp;lt; kind: Deployment
&lt;span class="nt"&gt;---&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; kind: ReplicaSet
13d12
&amp;lt;   strategy: &lt;span class="o"&gt;{}&lt;/span&gt;
24c23
&amp;lt; status: &lt;span class="o"&gt;{}&lt;/span&gt;
&lt;span class="nt"&gt;---&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I removed the fields strategy as well as status from replicaset.yaml. While creating ReplicaSet file this way, give the deployment name suffix like replicaset instead of deployment. I haven't done that in this example since I wanted to show what fields I exactly need to change.&lt;/p&gt;

&lt;h2&gt;
  
  
  ConfigMap
&lt;/h2&gt;

&lt;p&gt;Even if there are more than one entry to be added in a config map, just add one and then add rest in manifest file directly so you can save time in adding one by one in command line. Verify first syntax wise correct using dry-run.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl create configmap &amp;lt;config map name&amp;gt; &lt;span class="nt"&gt;--from-literal&lt;/span&gt; &lt;span class="nv"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;value &lt;span class="nt"&gt;--dry-run&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the deployment definition to a yaml file for future changes as well as reference&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create configmap &amp;lt;config map name&amp;gt; --from-literal key=value --dry-run -o yaml &amp;gt; configmap.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;slashpai@pai  ~  &lt;span class="o"&gt;(&lt;/span&gt;⎈ |kind-pai:default&lt;span class="o"&gt;)&lt;/span&gt; kubectl create configmap mongo-config &lt;span class="nt"&gt;--from-literal&lt;/span&gt; &lt;span class="nv"&gt;user_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mongo &lt;span class="nt"&gt;--dry-run&lt;/span&gt;
configmap/mongo created &lt;span class="o"&gt;(&lt;/span&gt;dry run&lt;span class="o"&gt;)&lt;/span&gt;
slashpai@pai  ~  &lt;span class="o"&gt;(&lt;/span&gt;⎈ |kind-pai:default&lt;span class="o"&gt;)&lt;/span&gt; kubectl create configmap mongo-config &lt;span class="nt"&gt;--from-literal&lt;/span&gt; &lt;span class="nv"&gt;user_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mongo &lt;span class="nt"&gt;--dry-run&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; yaml &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; configmap.yaml
slashpai@pai  ~  &lt;span class="o"&gt;(&lt;/span&gt;⎈ |kind-pai:default&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;cat &lt;/span&gt;configmap.yaml 
apiVersion: v1
data:
  user_id: mongo
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: mongo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may want to move the data section below metadata since that's where we place this normally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding more entries in manifest file
&lt;/h2&gt;

&lt;p&gt;Now you must have got an idea how to create manifest files for most used kubernetes objects. You can tweak like this for other objects not mentioned. The fields in manifest file created this way is not enough, if you have specific needs or need to add more fields.&lt;/p&gt;

&lt;p&gt;Let's see how we can add more fields in a pod definition file. For example, you want to inject an environment variable into a container from a ConfigMap. Since we know container related info is inside spec section of the pod, we can use &lt;code&gt;kubectl explain pod.spec.containers&lt;/code&gt; to get the exact field. See how this is done below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;slashpai@pai  ~  &lt;span class="o"&gt;(&lt;/span&gt;⎈ |kind-pai:default&lt;span class="o"&gt;)&lt;/span&gt; kubectl explain pod.spec.containers|grep &lt;span class="nb"&gt;env
     &lt;/span&gt;container&lt;span class="s1"&gt;'s environment. If a variable cannot be resolved, the reference in
     are expanded using the container'&lt;/span&gt;s environment. If a variable cannot be
   &lt;span class="nb"&gt;env&lt;/span&gt;  &amp;lt;&lt;span class="o"&gt;[]&lt;/span&gt;Object&amp;gt;
     List of environment variables to &lt;span class="nb"&gt;set &lt;/span&gt;&lt;span class="k"&gt;in &lt;/span&gt;the container. Cannot be updated.
   envFrom  &amp;lt;&lt;span class="o"&gt;[]&lt;/span&gt;Object&amp;gt;
     List of sources to populate environment variables &lt;span class="k"&gt;in &lt;/span&gt;the container. The
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I grepped for env, since I know field starts with env. If you don't know the field, you would need to scroll down the explain output and figure this out.&lt;/p&gt;

&lt;p&gt;From this I got to know it's the  &lt;code&gt;envFrom&lt;/code&gt; field that we need to use configmap and it's a list type (important to note the type). We can check the fields that comes under &lt;code&gt;envFrom&lt;/code&gt; similar way like above. But if we are only interested to know the fields without it's description, just add the &lt;code&gt;recursive&lt;/code&gt; flag&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;slashpai@pai  ~  &lt;span class="o"&gt;(&lt;/span&gt;⎈ |kind-pai:default&lt;span class="o"&gt;)&lt;/span&gt; kubectl explain pod.spec.containers.envFrom &lt;span class="nt"&gt;--recursive&lt;/span&gt;
KIND:     Pod
VERSION:  v1

RESOURCE: envFrom &amp;lt;&lt;span class="o"&gt;[]&lt;/span&gt;Object&amp;gt;

DESCRIPTION:
     List of sources to populate environment variables &lt;span class="k"&gt;in &lt;/span&gt;the container. The
     keys defined within a &lt;span class="nb"&gt;source &lt;/span&gt;must be a C_IDENTIFIER. All invalid keys will
     be reported as an event when the container is starting. When a key exists
     &lt;span class="k"&gt;in &lt;/span&gt;multiple sources, the value associated with the last &lt;span class="nb"&gt;source &lt;/span&gt;will take
     precedence. Values defined by an Env with a duplicate key will take
     precedence. Cannot be updated.

     EnvFromSource represents the &lt;span class="nb"&gt;source &lt;/span&gt;of a &lt;span class="nb"&gt;set &lt;/span&gt;of ConfigMaps

FIELDS:
   configMapRef &amp;lt;Object&amp;gt;
      name  &amp;lt;string&amp;gt;
      optional  &amp;lt;boolean&amp;gt;
   prefix   &amp;lt;string&amp;gt;
   secretRef    &amp;lt;Object&amp;gt;
      name  &amp;lt;string&amp;gt;
      optional  &amp;lt;boolean&amp;gt;
slashpai@pai  ~  &lt;span class="o"&gt;(&lt;/span&gt;⎈ |kind-pai:default&lt;span class="o"&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That drilled down the config to use as given below in the spec section of pod. Note the type for &lt;code&gt;envFrom&lt;/code&gt;, which we had figured out to be of list type.&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;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;mongo&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;mongo&lt;/span&gt;
    &lt;span class="na"&gt;envFrom&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;configMapRef&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;mongo-config&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Surely you can go to kubernetes documentation and get this info. But I found this is more easier since I don't like leaving my terminal so often.&lt;/p&gt;

&lt;p&gt;I hope this helps you create the manifest files with ease now. Thank you for reading this post.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
