<?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 Esh Romero on Medium]]></title>
        <description><![CDATA[Stories by Esh Romero on Medium]]></description>
        <link>https://medium.com/@eshlee?source=rss-787b772bd6ef------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-abHew1KfgRVVc8B7hVH3Q.jpeg</url>
            <title>Stories by Esh Romero on Medium</title>
            <link>https://medium.com/@eshlee?source=rss-787b772bd6ef------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 25 Nov 2026 00:17:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@eshlee/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[Inotify Minikube (watch feature in Minikube)]]></title>
            <link>https://itnext.io/inotify-minikube-watch-feature-in-minikube-aef6edeb6f08?source=rss-787b772bd6ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/aef6edeb6f08</guid>
            <category><![CDATA[minikube]]></category>
            <category><![CDATA[inotify]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[Esh Romero]]></dc:creator>
            <pubDate>Mon, 06 Jan 2020 04:02:05 GMT</pubDate>
            <atom:updated>2020-01-06T09:21:37.171Z</atom:updated>
            <content:encoded><![CDATA[<h3>Inotify Minikube (Run watch feature in Minikube)</h3><p>If you are running Minikube for your development environment and find yourself annoyed because your auto-reloading build system (Webpack <a href="https://webpack.js.org/configuration/watch/">watch</a>, <a href="https://pypi.org/project/watchdog/">watchdog</a>) is not working, this post is for you.</p><p><a href="https://github.com/kubernetes/minikube">Minikube</a> allows you to run Kubernetes locally. I am not convincing you to use it but if you are using a Kubernetes cluster in your production environment, it makes sense to use it as it gives you so many advantages.</p><blockquote>If you are using a Kubernetes cluster in your production environment, I recommend using Minikube.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qWI1qBdCeSHJdNRj-8Pf3g.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@moritz_photography?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Moritz Kindler</a> on <a href="https://unsplash.com/s/photos/mini-shipping-container?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Going back to the issue of the auto-reloading build system, this is because the <a href="http://man7.org/linux/man-pages/man7/inotify.7.html">inotify</a> events are not supported between shared folders as the virtual machine has a different filesystem (this is a known issue in VirtualBox and it was even tagged as wontfix <a href="https://www.virtualbox.org/ticket/10660">here</a>).</p><p>Another solution like CHOKIDAR_USEPOLLING=true is not an option because, from our experience, it consumes a lot of RAM and CPU over time causing us to force restart our virtual machines, hurting productivity.</p><p>We believe these watch features and Minikube are supposed to make us more productive but they don’t work seamlessly. But we have a solution!</p><p><strong>Notify-forwarder</strong> is a tool that can forward file system events to another machine with shared folders.</p><p><a href="https://github.com/mhallin/notify-forwarder">mhallin/notify-forwarder</a></p><p>It has two run options: <em>watch</em> and <em>receive.</em></p><pre># Run in host<br>$ notify-forwarder watch -c &lt;remote-ip&gt; &lt;host-path&gt; &lt;to-path&gt;</pre><pre># Run in VM<br>$ notify-forwarder receive</pre><p>The <em>watch</em> option watches for filesystem events in &lt;host-path&gt; and sends them to the &lt;remote-ip&gt; via UDP protocol in port 29324. The &lt;to-path&gt; is the remote path or the shared path in VM.</p><p>The <em>receive </em>option then replays the event inside the VM where the auto-reloading build system is running.</p><h4>Run notify-forwarder in Minikube</h4><p>The idea is to have a container running inside Minikube that runs <strong>notify-forwarder receive</strong>. Other containers should magically pick up these file changes because they are now actually mounted from the same filesystem inside the VM.</p><p>To run <strong>notify-forwarder receive</strong>, apply this manifest file</p><p>But first, here’s my setup:</p><ul><li>MacOS Mojave</li><li>Minikube v1.5.2</li><li>VirtualBox v5.2.32 (old I know :P)</li><li>Project directory path: /Users/esh/workspace</li></ul><blockquote>Note: If you have been using Minikube and VirtualBox for a while, you’d know that it mounts your entire home directory to the same path inside the VM so If you’re using MacOS, you’ll have the entire /Users mounted inside. Less path to worry about.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84812e408075e86fdd5398d870467894/href">https://medium.com/media/84812e408075e86fdd5398d870467894/href</a></iframe><p>Run <strong>kubectl apply -f notify-forwarder.yaml</strong></p><p>This will create a Kubernetes Service and a Deployment resource which creates a Pod of notify-forwarder app listening to port 29324. The service will then expose it to the host. Another important aspect is the mounted directory in the container so make sure it is set correctly.</p><p>To check if it is successfully running,</p><pre>$ kubectl get pod | grep notify-forwarder<br>notify-forwarder-fd66445c8-2gkmf    1/1     Running   1          1m</pre><pre>$ kubectl get svc | grep notify-forwarder<br>notify-forwarder   LoadBalancer   10.107.35.88     10.107.35.88   29324:30732/UDP                1m</pre><p>Take note of the minikube ip and the service external port</p><pre>$ export NOTIFY_LISTENER=$(minikube ip):$(kubectl get svc notify-forwarder --no-headers | awk &#39;{print $5}&#39; | cut -d / -f 1 | cut -d : -f 2)</pre><pre>echo $NOTIFY_LISTENER<br>192.168.99.100:30732</pre><p>Now run the <strong>watch</strong> option from the host machine.</p><p>Download the pre-built binary releases for your operating system</p><ul><li>Mac OS X 10.10 or newer, 64 bit: <a href="https://github.com/mhallin/notify-forwarder/releases/download/release%2Fv0.1.0/notify-forwarder_osx_x64">notify-forwarder_osx_x64</a></li><li>Linux 64 bit: <a href="https://github.com/mhallin/notify-forwarder/releases/download/release%2Fv0.1.0/notify-forwarder_linux_x64">notify-forwarder_linux_x64</a></li><li>FreeBSD 64 bit: <a href="https://github.com/mhallin/notify-forwarder/releases/download/release%2Fv0.1.0/notify-forwarder_freebsd_x64">notify-forwarder_freebsd_x64</a></li></ul><pre>$ ./notify-forwarder_osx_x64 watch -c $NOTIFY_LISTENER /Users/esh/workspace /srv</pre><p>by this, we are telling notify-forwarder to send filesystem change events from Host:/Users/esh/workspace to $NOTIFY_LISTENER:/srv .</p><p>Now why /srv? Because that is the mount path of the container where the <strong>receive</strong> option is listening. Other containers running the build system should now be able to receive file changes too.</p><p>With this approach, it can be easily automated using Ansible or Chef =)</p><p>Here’s the Dockefile of <strong>notify-forwarder</strong> for your reference</p><pre>FROM bitnami/minideb:jessie as build</pre><pre>RUN apt update &amp;&amp; apt install -y curl<br>RUN curl -OL <a href="https://github.com/mhallin/notify-forwarder/releases/download/release%2Fv0.1.0/notify-forwarder_linux_x64">https://github.com/mhallin/notify-forwarder/releases/download/release%2Fv0.1.0/notify-forwarder_linux_x64</a><br>RUN mv ./notify-forwarder_linux_x64 ./notify-forwarder<br>RUN chmod u+x ./notify-forwarder</pre><pre>FROM bitnami/minideb:jessie as final<br>COPY --from=build /notify-forwarder /usr/bin/notify-forwarder<br>ENTRYPOINT [&quot;notify-forwarder&quot;]</pre><p>Thanks for reading! I hope it helps and let me know if you have a different approach to this particular issue.</p><p>And as always, I am open to feedback and suggestions =)</p><p>References:</p><ul><li><a href="https://github.com/mhallin/notify-forwarder">mhallin/notify-forwarder</a></li><li><a href="https://www.datadoghq.com/container-report/">10 insights on real world container use</a></li><li><a href="https://minikube.sigs.k8s.io/">minikube</a></li><li><a href="https://www.virtualbox.org/ticket/10660">#10660 (File update in shared folder does not trigger inotify on Ubuntu) - Oracle VM VirtualBox</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aef6edeb6f08" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/inotify-minikube-watch-feature-in-minikube-aef6edeb6f08">Inotify Minikube (watch feature in Minikube)</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kong Gateway in Kubernetes]]></title>
            <link>https://itnext.io/kong-gateway-in-kubernetes-ad86981f93a5?source=rss-787b772bd6ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad86981f93a5</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[kong]]></category>
            <category><![CDATA[ingress]]></category>
            <dc:creator><![CDATA[Esh Romero]]></dc:creator>
            <pubDate>Tue, 31 Dec 2019 05:41:05 GMT</pubDate>
            <atom:updated>2020-01-02T07:43:11.621Z</atom:updated>
            <content:encoded><![CDATA[<p>Kong is an open-source API gateway that is built on top of a lightweight proxy, Nginx. In this post, I’ll show you how to setup and configure Kong in Kubernetes. You can know more about Kong by visiting the website: <a href="https://konghq.com/kong/">https://konghq.com/kong/</a></p><blockquote>At <a href="https://gengo.com/">Gengo</a>, we handle hundreds of millions of HTTP requests daily. We use Nginx as our gateway for internal and external traffic going to our microservices hosted in a Kubernetes cluster. Managing these proxies ourselves becomes problematic as we needed to control, monitor and secure the traffic without adding code changes and complexities in our existing setup. This is, of course, to allow us to scale fast.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*jPMYiRFN3gwpUO25ZzHxBQ.png" /></figure><p>King Kong to the rescue. It is a Lua application running in Nginx which means we can enjoy more functionality using plugins while still using a very lightweight proxy. Nginx on steroids =)</p><p>To use Kong in K8s, we will use the <a href="https://github.com/Kong/kubernetes-ingress-controller">kong-ingress-controller</a>. This allows us to configure Kong in a similar fashion of managing Kubernetes resources.</p><h3>Test setup</h3><ul><li>Minikube v1.5.2</li><li>Kubernetes v1.14.0</li></ul><p>Run this command to apply the controller.</p><pre>kubectl apply -f <a href="https://bit.ly/kong-ingress-dbless">https://bit.ly/kong-ingress-dbless</a></pre><blockquote>Note that this is not a production-grade deployment for Kong.</blockquote><p>This will create the required resources for Kong which are Namespace, Services, Deployment, CustomResourceDefinitions (more on this later), ClusterRoles and ConfigMaps.</p><p>Prior to the release of version 1.1, Kong is usually used with a database for its configurations but we don’t want that as we are aiming for a declarative setup.</p><p>To check if it is working, curl the kong-proxy service. In minikube, services that are type LoadBalancer must be accessible in the localhost. To do that, run</p><pre>$ minikube tunnel</pre><p>Now we can access our services from the localhost.</p><pre>$ export KONG_HTTP=$(minikube ip):$(kubectl -nkong get svc kong-proxy --no-headers | awk &#39;{print $5}&#39; | cut -d / -f 1 | cut -d : -f 2)</pre><pre>$ curl -i $KONG_HTTP</pre><pre>HTTP/1.1 404 Not Found<br>Date: Sun, 08 Dec 2019 12:10:23 GMT<br>Content-Type: application/json; charset=utf-8<br>Connection: keep-alive<br>Content-Length: 48<br>Server: kong/1.3.0</pre><pre>{&quot;message&quot;:&quot;no Route matched with those values&quot;}%</pre><p>Congratulations! Kong is working. But it doesn’t know how to proxy the request yet.</p><h4>Let’s set up a simple app,</h4><pre>$ curl -sL bit.ly/echo-server | kubectl apply -f -</pre><pre>service/echo created<br>deployment.apps/echo created</pre><h4>Basic routing configuration</h4><p>kong-ingress-controller watch for changes in the Ingress controller to set up a basic routing configuration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a4a90c3583204ac67c395b25733e335/href">https://medium.com/media/1a4a90c3583204ac67c395b25733e335/href</a></iframe><p>You should see something like this in the logs</p><pre>$ kubectl -n kong logs -f $(kubectl -n kong get pod — no-headers | awk ‘{print $1}’) --tail=2 ingress-controller</pre><pre>I1208 10:10:30.885602       1 status.go:342] updating Ingress default/api status to [{10.110.88.230 }]<br>W1208 10:10:30.902533       1 controller.go:135] successfully synced configuration to Kong</pre><p>Now curl the endpoint again with a host header of api.gengo.dev</p><pre>$ curl -i -H &quot;Host: api.gengo.dev&quot; $KONG_HTTP/</pre><pre>HTTP/1.1 200 OK<br>Content-Type: text/plain; charset=UTF-8<br>Transfer-Encoding: chunked<br>Connection: keep-alive<br>Date: Sun, 08 Dec 2019 12:20:14 GMT<br>Server: echoserver<br>X-Kong-Upstream-Latency: 14<br>X-Kong-Proxy-Latency: 3<br>Via: kong/1.3.0</pre><pre>Hostname: echo-758859bbfb-bx9tx</pre><pre>Pod Information:<br> node name: minikube<br> pod name: echo-758859bbfb-bx9tx<br> pod namespace: default<br> pod IP: 172.17.0.7</pre><pre>...</pre><p>Congratulations! You have the basic routing configuration. Now let’s inject some steroids.</p><h3>Custom Resource Definitions</h3><p>Since Kong has a lot to offer than the basic routing configuration we just set-up a while ago, it allows us to make further configurations by using custom resource definitions.</p><ul><li><strong>KongPlugin:</strong> Install and configure plugins in Kong</li><li><strong>KongIngress: </strong>Serves as “extension” of Ingress resource for fine-grained control of traffic (routing, load-balancing, or even health-checks)</li><li><strong>KongConsumer: </strong>this maps to Kong <a href="https://getkong.org/docs/latest/admin-api/#consumer-object">consumer</a> entity.</li><li><strong>KongCredential: </strong>allows setting-up of credentials that will be associated with KongConsumer.</li></ul><h4>KongPlugin</h4><p>This is what I really like about Kong. The power of the lightweight Nginx can be easily extended by using plugins. There is a <a href="https://docs.konghq.com/hub/">KongHub</a> if you wish to see the list of available plugins ranging from different functionalities (authentication, security, serverless, monitoring, logging, etc.)</p><p>One of my favorite plugin to use is the <strong>Serverless Functions</strong> where we can dynamically run Lua code during the access phase. The plugin has 2 kinds. Each one runs with a different priority in the plugin chain.</p><ul><li><strong>pre-function</strong> — runs before other plugins</li><li><strong>post-function</strong> — runs after other plugins</li></ul><p>The plugin below is an example of how you can read each segment of a JWT token in Lua.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0f056fbb51573d0e9dde35498332a2f/href">https://medium.com/media/b0f056fbb51573d0e9dde35498332a2f/href</a></iframe><p>and we can also use the <a href="https://github.com/openresty/lua-nginx-module#nginx-api-for-lua">Nginx API</a> for Lua. How cool is that?</p><p>To use this, we need to associate it with an Ingress by using annotations.</p><p>For example (assuming we have another plugin called http-jwt that checks the validity of the token before reading it)</p><pre>annotations:<br>  plugins.konghq.com: http-jwt,read-jwt-token</pre><h4>KongIngress Man!!</h4><p>In most cases Ingress resource is sufficient but if you want more control over routing, KongIngress is your man. Using this, all properties of <a href="https://getkong.org/docs/latest/admin-api/#upstream-objects">Upstream</a>, <a href="https://getkong.org/docs/latest/admin-api/#service-object">Service</a> and <a href="https://getkong.org/docs/latest/admin-api/#route-object">Route</a> entities in Kong related to an Ingress resource can be modified.</p><p>For your reference, here’s the full spec,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3121ea4a282132a702497c1752c2f93b/href">https://medium.com/media/3121ea4a282132a702497c1752c2f93b/href</a></iframe><p>All configurations are pretty much self-explanatory, refer to the <a href="https://docs.konghq.com/1.4.x/admin-api/#upstream-object">documentation</a> if not.</p><p>To use this, we need to associate it with an Ingress or Service by using annotations.</p><pre>annotations:<br>  configuration.konghq.com: kong-ingress-resource-name</pre><p>It can be associated with Ingress or Service but how do we know which one?</p><p>If you are doing configuration changes in the upstream or proxy node, it needs to be associated with Service while the route node is with Ingress</p><pre>upstream: # Associate with Service<br>  hash_on: none<br>  hash_fallback: none</pre><pre>proxy: # Associate with Service<br>  protocol: http<br>  path: /<br>  connect_timeout: 10000<br>  retries: 10<br>  read_timeout: 10000<br>  write_timeout: 10000</pre><pre>route: # Associate with Ingress<br>  methods:<br>  - POST<br>  - GET</pre><h4>KongConsumer</h4><p>There are cases that we want to have different rules for each user/consumer that will access an endpoint. For example, your rate-limiting condition on web client is different from a machine accessing your API programmatically. This can be achieved using Kong consumers.</p><p>Here’s a manifest file to create a consumer.</p><pre>apiVersion: configuration.konghq.com/v1<br>kind: KongConsumer<br>metadata:<br>  name: api-consumer<br>  annotations:<br>    plugins.konghq.com: api-rate-limit<br>username: api<br>custom_id: api-1</pre><pre>---<br>apiVersion: configuration.konghq.com/v1<br>kind: KongConsumer<br>metadata:<br>  name: web-consumer<br>  annotations:<br>    plugins.konghq.com: web-rate-limit, web-cors<br>username: web<br>custom_id: web-1</pre><p>In this example, we are creating 2 consumers each associated with different plugins according to their needs.</p><p>Simply associate KongPlugins with your consumers by using annotations.</p><p>The consumer is an opaque concept to Kong because it can be treated differently depending on the use case. It can be really confusing.</p><p>For instance, you can use it as one-to-one with your users or like in our example above. The core principle is that you can attach plugins to them, and hence customize request behavior.</p><p>In most cases, consumers get identified by authentication plugins so here comes the credentials part.</p><h4>KongCredential</h4><p>KongCredentials are separate entities with different types that can be assigned to KongConsumer.</p><ul><li><strong>key-auth</strong> for <a href="https://docs.konghq.com/plugins/key-authentication/">Key authentication</a></li><li><strong>basic-auth</strong> for <a href="https://docs.konghq.com/plugins/basic-authentication/">Basic authentication</a></li><li><strong>hmac-auth</strong> for <a href="http://docs.konghq.com/plugins/hmac-authentication/">HMAC authentication</a></li><li><strong>jwt</strong> for <a href="http://docs.konghq.com/plugins/jwt/">JWT based authentication</a></li><li><strong>oauth2</strong> for <a href="https://docs.konghq.com/hub/kong-inc/oauth2/">Oauth2 Client credentials</a></li><li><strong>acl</strong> for <a href="https://docs.konghq.com/hub/kong-inc/acl/">ACL group associations</a></li></ul><p>Take note that a consumer can have many credentials.</p><pre>apiVersion: configuration.konghq.com/v1<br>kind: KongCredential<br>metadata:<br>  name: web-apikey<br>consumerRef: web-consumer<br>type: key-auth<br>config:<br>  key: super-secret-key</pre><p>In our case, we use the JWT plugin integrated into Auth0 which only needs 1 consumer and 1 credential per Auth0 tenant. The manifest file looks like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/686f0da36e14e70bbb763539a90a6778/href">https://medium.com/media/686f0da36e14e70bbb763539a90a6778/href</a></iframe><p>So that’s it for now about Kong in Kubernetes. I hope you learned how to use Kong in Kubernetes. Let me know if you have comments/suggestions/questions in the comment section below.</p><p>Thanks for reading :)</p><blockquote>I’m open to feedback and suggestions so I can improve. :)</blockquote><p>References:</p><ul><li><a href="https://docs.konghq.com/?itm_source=website&amp;itm_medium=nav">Open-Source API Management and Microservice Management</a></li><li><a href="https://github.com/Kong/kubernetes-ingress-controller">Kong/kubernetes-ingress-controller</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad86981f93a5" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/kong-gateway-in-kubernetes-ad86981f93a5">Kong Gateway in Kubernetes</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Containers: Terminating with grace]]></title>
            <link>https://itnext.io/containers-terminating-with-grace-d19e0ce34290?source=rss-787b772bd6ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/d19e0ce34290</guid>
            <category><![CDATA[signal]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Esh Romero]]></dc:creator>
            <pubDate>Tue, 09 Jul 2019 07:56:51 GMT</pubDate>
            <atom:updated>2019-07-10T07:12:41.070Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R4gGgH46JufSwmJDDorqVg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@samuelzeller?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Samuel Zeller</a> on <a href="https://unsplash.com/search/photos/containers?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>So I learned that signals are being used to communicate with your processes from the host machine. Whether you want to reload the configuration, do some cleanup, or <strong>gracefully exit your application</strong>.</p><p>Let’s focus on the commonly used signal especially when performing a rolling update deployment. The <strong>SIGTERM</strong> and the <strong>SIGKILL</strong>.</p><p>In Kubernetes, when a pod initiates the terminating procedure, it does the ff:</p><ol><li>Pod is considered “dead” and the API server removes it from the service endpoint list and from replication controllers.</li><li>the<strong> preStop</strong> hook is executed.</li><li>The <strong>SIGTERM</strong> signal is sent to the pod then wait for a grace period of by default 30 seconds.</li><li>The <strong>SIGKILL</strong> is issued.</li></ol><p>Read <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod/#termination-of-pods">this</a> Kubernetes concept about the termination of pods for more information.</p><p>This appears like we don’t need to do anything because we assumed that our application inside a container gracefully exits. Therefore, no downtime at all. We are wrong. I am wrong :D</p><p>Note: For the examples, we will use the <strong>docker stop</strong> command because it sends <strong>SIGTERM</strong>. So similar signal when a pod gets terminated in Kubernetes.</p><blockquote>How do we ensure that our applications receives the signal?</blockquote><p>Let’s start with the most simple way…</p><h4><strong>Application as the main process (PID 1)</strong></h4><p>When your application is the main process, it can accept the signals directly.</p><p>Here’s a simple python application which I shamelessly copied from Stack Overflow (Here’s the <a href="https://stackoverflow.com/a/31464349/2591014">link</a> btw) that implements a signal handler for SIGINT and SIGTERM.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4b9f4a92e97c0d1e45aa184764cf2be/href">https://medium.com/media/c4b9f4a92e97c0d1e45aa184764cf2be/href</a></iframe><p>In our Dockerfile,</p><pre>FROM python:3.7.3-alpine3.9<br>COPY ./signals.py ./signals.py<br>ENTRYPOINT [&quot;python&quot;, &quot;signals.py&quot;]</pre><p>Now build the image</p><pre>$ docker build . -t python-signals</pre><p>Then run,</p><pre>$ docker run -it --rm --name=&quot;python-signals&quot; python-signals</pre><blockquote>If the last two steps are successful, you should see “Running…” message in stdout.</blockquote><p>Open a new terminal and check if the application we ran in the ENTRYPOINT of our Dockerfile is in PID 1.</p><pre>$ docker exec -it python-signals ps</pre><pre>PID   USER     TIME  COMMAND<br>    1 root      0:00 python signals.py<br>    6 root      0:00 ps</pre><p>If you run a <strong>docker stop </strong>command, the application will receive the issued <strong>SIGTERM</strong> and will be able to process it accordingly based on the actions you want it to perform.</p><pre>$ docker stop python-signals</pre><pre>Received SIGTERM signal<br>End of the program</pre><p>That is great! But how about running your application by using a bash script?</p><h4>Application is initiated by a bash script</h4><p>Often times a script is initiated from a bash script.</p><p>Problem with that is, the application won’t receive any signals and won’t react accordingly. In this case, when the container gets killed, the app will be killed brutally :(</p><p>Say you have a run.sh script like this:</p><pre>#!/bin/sh<br><br>ENVIRONMENT=&quot;staging&quot;<br>OTHERAPPVAR=true<br>python signals.py<br><br>## or for example run it using gunicorn<br>## with lots of different parameters</pre><pre># gunicorn [OPTION] [OPTION] ... app:app</pre><p>and in Dockerfile, we’ll gonna replace the ENTRYPOINT with run.sh.</p><pre>FROM python:3.7.3-alpine3.9<br>COPY ./signals.py ./signals.py<br>COPY ./run.sh ./run.sh<br>RUN chmod +x ./run.sh<br>ENTRYPOINT [&quot;./run.sh&quot;]</pre><p>Build and then run the container…</p><p>Open a new terminal and run ps to check what process is in PID 1:</p><pre>$ docker exec -it python-signals ps<br>PID   USER     TIME  COMMAND<br>    1 root      0:00 {run.sh} /bin/sh ./run.sh<br>    6 root      0:00 python signals.py<br>    7 root      0:00 ps</pre><p>Our application is in a different process ID now. So let’s see if by running <strong>docker stop,</strong> our application will receive the SIGTERM signal.</p><pre>$ docker stop python-signals<br>...</pre><p>This time, there’s no print message from the application saying goodbye. It was just killed.</p><p>Now, let’s go back to our run script and add <strong>exec</strong></p><pre>#!/bin/sh<br><br>ENVIRONMENT=&quot;staging&quot;<br>OTHERAPPVAR=true<br><strong>exec</strong> python signals.py</pre><p>The exec command allows us to execute a command that completely replaces the current process.</p><p>In our first version of run.sh, the current process is the actual bash script. Therefore, it is PID 1. It then created a child process for the python application which in our example, became PID 6.</p><p>This exec command replaces that current process leaving the application to be the PID 1 instead.</p><p>Now build, run and then run ps ,</p><pre>PID   USER     TIME  COMMAND<br>    1 root      0:00 python signals.py<br>   12 root      0:00 ps</pre><p>Voila! The application will be able to handle the signal now and can exit gracefully.</p><p>Thank you for reading. :)</p><blockquote>I’m open to feedback and suggestions so I can improve. :)</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d19e0ce34290" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/containers-terminating-with-grace-d19e0ce34290">Containers: Terminating with grace</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Run chef recipes in travis CI]]></title>
            <link>https://medium.com/@eshlee/run-chef-recipes-in-travis-ci-b3114cd57244?source=rss-787b772bd6ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3114cd57244</guid>
            <category><![CDATA[chefs]]></category>
            <category><![CDATA[travis-ci]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[Esh Romero]]></dc:creator>
            <pubDate>Thu, 04 Jul 2019 01:16:46 GMT</pubDate>
            <atom:updated>2019-07-04T01:20:10.183Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JhMVPiOi3ac9m3sDmDm1aA.jpeg" /></figure><p>In Gengo, we use chef template resource to generate our Kubernetes deployment yaml files. There are certain scenarios of failed deployments due to failures in rendering the template.</p><p>Since we use TravisCI for our pull requests checks, why not use it to test the template first before merging the changes into our master branch?</p><p>The key here is to run chef-solo in the localhost, so you need a solo config file that points all node, role, data_bag, cookbook paths to correct folders.</p><p>That can be something like this solo-test.rb</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbb994025bd1be68c42866765d5646d5/href">https://medium.com/media/fbb994025bd1be68c42866765d5646d5/href</a></iframe><p>In .travis.yaml ,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56992ab06bd4261acc213de8ab94d10e/href">https://medium.com/media/56992ab06bd4261acc213de8ab94d10e/href</a></iframe><p>Now you can have something like this in your run_tests.sh ,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11fba9c6143c882d65fdbff43df3b6f6/href">https://medium.com/media/11fba9c6143c882d65fdbff43df3b6f6/href</a></iframe><p>Specifying it all in your run_tests.sh can be a lot. In our case, we have hundreds of templates so I created a test recipe that runs template resource block on each file so I just only need to call a single recipe.</p><h4>Multiple chef recipes running in parallel</h4><p>Sometimes you may want to run multiple chef recipes. That could be slow especially when running it in Travis so you might want to execute them in parallel. You can do this by specifying a lockfile on each chef-solo command.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11090a7959f57278a73c6cb53d73a793/href">https://medium.com/media/11090a7959f57278a73c6cb53d73a793/href</a></iframe><p>The --lockfile allows Chef to run in a separate process. And as you know, adding &amp; in your command will send the process in the background. Hence, allowing us to run them in parallel.</p><p>However, we need to log the output from a file and we want to wait for all of them to finish. Once it’s done, we can just check the log file for errors.</p><p>Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3114cd57244" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RDS Read replica on different VPC]]></title>
            <link>https://medium.com/@eshlee/rds-read-replica-on-different-vpc-3c534a0a8b7?source=rss-787b772bd6ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c534a0a8b7</guid>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[rds]]></category>
            <dc:creator><![CDATA[Esh Romero]]></dc:creator>
            <pubDate>Thu, 04 Jul 2019 00:21:20 GMT</pubDate>
            <atom:updated>2019-07-04T00:30:06.234Z</atom:updated>
            <content:encoded><![CDATA[<p>We recently had a scenario wherein we have a huge RDS cluster and we want to migrate it into same region but different VPC.<br>AWS supported that but not by using console by the time of this writing. You must also have a newer version of awscli. To do that,</p><p>“Assuming there is already a db subnet group and security group in the new VPC”</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03c238430e9964e838c01f1592e3a318/href">https://medium.com/media/03c238430e9964e838c01f1592e3a318/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c534a0a8b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TiredI am tired.]]></title>
            <link>https://medium.com/@eshlee/tiredi-am-tired-fa5c51239d29?source=rss-787b772bd6ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa5c51239d29</guid>
            <dc:creator><![CDATA[Esh Romero]]></dc:creator>
            <pubDate>Fri, 15 Jan 2016 13:11:23 GMT</pubDate>
            <atom:updated>2016-09-06T13:54:38.010Z</atom:updated>
            <content:encoded><![CDATA[<p>TiredI am tired.</p><p>Every day, I have to work. I have to deal with other people giving me so much pressure and I hate that. Can we have a life that is not complicated? Can we have a life that has no competition? Can we have a life without pressure? Is it normal about life?</p><p><em>Originally published at </em><a href="https://blog.esh.ph/2016/01/tired/"><em>blog.esh.ph</em></a><em> on January 15, 2016.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa5c51239d29" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Siargao — Cloud 9]]></title>
            <link>https://medium.com/@eshlee/siargao-cloud-9-5bd5f49de663?source=rss-787b772bd6ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bd5f49de663</guid>
            <category><![CDATA[travel]]></category>
            <category><![CDATA[surfing]]></category>
            <dc:creator><![CDATA[Esh Romero]]></dc:creator>
            <pubDate>Wed, 06 May 2015 14:22:17 GMT</pubDate>
            <atom:updated>2016-09-06T13:53:46.892Z</atom:updated>
            <content:encoded><![CDATA[<p>Siargao — Cloud 9</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mqlWATduebLKnQJH.jpg" /></figure><p>So we went here April 2015. Hoping that I can try surfing. But after reaching this place, in great fear and awe, I said no, not yet. This place is truly amazing. I thought only a surfer, can appreciate the place but I was wrong. There are lots of things you can do in this place. In fact, watching the huge waves forming like number 9 while surfers riding on top of it will make you feel relaxed and wonder.</p><p><em>Originally published at </em><a href="https://blog.esh.ph/2015/05/siargao-cloud-9/"><em>blog.esh.ph</em></a><em> on May 6, 2015.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bd5f49de663" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>