<?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 Bao Huynh on Medium]]></title>
        <description><![CDATA[Stories by Bao Huynh on Medium]]></description>
        <link>https://medium.com/@huynhthaibao07?source=rss-297808c6105d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*gHc13ON4Yu2ik8hWbA_ZmA.jpeg</url>
            <title>Stories by Bao Huynh on Medium</title>
            <link>https://medium.com/@huynhthaibao07?source=rss-297808c6105d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 21:23:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@huynhthaibao07/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[CI/CD: Boosting your pipeline’ speed up to x3 times]]></title>
            <link>https://faun.pub/ci-cd-boosting-your-pipeline-speed-up-to-x3-times-86a6c6ad46c9?source=rss-297808c6105d------2</link>
            <guid isPermaLink="false">https://medium.com/p/86a6c6ad46c9</guid>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[gitlab-ci]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Bao Huynh]]></dc:creator>
            <pubDate>Sun, 06 Oct 2019 16:30:20 GMT</pubDate>
            <atom:updated>2019-10-20T17:22:21.560Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Long build-time pipeline issue</h3><p>For months, developers have been complain with me about waiting for dockerization pipeline so so long. It really reduces the productivity of dev teams by trapping them in long waiting queue before moving to deploy stage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*AwjO71eHOup8R5yJkmB4aA.png" /></figure><p>It’s easy to realize that upgrading HW for gitlab-runner / jenkins slave does not help in this case. That’s why we have to look deeper in this case.</p><h3>2. Why is your build surprisingly slow</h3><p>By default, every pipeline will be started from scratch, which means dependencies will be pulled again and again every time. That unnecessary repetitive pulling results in making the build so <strong><em>SLOW.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A8kCffHLb9Fili_KKJF4aA.png" /></figure><p>We all know that if using cache layer in docker will speed up the building process, that’s could be achieved easily on local machine.</p><p>But how could we achieve that on remote gitlab-runners machine (by default, Gitlab does not cache anything for pipelines).</p><h3>3. The solution: dependencies caching</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KD1DbAZWMqMBuo0a-SqDAg.png" /><figcaption>Speed the pipeline up — Credit by Shutterstock / Nikifor Todorov</figcaption></figure><h4>3.1 Simple case: caching for normal builds</h4><p>Fortunately, <strong>“--from-cache”</strong> option from docker gives us the power to speed up pipeline on runners. This option will tell “docker build” command to get cache from <em>existing docker image locally.</em></p><blockquote><em>“What ? local existing docker image ? If pipeline start from scratch, where can we get that ?”</em></blockquote><p>The answer is: If we don’t have, we will create it in advance and pull it right before “docker build” command execution.</p><pre>- docker pull $MY_IMAGE:latest  || true<br>- docker build --target runtime-image --cache-from $MY_IMAGE:latest -t $MY_IMAGE:$VERSION -t $MY_IMAGE:latest .</pre><p>The “|| true” ensures the build will pass the first time you run it, since in that case the pull will fail.</p><p>Here is an complete example .gitlab-ci.yml for pipeline with “dependencies caching”</p><pre>variables:<br>  MY_IMAGE: docker.mycompany.org/sso</pre><pre>stages:<br>- dockerize<br>- deploy</pre><pre>dockerize:<br>  stage: dockerize<br>  script:<br>  # Pull the cache image =&gt; populate the cache<br>  - docker pull $MY_IMAGE:uat_latest  || true</pre><pre>  # Build docker image from cache:<br>  - docker build --target runtime-image --cache-from $MY_IMAGE:uat_latest -t $MY_IMAGE:$VERSION -t $MY_IMAGE:uat_latest .</pre><pre>  # Push the version<br>  - docker push $MY_IMAGE:$VERSION<br>  - docker push $MY_IMAGE:uat_latest<br>  tags:<br>  - shell<br>  only:<br>  - uat</pre><h4>3.2 Frequent use case: multi-stage docker</h4><ul><li>Most developers utilize <a href="https://docs.docker.com/develop/develop-images/multistage-build/">mult-stage</a> docker build for image size optimization.</li><li>Using the same pipeline in <em>3.1</em> won’t help to achieve caching for whole layers, it only have caching layer for latest image base. The earlier will be missing and your pipeline is still not completely improved.</li></ul><p>To achieve caching for earlier layers, we have to push &amp; pull for every image-based in each stage (suppose we have 2 image-based: <strong><em>uat_builder</em></strong> and <strong><em>uat_latest</em></strong>). Below .gitlab-ci.yml demonstrates on how to do it:</p><pre>variables:<br>  CI_IMAGE: docker.mycompany.org/sso</pre><pre>stages:<br>- dockerize<br>- deploy</pre><pre>dockerize:<br>  stage: dockerize<br>  script:<br>  # Pull the cache image =&gt; populate the cache<br>  - docker pull $CI_IMAGE:uat_builder || true<br>  - docker pull $CI_IMAGE:uat_latest  || true</pre><pre>  # Build docker image from cache:<br>  - docker build --target builder --cache-from $CI_IMAGE:uat_builder --tag $CI_IMAGE:uat_builder .<br>  - docker build --target runtime-image --cache-from $CI_IMAGE:uat_builder --cache-from $CI_IMAGE:uat_latest -t $CI_IMAGE:$VERSION -t $CI_IMAGE:uat_latest .</pre><pre># Push the new version:<br>  - docker push $CI_IMAGE:$VERSION<br>  - docker push $CI_IMAGE:uat_builder<br>  - docker push $CI_IMAGE:uat_latest<br>  tags:<br>  - shell<br>  only:<br>  - uat</pre><pre>......</pre><p><strong>Explanation: </strong>below tables summarizes caches that our final image get from:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FYhzmYxsVEWVtm3Cg6JaZQ.png" /></figure><h3>4. RESULT SHOWS UP</h3><p>Tada !… Time reduce significantly: 8min → nearly 1min30s (~70% in improvement)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SiAEVcY9RdQLCGFQE6XwVg.png" /><figcaption>Time-built comparison before &amp; after using “Caching Dependencies”</figcaption></figure><p>We can see that “dependencies installation” (step 7+8+9) has been cached, results in so much time reduction.</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=86a6c6ad46c9" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/ci-cd-boosting-your-pipeline-speed-up-to-x3-times-86a6c6ad46c9">CI/CD: Boosting your pipeline’ speed up to x3 times</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[Passing Certified Kubernetes Administrator: My lessons learned]]></title>
            <link>https://faun.pub/passing-certified-kubernetes-administrator-exam-tips-d5107d8e3e7b?source=rss-297808c6105d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5107d8e3e7b</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[certificate]]></category>
            <category><![CDATA[cka]]></category>
            <dc:creator><![CDATA[Bao Huynh]]></dc:creator>
            <pubDate>Sun, 06 Oct 2019 03:17:23 GMT</pubDate>
            <atom:updated>2019-10-23T14:55:51.162Z</atom:updated>
            <content:encoded><![CDATA[<p>Passing Certified Kubernetes Administrator (CKA) is not really difficult as most people though. Let’s see how to get it !</p><p>Well-prepared &amp; good strategies are the keys to achieve the certificate easily. Here are all of the lessons learned with my CKA journey.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lDB5AntLmMw86uGjdIEHgA.png" /><figcaption>Certified Kubernetes Administrator Certificate issued by CNCF</figcaption></figure><h3><strong>Before the exam</strong></h3><p><strong>1. Knowledge recall</strong></p><p>People should review their knowledge for a comprehensive exam like CKA. Although I have been working work K8S for nearly a year, but some section K8S which is not frequently used takes me a lot of time to tackle.</p><blockquote>For me, 3 weeks with <a href="https://www.udemy.com/course/certified-kubernetes-administrator-with-practice-tests/"><strong>Udemy</strong></a> course with practice tests is completely necessary. It won’t take long to help you to realize that how helpful the course is.</blockquote><p><strong>2. Better memory, better debugging skill</strong></p><p>Although CKA online courses explain everything very well, but how many of them will stay in your mind until the exam day ?</p><p>It’s better to have your own note about what you’ve learned. Taking your own note always make your brain to memorize better than ever. Here is mine:</p><blockquote><a href="https://github.com/baohuynh09/CKA-knowledge-note">https://github.com/baohuynh09/CKA-knowledge-note</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3sSx5eamS3C11McECzMp6g.png" /><figcaption>Take note for longer memory</figcaption></figure><p><strong>3. Practice, practice &amp; practice</strong></p><p>Yes, practice is the key !</p><p>The more <em>practice</em> you do, the more <em>confidence</em> you get.</p><h3><strong>CKA Curriculum &amp; Weights</strong></h3><p><a href="https://github.com/cncf/curriculum">CKA Exam Curriculum</a> is the official document from CNCF with detailed weight on each domain of Kubernetes. Focus on sections with highest score but don’t forget the others.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hFvvNCHU1M24jJtWgfIAfA.png" /><figcaption>CKA Curriculum by CNCF Publication</figcaption></figure><p><strong><em>There is no doubt that people are so curious about REAL questions in my CKA exam ? Here they are :D</em></strong></p><ul><li><a href="https://kubernetes.io/docs/tasks/administer-cluster/configure-upgrade-etcd/"><strong><em>Create-backup / restore-backup cluster data</em></strong></a> with ETCD server via TLS connection. Try to remember options with create-backup/restore-backup command (since they’re not listed fully in CKA document, especially for restore-backup command !!!)</li><li>Query resources metadata with <a href="https://kubernetes.io/docs/reference/kubectl/jsonpath/"><strong><em>jsonpath</em></strong></a>: CKA exam takes me to surprise when requiring up to 5 questions that involves <em>jsonpath</em> skill to solve the problem. If you don’t familiar with <em>jsonpath, </em>go for it right now !</li><li><a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/"><strong><em>DNS for pods &amp; service</em></strong></a><strong><em>s</em></strong>: you should understand how DNS is implemented in K8S cluster. <em>Try to resolve the service-name &amp; pod-name</em> by your own (with <em>nslookup</em> command).</li><li><a href="https://kubernetes.io/docs/tasks/configure-pod-container/static-pod/"><strong><em>Deploy pod without using kube-scheduler</em></strong></a>: differentiate the difference between static pod / dynamic pod.</li><li><strong><em>CLEARLY understand working mechanism &amp; configuration of K8S cluster components</em></strong> (etcd servers, api-server, kubelet,…) Some of the debugging questions you will see in the exam are:</li></ul><p><em>debugging why “kubectl get pods” does not work (api-server is not listening)</em></p><p><em>debugging why deployment can not be scaled (kube-controller-manger issued)</em></p><p><em>debugging why pods is pending for long time (kube-scheduler issued),</em></p><p><em>etc,…..</em></p><p>Wanna solve above debugging question in couple of minutes ? I think there’s <em>no way better</em> <em>than</em><strong> </strong>understand their configs &amp; working mechanism as much as possible.</p><h3>During the exam (tips &amp; tricks)</h3><p><strong>1. Alias save time</strong></p><p>CKA requires lots of practice &amp; debugging skill using kubectl commands. Using alias is always on top of my favorite selection for time saving method. Put below aliases in <em>~/.bashrc</em> and start making friend with it.</p><pre># Get K8S resources<br>alias k=&quot;kubectl&quot;<br>alias kp=&quot;kubectl get pods -owide&quot;<br>alias kd=&quot;kubectl get deployment -o wide&quot;<br>alias ks=&quot;kubectl get svc -o wide&quot;<br>alias kn=&quot;kubectl get nodes -owide&quot;</pre><pre># Describe K8S resources <br>alias kep=&quot;kubectl describe pod&quot;<br>alias ked=&quot;kubectl describe deployment&quot;<br>alias kes=&quot;kubectl describe service&quot;</pre><p><strong>2. Calibrate your time per question</strong></p><ul><li>24 questions for 3 hours, that means ONLY <strong>7 mins</strong> should be used for each question.</li><li>Scan through the question quickly, if the answer appears in your mind immediately, go for it. Otherwise, skipping to next questions is always a good choice.</li></ul><p><strong>3. “Note”: your brain’s best friend during exam time</strong></p><p>Don’t underestimate your <strong>Note</strong>. You will find it very very useful, especially in case: “<em>Record your skipping questions</em>”. Back to these questions when others are completed.</p><p><strong>4. Make sure you’re on the right Cluster for each question</strong></p><pre>kubectl config use-context &lt;context_name&gt;</pre><ul><li><strong>ALWAYS</strong> do above command before tackling any question (since there are 6 clusters used in the exam). Working on wrong cluster definitely pushes you into the panic &amp; wasting your remaining time.</li><li>During the exam, on top of the question, there is always an instruction on how to switch to corresponding cluster</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AUhV2TitEJDOheTRzg5qLA.png" /><figcaption>Multi clusters with different contexts</figcaption></figure><p><strong>5. Mastering Vim boots your speed</strong></p><p>During the exam, test takers are requested to manipulate declarative yaml files to create/update K8S resources (change replicas, name, add volumeMount, etc,…).</p><p>Being familiar with Vim plays an important role in getting everything done smoothly with manifest files. Some of actions usually taken in Vim are:</p><ul><li><em>Cursor navigation</em> (up, down, left, right, jumping word-by-word, to-end-of-line, to-beginning-of-line,…)</li><li><em>Delete</em> a word or the whole line</li><li><em>Replace</em> multiple words (using sed)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lyb_4a66FSJ3DW9IOJWkCQ.png" /><figcaption>Vim is the only editor you get during the exam</figcaption></figure><p><em>Note</em>: Not familiar with Vim ? Don’t worry, open console, then “vimtutor” will make you become an guru soon.</p><p><strong>6. Failure on updating K8S resources on-the-fly</strong></p><ul><li>Sometimes you will find it impossible to update yaml files of K8S resource (service, deployment, pod,…) on-the-fly.</li><li>The reason is your updated config conflicts with current config (as indications on lines starting with #) and your new change will be discard when exit editing.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NsNiB8Crw60vRvvMrA16mg.png" /></figure><p>But for some reason, you still need to try out with your new config. How to get it done ? It quite easy. Actually, your new config is not completely removed as it is was saved in tmp folder (“/var/folders/fm/” in my case).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RAFXrNGpCDgLcdMlRXU9PA.png" /></figure><p>Just delete your current deployment and then deploy with new one from /var/folder/fm/x32pzcgn…</p><pre>$ kubectl delete deployment &lt;deployment_name&gt;</pre><pre>$ kubectl create -f /var/folder/fm/x32pzcgn/....</pre><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=d5107d8e3e7b" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/passing-certified-kubernetes-administrator-exam-tips-d5107d8e3e7b">Passing Certified Kubernetes Administrator: My lessons learned</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[Maximize your gitlab-runner power with  CI/CD concurrent pipelines]]></title>
            <link>https://faun.pub/maximize-your-gitlab-runner-power-with-ci-cd-concurrent-pipelines-a5dcc092cee7?source=rss-297808c6105d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5dcc092cee7</guid>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[gitlab-runner]]></category>
            <dc:creator><![CDATA[Bao Huynh]]></dc:creator>
            <pubDate>Sun, 04 Aug 2019 11:05:28 GMT</pubDate>
            <atom:updated>2019-10-20T17:24:17.521Z</atom:updated>
            <content:encoded><![CDATA[<h3>Maximize your gitlab-runner power with CI/CD concurrent pipelines</h3><h3>1. Gitlab-runner 101</h3><p>Gitlab-runners are responsible for pipeline execution requested from Gitlab server. There are many configurations out there but in this post, we just focus on concurrency pipeline settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5c0WBSvqaIMlGkS_OlJEww.png" /><figcaption>Gitlab: great tools for Git solution &amp; CICD pipelines</figcaption></figure><p>Natively, all of the gitlab-runner information (name, registered token, executor type, shell…) are listed in/etc/gitlab-runner/config.toml</p><pre>listen_address = &quot;0.0.0.0:9252&quot;<br>check_interval = 0</pre><pre>[[runners]]<br>  name = &quot;gitlab-runner-v10-20-[executor-1]&quot;<br>  url = &quot;<a href="https://git.chotot.org/ci">https://git.mycompany.org/ci</a>&quot;<br>  token = &quot;45148ba493352311234sfdfdfdf&quot;<br>  executor = &quot;shell&quot;</pre><h3>2. Concurrency pipeline issue…..</h3><p>When my dev team is at small size, the pipeline is quite light &amp; not take long time to complete. Moreover, not so many pipelines run in parallel. 3 gitlab-runners running separately with default configuration (like above one) always make them happy.</p><p>It comes to trouble when team grows up resulting in number of pipeline increase rapidly. Nearly one third of their pipeline stuck in “<em>pending</em>” state (waiting in the queue until there’s ready runner picking up). They’re continuously pinging at me:</p><blockquote>Why is my pipeline hanging for 20 mins ? What’s wrong with those runners ?</blockquote><p>Checking all the runners immediately but they’re still healthy, resources (RAM + CPU) are underused.</p><p>However, it’s easy to realize that each of them pick only ONE job at a specific time. That’s the root cause</p><blockquote>Stuck with too many concurrent pipelines …….</blockquote><h3>3. Here comes the solution</h3><p>Gitlab provides us lots of configuration for gitlab-runner</p><p><a href="https://docs.gitlab.com/runner/configuration/advanced-configuration.html">Advanced configuration | GitLab</a></p><p>In our case, 3 important options are:</p><ul><li>concurrent (<em>global section</em>): limits how many jobs globally can be run concurrently….That means, it applies to all the runners independently of the executor [docker, ssh, kubernetes etc]</li><li>limit (<em>runner section</em>): Limit how many jobs can be handled concurrently by this token. Suppose that we have 2 runners registered by 2 different tokens, then its limit could be adjusted separately : runner-one limit = 3, runner-two limit =5,…</li><li>request_concurrency (<em>runner section</em>): Limit number of concurrent requests for new jobs from GitLab (default 1)</li></ul><p>Below spec will help us to understand clearly about 3 options</p><pre>root@gitlab-runner-v9-18:~# cat /etc/gitlab-runner/config.toml<br>listen_address = &quot;0.0.0.0:9252&quot;<br><strong>concurrent = 6<br></strong>check_interval = 0</pre><pre>[session_server]<br>  session_timeout = 1800</pre><pre>[[runners]]<br><strong>  limit = 3<br>  request_concurrency = 3<br></strong>  name = &quot;gitlab-runner-v9-18-[executor-1]&quot;<br>  url = &quot;<a href="https://git.chotot.org/ci">https://git.mycompany.org/ci</a>&quot;<br>  token = &quot;abcdef3a95c29874d803f5eaef10&quot;<br>  executor = &quot;shell&quot;</pre><pre>[[runners]]<br><strong>  limit = 3<br>  request_concurrency = 3<br></strong>  name = &quot;gitlab-runner-v9-18-[executor-2]&quot;<br>  url = &quot;<a href="https://git.chotot.org/ci">https://git.mycompany.org/ci</a>&quot;<br>  token = &quot;abdefccc6507f4d22b853977df2f094&quot;<br>  executor = &quot;shell&quot;</pre><p>With above specs, one gitlab-runner hosts now could run in parallel up to 6 jobs concurrently (2 runners, and each runner have 3 sub-process)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VuagLqItrNm3G0TP760YsQ.png" /><figcaption>Multi runners on the same host</figcaption></figure><p>Note: don’t put too much limits (10,15,…) per runners. It sometimes results in unexpected corruption for your CI job (ie: network timeout, disk i/o timeout,…)</p><h3>4. Monitor your gitlab-runners</h3><p>It’s very nice of gitlab to integrate metrics exporter natively in the gitlab-runner package as well. To get metrics exposed to Prometheus, simply declareport9252 (or whatever) in fieldlisten_address inconfig.yaml</p><pre>root@gitlab-runner-v9-18:~# cat /etc/gitlab-runner/config.toml<br>listen_address = &quot;0.0.0.0:<strong>9252</strong>&quot;<br>check_interval = 0</pre><p>Metrics should be visible under http://&lt;gitlab-runner-ip&gt;:9252/metrics.</p><p>Get those metrics visualized on Prometheus for monitoring</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YD0NI4co6JrR9mOCWnyplg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l50YA8hsRlGUealz6M0NPQ.png" /></figure><p><em>NOTE</em>: There are many metrics but we should focus on Error Total N (accumulative metrics) and Request Concurrency. If Error Total N is so high (100–200 or above), means that there’s problem with your runner’s resources / network…</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=a5dcc092cee7" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/maximize-your-gitlab-runner-power-with-ci-cd-concurrent-pipelines-a5dcc092cee7">Maximize your gitlab-runner power with  CI/CD concurrent pipelines</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[Terraform: remove element from EC2 list without destroying others when “terraform plan” again]]></title>
            <link>https://faun.pub/terraform-remove-element-from-ec2-list-without-destroying-others-when-terraform-plan-again-dbfe1ed291b4?source=rss-297808c6105d------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbfe1ed291b4</guid>
            <category><![CDATA[tips-and-tricks]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Bao Huynh]]></dc:creator>
            <pubDate>Wed, 23 Jan 2019 16:54:39 GMT</pubDate>
            <atom:updated>2019-10-21T17:17:57.694Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>1. When removing element from a list of instance with Terraform…</strong></h3><p>I believe that everyone encountered this problem once when managing resources with terraform, so did I. Below is my share after some hours of investigation and testing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/0*9bk_tZYM0uItKe-h" /></figure><p>Normally, terraform manages element with index. Therefore, remove an element in the list will also affect the rest. For example: have 4 instances name mongo-server as below</p><pre>aws_instance.mongo-server[0]<br>aws_instance.mongo-server[1]<br>aws_instance.mongo-server[2]<br>aws_instance.mongo-server[3]</pre><p>I need to destroy mongo-server[1] for some reason (saving cost, corrupt data,…). This could be achieved easily with “terraform destroy” command as below:</p><pre>terraform destroy — target aws_instance.mongo-server[1]</pre><p>Of coures, records for mongo-server[1] is removed from tfstate file………But, wait, what happen when you update again with “terraform plan” ?</p><pre>Destroy below instances:<br>- aws_instance.mongo-server[2]<br>- aws_instance.mongo-server[3]</pre><pre>Add new instances:<br>+ aws_instance.mongo-server[1]<br>+ aws_instance.mongo-server[2]</pre><p>Terraform destroy &amp; re-create mongo-server[2] &amp; [3] although there’s no changes were made on it ? Why, terraform why ?</p><p><strong><em>The answer:</em></strong> terraform manages instances based on index, which is assign to each of them during creation. When there’s changes in list of index, the rest will be updated:</p><p>In our example</p><p>List of index after creation:</p><pre>00 01 02 03</pre><p>After deletion mongo-server[1]:</p><pre>00     02 03</pre><p>Hence, terraform will abandon“02 03” index and reassign to “<strong>new</strong> 01 02” to get index list going continuously.</p><p>This really annoys us when others instances and we have to deploy our platform/service to get our everything back. That’s really a nightmare when you have hundreds or thousands instances along with the list.</p><h3><strong>2. When magic happens…</strong></h3><p>To overcome, here is the tricks</p><blockquote>using” terraform state mv” to swap the needed-delete-one with the last.</blockquote><p>Ex: in our example, we want to remove mongo-server[1]. Therefore, we swap it with the last one (mongo-server[4]).</p><pre>terraform state mv aws_instance.mongo-server[1] aws_instance.mongo-server[99]<br>terraform state mv aws_instance.mongo-server[4] aws_instance.mongo-server[1]<br>terraform state mv aws_instance.mongo-server[99] aws_instance.mongo-server[4]</pre><blockquote>reduce the instances count → terraform will delete the last one (biggest index) → that’s the element we already swapped in previous step.</blockquote><pre>variable &quot;ec2_number_of_instances&quot; {<br>description = &quot;Number of ec2 instances on aws&quot;<br>default     = &quot;3&quot; &lt;---- reduce to 3 instances<br>}</pre><p>Let’s “terraform plan” to see the magic.</p><p>Tada ! Terraform only destroy the needed, the others are not affected. So cool, right ? Hope you find this tricks useful :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*OCeWAfnNdgGQZF_PQsePYw.jpeg" /></figure><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=dbfe1ed291b4" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/terraform-remove-element-from-ec2-list-without-destroying-others-when-terraform-plan-again-dbfe1ed291b4">Terraform: remove element from EC2 list without destroying others when “terraform plan” again</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[Continuous Integration (CI) get easy more than ever with Github + TravisCI + GKE/GCR]]></title>
            <link>https://medium.com/@huynhthaibao07/continuous-integration-ci-get-easy-more-than-ever-with-github-travisci-gke-gcr-87c844fb871e?source=rss-297808c6105d------2</link>
            <guid isPermaLink="false">https://medium.com/p/87c844fb871e</guid>
            <category><![CDATA[travis-ci]]></category>
            <category><![CDATA[gke]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[ci]]></category>
            <dc:creator><![CDATA[Bao Huynh]]></dc:creator>
            <pubDate>Wed, 16 Jan 2019 17:00:34 GMT</pubDate>
            <atom:updated>2019-01-23T16:42:29.050Z</atom:updated>
            <content:encoded><![CDATA[<h3>Continuous Integration (CI) get easier than ever with Github + TravisCI + GKE/GCR</h3><h3><strong>1. Reasons for choices</strong></h3><p><strong>1.1 Why Github</strong></p><ul><li>Widely expose with OSS project, great places to link other open-source public project.</li><li>Support multi-platform CICD (Travis, CircleCI, Codeship..)</li><li>Currently support private repo for free</li></ul><figure><img alt="Image result for travis ci" src="https://cdn-images-1.medium.com/proxy/1*U5euNs758Jx_ND9uVq1TDg.png" /><figcaption>Figure 1: TravisCI &amp; Github</figcaption></figure><p><strong>1.2 Why TravisCI</strong></p><p>There’s many CI tools out there but for some reason, TravisCI is rising as a best choice for us at the moment:</p><ul><li>Support <em>popular</em> yaml style for configuration. It’s even get easier when switch to other yaml-based CI platform (GitlabCI, CircleCI,..)</li><li>Integrate nicely with github</li><li>Flexible with user’s choice: serverless worker (community edition) or on-premis worker (enterprises edition)</li></ul><h3>2. What we need ?</h3><ul><li><em>Github</em>: repositories for managing code with version control</li><li><em>TravisCI</em>: CI platform (like gitlab-ci, jenkins-ci,…)</li><li><em>GCR</em> (<em>Google Container Registry</em>): public container registry</li><li><em>GKE</em> (<em>Google Kubernetes Engine</em>): Kubernetes cluster provided by Google</li></ul><p>This note will guide how to integrate all above platforms to have full CI procedure with least effort</p><h3>3. Setting-up perquisites</h3><p><strong>3.1 Github</strong></p><ul><li>Create an account on GitHub + put your code on GitHub repo .</li></ul><p><strong>3.2 TravisCI</strong></p><ul><li>Login <a href="https://travis-ci.com/">https://travis-ci.com/</a> with your GitHub account + follow guidance to link GitHub &amp; TravisCI pipeline → From now on, every commits pushed to Github will trigger CI automatically on TravisCI (with configuration in <em>.travis.yml)</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ePLscuLiaSAk--yTGqx-dw.png" /><figcaption>Figure 2: Acitve repositories linked from my Github account</figcaption></figure><p><strong>3.3 GCR/GKE (Google Container Registry/Google Kubernetes Engine)</strong></p><ul><li>GCR: registry for storing docker image. Please register a project on GRC in advance:</li><li>GKE: Kubernetes cluster on GCP. GCP will handle master nodes, while workers are taken care by us. Creating GKE cluster details: <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-cluster">https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-cluster</a></li></ul><p><strong>3.4 CI Procedure Workflow</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aAzouNSCbWRRlkoEKSfxTA.png" /><figcaption>Figure 3: CI procedure workflow</figcaption></figure><h3>4. Authentication with GKE</h3><blockquote><a href="https://cloud.google.com/kubernetes-engine/docs/how-to/role-based-access-control"><strong>https://cloud.google.com/kubernetes-engine/docs/how-to/role-based-access-control</strong></a></blockquote><p>As stated, <strong>two levels of authentication</strong> must be provided in order to deploy any k8s app on GKE:</p><ul><li>Authenticate with GCP via <strong>IAM</strong> <strong>service-account</strong> (permission for accessing GKE <strong><em>clusters</em> </strong>&amp; other resources + GCR for pushing/pulling image)</li><li>Authenticate with GKE via <strong>RBAC</strong> (permission for resource-accessibility on each GKE cluster)</li></ul><p><strong>4.1 GCP IAM Service-account</strong></p><p>Visit <a href="https://console.cloud.google.com/iam-admin/iam">https://console.cloud.google.com/iam-admin/iam</a> to provide accessibility for new <strong><em>Service-account</em></strong></p><ul><li>Add role “Storage Object Admin” for GCP Service-account → access storage, specifically Google Container Registry (GCR)</li><li>Add role “Kubernetes Engine Developer” → access GKE cluster</li></ul><blockquote>Service-account will be granted permission as “<strong>roles/container.developer</strong>” (full access to Kubernetes API objects inside Container Clusters)</blockquote><p><em>More roles defined here: </em><a href="https://cloud.google.com/iam/docs/understanding-roles#predefined_roles">https://cloud.google.com/iam/docs/understanding-roles#predefined_roles</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aTeNJPLW_fGQJZT9dqf2BA.png" /></figure><ul><li>Grants permission with roles/container.developer (make sure that the person who runs this command is “GCP account owner”)</li></ul><p>gcloud projects add-iam-policy-binding &lt;your-project-name&gt; --member &lt;your-service-account-identity&gt; --role roles/container.developer</p><ul><li>Check again to ensure roles is granted to Service-account</li></ul><p>gcloud iam service-accounts get-iam-policy &lt;your-serivce-account-identity&gt;</p><p><strong>4.2 GKE RBAC (Role-based access control)</strong></p><ul><li>Grant K8S RBAC permission to Service-account “Tiller” (<a href="https://github.com/fnproject/fn-helm/issues/21">https://github.com/fnproject/fn-helm/issues/21</a>) (create once so run those at local machine, not in .travis.yml)</li></ul><p>Please make sure that account running below command have “cluster-admin” along with its “clusterrole”. Otherwise, please ask your GCP account owner for granting permission.</p><pre># Authenticate<br>$ gcloud container clusters get-credentials &lt;your-GKE-cluster-name&gt; --zone &lt;zone-of-GKE-cluster&gt; --project &lt;your-project-name&gt;</pre><pre># Create serviceaccount tiller<br>$ kubectl create serviceaccount --namespace kube-system tiller<br>$ kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller</pre><p><strong>4.3 Insert credentials of GCP Serviceaccount to TravisCI</strong></p><ul><li>After creating GCP Service-account, download that credentials JSON key to local machine</li><li>Get base64 code of secret JSON file:</li></ul><pre>$ base64 project-name-abcxyz123.json →  output: &lt;key_64based&gt;</pre><ul><li>Back to page TravisCI → Travis Setting → Add Environment Variables</li></ul><pre>“GCLOUD_SERVICE_KEY_STG=&lt;key_64based&gt;” (revoke later in .travis.yml for GCP authenticate)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*9ZCWm08I8G27N3VqLJeFfw.png" /><figcaption>Figure 4: Insert credentials for authentication with GCP</figcaption></figure><h3>5. travis.yml configuration for TravisCI</h3><p><strong>5.1 GCP authentication flow</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s4xZcXltO_tQlx5Wd8HCUA.png" /><figcaption>Figure 5: GCP authentication flow</figcaption></figure><p><strong>5.2 Configuration for TravisCI</strong></p><p>Authenticate and deploy on GKE with Helm (.travis.yml)</p><pre>env:<br>GKE_cluster_name= &lt;your_cluster_name&gt;<br>GKE_zone=         &lt;zone_of_your_cluster&gt; <br>GKE_project_id=   &lt;ID_of_your_project&gt;</pre><pre>script:<br># Main code to authenticate with GCP<br>- echo $GCLOUD_SERVICE_KEY_STG | base64 --decode -i &gt; ${HOME}/gcloud-service-key.json<br>- gcloud auth activate-service-account --key-file ${HOME}/gcloud-service-key.json<br>- gcloud components install kubectl</pre><pre># Deploy with helm<br>- gcloud container clusters get-credentials $GKE_cluster_name --zone $GKE_zone --project $GKE_project_id<br>- helm install -n first-deployment helm</pre><p><strong>5.3 Demo time :)</strong></p><p>Yolo, time for demo ! Push some commits to Github and get TravisCI does all the rest for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6eAu0BsOUd2uRng3_1cBUA.png" /><figcaption>Figure 6: Job build console</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2-IP8SQHF58tnhVSjn6VHg.png" /><figcaption>Figure 7: Successful build with 2 stages (Dockerize and Deploy_app)</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87c844fb871e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>