<?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 Vivek Singh on Medium]]></title>
        <description><![CDATA[Stories by Vivek Singh on Medium]]></description>
        <link>https://medium.com/@viveksinghggits?source=rss-8ef54e761cc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*DS6_SLpczVMd3yvT5-S6_w.png</url>
            <title>Stories by Vivek Singh on Medium</title>
            <link>https://medium.com/@viveksinghggits?source=rss-8ef54e761cc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 21:03:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@viveksinghggits/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[I created a YouTube channel]]></title>
            <link>https://medium.com/@viveksinghggits/i-created-a-youtube-channel-7e7e1408634b?source=rss-8ef54e761cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e7e1408634b</guid>
            <dc:creator><![CDATA[Vivek Singh]]></dc:creator>
            <pubDate>Sun, 13 Sep 2020 15:31:46 GMT</pubDate>
            <atom:updated>2020-09-13T15:31:46.911Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*URDqYzoASSryaRtHR9PKrQ.png" /></figure><p>Hey Everyone,</p><p>Probably you know me from my previous posts that I am a software developer working around cloud Native technologies like Kubernetes using Go as a programming language.</p><p>While, sharing what I have learned at my work or otherwise, using blog posts was a great idea, I created YouTube channel to share what I have been learning at work or by creating some other Side Projects.</p><p>I would usually be talking about Containers, Kubernetes, Go or Software Engineering in general in this channel. Here is the link to YouTube channel if you want to check that out</p><p><a href="https://www.youtube.com/channel/UCFrZ2AgmUq3AINd7VlTLOBw">Vivek Singh</a></p><p>Please check it out and let me know if you have any feedback suggestion.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e7e1408634b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Securing k8s application using ingress rule/nginx ingress controller]]></title>
            <link>https://faun.pub/securing-k8s-application-using-ingress-rule-nginx-ingress-controller-a819b0e11281?source=rss-8ef54e761cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/a819b0e11281</guid>
            <category><![CDATA[http-basic-authentication]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Vivek Singh]]></dc:creator>
            <pubDate>Sun, 24 Nov 2019 07:43:20 GMT</pubDate>
            <atom:updated>2019-11-25T12:05:29.845Z</atom:updated>
            <content:encoded><![CDATA[<h3>Securing your k8s application using Ingress resource</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H-qXwE0t0SUNaCZ1" /><figcaption>Photo by <a href="https://unsplash.com/@scottwebb?utm_source=medium&amp;utm_medium=referral">Scott Webb</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this blog post we are going to look into how we can secure a Kubernetes application at the ingress level. I am saying ingress level because there are other ways to secure your application which we can talk in other blog post maybe.</p><p>But before diving into that let’s take a step back and look into how we actually expose our Kubernetes application to the outer world.</p><p>I have discussed this briefly in one of my other blog post as well.</p><p><a href="https://medium.com/faun/hello-world-of-kubernetes-part-1-d1153fc2fc37">Hello World!!! of Kubernetes [Part 1]</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/223/1*_ghJ2Eq-Fl46aQT2EcxTow.png" /></figure><p>As you can see in the diagram to expose the Deployment (application), which eventually is managing a set of pods using ReplicaSets, ideally we create a Service and then that service will be exposed to the outer world using Kubernetes Ingress resources.</p><p>While creating Service you can argue that which kind (type) of service you should go with, we will not discuss that in detail in this post but in very simple words if the the service that exposes your application is being accessed by other application in the same cluster, you should go with ClusterIP type of service or you can look up to the NodePort and LoadBalancer types.</p><h3>Kubernetes Ingress resource</h3><p>I have already talked about Kubernetes Ingress resource in my previously mentioned post but to summarise that, Ingress is like any other Kubernetes resource that is used to expose your application to outside world. There are other ways to expose your application to the outside world like creating Service of type NodePort or if you are on a cloud provider, using LoadBalancer.</p><p>But using Ingress to expose your application to outside words has several benefits over the other option of creating service. For example in Service you can not have resource path or host based routing.</p><p>To get the Ingress resource working we also need an ingress controller, otherwise the Ingress resource that you create will silently fail and have no effect. Deploying the ingress controller totally depends on how you have setup your Kubernetes cluster, since I am running minikube cluster, I will be using nginx ingress controller and I can enable that just by running command</p><pre>minikube addons enable ingress</pre><p>You can follow <a href="https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/">this link</a> to get to know about the options that we have for ingress controllers.</p><p>What we are going to do now is run an Elasticsearch in out Kubernetes cluster, access it without security and then secure it using basic authentication. This blog post is highly inspired by the post that is there in nginx’ <a href="https://kubernetes.github.io/ingress-nginx/examples/auth/basic/">examples</a> page.</p><p>Run an Elasticsearch instance using below command</p><pre># we are going to use imperative ways of creating some of the <br># resources, these resource can very well be created using manifests<br># as well.</pre><pre># this is not how you are going to run Elasticsearch on production <br># envs, but we are not focusing on that as of now.</pre><pre>kubectl run elasticsearch --image elastic/elasticsearch:6.6.2</pre><p>this command creates a deployment named elasticsearch in our cluster that eventually runs an Elasticsearch instance. To access the this cluster from outside as shown in the previous diagram we will have to create a service and then an ingress.</p><p>Create the service to expose the deployment (elasticsearch) that we have created earlier</p><pre>~ kubectl get deployments.apps <br>NAME            READY   UP-TO-DATE   AVAILABLE   AGE<br>elasticsearch   1/1     1            1           44m</pre><pre>~ kubectl get service<br>NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE<br>kubernetes   ClusterIP   10.96.0.1    &lt;none&gt;        443/TCP   4d9h</pre><pre>~ kubectl expose deployment elasticsearch --type ClusterIP --port 9200<br>service/elasticsearch exposed</pre><pre>~ kubectl get service<br>NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE<br>elasticsearch   ClusterIP   10.104.116.45   &lt;none&gt;        9200/TCP   11m<br>kubernetes      ClusterIP   10.96.0.1       &lt;none&gt;        443/TCP    4d9h</pre><p>As you can see we have created the deployment that runs Elasticsearch instance and a Service to expose that deployment, now lets go ahead and try to create the ingress that will expose this Service (elasticsearch), that we have created, to the outside world.</p><pre>apiVersion: networking.k8s.io/v1beta1<br>kind: Ingress<br>metadata:<br>  # name of this ingress rule<br>  name: es-ingress<br>spec:<br>  rules:<br>  # specify the protocal, this rule should be applied for<br>  - http:<br>      paths:<br>      # specify the resource path to which this rule should be applied<br>      - path: /<br>        # specify the service, the request should be forwarded to <br>        backend: <br>          serviceName: elasticsearch<br>          servicePort: 9200</pre><p>Create the ingress by saving the above manifest to a file let’s say ingress.yaml and then running</p><pre>kubectl create -f ingress.yaml</pre><p>Once we have created the running kubectl get ingress command should return below</p><pre>~ kubectl get ingresses.<br>NAME         HOSTS   ADDRESS   PORTS   AGE<br>es-ingress   *                 80      7s</pre><p>Now, if you go back to the diagram that I showed earlier, we have created all the components that are required to access our application from outside. Now lets just go ahead and try to access our application by accessing the minikube ip, you can get the that using the command minikube ip.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*NiH1wE8JB-B1LMQIbxYGnw.png" /><figcaption>accessing ES instance using minikube ip</figcaption></figure><p>And you can see that we are successfully able to access the Elasticsearch instance.</p><p>Now there is an important thing to understand here, and that is the URI that we are using to access that Elasticsearch instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*5E4PZwzlK7_kAAvAR32weg.png" /><figcaption>ingress port</figcaption></figure><p>If you just get the details of the ingress that we have just created, you will easily get to know that the ingress is listening on the port 80 and that’s why we are not providing any port while accessing Elasticsearch here because HTTP default port is 80 . Now we know that Elasticsearch ideally serves on port 9200, that simply means traffic is somehow being redirected on 9200 of the pod that has been created.</p><p>To understand that lets describe the ingress resource</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*xqjmrlwxgECKd0HXB_LsfA.png" /><figcaption>we can easily see that this ingress will redirect all the traffic to the service elasticsearch on port 9200</figcaption></figure><p>here you can see, under Rules and Backends, that the ingress will redirect all the traffic that comes at the resource path / to the service names elasticsearch on port 9200 and we know that, that service (elasticsearch) is going to redirect the traffic to correct port of the pod because we got that service by exposing the deployment.</p><p>Now that we have the our application accessible from outside of cluster, lets try to secure it.</p><h3>Securing the application</h3><p>Securing the Elasticsearch application that we just deployed has three main and simple parts.</p><h4>Create credentials file</h4><p>To create a credentials file that will store your username and password run below command</p><pre>user@anakata ~ htpasswd -c auth &lt;username&gt;<br>New password: <br>Re-type new password: <br>Adding password for user &lt;username&gt;</pre><p>After this command you will have file named auth in you current directory. The credentials that you entered here will be used to login to your application when asked for username and password.</p><h4>Create the secret resource using credentials file</h4><p>Now we will have to create secret that will be referred in our ingress resource to secure our application. use below command to create the secret</p><pre># kubectl create secret generic &lt;secret-name&gt; --from-file &lt;file-name&gt;<br>kubectl create secret generic basic-auth --from-file auth <br>secret/basic-auth created</pre><p>To get to know more about secrets you can refer to below blog post</p><p><a href="https://medium.com/faun/hello-world-of-kubernetes-part-3-5076682add36">Hello World!!! of Kubernetes [Part 3]</a></p><p>Once we have the secret created lets go ahead and change the ingress resource in such a way that it will now ask for username and password if someone tries to access the ingress at resource path / .</p><h4>Change ingress rule to secure the service using the secret</h4><p>Change the ingress manifest that we had earlier to the manifest below, we are just introducing the <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/">annotations</a> to the Ingress resource.</p><pre>apiVersion: networking.k8s.io/v1beta1<br>kind: Ingress<br>metadata:<br>  # name of this ingress rule<br>  name: es-ingress<br>  annotations:<br>    # type of authentiation <br>    nginx.ingress.kubernetes.io/auth-type: basic<br>    # secret reference that contins the credential detals<br>    nginx.ingress.kubernetes.io/auth-secret: basic-auth<br>spec:<br>  rules:<br>  # specify the protocal, this rule should be applied for<br>  - http:<br>      paths:<br>      # specify the resource path to which this rule should be applied<br>      - path: /<br>        # specify the service, the request should be forwarded to <br>        backend: <br>          serviceName: elasticsearch<br>          servicePort: 9200</pre><p>save this manifest with whatever name you like (es-ingress.yaml) and then create it using kubectl create -f es-ingress.yaml command. Please make sure to delete the previously created ingress using kubectl delete ingress es-ingress.</p><p>Once you have created the new ingress, lets try to access the same URL, and see what happens</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*pQNuasJq44lmun4k5EQ4Hg.png" /><figcaption>secured ES instance</figcaption></figure><p>and here we go, we are asked for the username and password and if we provide the same username and password that we created the auth file with, we will successfully be able to access the Elasticsearch application.</p><p>Now that we have secured our application successfully, we should take a deeper look into the ingress yaml file that we had to create the ingress resource.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*JLaCzzCgUYnhS1aucBkUkw.png" /></figure><p>In the line number 8 and 10 we are telling ingress to use the basic authentication and the secret name respectively. The line I would like to talk about is 17, the value of path is / and that simply means that this authentication will be applied to all other sub resource, for example if you are running another service (serviceone) and access serviceone by minikubeip/serviceone , you will be asked for the credentials which is not the requirement. Because you dont want that service (serviceone) to be secured through basic authentication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*ft817HdUtu8KxPRPfWOFrA.png" /><figcaption>accessing serviceone also asks for credentials which is not expected</figcaption></figure><p>To resolve that what we can do is configure Elasticsearch to be accessed on another resource path let’s say /secured-es, and then we will configure ingress in such a way that it will only secure the requests that are coming at resource path /secured-es.</p><p>To do that just change the path in line number 17 to /secured-es from / and then try to access the the endpoint minikubeip/secured-es</p><p>You will still get the prompt for username and password, please enter the password and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*LcN-Pdy62uV-KvL2XhZE5A.png" /></figure><p>whoa, it seems things are breaking now. It seems that we are able to talk to the Elasticsearch cluster but we are not querying the root (/) resource path which is what we are supposed to do. It seems that now we are querying the resource path /secured-es in Elasticsearch instance and it returns this error.</p><blockquote>The reason is by default the requests will be forwarded to same resource path that is mentioned in your ingress file, but what if your application is listening at root resource path (/)or somewhere else. If we have mentioned a resource path in the ingress where our application is not listening we will have to rewrite the target to the resource path where our application is listening. For example in ingress manifest we are providing the path /secured-es but our application (Elasticsearch) is listening at / so will have to rewrite the target to /.</blockquote><p>We can easily do that by adding another annotation nginx.ingress.kubernetes.io/rewrite-target with the value of resource path (/) where your application is listening, in the ingress manifest and this will enable us to only secure the resource path /secured-es where our Elasticsearch application is deployed and other resource paths will be accessible without any issues.</p><p>The final ingress resource would be, as you see we have added line 11 to rewrite the target to /</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*NTl4L0q6bw-8wgbNDm0t4g.png" /><figcaption><a href="https://gist.github.com/viveksinghggits/ef6a2abd2002b863400b2f7d7fae7c93">https://gist.github.com/viveksinghggits/ef6a2abd2002b863400b2f7d7fae7c93</a></figcaption></figure><p>Now accessing resource path /secured-es will ask for username and password</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*6MmJ0A_vAhqqzH38xq_Qow.png" /></figure><p>But other endpoints will not be secured, as required</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*HDwN7Hl4u0zVcPWu6nIOHw.png" /><figcaption>we are getting 404 here because we dont have any application for resource path /serviceone</figcaption></figure><p>The things that we discussed at the very last can be a but confusing please let me know your questions either here or ping me on <a href="https://twitter.com/viveksinghggits">twitter</a>, I would be more than happy to help.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*q8snkG3cBIz21Dkw" /></figure><p><strong>Follow us on </strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong> and </strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong> and join our </strong><a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook Group</strong></a>💬<strong>.</strong></p><p><strong>To join our community Slack </strong>🗣️ <strong>and read our weekly Faun topics </strong>🗞️,<strong>click here⬇</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/30/0*9oUI61xFXneOLtU0" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Tptt7fOzRsGnI1YN" /></figure><h3>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a819b0e11281" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/securing-k8s-application-using-ingress-rule-nginx-ingress-controller-a819b0e11281">Securing k8s application using ingress rule/nginx ingress controller</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing apps for Elasticsearch, here are some things you should take care of.]]></title>
            <link>https://medium.com/analytics-vidhya/writing-apps-for-elasticsearch-here-are-some-things-you-should-take-care-of-828135c2995b?source=rss-8ef54e761cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/828135c2995b</guid>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Vivek Singh]]></dc:creator>
            <pubDate>Sun, 10 Nov 2019 06:44:21 GMT</pubDate>
            <atom:updated>2019-11-20T03:31:02.917Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*MqpRoHQPr6czzcIzU-baEg.png" /><figcaption>image courtesy <a href="http://www.percona.com/">percona.com</a></figcaption></figure><p>I have been writing an application in Python recently that communicates to an Elasticsearch cluster to read/write the data (document) from/to it. Let’s take an example of below code that communicates to the our Elasticsearch cluster.</p><pre>from elasticsearch import Elasticsearch</pre><pre><br>def add_document(i_index, i_doc_type, i_id, i_body):<br>    es = es_connect()<br>    try:<br>        res=es.index(index=i_index, doc_type=i_doc_type, id=i_id, body=i_body)<br>        count_success=res.get(&quot;_shards&quot;,{}).get(&quot;successful&quot;)<br>        return count_success<br>    except Exception as ex:<br>        raise Exception(ex)</pre><pre>def es_connect():<br>    try:<br>        es = Elasticsearch(hosts=[{&quot;host&quot;: es_host, &quot;port&quot;: es_port}])<br>        return es<br>    except Exception as ex: <br>        raise Exception(&quot;Failed connecting to Elasticsearch&quot;)</pre><p>You might have figured out that add_document can be called to add a document to a specified Elasticsearch index and doctype, which eventually calls es_connect to get the connection to the Elasticsearch cluster using the host: es_host and port: es_port.</p><pre>def get_document(i_index, i_doc_type, i_id):<br>    es = es_connect()<br>    try:<br>        res=es.get(index=i_index, doc_type=i_doc_type, id=i_id)<br>        return res <br>    except Exception as ex: <br>        raise Exception(&quot;Document ID not found&quot;)will be setup Thu</pre><p>Now lets assume your application has two components/services componentA and componentB. componentA adds a document to the Elasticsearch cluster and componentB tries to fetch the same document, updates it and then adds it back to the Elasticsearch cluster.</p><p>The issue that I faced in this scenario was, sometimes when componentB tried to fetch the ES document, the operation failed with Document not found, even though the componentA wrote the document and we tried to get the document with same document id. Now if we see the official elastic search documentation</p><blockquote>By default, Elasticsearch periodically refreshes indices every second, but only on indices that have received one search request or more in the last 30 seconds.</blockquote><p>So, if the time difference between execution of componentA and componentB is less than 1 second the document that was written by componentA might not be available across all the nodes for search. In other words we can say that the document that the componentA wrote was not available for search immediately after it was written. To resolve this we will look into a parameter named refresh.</p><h3>refresh</h3><p>We can either set the value of refresh at the index level, change the setting of the index or you can provide the refresh setting while storing the document using .index function/API. You can checkout this <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html">doc</a> on how to set the index setting.</p><p>For the other option below is how you can change the code that calls the .index function</p><pre>def add_document(i_index, i_doc_type, i_id, i_body):<br>    es = es_connect()<br>    try:<br>        res=es.index(index=i_index, doc_type=i_doc_type, id=i_id, body=i_body, refresh=&#39;true&#39;)<br>        count_success=res.get(&quot;_shards&quot;,{}).get(&quot;successful&quot;)<br>        return count_success<br>    except Exception as ex: <br>        raise Exception(ex)</pre><p>If you noticed we have introduced refresh=’true’ and now the document that will be added to the Elasticsearch cluster, using add_document function, will be available for search immediately after it is added to the cluster.</p><p>There are some consequences of using refresh=’true’ on the performance part, so please make sure you are using this only when you are going to have functional issues in you application due to unavailability of the document immediately after it is added. More about this can be read at <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-refresh.html">this link</a>.</p><h3>VersionConflictEngineException</h3><p>VersionConflictEngineException is usually experienced when we are trying to update a document of the Elasticsearch index and as the name suggests there are some issue with the version.</p><p>For every Elasticsearch document, it maintains a version of that document. For example if we just create an index and try to put a document in that index</p><pre>POST /index_name/_doc<br>{<br>    &quot;user&quot; : &quot;Vivek&quot;,<br>    &quot;post_date&quot; : &quot;2009-11-15T14:12:12&quot;,<br>    &quot;message&quot; : &quot;trying out Elasticsearch&quot;<br>}</pre><pre>#returns<br>{<br>    &quot;_index&quot;: &quot;index_name&quot;,<br>    &quot;_type&quot;: &quot;_doc&quot;,<br>    &quot;_id&quot;: &quot;7kRpUW4BJVpxMvy30qnq&quot;,<br>    &quot;_version&quot;: 1,<br>    &quot;result&quot;: &quot;created&quot;,<br>    &quot;_shards&quot;: {<br>        &quot;total&quot;: 2,<br>        &quot;successful&quot;: 1,<br>        &quot;failed&quot;: 0<br>    },<br>    &quot;_seq_no&quot;: 0,<br>    &quot;_primary_term&quot;: 1<br>}</pre><p>You can clearly see that the document was created and the version of the created document is “_version”:1. Now Lets say we are trying to update this document from our python code and definition of update_document is somewhat like below</p><pre>def update_document(i_index, i_doc_type, i_id, i_body):<br>        es= es_connect()<br>        try:<br>                result =  es.update(index=i_index, doc_type=i_doc_type, id=i_id, body=i_body)<br>                return result<br>        except Exception as e:<br>                print(&quot;There was an exception updating the document&quot;, e)</pre><p>Now consider this scenario, before updating the document we are getting the Elasticsearch document (with version 1) and then trying to update it with some modified data. But between us getting the data from Elasticsearch and updating it, some other program or process changed that same document, eventually changing the version (making is version 2) of that document. Now if our program tries to update the same document it will see that when it got the document it has version 1 but now it has been changed to 2, and updating that document might override changes that someone else did to this document, and that’s why we get VersionConflictEngineException.</p><p>In other words we can say that if we get version n of the document from the Elasticsearch cluster we will be trying update the same version, if the document with the same ID has the version n+x now (when we are trying to update it), it simply means that meanwhile someone else made some changes into that document and it will result in VersionConflictEngineException.</p><p>We usually handle this issue by retrying to update the same document but with updated version number. After getting this error what we can do is make another get request get the updated document (with latest version) of the document and then update that document with our changes.</p><p>Now the important question that arises is how many times we should retry to update the document? From my personal experience I say if n processes are trying to update your document concurrently, its better to retry n-1 times.</p><p>A part from manually retrying the to update the document we can pass a parameter (retry_on_conflict) while calling update API that will take care of retrying the update if VersionConflictEngineException occurs. Below is description of this parameter from elasticsearch package.</p><pre>:arg retry_on_conflict: Specify how many times should the operation be<br>            retried when a conflict occurs (default: 0)</pre><p>I would love to hear your feedback on this, you can reach out to me on <a href="https://twitter.com/viveksinghggits">twitter</a> if you have any question/suggestion about this post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=828135c2995b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/writing-apps-for-elasticsearch-here-are-some-things-you-should-take-care-of-828135c2995b">Writing apps for Elasticsearch, here are some things you should take care of.</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hello World!!! of Kubernetes [Part 3]]]></title>
            <link>https://faun.pub/hello-world-of-kubernetes-part-3-5076682add36?source=rss-8ef54e761cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/5076682add36</guid>
            <category><![CDATA[linux-foundation]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[cncf]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Vivek Singh]]></dc:creator>
            <pubDate>Tue, 29 Oct 2019 17:44:35 GMT</pubDate>
            <atom:updated>2019-11-15T21:12:32.759Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8bTIxMyYKbMhKlUP" /><figcaption>Photo by <a href="https://unsplash.com/@sapegin?utm_source=medium&amp;utm_medium=referral">Artem Sapegin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In the last blog post of this series we discussed about how to use several kubernetes resources to get multiple tiers of your application deployed on kubernetes cluster. In this post we are going to discuss about some other kubernetes resources so that we can improve the way we deployed the application in the last posts.</p><p>If you noticed while getting our application into kubernetes we have provided password and some other environment variables, that are required to the application, hardcoded in the manifest itself. You can find the examples <a href="https://github.com/viveksinghggits/kubernetes101/blob/master/run-mysql/mysql-deployment.yaml#L22">here</a>, <a href="https://github.com/viveksinghggits/kubernetes101/blob/master/restapi-ui/webapp/index.html#L34">here</a> and <a href="https://github.com/viveksinghggits/kubernetes101/blob/master/restapi-k8s/restapi-deployment.yaml#L22-#L27">here</a>.</p><blockquote>You can easily tell that providing the configuration in the resource manifests itself is not the very best way to provide the environment variable to your application. Some of the reason why its not very ideal are mentioned below</blockquote><p>a) By mentioning the configuration in the manifests you are exposing these details to everyone, for example the password in mysql deployment and b) if the configuration are directly mentioned in the applications manifests and you have to change them, you will eventually have to change the manifest and re-apply it. Which will result in the re-creation of the pods.</p><p>To overcome the problems that are mentioned above we can use secrets and configmaps resources.</p><h3>ConfigMaps:</h3><p>Configmaps are kubernetes resources that can be used to store configurations that your application requires. For example if your application talks to an elasticsearch cluster or a kafka cluster you can store the details of these clusters in the configmaps and then read these configmaps from you application code. You can create configmaps in many ways, either directly from literal or a file that has your configurations. Below is an example of how you can create the configmap</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6PM16pMbW4v_jLb7Y41-8A.png" /><figcaption>Creating a configmap from literal</figcaption></figure><p>Or you can create a configuration file and then create the configmaps out of that configuration file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*hyzgjlXB2HyTSEkNTwBmSg.png" /><figcaption>Creating the configmap out of the configuration file</figcaption></figure><p>You can see that we created a configuration file that has all the config details that we need in our application and then eventually the configmap is created using that configuration file.</p><h3>Secrets:</h3><p>Secrets are kubernetes resources that are used to store configurations in more secure way than the configmaps. The data that we store in the secrets are encoded (not encrypted) using base64 encoding mechanism.</p><blockquote>Please make a note that the configurations that are stored in the secrets are not encrypted they are just encoded and if someone get a hold of the secrets they can easily get to know the stored configuration.</blockquote><p>You can create secrets like we created the configmaps in the previous step. If you are creating the secrets using --from-literal flag the value that you provide will be automatically encoded, but if you are creating the secrets using a config file you will have to manually encode (base64) the values and then put them into the config file.</p><p>Please make a note that you will have to provide the secret type as well while creating secrets, so the format will somewhat be like below</p><pre>kubectl create secret &lt;secret-type&gt; &lt;secret-name&gt; --from-literal= or --from-file</pre><p>We provided secret type here because different type of secrets are used for different purposes, for example if you are using the secret to store the credentials of you private docker registry you will have to create a secret of type docker-registry.</p><h3>Using ConfigMaps or Secrets into a POD:</h3><p>Below are some ways in which the configmaps or secrets can be used in the pod</p><p>a) Use the values of the configmap/secret as environment variable for you application, either<a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-container-environment-variables-using-configmap-data"> a value</a> from the configmap or the <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#configure-all-key-value-pairs-in-a-configmap-as-container-environment-variables">entire configmap</a> can be used as environment variable in the manifest file. We will see can example below.</p><p>b) <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#add-configmap-data-to-a-volume">Mount</a> the configmap/secret at a specific mountpath so that the application can read those configurations from the mountpath.</p><p>Now we will go ahead and use the concepts that are discussed above to change our application that we deployed in last posts.</p><p>Let’s create the secret that we will be using to provide secret to our mysql database deployment</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*WMfa5FLI-0v2KIwnCM0Asw.png" /><figcaption>Create the secret that we will use to inject the env variable into the mysql pod</figcaption></figure><p>To get the details about the secret you can run below command</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*C6ETpdroR3MJ2YfcyPa70g.png" /><figcaption>you can see in the output of the both the command that we are not actually able to see the value of the password because it has been automatically encoded.</figcaption></figure><p>After creating the secret change the mysql-deployment.yaml file that deploys the mysql application to use the secret that we have just created to pass the <em>MYSQL_ROOT_PASSWORD</em> environment variable from the secret. The changed file is checked in the cm-secret branch in the <a href="https://github.com/viveksinghggits/kubernetes101">same repo</a>.</p><p>Once you have created the deployment using kubectl create command wait for the pod to be in running state and then you can exec into the pod and try to access the mysql database by providing the password that we have specified in while creating the secret.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*9wixHpETOUpqIOL8nt8KDA.png" /><figcaption>create the mysql deployment</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*ePj1xN-FhMHFpsdjTz3r1g.png" /><figcaption>exec into the mysql pod to make sure the password is being taken from the secret that we have created.</figcaption></figure><p>you can see in the attached image that now we are able to login to the mysql database through the password that we have specified in the secret that we have created above.</p><p>Now that we have the database running, we can go ahead and deploy the restapi component that will talk to this database. To do that you will just have to follow the steps that are there in the <a href="https://github.com/viveksinghggits/kubernetes101">github repo.</a></p><p>Make sure that once you have to<a href="https://github.com/viveksinghggits/kubernetes101/tree/cm-secret#restapi"> created the image</a> for the restapi, you will have to provide the <a href="https://github.com/viveksinghggits/kubernetes101/blob/cm-secret/restapi-k8s/restapi-deployment.yaml#L22-#L27">configuration</a> detail to this restapi component so that it can talk to the mysql service that we have already created.</p><p>There you can see that the value of APIPATH and DBHOST are not that sensitive so we will use configmaps to store these values, and retapi deployment manifest will use that configmap to set the env variables APIPATH and DBHOST. The third env variable that we have is password to connect to the database that we have already created in the previous step. If you remember we created a secret named mysql-password that contains the password to connect to the mysql instance. What we can do now is, use the same secret in the restapi deployment manifest to talk to the mysql database, but if the secret is not present in the same namespace or the cluster you will have to create the secret once again in the same cluster/namespace where your restapi instance is running.</p><p>Once you have build the image for the restapi application by following the command that is mentioned in the github repo, follow these commands to create the configmaps that are going to store the configuration APIPATH and DBHOST.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kFrh7XVN8dvE6jTBO3tD4A.png" /><figcaption>create the configmap that is going to store the APIPATH and DBHOST env variables’ values</figcaption></figure><p>Once you have created these configmaps we will have to change the restapi deployment file so that it will use the configmap to get the env variables in place of hardcoding it in the manifest. After changing the manifest create the restapi deployment, service and ingress using the commands that are mentioned in the github repo and try to list the pods if the pods are running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*1Kei_Lt_88FJFsZ47RmcIQ.png" /></figure><p>you can see that the one replica of mysql pod and 3 replicas of restapi pods are successfully running.</p><p>To make sure that the env variable are set successfully lets exec into the restapi pod and try to list the env variables</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*taQ6DQu5n1A8qq7NcJPZhQ.png" /><figcaption>you can see that the env variable DBHOST, DBPASS and APIPATH are successfully set and will be used by restapi code to talk to the mysql database pod that is running in backend</figcaption></figure><p>Now that we have the restapi application (deployment, service, ingress) running lets try to access it. Make sure to have ingress enabled if you are running this example on minikube, using the command</p><pre>minikube addons enable ingress</pre><p>Get the minikube IP using the command <em>minikube ip</em> and try to access the URL <em>minikubeip/api/v1/books</em> in the browser. Surprisingly you are going to have some problem because the restapi application tries to query a table (books) in the database (testlocal) of the mysql instance that we are running. Since we have just created the mysql instance and didn’t create the database or the table we are facing that issue. Let’s try to create the database and the table using the commands that are mentioned in below screenshot.</p><pre>create database testlocal;<br>use testlocal;<br>create table books (id varchar(100), title varchar(100), isbn varchar(100))<br>insert into books values (&quot;1&quot;, &quot;The Everything Store&quot;, &quot;ISBN 1&quot;);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*HjP2wmWOcq44oNoaMOWi-Q.png" /><figcaption>Create the database, table and make an entry in the table</figcaption></figure><p>After creating an entry in the table if you try to access the endpoint <em>minikubeip/api/v1/books</em> you will be able to see the details of the book that we just inserted in the books table in the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*7IUl0vYoyAWwYULb-DSlxA.png" /></figure><p>That is almost all about what I wanted to discuss about configmaps and secret in this post. There are some other controllers (Daemonsets) and some other kubernetes constructs (StaticPod, kube-proxy) that we didn’t discus in this or the previous posts but I highly encourage you to go through them in your free time.</p><p>You can always reach out to me on <a href="https://twitter.com/viveksinghggits">Twitter</a> if you have any questions or suggestion about this or any other previous post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*Piks8Tu6xUYpF4DU" /></figure><p><strong>Follow us on </strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong> and </strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong> and join our </strong><a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook Group</strong></a><strong> </strong>💬<strong>.</strong></p><p><strong>To join our community Slack </strong>🗣️ <strong>and read our weekly Faun topics </strong>🗞️,<strong> click here⬇</strong></p><figure><a href="https://www.faun.dev/join/?utm_source=medium.com%2Ffaun&amp;utm_medium=medium&amp;utm_campaign=faunmediumbanner"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oSdFkACJxs5iy1oR" /></a></figure><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5076682add36" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/hello-world-of-kubernetes-part-3-5076682add36">Hello World!!! of Kubernetes [Part 3]</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hello World!!! of Kubernetes [Part 2]]]></title>
            <link>https://faun.pub/hello-world-of-kubernetes-part-2-c5a41681f8e5?source=rss-8ef54e761cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5a41681f8e5</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[cloud-native]]></category>
            <dc:creator><![CDATA[Vivek Singh]]></dc:creator>
            <pubDate>Fri, 25 Oct 2019 18:27:31 GMT</pubDate>
            <atom:updated>2019-11-15T21:12:15.106Z</atom:updated>
            <content:encoded><![CDATA[<p>In last post we discussed about how you can create an app (a REST API) and then get that APP deployed on kubernetes using kubernetes resources. We talked about Kubernetes Architecture, Pods, Deployments, Services and Ingresses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*zYebJiKLEuTaki0iLLkA2A.png" /><figcaption>Image by foxutech.com</figcaption></figure><h3>Overview</h3><p>In this post we will be continuing the same application and will introduce two more tier (components) to that app, front end and database. The database that we are going to use is mysql. So an overview would be, three components, frontend, backend and the database as the projects restapi-ui, restapi and run-mysql respectively. We have already talked about restapi that we built in last post, I have improved the same restapi code to talk to mysql database. Below diagram explains what are we going to be building today.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*DuTK7UmDKlsQSl0EXSKvrw.png" /></figure><p>Our final goal is to create these components and make them talk to each other using kubernetes resources , lets go into more details and discuss which kubernetes resource we are going to use to achieve this.</p><p>I will only be talking about the resources that are involved in the applications all the steps on how to deploy them, code and manifests are checked in <a href="https://github.com/viveksinghggits/kubernetes101">here</a>. You can follow this github’s readme and this document in parallel.</p><h3>Database (MySQL)</h3><p>As we know that the basic entity to run an application on kubernetes is pod, so we will have to create a pod that runs mysql in it. We can use the mysql image to run into a pod but the next challenge would be the persistence of the data that will be stored in this mysql instance. To have the persistence storage kubernetes provides a resource named PersistentVolue.</p><h4>PersistentVolume</h4><p>Persistent volume is actually backed by actual storage that is provisioned by your cluster administrator, and that provision can be done using any of the already provided solution. For example we can have Persistent Storage backed by an NFS, AWSElasticBlockStore, HostPath or any other solution that is supported by kubernetes. A full list of available solutions or types can be found <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#types-of-persistent-volumes">here</a>. In your example to run the mysql server we will be using HostPath (local storage) persistent volume type.</p><blockquote>I am going to use HostPath for demo purpose and it is not advised to use HostPath persistent volume type for production use case.</blockquote><p>Once we have the volume, the pod that is running in the mysql server should be able to use this Persistent Volume, to use a persistent volume kubernetes provides another resource named PersistentVolumeClaim.</p><h4>PersistentVolumeClaim</h4><p>PersistentVolumeClaims (PVC) are used by pods usually, in order to request some storage and that request will be fulfilled by the PersistentVolumes that we already have in the cluster. So let’s say if we want to run msyql with 20G of persistent storage we will create a PVC that will request 20G of space and this request will eventually be fulfilled by a PersistentVolume. Now that you have idea of why are we going to use the PVC and PVs, you can follow the github’s README to create them.</p><h4>Deployment</h4><p>Once we have the PV and PVCs created, and PVC is bound to the PV, it’s time that we create a POD using deployment controller that we actually have mysql image running. I will not be going into more details of pod, deployment and services because we have discussed them in last post, but if you have any question please do let me know, I will be happy to discuss them. You can follow the steps that re mentioned in the Github’s readme to deploy the deployment.</p><h4>Service</h4><p>Once we have deployment ready wcreatede will have to create service so that we can access the pods of the mysql deployment from other components (pods) in the kubernetes cluster.</p><h3>restapi</h3><p>Once we have the above components created in our systems, we can say that database part is ready and we can move to the other component in our application that is restapi. To run the restapi application we will have to first create docker image out of our restapi code that is in the restapi directory of the repo. Create the docker image by following the commad that is mentioned in the README.</p><p>Once we have the docker image of the restapi we can deploy this image in our kubernetes cluster by following the steps that are mentioned <a href="https://github.com/viveksinghggits/kubernetes101#restapi-k8s">here</a>. The steps in github repo also include the step to create the ingress that will be used by restapi-ui component to talk to the restapi component.</p><h3>restapi-ui</h3><p>Now that we have the restapi running we will have to create the UI so that we can talk to the restapi and the restapi will eventually talk to the database to get the data that is stored in there.</p><p>Like restapi component we will have to first make the docker image for the restapi-ui component. Please make a note that we have exposed the restapi component using the ingress resource so that it will be accesed through the minikube’s IP to please make sure the change <a href="https://github.com/viveksinghggits/kubernetes101/blob/master/restapi-ui/webapp/index.html#L34">this line</a> before creating docker image for the restapi-ui component.</p><p>Once we have the docker images created for the restapi-ui component we can create this component on the cluster using the command that are mentioned in the repo.</p><p>Once we have the ingress created for the restapi-ui we can access the UI at the path <em>minikube-ip</em>. Because the ingress is listening at the path <em>/</em> and redirects the traffic to the service that exposes the restapi-ui deployment.</p><h3>Why Statefulset ?</h3><p>Statefulset is another <a href="https://kubernetes.io/docs/concepts/architecture/controller/">controller</a> like deployment and replicasets that can be used to deploy/manage pods in the kubernetes cluster. Running a stateless or single instance stateful application on kubernetes cluster can easily be done using deployment without any issue. But the problem arises when we have multiple instances of a stateful application to run on a kubernetes cluster.</p><p>The reason why we use statefulsets to run replicated/multi instances of stateful application is that the pods that are created by statefulset will have same hostname, SRV record and A records and this feature along with some other help us to run replicated stateful applications on kubernetes cluster. More details on this can be found <a href="https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#pods-in-a-statefulset">here</a>.</p><p>In the next article we will be going through other resources of kubernetes for example StaticPods, ConfigMaps/Secrets etc and how do developers leverage them to make production ready applications.</p><p>I have tried to explain almost all the points that you need to be aware of in order to run through the example that is in the github repo, if you can any question/suggestion you can either ask here or contact me on <a href="https://twitter.com/viveksinghggits">twitter</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*Piks8Tu6xUYpF4DU" /></figure><p><strong>Follow us on </strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong> and </strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong> and join our </strong><a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook Group</strong></a><strong> </strong>💬<strong>.</strong></p><p><strong>To join our community Slack </strong>🗣️ <strong>and read our weekly Faun topics </strong>🗞️,<strong> click here⬇</strong></p><figure><a href="https://www.faun.dev/join/?utm_source=medium.com%2Ffaun&amp;utm_medium=medium&amp;utm_campaign=faunmediumbanner"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oSdFkACJxs5iy1oR" /></a></figure><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5a41681f8e5" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/hello-world-of-kubernetes-part-2-c5a41681f8e5">Hello World!!! of Kubernetes [Part 2]</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I recently cleared CKA, here are some suggestions.]]></title>
            <link>https://faun.pub/i-recently-cleared-cka-here-are-some-suggestions-680b192a88f3?source=rss-8ef54e761cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/680b192a88f3</guid>
            <category><![CDATA[cka]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[certification]]></category>
            <category><![CDATA[cncf]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Vivek Singh]]></dc:creator>
            <pubDate>Wed, 02 Oct 2019 16:18:53 GMT</pubDate>
            <atom:updated>2019-11-30T15:32:21.835Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pyY7qX_cOnu6JkhUtlv9oQ.png" /></figure><p>I appeared for <a href="https://www.cncf.io/certification/cka/">CKA</a> on Sat 28th of Sept, it was an amazing experience and in this post I will try to share some things that you should be getting your hands on, before appearing for the exam.</p><p>The exam consists of 24 questions, you are supposed to complete these questions in 3 hours and you have to score 74% in order to pass the exam. You are allowed to open only two browser tabs, one will the exam interface and in the other tab you can open any of the allowed web pages, one of them is k8s <a href="http://docs.kubernetes.io/">official docs</a>. You can get a list of all the link that you can visit, in the candidates handbook and it says you can access <a href="https://kubernetes.io/docs/">https://kubernetes.io/docs/</a>, <a href="https://github.com/kubernetes/">https://github.com/kubernetes/</a> and <a href="https://kubernetes.io/blog">https://kubernetes.io/blog</a>.</p><p>Candidate’s handbook says that you can copy 1–2 lines of data from the official documentation and that’s sufficient, you wont actually need to copy entire yaml file into your test. Its better to generate that yaml file by yourself and then edit hat yaml file to have specific details, we will talk about that later.</p><p>There are, I think, 6 clusters that you will have to work on and a command will be given at the very start of every question to get into the correct context/cluster to make sure you are working on the right cluster.</p><h3>Practice</h3><p>Practice is key to everything, the exam is totally based on questions that you will have to perform on live cluster. So until and unless you have actually done those things on live cluster before it will be hard for you but if you have done some practice/hands on you don’t have to worry much about this.</p><p>The best way to practice k8s concepts is to get minikube installed and go through the <a href="https://kubernetes.io/docs/tasks/">tasks</a> page of the official k8s docs. Once you have gone through the official k8s docs tasks you will be confident enough to appear in the exam.</p><p><a href="https://kubernetes.io/docs/tasks/">Tasks</a></p><h3>Logs</h3><p>Something doesn’t work? check the logs. Be it any control plane component or any other component that is installed as a linux service, and logs will get you an answer. For example if you scaled a deployment but don’t see the new pods spinning up, check the log of the concerned k8s core component.</p><p>Now the most important part is to figure out which component we should check the log of? For example if new pods were not created after scaling the deployment, which component we should check the log of, kube-apiserver, controller-manager, scheduler, etcd, kubelet or kube-proxy. That’s where the basic understanding of k8s comes into play. If you have basic understanding of k8s you might know that controller-manager is set of different controllers and is responsible to make expected number of replicas for your deployment. Similarly if you see that a pod is in pending state you should see the logs of kube-scheduler because this is the component that is responsible for scheduling a pod on a particular node.</p><p>To get comfortable with these type of questions you will have to read about the core components in detail separately, if you have good understanding of the core components you will easily be able to figure out the component to check the log of, if something goes wrong.</p><h3>Basic Understanding of systemd</h3><p>There are chances that some of the component of the cluster will be running as linux services and not as k8s pods, and you might have to debug those components to check any issues in them. So it will always be a plus to have goo understanding of how to change configuration of, check logs of, start or stop a systemd service.</p><p>You can read more about systemd essentials in below article</p><p><a href="https://www.digitalocean.com/community/tutorials/systemd-essentials-working-with-services-units-and-the-journal">Systemd Essentials: Working with Services, Units, and the Journal | DigitalOcean</a></p><h3>Linux Basic Commands</h3><p>You will be working on linux based machines so it’s always beneficial to know some basic command of linux based operating systems. For example how to redirect output to a file (&gt;), filter somethings from a file (grep), find, get last or first rows from the output and cut command.</p><h3>K8S Imperative Commands</h3><p>When you are asked to, let’s say create a pod, it’s not very ideal to write the entire manifests manually because its time consuming and you are likely to make some indention mistakes while writing the yaml. So its better to have the basic manifest of the resource generated and then edit that manifest with what is actually required by the question. Here are some example of the imperative commands</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94d186707994438dd60cc27dc4c4ea64/href">https://medium.com/media/94d186707994438dd60cc27dc4c4ea64/href</a></iframe><h3>Deployment’s Manifest</h3><p>You should be able to create a manifest of either Deployment, ReplicaSet of DaemonSet without help of imperative command. This gives you confident to edit the manifests and I think you can’t create daemonset or statefulset using imperative command.</p><h3>Simple Networking</h3><p>You should be aware of some linux networking commands for example nslookup, ping, curl or dig in order to check the connectivity between the hosts or components.</p><p>This becomes very handy, if you have questions where you have to check the connectivity between the services or pods.</p><h3>StaticPodPath</h3><p>The mistake that I make sometimes in the case of StaticPods is, lets say you are asked to delete a pod and you know that, that pod is a static pod, you will figure the staticpodpath and then try to delete that file from the dir that is set as staticpodpath. Now the problem is if the static pod is running on the worker-node1 and you are on master node you will try to delete the pod manifest file from the master node’s staticpodpath dir which will not be there. So make sure you are checking on the right node where that static pod is running.</p><p>I will love to hear your feedback and add some other points if you have any suggestions or questions about this. I am quite active on <a href="https://twitter.com/viveksinghggits">twitter </a>so reach out to me there to discuss about this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*Piks8Tu6xUYpF4DU" /></figure><p><strong>Follow us on </strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong> and </strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong> and join our </strong><a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook Group</strong></a><strong> </strong>💬<strong>.</strong></p><p><strong>To join our community Slack </strong>🗣️ <strong>and read our weekly Faun topics </strong>🗞️,<strong> click here⬇</strong></p><figure><a href="https://www.faun.dev/join/?utm_source=medium.com%2Ffaun&amp;utm_medium=medium&amp;utm_campaign=faunmediumbanner"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oSdFkACJxs5iy1oR" /></a></figure><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=680b192a88f3" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/i-recently-cleared-cka-here-are-some-suggestions-680b192a88f3">I recently cleared CKA, here are some suggestions.</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hello World!!! of Kubernetes [Part 1]]]></title>
            <link>https://faun.pub/hello-world-of-kubernetes-part-1-d1153fc2fc37?source=rss-8ef54e761cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1153fc2fc37</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubernetes-helloworld]]></category>
            <category><![CDATA[kubernetes-tutorial]]></category>
            <dc:creator><![CDATA[Vivek Singh]]></dc:creator>
            <pubDate>Wed, 27 Mar 2019 16:05:26 GMT</pubDate>
            <atom:updated>2019-11-15T21:11:58.255Z</atom:updated>
            <content:encoded><![CDATA[<p>So, I started working with containers and Kubernetes some months back, was an absolute beginner to the field before that and thanks to my awesome colleagues at <a href="https://twitter.com/infracloudio">Infracloud</a> I got know Kubernetes and containers better.</p><p>I would like share how I started working with Docker and Kubernetes in this guide.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*KsejWtOoUGdxbGsIyGjQdQ.jpeg" /><figcaption>Courtesy: <a href="https://blog.opendigerati.com/deploy-your-applications-to-kubernetes-using-gitlab-ci-and-k8s-deploy-helper-1-0-0-32b8a080bd08">blog.opendigerati.com</a></figcaption></figure><p>When we tell someone who is new to Kubernetes that, Kubernetes is a container orchestrator, the very first question that comes into their mind is what does orchestration actually mean? How can I create a container out of an application that I already have and how can I orchestrate that application using kubernetes.</p><p>We are going to look into all of these questions in this guide so that you will be able to understand why you should use Kubernetes and how to start with it. We will not look much into the definition of the terminologies, we will be more focused on actually doing the things.</p><p>Let’s take an example of a simple API written in GoLang and we will make a container (docker) for that API and finally will try to deploy that API (container) in the Kubernetes cluster (minikube) that we have.</p><p>To actually go through this guide and do the tasks you just need a Kubernetes cluster (<a href="https://github.com/kubernetes/minikube">minikube</a> in our case) and docker running on your machine. I am running Kubernetes version v1.13.3, and docker version 18.09.2 on my machine.</p><h3>1. Make an API</h3><p>Below is the code of the API that we will try to make container of</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed5d304e1f7ca5974a58c536b7b9f39c/href">https://medium.com/media/ed5d304e1f7ca5974a58c536b7b9f39c/href</a></iframe><p>If you see, we are getting the resource path from the env variable this is just to display another functionality where you can pass the env variable to the container while creating the deployment of that container. So while creating deployment for the container that is running this API you will have to provide the env variable names APIPATH.</p><p>If you just run the above code using go run main.go you will have an API listening on port 8080 and at the resource path will be the value of the environment variable APIPATH. You can use below command to set the environment variable</p><pre>export APIPATH=/api/books</pre><p>Make a get request to the URL localhost:8080/api/books and you will be able to get two book objects as in json format.</p><h3>2. Make a Container of that API</h3><p>Next step is to make a docker container for the API. Below docker file can be used to make a container of the above Go program</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21af396284b0087c038710beccbbeacc/href">https://medium.com/media/21af396284b0087c038710beccbbeacc/href</a></iframe><blockquote>If you run docker build to make an image out of this Dockerfile using <strong>docker build -t restapi:1.0 .</strong> you will be able to see a docker image created on your machine.</blockquote><p>Next step is to run the image and make a container out of this image so that we can check if we are able to access the API that is containerized.</p><pre>docker run -d -p 8080:8080 restapi:1.0</pre><p>So we are exposing 8080 port of host machine to 8080 port on the container because we can see in the main.go our API is listening at the port 8080. Now, If we try to access localhost:8080 we will be able to see the same output as we saw when we ran main.go (output of step 1).</p><p>So, now what we have is an API containerized using Docker and listening on host port 8080. Our goal now is to deploy this image restapi:1.0 onto Kubernetes.</p><h3>Kubernetes</h3><p>Kubernetes is all about decoupled transient services, it simply means it consists of some services that can be terminated and replaced at any point of time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*GlUFwFgt4OeOytj_uU6-9A.png" /><figcaption>Courtesy: Linux Foundation</figcaption></figure><blockquote>In the simplest form, Kubernetes is made up of a central master and some worker nodes. The master runs an APIServer, a Scheduler, various controllers and a storage system to keep the state of the cluster, container settings and network configuration.</blockquote><p>Kubernetes exposes an API via the <strong>kube-apiserver. </strong>You can communicate with this API using a local client called <strong>kubectl</strong> or you can write your own client and use curl command.</p><p>The <strong>kube-scheduler</strong> is forwarded the requests for running containers coming to the API and it finds a suitable node (minions) to run that container on. In other words we can say that if a request to run a container comes to kube-apiserver this request is forwarded to the <strong>kube-scheduler</strong> and then it finds a suitable node to run that container on.</p><p>Each node in the cluster runs two processes: a <strong>kubelet</strong> and <strong>kube-proxy</strong>.</p><p>The <strong>kubelet</strong> receives requests to run the containers, manages any necessary resources and watches over them on the local node. Kubelet interacts with the local container engine which is docker by default, but it could be rkt or cri-o which is growing in popularity or any other.</p><p>The <strong>kube-proxy</strong> creates and manages networking rules to expose the container on the network.</p><p>Enough of the terminologies, let’s look up the services that are required to run our container that we have created in step 2.</p><h3>PODs</h3><p>So Kubernetes uses objects named PODs to serve your containerized images, and these objects in Kubernetes’ terms are called resources.</p><p>If you have created an image and image is present locally, you will have to load that image into minikube’s docker daemon because it uses its different docker daemon and Kubernetes will not be able to access the image if the image is not present in the minikube’s docker daemon. To do this you can use below command</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*3DN63AIgXkbUrV_pIN0hXg.png" /><figcaption>restapi:1.0 should be replaced by your image name</figcaption></figure><p>Once you have the images ready in minikube’s docker daemon you can create PODs that will serve this image. Now the important part comes into picture, you can directly create a POD in Kubernetes for your restapi:1.0 but if due to certain reason your POD fails and is not running anymore you will have to manually create another POD so that the requests to restapi:1.0 can be served through the newly created POD. TO resolve this issue we can another resource called deployment.</p><h3>Deployment</h3><blockquote>This is where orchestration part comes to rescue, you can create another Kubernetes resource named deployment and tell that deployment that I need three replicas of this image (restapi:1.0) running on my cluster. Now if anything bad happens, deployment resource is responsible to re-create another POD with that container. This is very trivial example of how Kubernetes provisions the containers.</blockquote><p>There are several ways to create resources in Kubernetes, some of the popular ways are using the CLI or through the resource definitions. We will be using later one, so we will have resource definition in the yaml format and we can use kubectl create -f &lt;filename&gt; to create the resource that is defined in the filename. We will be creating all these resources in api-dev <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/">namespace</a>, so if you see<strong><em> </em></strong>-n api-dev in a command that means we are just trying to run that command for api-dev namespace.</p><p>Create a file (let’s call it restapi-deployment.yaml) using below resource definition</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53c55435d34cf7bd164016c9b3a1f17b/href">https://medium.com/media/53c55435d34cf7bd164016c9b3a1f17b/href</a></iframe><p>and create the deployment resource in your Kubernetes cluster using</p><pre>kubectl create -f &lt;filename&gt; -n api-dev</pre><p>One thing to note here is the label that we are giving to the PODs, I will explain later, why are we giving the label to the PODs. You can also see that we are providing the env var APIPATH that this env var is being used to make an endpoint for the API.</p><p>Once the deployment is created successfully you will have three PODs running, and describing those PODs (kubectl describe &lt;podname&gt; -n &lt;namespace&gt;) will let you know that these PODs are running restapi:1.0 image as we mentioned in the deployment and all these PODs will be having the label that we defined in the deployment resource definition.</p><p>Since all the PODs are running successfully we can verify if everything works fine by forwarding a host machine’s port to that POD using below command (kubectl port-forward utility)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*u3ql3k-cyEpwKyu1EPBcIQ.png" /><figcaption>Please make sure change the POD’s name</figcaption></figure><p>and then we can curl the url localhsot:8081/api/books to get all the books.</p><p>So, yes now we have an API running on Kubernetes and we checked using port forward that it is returning the correct output.</p><p>Now the next step would be to expose this API to the outside world so that we can access this from where ever we want. One option would be use port-forward (its so bad that I shouldn’t even mention it here), but we will have to run port forward for as many PODs are running for that image, and we will be associating different port each time, re-creating the POD will change its name the port that was mapped to it will not work anymore.</p><h3>Services</h3><p>To resolve the issue Kubernetes has the concept of services. So the issue that we had with port forward was that we will have to run the command for each POD that we have and PORT forward is dependent on the POD name and this will result in an issue if deployment re-created the POD due to certain reasons. Service groups the PODs, so you will not have to create a service for each POD that you have, and it groups them by the label so you don’t need to worry about re-creation of the PODs because Pod will have the same label every time it is getting re-created.</p><p>So when we create the service we tell the service to group the PODs that have a specific label set on them. These labels are being provided to the PODs by the deployment that we are creating, so the step where we create the deployment, we provide the labels these PODs should be created with and the service will group PODs with the label that are defined the service’s resource definition.</p><p>Create the service resource using below resource definition</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db594518d20521af1fd7a36bfdcde440/href">https://medium.com/media/db594518d20521af1fd7a36bfdcde440/href</a></iframe><p>So you can note here that service is *listening* on port 8081 and it will be forwarding the request to the PODs on port 8080.</p><p>Now that we have service created, we should check if the things are working perfectly till now. Use port-forward command to map the host’s port to the service’s port and you should be able to see the correct output of the API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*uG8K-qnPIxkB624ntWFT6A.png" /><figcaption>8080 is host machine’s port and 8081 is k8s service’s port</figcaption></figure><p>If you just curl localhost:8080/api/books you will be able to see the same output that you saw in previous steps. But as you can see to actually access the API we are stil port forwarding, and the API is not available outside of the cluster but it is, inside the cluster.</p><p>To check if API is accessible inside the cluster you will have to get a shell to one of the PODs that are running and curl the service. Go get the pods</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*6_npLIt3XBkXX9MugO0cNw.png" /><figcaption>listing all the PODs</figcaption></figure><p>To execute any command from inside the POD, get the shell to the POD using below command</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*gs9OIi2yyy6fAAHwJhg3fQ.png" /><figcaption>as you can see you inside the POD now</figcaption></figure><p>To, curl the service from inside the POD, you will just have to run curl &lt;servicename&gt;:&lt;port&gt;/path<strong><em>. </em></strong>In our case service name is restapi-service, port where the service is exposed is 8081 (see the resource definition) and the path is /api/books<strong><em>.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z-ubtCl29k7nj5gV1cuVbw.png" /></figure><p>So, as you can see we are able to access the API from inside the cluster but not from the outside of the cluster.</p><h3>Ingress</h3><p>Now we have our running API and we are able to access it from inside the Kubernetes cluster, but to access this resource (service) from outside the cluster we will have to leverage the power of the ingress resources of Kubernetes.</p><p>If we see the image that we have in Kubernetes office docs</p><pre><strong>     internet<br>        |<br>   [ Ingress ]<br>   --|-----|--<br>   [ Services ]</strong></pre><p>As we can see ingress enables us to access the services from outside of the Kubernetes cluster or from the internet.</p><p>Usually ingresses only work if we have an <a href="https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/">ingress controller</a> installed but in the case of minikube you don’t actually need an ingress controller. You just need to enable the ingress addon on the minikube using below command</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*3xyGMjHXroP9vmQbvxiyIA.png" /></figure><p>Ok, so once we have addon enabled we can create the ingress resource and define the rule to which this ingress should respond to and which service the requests will be served with.</p><p>Create a file name restapi-ing.yaml with below resource definition</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a26bc9b8ddbb07d8d616ca1d515516d9/href">https://medium.com/media/a26bc9b8ddbb07d8d616ca1d515516d9/href</a></iframe><p>and create the ingress resource using below command</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*KVTnaBsZL0O5GuIDrbLE9Q.png" /><figcaption>all the resource mentioned above can be created using this command, api-dev is namespaces we are creating all the resources in.</figcaption></figure><p>You can clearly see that this ingress will be forwarding any request at the path /api/books to the service restapi-service on the port 8081.</p><p>If you try to access the API using localhost:8080/api/books, you will not be getting any response; to access the API from outside of the cluster you will have to use the minikube’s host IP, you can get the minikube’s host IP using command</p><pre>minikube ip</pre><p>and make a get request to minikube_ip/api/books.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*u_0Y0-m3pbYde-XOJrs7Qg.png" /></figure><p>I am planning to write another part of this guide, that will include PersistentVolume, PersistentVolumeClaim, StatefulSet and DaemonSet and some other services.</p><p>I would really appreciate if you have any suggestion or improvement to this guide, I will be happy to update it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*Piks8Tu6xUYpF4DU" /></figure><p><strong>Follow us on </strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong> and </strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong> and join our </strong><a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook Group</strong></a><strong> </strong>💬<strong>.</strong></p><p><strong>To join our community Slack </strong>🗣️ <strong>and read our weekly Faun topics </strong>🗞️,<strong> click here⬇</strong></p><figure><a href="https://www.faun.dev/join/?utm_source=medium.com%2Ffaun&amp;utm_medium=medium&amp;utm_campaign=faunmediumbanner"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oSdFkACJxs5iy1oR" /></a></figure><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1153fc2fc37" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/hello-world-of-kubernetes-part-1-d1153fc2fc37">Hello World!!! of Kubernetes [Part 1]</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Accessing Centralized configurations in Spring Boot]]></title>
            <link>https://medium.com/@viveksinghggits/accessing-centralized-configurations-in-spring-boot-428d77457b2d?source=rss-8ef54e761cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/428d77457b2d</guid>
            <category><![CDATA[spring-cloud]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Vivek Singh]]></dc:creator>
            <pubDate>Tue, 07 Aug 2018 19:13:01 GMT</pubDate>
            <atom:updated>2018-08-07T19:13:01.737Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>When we talk about microservices architecture, we don’t just say that we should have our complete functionality divided into smaller services and then these services can communicate to each other through some mechanism, what we actually mean is having a centralized configuration , service registry to mange the services and other concepts to implement <a href="https://12factor.net/">12 factor methodology</a>.</blockquote><p>In this post we will be discussing about Centralized Configuration, creating a Centralized configuration server and some services that will use this config server to get the properties.</p><h3>Need.?</h3><p>So, what was the need to create a common config server, all the services can get the properties from. Below are some of the points that suggest us to go for centralized, version controlled config directories and these are taken from the book <a href="http://shop.oreilly.com/product/0636920038252.do">Cloud Native Java</a> by <a href="https://twitter.com/starbuxman">Josh Long.</a></p><ol><li>Changes to an application’s configuration, as configured, would require restart.</li><li>There is not traceability: how do we determine what changes were introduced into production and, if necessary, roll back those changed?</li><li>Configuration is decentralized; it’s not immediately apparent where to go to change what.</li><li>There is no out-of-the-box support for encryption and decryption for security.</li></ol><h3><strong>Creating a config server</strong></h3><p>To create a config server, we will have to include below dependency in out projects pom.xml (if maven is being used) and we are good to create the configuration directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*i3-8Z8le9IFLQpHU0MfOWw.png" /></figure><p>once you have added above dependency in your project you can install the spring cloud config server by annotating your SpringBootApplication class with the annotation @EnableConfigServer</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*C70J5A_DouQn146AjaZhgw.png" /></figure><p>Once you have annotated the mail class with this annotation you will have to tell this server, the repository where your properties are located. This directory (repository) can be on any remote location accessible via HTTP or in your local machine. You can optionally change the port where this config server will running at, by default the port will be 8080 but conventionally it should be 8888. To do the above mentioned things we will have to change our application.(properties/yml) file as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*-9_bmuyu2qELPmR1_p8gIw.png" /></figure><p>the property server.port will decide the port this server will be running on and the other property will tell the repository where all the configuration properties are stored at, in this example the repository is my local machine by it can be any versioned repository.</p><p>This directory springcloud-configserver will store the properties file of all the services that we have in our application, lets take an example that we have a service named <strong>one-service </strong>and want this service to access the properties from config server. What we can do is, we can create a file named one-service.properties and this file will be used by another service named one-service. Create the file and enter any key vale pair that we will access from another service i.e. one-service. Lest say we created a file named one-service.properties and entered below value in it, we will use this value in a config client later</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*pYDvttwhgbMTzR5iMZ9nAQ.png" /></figure><p>Now run the config server and access the URL <a href="http://localhost:8888/one-service/master">http://localhost:8888/one-service/master</a></p><p>and you will be able to see the configurations that are inside the file one-service.properties.</p><h3>Creating Config Client</h3><p>To create a client (service) that will use the properties that we have configured in Config Server we will have to add below dependency to make the project config client</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/415/1*uGTC_Eu_-odtY_xXRD1Azw.png" /></figure><p>and this client will look for the config server at the default location <a href="http://localhost:8888/">http://localhost:8888</a> and one more thing we will have to change the name of this application to one-service so that it can fetch the values from the properties file one-service.properties that is in the versioned directory springcloud-configserver (configured in config server).</p><p>To use the value that is present in the one-service.properties we have to user @Value annotation and and with the name of the key that is there in the properties file.</p><p>Lets say we wrote below controller</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*leia_wqwwSkseeOwM83VGQ.png" /></figure><p>and access the URL <a href="http://localhost:8080/hi">http://localhost:8080/hi</a> we will be able to see the value of the <strong>databaseurl </strong>property that is configured in the config server.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=428d77457b2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Internal working of HashSet (how it ensures not to store duplicate objects)]]></title>
            <link>https://medium.com/@viveksinghggits/internal-working-of-hashset-how-it-ensures-not-to-store-duplicate-objects-c1eb2e9244e8?source=rss-8ef54e761cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1eb2e9244e8</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java-collection]]></category>
            <dc:creator><![CDATA[Vivek Singh]]></dc:creator>
            <pubDate>Tue, 05 Jun 2018 16:26:10 GMT</pubDate>
            <atom:updated>2018-06-05T16:26:10.341Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>While going through the collections framework in java recently, a question came into my mind; what if I don’t want to store the duplicate values in the collection but I want the collection API to treat two objects duplicate if one of their properties are same.</blockquote><p>So lets say I have below model class</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*R4aV8Fqbg9zt58YhB3UJmA.png" /><figcaption>Person model class</figcaption></figure><p>and I am willing to store the objects of this class into a HashSet, but the condition is<strong> if two persons are having same name the HashSet API should treat them as one and only one should be stored in the collection(HashSet doesn’t store the duplicate values).</strong></p><p>To do this we will have to first identify how the values are being stored, and in which data structure, when we call <em>.</em><strong><em>add</em> </strong>method on the <strong><em>Set</em></strong> type. Here is the code that is being called when we call .add method in the Set type</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*NIQ-XzvIocsO2noCnQDOPA.png" /><figcaption>definition of the add method in HashSet class</figcaption></figure><p>We can see here the object that we are passing to add into the HashSet is being put into the map variable, and this map has below declaration in the same HashSet class</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*mzhq8SbmTFBpvhITQyuABQ.png" /><figcaption>put method on this map is being called when we call add on HashSet</figcaption></figure><h4>So whatever the value we are passing to add into the HashSet is eventually being added into a HashMap as a key, now the important point here is, we know that HashMap will not allow the duplicate keys to be added into it, implementation of HashSet results into not allowing the duplicate values to be added into it.</h4><p>If we want to change how HashSet adds value into it, we will have to look how the keys are being stored into a HashMap to know this lets see the definition of the .<strong><em>put </em></strong>method in <strong><em>HashMap</em></strong> class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*I7l1Y1FpXlBvFVdvNBN-Zg.png" /><figcaption>definition of the put method in HashMap class</figcaption></figure><p>By seeing the above definition of the put method we will try to figure out how HashMap ensures that no duplicate keys will be stored in it.</p><blockquote>If we see the underlined code in above image we can see the condition checks, if the object’s (which is passed to map.put or set.add) hash (derived from hashcode) is equal to already stored element in the HashMap and it is equal to already stored element or equals method if called on two returns true, the object will not be stored into the HashSet or the key will not be stored into the HashMap.</blockquote><p>Now that we know equals and hashCode methods play very important role deciding whether the passed object is duplicate or not and we have not defined any such method in our Model class, super class’ (Object class’)equals and hashCode will be called at this point. But if we want to change the case we will have to define (override) our own equals and hashCode methods.</p><p>Let’s say we don’t want to store two Person objects if their names are same we should change equals method in such a way that if name of two Person’s objects are same this method should return true.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*X9KxwN2R3gaobV-EaemWbA.png" /><figcaption>checking just the equality of names of the Persons</figcaption></figure><p>this implementation of the equals is doing exactly what we are expecting, returning true if the name of the object’s are same.</p><p>Now we have to override the hashCode method also (<a href="https://stackoverflow.com/questions/2265503/why-do-i-need-to-override-the-equals-and-hashcode-methods-in-java">we should always override hashCode if overriding equals</a>), so that the condition that is written in the definition of the put method will be true for the objects having the same name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/1*a8ih6dZtnzeuS1ShdFaTSg.png" /><figcaption>this is not a good implementation of the hashCode though but we did this just to return the same hashCode for the objects having same name</figcaption></figure><p>and after overriding these two methods in the Person class if we try to add two Person objects with the same name the object will not be added and below code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*z0znmUkN7eHZMklpXlvo1Q.png" /></figure><p>will result into</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*6hdmWcPtlcZ4oJh5YKgkRQ.png" /></figure><p>We can clearly see that the other object with name “Mayank” is not added into the Set, even though the mayank and saurabh are entirely different references.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1eb2e9244e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Here is how I configured a free SSL certificate issued by Amazon Certificate Manager to my web…]]></title>
            <link>https://medium.com/@viveksinghggits/here-is-how-i-configured-a-free-ssl-certificate-issued-by-amazon-certificate-manager-to-my-web-b86e812c07bb?source=rss-8ef54e761cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/b86e812c07bb</guid>
            <category><![CDATA[load-balancer]]></category>
            <category><![CDATA[route-53]]></category>
            <category><![CDATA[elastic-beanstalk]]></category>
            <category><![CDATA[free-ssl-certificate]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Vivek Singh]]></dc:creator>
            <pubDate>Mon, 04 Dec 2017 22:51:31 GMT</pubDate>
            <atom:updated>2017-12-05T20:26:19.988Z</atom:updated>
            <content:encoded><![CDATA[<h3>Here is how I configured a free SSL certificate issued by Amazon Certificate Manager to my web application</h3><p>I work for an Indian telecom company but recently was working on a personal project also. It was a web application and I deployed the project that I was working on, on AWS Elastic BeanStalk and shared the URL with some of my friends just to get insights of it.</p><p>Deploying a web application on Elastic BeanStalk is pretty simple, you just have to go to the ELB dashboard and create an environment to deploy your web application. You can choose the environment to be a <strong>web server</strong> or a <strong>worker </strong>environment, since I was supposed to deploy a web application I created web server environment and deployed the web application there. We can choose every configuration of the web server in the next page that we get after selecting the web server or worker environment, like platform (servers- tomcat, glassfish or others) and the domain name of this ELB environment.</p><p>Once you have created the environment you can deploy a packaged application in form of war file on this environment and that will be accessible using the domain name that you chose while creating the environment.</p><p>Now the next step is to configure your domain name(website URL that you purchased) in a such a way that it will be redirected to the environment that you just created. I purchased my domain name from third party that’s why I had to configure DNS of the domain to point to ELB environment that I just created. To facilitate this routing domain issue Amazon provides a domain name system Route53(<a href="https://aws.amazon.com/route53/">https://aws.amazon.com/route53</a>), to point your URL that you purchased from another provider to the ELB environment you will have to create a hosted zone under the Route53 service. As soon as you create a hosted zone for a domain you will get the “<strong>NS” record types</strong> and these record types will used to change the domain name server, where you purchased the domain name from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*3UTzTZuQhGjE4GeQMKf0Ig.png" /><figcaption>after creating a hosted zone</figcaption></figure><p>Once you have successfully configured these NS record types you will now have to create another record set for this hosted zone and the type will be “A”, click on Create Record Set</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*bJRRJ7e2i7mv7EboNl0J7w.png" /><figcaption>Creating a new Record Set</figcaption></figure><p>and fill all the values in the form that you get after that, name will be the domain name and value will be IP address of the ELB environment that you created at very start. We can get this IP address by going services-EC2-Instances and choose the environment that you created in at the very start you will get all the information about that instance or the environment. You have to get “IPv4 Public IP” from there to configure in this value field and you are done, now whenever you access the domain that is mentioned here you will be redirected to the web application that is deployed on the instance that you created in at start.</p><blockquote>Please note that if our instance is being handled by a load balancer, we will choose the record set type “A” but will not configure the IP address in the value field because the IP of the instance may change if the request to the instance in coming from the load balancer. In the case of load balancer we will choose Type as “A” and Alias “Yes”, then we will have an option to select the load balancer in the target field.</blockquote><p>Once we have set the values of record set type NS that we got after creating the hosted zone, as the name servers for our domain we can easily access our website by going to that domain.</p><p>Now, next steps that comes is generating SSL certificates using Amazon Certificate Manager and deploying it so that the domain that you configured lets say abc.com can be served on HTTPS.</p><p>Go the certificate manager dashboard and click on Request a certificate to request the certificate for you domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AGLZPa-40lmIaC61E2wULA.png" /><figcaption>Amazon Certificate Manager dashboard</figcaption></figure><p>Amazon will issue the certificate only once it has verified the domain that you are requesting the certificates for, is owned by you, there are two ways to do it. You can either choose for DNS or Email,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*_dLwLXkt5WvKHJ_o7zON9g.png" /><figcaption>Two options to prove the ownership of your domain, you are requesting the certificated for</figcaption></figure><p>if you choose for DNS you will have to make a record set entry in hosted zone that we created sometime back with the record type as “CNAME”, you can get the name and the value of this record set at after clicking on the review and then request certificate buttons. If the domain that you requested the certificates for is hosted on Amazon’s Route53 you will be having an option to make the entry of record type “CNAME” automatically, you can click on that button and the record set’s entry will be made in Route53 hosted zone. If you are not able to see the button click on the domain you requested the certificates for and you will have an option to download the key and value pair of “CNAME” record type.</p><p>If you choose for Email validation they will send a mail(on the domain that you mentioned in the first page while requesting the certificate) to you and once you approve that the certificate will be issued by amazon and it can be used by any of your instance. Once the certificate is issued here is how the dashboard will look like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*olCIkitNgmYBuYj-qMKzBA.png" /><figcaption>The SSL certificate has been issued by Amazon CA</figcaption></figure><p>Now the next step will be configure this certificate to the ELB instance that you have created, the simplest way to do this is <strong>create a Load Balancer and then use this certificate in that load balancer.</strong></p><p>We can create a load balancer for the instance that we have created earlier and then all the requests to our domain will be redirected to the instance through this Load Balancer.</p><p>To create a load balancer you can go to Services-Elastic BeanStalk, there you will be able to see all the applications (environments) created by you, click on one of the environments you want configure the Load Balancer for. After clicking on the application you will be able to see the dashboard of that application like below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Wf243ZyqmE2UfhcJvd9ag.png" /><figcaption>Dashboard of an Elastic BeanStalk instance</figcaption></figure><p>Click on Configuration and there you will be able to see all the configuration related details of this application under the headings <strong>Web Tier, Network Tier, Data Tier etc. . </strong>If you are not able to see the network tier, simply means the load balancer is not configured for that instance.</p><p>To configure the load balancer click on settings button for <strong>Scaling</strong> option under <strong>Web Tier </strong>and there you will be having an option to choose the <strong>Environment Type</strong>, with options Single Instance and Load Balancing, you can choose the Load Balancing one and click on Apply to apply the changes. Now you can go the Elastic BeanStalk dashboard and click on the environment you configured the Load Balancer for, now you will be able to see the load balancer under the heading Network Tier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*5sLXvBCfxezpqDdJgYIrXA.png" /><figcaption>you will be able to see this after clicking on the Configuration link present in the Elastic BeanStalk dashboard</figcaption></figure><p>To add the SSL certificate that we have generated, click on the setting icon next to Load Balancing option and there you will have an option with name <strong>SSL Certificate Id </strong>under the heading <strong>Load Balancer </strong>to add the certificate that you have generated. You will be able to see all the certificates that have been issued by the ACM, you can choose any of the certificates you want and you are ready to go.</p><p>Now what we have to keep in mind that earlier we didnt have any load balancer and all the requests to the domain were being forwarded to the EC2 instance directly because of the A type record set that we configured in Route53 was pointing to the public IP of EB instance, but now there is a Load Balancer in between and due to this the public IP of the EB instance may change.</p><p>So, now we will configure the details of the load balancer in the Route53 where we configured the details of EC2 instance’, to do this go to the Route53 service once again and select the hosted zone that we have already created its record type A is pointing to the Public IP of the Elastic BeanStalk. Click on this record set to modify it choose alias as Yes this time. For target field, you will be able to see all the load balancers and the instances that you have already created, choose the Load Balancer that we have created in the previous step and click on the save record button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*awEYHAic3XajcFdTzSGsVg.png" /><figcaption>Setting the Hosted Zone Record Set for Load Balancer</figcaption></figure><p>you are done you can access the domain my https now.</p><p>Please dont mind the mistakes if there are any, (I will appreciate you pointing them out though) I am planning to continuously make the changes in this post to make it better.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b86e812c07bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>