<?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 Ahmet Türkmen on Medium]]></title>
        <description><![CDATA[Stories by Ahmet Türkmen on Medium]]></description>
        <link>https://medium.com/@mrturkmen?source=rss-83cc93a775d1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WOZRmKaBFrB7yF4iyGAYSg.jpeg</url>
            <title>Stories by Ahmet Türkmen on Medium</title>
            <link>https://medium.com/@mrturkmen?source=rss-83cc93a775d1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 22:26:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mrturkmen/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[rejection]]></title>
            <link>https://mrturkmen.medium.com/rejection-9a3b8555c843?source=rss-83cc93a775d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a3b8555c843</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[interview-tips]]></category>
            <category><![CDATA[technical-interview]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[faang]]></category>
            <dc:creator><![CDATA[Ahmet Türkmen]]></dc:creator>
            <pubDate>Mon, 09 Dec 2024 09:00:31 GMT</pubDate>
            <atom:updated>2024-12-09T22:41:07.920Z</atom:updated>
            <content:encoded><![CDATA[<p>What I like about interviews is that they can directly show your weaknesses to you. When you think about a friend, girlfriend, parents and even your teacher, they all might say that you are great. Well, maybe you are really good at what you do but hearing it from someone who has objective views on you is very effective. It is all about trade offs. Here, objective views refer to from the perspective of conducting interviews to you, it will not be fair to have your closest friend as interviewer. All judgment is done based on your technical skills rather than personal thoughts. Sure, you do not want to hear bad judgments from your close friends, girlfriend or parents. However you might still want to see your value in industry independently from what your friends, parents think about. Therefore, I started interviewing with companies to find my weaknesses and desired job.</p><p>I have been rejected by many companies even before the screening, and an automated message appears at your inbox daily :) At the beginning, you feel upset, but once you see the general situation, you start to get used to it. I mean, there are some ridiculous job advertisements which request more than six years of experience on certain technologies but recruiting you as an intern. Despite all these scenarios, it is still not easy to get to the first stage. Nevertheless, I had some full time position interviews in the past. At least four of them took around 5–6 hours of technical interview with different people each hour. The last one was not an exception, it took seven hours, and I am glad to have this interview regardless of its result.</p><p>I recently had an interview at one of the MAANG companies. I can say that I really liked the process, all the people in the interview were so nice. Due to the time difference, it was a little bit difficult to arrange interview hours but it was managed thanks to their understanding and effort. It provided me with lots of “aha” moments, I understood my existing strengths and weaknesses even though it was painful. I had a chance to meet and talk with great people, in particular with ones who worked on a topic which is close to my master thesis topic. After hours of interviews and waiting for the result, I have been rejected for the position. Of course, there might be many reasons behind the rejection, I can easily think and to be honest the first thing comes to mind, being not good enough. It might be true actually, even though it might be difficult to accept, however it might not be true as well. The trick I guess, keep continuing to apply and get interviews then eventually you will see whether it is true or not.</p><p>Except for the unexpected, I have seen a discussion on quota and I would like to quote an argument from there, I totally agree on this argument.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*6usrzbpfb0Zeby0a.png" /></figure><p>The last interview was composed of all areas in computer science; architecturing, system design, programming, multi-thread programming, however at each step, there was live coding. People are thinking with you on live coding and trying to help you to understand the concept as well as they try to understand how you think. Attitudes of the people were always positive, at least in my experiences. The small details matter when it comes to detailing a concept, programming or understanding the question. Understanding the process of what actually has been asked can be fastened by practicing the questions on leetcode, hackerrank, and other similar websites. Watching videos on Youtube about some concepts is beneficial however they do not really assist you in detailing a concept, at least for me. Technical books, Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems, System Design Interview — An insider’s guide, Software Architecture: The Hard Parts and many more technical books provide theories behind certain technologies, more details which are asked in the interviews. Therefore, keeping a habit of reading them proactively while practicing on the coding questions websites ( leetcode, hackerrank) will provide all necessary knowledge. I missed some parts due to time constraints that I have at the moment ( -finishing up master thesis, studying, working, etc- ), however I will be back on track after some time. And at the end, a company will try to choose the person who is the best fit for the role :)</p><p>The outcomes from the failures that I experienced; invest in education, keep trying, work, work, work, no easy solution.</p><ul><li>Keep reading technical blogs and books</li><li>Practicing coding exercises ( even though for some cases this is not that critical)</li><li>Review code, check on popular Github repositories</li><li>Understand the details, focus on small points</li><li>Try to implement the theory that you have learned during your studies</li><li>Try to understand huge architectures by dividing the components</li><li>Reading should be careful, not just checking out, focusing on something which looks easy might make it harder to understand</li><li>Explain your learnings to someone who has no idea about what you are talking about, if they are just smiling, but no questions asked, then most probably you failed to explain, they are just acting nicely to you :)</li><li>Apply to the jobs which are relevant to you, do not apply blindly and expect to have returns.</li><li>When you have a rejection after long hours of interviews, do a post-mortem :) and focus the outcome of the post-mortem, then keep learning, applying and trying</li></ul><p>Good luck !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/0*gYKGIb-ht4LJprBF.png" /></figure><p><em>Originally published at </em><a href="https://mrturkmen.com/posts/rejection/"><em>https://mrturkmen.com</em></a><em> on December 9, 2024.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a3b8555c843" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[hot config reload with OS signal]]></title>
            <link>https://mrturkmen.medium.com/hot-config-reload-with-os-signal-d968fcfd3234?source=rss-83cc93a775d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/d968fcfd3234</guid>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[application-development]]></category>
            <category><![CDATA[golang-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Ahmet Türkmen]]></dc:creator>
            <pubDate>Sun, 18 Apr 2021 05:30:03 GMT</pubDate>
            <atom:updated>2021-04-19T00:55:07.924Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eOcW715AEc07mxhqO8Es3g.png" /></figure><p>Imagine a scenario where you have a monolithic application which uses a config file to store information about log directories, cert dirs and other service information. As an example to it following config file (- it is taken and modified from Haaukins project which I work on- ) can be considered:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4374f2b0e066b34941048b09bcc4850e/href">https://medium.com/media/4374f2b0e066b34941048b09bcc4850e/href</a></iframe><p>In this config file we have some set of keys which are defined to be used inside the application, however let’s say we would like to update some values from the config file. Then in normal cases (-if no hot reload kind of function implemented- ), user needs to restart entire application. It means application will have some down time, it may be less or more however it is not good way of doing it, in particular to update only a value from config file.</p><p>In this point, os signals can be used to update config file without restarting or closing the application. There are some other libraries which it is possible to enable watch on config file mode. It means the library will immediately notify entire application when there is change on the config file. However in this scenario, I assume that there is no such a library or framework is integrated.</p><p>Here I am considering the situation from Go language perspective, this may differ or not needed for some programming languages or frameworks.</p><p>Channel and go routine will be used to listen any SIGHUP signal to the process of the application.</p><p>First of all, it is nice to create the function which will re-assign config variable of the application when SIGHUP signal received.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc36e5a534c68ce38d1836e7b316fd38/href">https://medium.com/media/fc36e5a534c68ce38d1836e7b316fd38/href</a></iframe><p>When SIGNUP signal received by user given function above needs to be called to update configuration file.</p><p>Here is the code which listens any SIGHUP signal to the application</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/496caab1f7c685e7b63300a6da2630c2/href">https://medium.com/media/496caab1f7c685e7b63300a6da2630c2/href</a></iframe><p>This function can be called before or after the application started. It can be called as shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8aa24c1232fb9c85e802f4cf78a63f4/href">https://medium.com/media/c8aa24c1232fb9c85e802f4cf78a63f4/href</a></iframe><p>Then it can be tested with :</p><pre>kill -SIGHUP &lt;process-id&gt;</pre><p>It will create SIGHUP signal on the process to call ReloadConfig function.</p><p>This is how OS Signal can be used to update configuration file in an application which is written in Go, when you do not have already implemented library or framework.</p><p><em>Originally published at </em><a href="https://mrturkmen.com/posts/hot-reload-with-os-signals"><em>https://mrturkmen.com</em></a><em> on April 18, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d968fcfd3234" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[packer: build custom images on cloud and local]]></title>
            <link>https://mrturkmen.medium.com/packer-build-custom-images-on-cloud-and-local-85b04709f59e?source=rss-83cc93a775d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/85b04709f59e</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[amazon]]></category>
            <category><![CDATA[command-line]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Ahmet Türkmen]]></dc:creator>
            <pubDate>Sat, 17 Apr 2021 09:00:03 GMT</pubDate>
            <atom:updated>2021-04-19T00:40:36.113Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qJerJIwkeNlCMomP.png" /></figure><p>Build custom AMI on AWS</p><p><strong>THE REPOSITORY: </strong><a href="https://github.com/mrtrkmnhub/ubuntu-packer"><strong>https://github.com/mrtrkmnhub/ubuntu-packer</strong></a></p><p>In this blog post, provisioning and customizing images using packer will be shown with a template repository.</p><p>If you are asking or wondering what is Packer, the official definition is :</p><blockquote><em>Packer is a free and open source tool for creating golden images for multiple platforms from a single source configuration. (From Official Website).</em></blockquote><p>This post includes provisioning of ubuntu image on AWS and local.</p><p>In an ideal repository of Packer template, it would be nice to have a skeleton where it includes uploads, http, scripts folders along packer configuration file with a readme. Overall, the structure of folder might look like this :</p><pre>    ├── http<br>    │   └── preseed.cfg     <br>    ├── readme.md           <br>    ├── scripts             <br>    │   ├── cleanup.sh          # cleans up /tmp <br>    │   ├── install_tools.sh    # installs custom tools<br>    │   └── setup.sh            # setting up config in system wise<br>    ├── ubuntu-20.04.json       # packer config for ubuntu 20.04<br>    └── uploads                <br>        └── .gitkeep</pre><p>In this setup, http/preseed.cfg defines answers to the questions which may be asked during installation of Ubuntu operating system. More information regarding to <em>preseed.cfg</em> file can be checked from <a href="https://wiki.debian.org/DebianInstaller/Preseed">its wiki</a></p><ul><li>scripts folder composed of bash scripts, chef, ansible or any other installer configuration files or scripts which will install customized tools and define settings of ubuntu image.</li><li>uploads folder includes all files, deb packages, or any other files which will be copied to image which will be inside customized image.</li></ul><h3>Anatomy of Packer Configuration File</h3><p>Any packer file composed of three main components which are ;</p><p>Define the desired platform and platform configurations, including API Key information and desired source images. Example snippet is given from the Packer file:</p><p>In the builders config, we are defining some set of keys in JSON file, which are very obvious from its name, we are considering to build image locally. All the keys are important in given builders config however most important and might need to update time to time is iso_urls which are the places where packer download iamges and customize it according to your scripts. Another crucial key is to have headless value true which means that there will be no GUI running when packer command is executed to run the Packer JSON file.</p><h3>Provisioner</h3><p>Defines how to configure the image most likely by your using existing configuration management tools like Ansible, Chef, Puppet or pure bash scripts.</p><p>In our example, bash scripts will be provided to install tools and update configuration of ubuntu image to make it customized. Provisioner section of a Packer JSON file can be seen as below:</p><p>Here we are defining existing bash scripts in order to execute in the process of customizing Ubuntu image. The steps under provisioners are pretty clear.</p><h3>Post Processors</h3><p>Related to the builder, runs after the image is built, it is generally used to generate or apply artifacts. In this example, it is not required however more information can be found here: <a href="https://www.packer.io/docs/post-processors">post processors</a></p><h3>Communicator</h3><p>How packer works on the machine image during the creation. By default it is over SSH communication and it does not need to be defined explicitly. More information can be found here: <a href="https://www.packer.io/docs/communicators">communicator</a></p><p>Over all packer file can be seen as follow:</p><h3>How to run locally</h3><p>This file can be run from the place where <a href="https://github.com/mrtrkmnhub/ubuntu-packer/blob/master/on-local/ubuntu-20.04.json">ubuntu-20.04.json</a> file is located.</p><pre>$ packer build ubuntu-20.04.json</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tQEnOOaljLuaZwks.png" /></figure><p>It will start to build custom image by installing tools which are defined under scripts and configure username and password according to preseed.cfg and setup.sh files.</p><p>It is more practical and preferrable to use if you already have an cloud option to consider. This packer configuration will create custom image directly on cloud and save it to AMIs to your AWS account.</p><p>The anatomy of packer files is similar, only section which needs to be changed compared to local one, is builders section. It is defining all required AWS variables and AMIs to customize.</p><p>As an cloud example AWS will be used to create custom image.</p><h3>Builders on Cloud</h3><p>In this configuration, all keys are important to consider, however there are some which are crucial and required to run it. More information about the keys can be found here: <a href="https://www.packer.io/docs/builders/amazon">Amazon AMI Builder</a></p><p>We would like to create a custom Ubuntu-20.04 image on cloud and save it as AMI to run it later, we are searching its pattern from available AMIs on AWS Management Console or it can be found through out this website : <a href="https://cloud-images.ubuntu.com/locator/ec2/">https://cloud-images.ubuntu.com/locator/ec2/</a></p><p>Once you have declared which AMI to customize, it needs to be located under source_ami_filter with wildcards and owners. Setting most_recent to true means that when this Packer JSON file is executed it will fetch and customize last updated AMI.</p><p><strong>Access Key, Secret Key</strong> are required and should not be exposed to public in any moment, if exposed, they need to be updated immediately. They will be used to communicate with AWS to fire up instances to create custom image according to given settings defined in builders and provisioners.</p><p>The values of keys are defined in <strong>variables</strong> and parsed from out of it.</p><p>In variables section, <strong>username, instance_type, aws_access_key, aws_secret_key</strong> variables should be set correctly to create the image on cloud. Other variables are optional and variables section can be populated more.</p><h3>Customize settings on Cloud</h3><p>On cloud builds, cloud configuration file should be used instead of preseed.cfg to customize settings. The <strong>defaults.cfg</strong> file where it contains custom settings such as default username, password, changing visudo file and more. Example <strong>defaults.cfg</strong> can be as follow:</p><p>More information regarding to <strong>defaults.cfg</strong> file can be found here and customized more: <a href="https://cloudinit.readthedocs.io/en/latest/topics/examples.html">https://cloudinit.readthedocs.io/en/latest/topics/examples.html</a></p><p>Once variables are set, it can be run in same way with the local one.</p><pre>$ packer build aws_packer.json</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LqxwKf4BgEzRLlxK.png" /></figure><p>Complete packer JSON file : <a href="https://github.com/mrtrkmnhub/ubuntu-packer/blob/master/on-aws/aws-packer.json">aws_packer.json</a></p><p>As a summary, Packer is really cool tool to use to automate the process of creating custom images and it can be used for Dockers as well. For local example in this post, it will produce OVA file to import, on cloud it will generate custom AMI under your AWS account.</p><p>All scripts and config files can be found in this repository: <a href="https://github.com/mrtrkmnhub/ubuntu-packer">https://github.com/mrtrkmnhub/ubuntu-packer</a></p><p><em>Originally published at </em><a href="https://mrturkmen.com/posts/build-with-packer/"><em>https://mrturkmen.com</em></a><em> on April 17, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85b04709f59e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy with Ansible on CI/CD]]></title>
            <link>https://mrturkmen.medium.com/deploy-with-ansible-on-ci-cd-6b0d815a7fc9?source=rss-83cc93a775d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b0d815a7fc9</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Ahmet Türkmen]]></dc:creator>
            <pubDate>Sat, 12 Dec 2020 17:42:00 GMT</pubDate>
            <atom:updated>2021-01-02T21:31:52.764Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/659/0*8x-cwuYBNMsYpWSL.png" /></figure><p>In this post, deployment process of an application with Ansible will be explained. Traditionally applications can be deployed in different ways, quite similar approach to deploy applications like in Ansible is executing bash script which has ssh commands. To give an example, Travis continuous integration has a feature where a bash script can be defined to deploy application and through given instructions within bash script, application can be successfully deployed.</p><p>Details regarding to deployment using Travis bash scripting can be found <a href="https://docs.travis-ci.com/user/deployment/script/">here</a></p><h3>Travis Script Deployment</h3><p>I would like to give an real case example from one of the project which I work on. We were using Travis script deployment for a while and it works pretty well. The bash script which I use in our deployment process is given below:</p><pre>#!/usr/bin/env bash<br>f=dist/hknd_linux_amd64/hknd<br>amigo=./svcs/amigo<br>user=ntpd<br>hostname=sec02.lab.es.aau.dk<br>keyfile=./travis_deploy_key<br>deploy_path=/data/home/ntpd/daemon/hknd<br>amigo_path=/data/home/ntpd/daemon/svcs/amigo<br><br>if [ -f $f ]; then<br>    echo &quot;Deploying &#39;$f&#39; to &#39;$hostname&#39;&quot;<br>    chmod 600 $keyfile<br>    ssh -i $keyfile -o StrictHostKeyChecking=no $user@$hostname sudo /bin/systemctl stop hknd.service<br>    scp -i $keyfile -o StrictHostKeyChecking=no $f $user@$hostname:$deploy_path<br>    scp -i $keyfile -r -o StrictHostKeyChecking=no $amigo $user@$hostname:$amigo_path<br>    ssh -i $keyfile -o StrictHostKeyChecking=no $user@$hostname sudo /bin/systemctl start hknd.service<br>else<br>    echo &quot;Error: $f does not exist&quot;<br>    exit 1<br>fi</pre><p>As you can observe from the bash script, every step of the deployment is given as ssh/scp commands. There is no harm regarding to it as long as it contains few steps. However, as time pass more configurations, applications will required to be deployed, updated, modified and checked, then it might turn into headache. Therefore, having well structured deployment steps using Ansible will put us to safe side.</p><p>Before jumping into deployment with Ansible, I would like to point out some factors which can be counted as disadvantages of not integrating Ansible to deployment process.</p><ul><li>Not common way of utilizing resources</li><li>Not well structured deployment scripts which has high potential of being not working very well.</li><li>Having plain ssh commands increase likelihood of having issues regarding to settings, deployments and more.</li></ul><p>There are many more drawbacks of using pure bash scripts in deployment process, however, these issues may not be applicable for all them.</p><p>For our case, I would like to convert our bash script given above to Ansible which has more elegant structure and easy to manage.</p><h3>Move to Ansible</h3><p>Since the bash script does not contain complex instructions, it would be very easy to convert it into Ansible playbooks. Before starting to convert it into Ansible playbook, necessary ssh connection should be set correctly for development and production environments. (- test environment as well if required -).</p><p>Setting ssh connection between server and ansible user is pretty straitforward, it contains following steps;</p><ul><li>Generate SSH Key pair</li><li>Copy public key to authorized_keys on server side</li><li>Encrypt private key</li><li>Have decrypt script to use private key on CI without compromising it.</li></ul><p>Overall simplified flow for deployment is given below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ipv1PtUcYPQlpPvd.jpeg" /></figure><p>As it is declared from overall picture above, we need to provide encrypted ssh key and script for decryption together, in order to use plain private key to access the server.</p><p>In this setup, Github CI will be control node which will have access to server where we would like to deploy the application.</p><p>Let’s start to complete steps,</p><ul><li><strong>Generate SSH Key pair</strong></li></ul><pre>$ ssh-keygen</pre><p>You can keep everything default or provide some information about the questions when you run it. Once, execution of command finished, there will be public and private key, you need to append the public key to user’ authorized keys file on server. Afterwards, connection should be established, you may want to test it using traditional ssh command.</p><ul><li><strong>Encrypt Private Key</strong></li></ul><p>In order to use the ssh key which is generated before, we need to encrypt the key, I preferred to use gpg tool, there are many examples about it on internet, you can check it if you wish.</p><pre>$ gpg --symmetric --cipher-algo AES256 &lt;private-key-file&gt;</pre><p>The command will prompt you to provide passphrase to encrpyt and decrypt the private key when required. Choose strong and long passphrase. Once it is done, include encrpyted file into git. (- which means commit it as well-)</p><p>Once they have completed, the rest is structing Ansible playbook to deploy the file to server.</p><h3>Example Repo</h3><p>I am going to create a repository on Github to demonstrate what I have described earlier in action.</p><p>For the demo purposes, I will upload a service file to server and start it, simplified version of given bash commands above.</p><p>Ansible playbook will contain following;</p><ul><li>Stopping already running service</li><li>Changing binary file of the service</li><li>Starting it again</li></ul><p>The tasks can be extended according to user needs however to keep it short and show how Ansible could be used on continuous integration, I will continue to have minimal playbook.</p><p>Link to example repository: <a href="https://github.com/mrturkmenhub/ansible-deploy">https://github.com/mrturkmenhub/ansible-deploy</a></p><p>The structure of the repository as following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/0*1GX6FFhR26Df2F4I.png" /></figure><p>As it can be observed from the figurre above, I have only three tasks which are combined under <a href="https://github.com/mrturkmenhub/ansible-deploy/blob/master/main.yml">main.yml</a>.</p><p>Some configuration regarding to Ansible, such as private key, inventory file location declaration is saved to file <a href="https://github.com/mrturkmenhub/ansible-deploy/blob/master/ansible.cfg">ansible.cfg</a> among ssh connection configuration.</p><p><a href="https://github.com/mrturkmenhub/ansible-deploy/blob/master/inventory">Inventory</a> file contains server(s) to deploy the application.</p><p>This post is not about how to write ansible playbooks, hence, I am going to skip to explain it. If you would like to check and understand it you can check following repositories for examples;</p><ul><li><a href="https://github.com/mrturkmenhub/DevOps-Learning-Journey">DevOps Learning Journey</a></li><li><a href="https://mrturkmen.com/assets/notes/20201205-introduction-to-ansible.pdf">Handwritten notes about Ansible</a></li></ul><p><a href="https://github.com/mrturkmenhub/ansible-deploy/blob/master/.github/scripts/decrypt.sh">Decrypt script</a> is crucial file which is decrypting encrypted private key to access the server.</p><p><strong>** DO NOT FORGET TO SET YOUR SECRET_PASSPHRASE TO SECRETS OF THE REPOSITORY **</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*txzn0AZ-z0vqEPqv.png" /></figure><h3>The workflow file</h3><p>The workflow file for this repository is pretty straitforward to create as well, what needs to be done is that ansible should be installed into environment. Afterwards, running ansible playbook command after decrpyting the encrypted private key will complete the tasks.</p><p>The generated workflow is for giving demonstration, in normal production case, the pipeline should <strong>NOT</strong> be broken, each step from testing to production deployment should be as much as automated.</p><p>The completed <a href="https://github.com/mrturkmenhub/ansible-deploy/blob/master/.github/workflows/deploy.yml">workflow file</a>:</p><pre># This is a basic workflow to help you get started with Actions<br><br>name: CI<br><br># Controls when the action will run. <br>on:<br>  # Triggers the workflow on tagged commits  <br>  push:<br>    tags:<br>      - &#39;*.*.*&#39;<br><br>  # Allows you to run this workflow manually from the Actions tab<br>  workflow_dispatch:<br><br># A workflow run is made up of one or more jobs that can run sequentially or in parallel<br>jobs:<br>  # This workflow contains a single job called &quot;build&quot;<br>  build:<br>    # The type of runner that the job will run on<br>    runs-on: ubuntu-latest<br><br>    # Steps represent a sequence of tasks that will be executed as part of the job<br>    steps:<br>      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it<br>      - uses: actions/checkout@v2<br>      <br>      - name: Install Ansible<br>        run: |<br>          sudo apt update -y<br>          sudo apt install software-properties-common -y<br>          sudo apt-add-repository --yes --update ppa:ansible/ansible<br>          sudo apt install ansible -y<br>     <br>      - name: Set Execute command to bash script<br>        run: chmod +x ./.github/scripts/decrypt.sh<br>    <br>      # Runs a single command using the runners shell<br>      - name: Decrypt large secret<br>        run: ./.github/scripts/decrypt.sh<br>        env:<br>          SECRET_PASSPHRASE: $<br>        <br>      - name: Escalate Private Key Permissions<br>        run: chmod 400 ~/.privkey<br><br>      - name: Run ansible command<br>        run: |<br>          ansible-playbook -i ./inventory main.yml<br>        env:<br>          ANSIBLE_CONFIG: ./ansible.cfg<br><br>      - name: Clean Key<br>        run: rm -rf ~/.privkey</pre><p>The final result from Github actions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_IYhFYGwEHiwboir.png" /></figure><p>Keep in mind that this is just a minor portion of a long pipeline which has all unit tests, checks, linting and integration tests. Without proper pipeline in place, having Ansible might not be logical or required. Consider your cases when you would like to move to deployment with Ansible.</p><p>Cheers !</p><p>Ahmet Turkmen © 2020</p><p><em>Originally published at </em><a href="https://mrturkmen.com/deploy-with-ansible/"><em>https://mrturkmen.com</em></a><em> on December 12, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b0d815a7fc9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Download Youtube Playlists and Release through Github Actions [ CI/CD ]]]></title>
            <link>https://mrturkmen.medium.com/download-youtube-playlists-and-release-through-github-actions-ci-cd-27e671eaaa67?source=rss-83cc93a775d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/27e671eaaa67</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[youtube]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[youtuber]]></category>
            <dc:creator><![CDATA[Ahmet Türkmen]]></dc:creator>
            <pubDate>Tue, 24 Nov 2020 10:55:00 GMT</pubDate>
            <atom:updated>2021-04-19T01:07:54.388Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*cGTTNLMSnAi4WuC4.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZMNymAOVJnM31RZd.png" /></figure><p>In some moments, Youtube algorithm is working perfect, but sometimes it shows a video from ten years ago from nowhere. For the moments where it shows and suggests videos/playlists to us, we might want to save the list of playlist and watch in some other time. It could be on a plane, train, bus, whenever you are planning to spent some time. However, taking the URL of a playlist and saving it to your cute note program might not be sufficient enough. There is a high chance that it will be forgotten or missed, therefore, I thought that it would be nice to have an automated way of saving playlists on somewhere and download them when I need. (- in particular, when there is no or limited internet connection -).</p><p>In this blog post, I will go through a simple project which downloads all the videos in a playlist and generates seperate tar.gz files for each playlist to release on Github using Github actions.</p><h3>Requirements</h3><p>Whenever starting a project, it is always nice to imply <a href="https://en.wikipedia.org/wiki/Divide-and-conquer_algorithm">divide and conquer</a> approach if you know what you would like to achieve. Divide and conquer approach will hugely assist you during the development and planning no matter what is the size of the project. As first step, let’s define what we need for accomblishing such a thing. ]</p><ul><li>A library/program which downloads Youtube videos from given URL.</li><li>A library/program which compress the downloaded videos to minimize the size.</li><li>A workflow on Github Actions to trigger releases.</li></ul><p>When the given components are clarified, only one more step left to have. There should be main component which combines the requirements given above. For this purpose, I will use Go programming language.</p><h3>Available Tools</h3><p>When existing libraries, tools and open source projects checked for the first requirement, there are some on Github, namely;</p><ul><li><a href="https://github.com/iawia002/annie">annie</a>: 👾 Fast, simple and clean video downloader</li><li><a href="https://github.com/rg3/youtube-dl">youtube-dl</a>: Command-line program to download videos from YouTube.com and other video sites</li><li><a href="https://github.com/soimort/you-get">you-get</a>: Dumb downloader that scrapes the web</li><li><a href="https://github.com/rylio/ytdl">ytdl</a>: YouTube download library and CLI written in Go</li></ul><p>These are the tools which enable users to download Youtube videos by providing the URL or the ID.(- some of them supports different social media platforms too, e.g vimeo -).</p><p>To make things simpler, I chose to use <a href="https://github.com/rg3/youtube-dl">youtube-dl</a>, since it is more promising than others and formats the output very well according to user output pattern.</p><p>Another point is to clarify which tool/library should I use to compress the downloaded videos from Youtube. With help of a little bit googling, I found out that pigz is quite nice tool which compress given folder/file in paralel by using all available cores of the machine. The second requirement is cleared as well, now it is time to combine both of them in one and add Github workflow on top it.</p><p>I will mention about the Github workflow file, after structure of the program which automates the process.</p><h3>Code Structure</h3><p>To make things faster (- in terms of development time -), I decided to go with using pre-existing binary file to execute commands, what I mean by that is basically having a pre-installed tool (youtube-dl &amp; pigz) on the system before using this application.</p><p>If the readme file of <a href="https://github.com/ytdl-org/youtube-dl">youtube-dl</a> is checked, youtube-dl can be installed as command line tool into your environment. It means that we can call the tool whenever we need from our application. There are other ways to accomblish it as well, such as instead of using pre-existing binary file, we can implement the functions in our application. However, the main idea of this post is NOT about how to create or use the library, the main idea is to present how it easy to have automated way of retrieving Youtube playlist videos and saving to Github Releases. The other requirement regarding to compress can be used in similar way. (- using a pre-existin command from system -)</p><p>To make things simple and extendable (- which means in case of more integration of tools we should be able to accomblish it without changing, many lines of code -), I will generate a main Client struct which will have exec function and it will be <a href="https://en.wikipedia.org/wiki/Method_overriding">overridden</a> according to command we pass.</p><p>The main client struct :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb6b9bc9b891cfd80f7afeee982b0b68/href">https://medium.com/media/eb6b9bc9b891cfd80f7afeee982b0b68/href</a></iframe><p>Client struct has some fields which enables us to override whenever we want, the struct contains exec(cmd string, args ...string) ([]byte, error), shellPipe(stdin io.Reader, cmd string, args ...string) ([]byte, error), and shellExec(cmd string, args ...string) ([]byte, error) functions. It can be extended according to our requirements in the future. The explanations of the functions are given on top of functions inside the source code.</p><p>For the youtube-dl client, I implemented only a function (-the client functionalities are really easy to extend-), which downloads all videos on given playlist by using pre-existing command line tool youtube-dl.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/126d381eed1afcdab033989ba9f1f4b3/href">https://medium.com/media/126d381eed1afcdab033989ba9f1f4b3/href</a></iframe><p>For any other additional tool to use, it is extremely practical to add, for tar tool I have implemented following for specific purpose ( -which is compressing downloaded videos in parallel- ).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ef500890bdf382b6d0987f1732337fe/href">https://medium.com/media/4ef500890bdf382b6d0987f1732337fe/href</a></iframe><p>Now, it is clear that for the both statements in the requirements section has been done. However, I wanted to keep track of what I have downloaded and release, for this reason, I have created two different csv files. They are called playlist-list.csv and old-playlist-list.csv under resources/ directory in the repository, playlist-list.csv will include all list of playlist URLs with preferred folder name to download. Futhermore, as you can guess, old-playlist-list.csv will include all the playlists which are downloaded and released. Once the playlist is downloaded and released with Github actions playlist-list.csv will be wiped and all content will be appended into old-playlist-list.csv file.</p><p>It will give easy way of checking what has been downloaded and released.</p><p>The code for reading and writing to csv files are pretty easy, and can be checked under <a href="https://github.com/mrturkmenhub/youtubeto/blob/master/main.go">main.go</a> in the repository.</p><h3>Workflow File</h3><p>The workflow file will include some steps, which are;</p><ol><li><a href="https://github.com/mrturkmenhub/youtubeto/blob/004330baeee663dd12a05c4b1aaa99bba5bb4f14/.github/workflows/releaseplaylists.yml#L24">Install pigz</a> : required to compress data in parallel.</li><li><a href="https://github.com/mrturkmenhub/youtubeto/blob/004330baeee663dd12a05c4b1aaa99bba5bb4f14/.github/workflows/releaseplaylists.yml#L29">Install youtube-dl</a> : required to download playlist from given URL.</li><li><a href="https://github.com/mrturkmenhub/youtubeto/blob/004330baeee663dd12a05c4b1aaa99bba5bb4f14/.github/workflows/releaseplaylists.yml#L34">Build Binary</a> : required to have combined binary which handles both download and compress using pre-existing tools on the system.</li><li><a href="https://github.com/mrturkmenhub/youtubeto/blob/004330baeee663dd12a05c4b1aaa99bba5bb4f14/.github/workflows/releaseplaylists.yml#L38">Create Release</a> : the step which initializes releases.</li><li><a href="https://github.com/mrturkmenhub/youtubeto/blob/004330baeee663dd12a05c4b1aaa99bba5bb4f14/.github/workflows/releaseplaylists.yml#L51">Run Binary</a> : executes the program</li><li><a href="https://github.com/mrturkmenhub/youtubeto/blob/004330baeee663dd12a05c4b1aaa99bba5bb4f14/.github/workflows/releaseplaylists.yml#L55">Upload videos to Github releases</a> : uploads downloaded content to releases.</li><li><a href="https://github.com/mrturkmenhub/youtubeto/blob/004330baeee663dd12a05c4b1aaa99bba5bb4f14/.github/workflows/releaseplaylists.yml#L61">Remove playlist and append downloaded playlists to old list</a> : updates the list inside the playlist file and commits on master branch.</li></ol><p>The steps given above are clickable to see inside the workflow on repository.</p><p>This small project is created for exclusive purpose, and it is very suitable to extend functionalities. However, there are many gaps regarding to the project such as;</p><ul><li>it does NOT check the given playlists whether they have been already released or not.</li><li>it does NOT split created tar.gz files into 2 GB splits ( since it is required to have a file on Github releases under 2GB, but there is NO limitation for overall size of files on Github releases.)</li><li>Does NOT have error handling mechanism and more.</li></ul><p>These are the points which appears when the project is checked at first glance, however there are more missing points which could be done. However, the main aim was to give idea how to accomblish automated way of downloading youtube videos and releasing with Github actions.</p><p>I am personally using it for personal needs whenever I find useful playlist, I include it into playlist-list.csv file and pushing the changes by tagging the commit in semantic versioning format.</p><p>There are tons of other services which could be integrated such as Slack, Discord, Mail or any another notification systems and more, however, to keep the post short and do not bother you, it is enough for now as it is.</p><p>The rule for the workflow could be easily changed, like instead of running it in tagged commits, it can run in scheduled way by changing run condition only, as shown below.</p><pre>name: Download &amp; Release Youtube Playlists</pre><pre>on:<br>  schedule:<br>    - cron: &#39;0 0 * * *&#39; # every day at midnight </pre><p>If you require or would like to have more features, or fixes, suggestions and etc, you are more welcome to open issues.</p><h3>Github Limitations</h3><p>Since we are using Github actions, we have some limitations regarding to usage of it.</p><p>The limitations regarding to file sizes in releases, according to Github Statement here: <a href="https://docs.github.com/en/free-pro-team@latest/github/managing-large-files/distributing-large-binaries">Distributing large binaries</a></p><p>Basically, a file size which will be uploaded to releases should <strong>NOT</strong> exceeds 2 GB. However, keep in mind that it is per file, there is <strong>NO</strong> limitation for overall size of the release :). It means that repository will be updated to split files into chunks if size of the file exceeds 2 GB. So, in case of 15 GB of playlist, it should be uploaded in 2GB chunks to releases. (- a feature which is NOT exists on <strong>youtubeto</strong> yet -)</p><p>There are some more limitations:</p><p><strong>Job execution time</strong> — Each job in a workflow can run for up to 6 hours of execution time. If a job reaches this limit, the job is terminated and fails to complete.</p><p><strong>Workflow run time</strong> — Each workflow run is limited to 72 hours. If a workflow run reaches this limit, the workflow run is cancelled.</p><p>More details about limmitations on Github Actions: <a href="https://docs.github.com/en/free-pro-team@latest/actions/reference/usage-limits-billing-and-administration">Usage Limits</a></p><p>It is good to keep in mind the given limitations above.</p><p>Job execution time and Workflow run time can be easily fixed if you have your own server.</p><p>If you would like to run Github Actions in your server, there is no limitation regarding to Job execution time and Workflow run time.</p><p>Check out how to setup Github Actions for your server from here:</p><p><a href="https://docs.github.com/en/free-pro-team@latest/actions/hosting-your-own-runners/about-self-hosted-runners">Setup self hosted runners</a></p><h3>Repository</h3><p><a href="https://github.com/mrturkmenhub/youtubeto">youtubeto</a>: Automated Youtube PlayList Releaser</p><h3>Demo</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*_4PZuoQ7vWSL888e.jpg" /></figure><p>Ahmet Turkmen © 2020</p><p><em>Originally published at </em><a href="https://mrturkmen.com/download-release-youtube-playlists/"><em>https://mrturkmen.com</em></a><em> on November 24, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27e671eaaa67" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build & Release Latex with Github Actions]]></title>
            <link>https://mrturkmen.medium.com/build-release-latex-with-github-actions-8a24b0620995?source=rss-83cc93a775d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a24b0620995</guid>
            <category><![CDATA[latex]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[academia]]></category>
            <dc:creator><![CDATA[Ahmet Türkmen]]></dc:creator>
            <pubDate>Mon, 26 Oct 2020 16:25:00 GMT</pubDate>
            <atom:updated>2020-12-25T12:50:37.437Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, I will be describing to setup a workflow to build and release your Latex files through Github actions. First of all, keep in mind that this post is not about what is Latex and how to use it.</p><p>It is extremely nice to integrate daily development tools such as CI/CD to your preparation of paper, without any hassle. Why is that because it is cool to track of what has been changed on a paper over time. In fact, having a couple of people who are responsible in different parts of paper, sometimes blocks others. Therefore, having such a workflow will increase productivity for everyone in a group. Whenever pull request created to main branch, it will be easy to check typos, logic errors and missing points by others.</p><h3>Latex preparation</h3><p>I am assuming that you have agreed to work on Latex template to complete a paper. In this case, there is only small step left to do, create a Github repository (-it should be on Github, Github Actions will be used-) and push all files of your Latex template. (-in general, in following structure-)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HFvuxPFV0os8gVxS5ykvUg.png" /><figcaption>Skeleton</figcaption></figure><p>The given example structure can be changed according to your wishes, however important and logical part is that having main.tex on root directory of repository.</p><p>Once it is set, there is only one step to complete which is setting up Github Action workflows.</p><h3>Setup Github Actions</h3><p>There are a few different Github Actions to use for compiling Latex document to PDF on marketplace. Most preferred one is <a href="https://github.com/xu-cheng/latex-action">https://github.com/xu-cheng/latex-action</a> and it is quite easy to integrate and use.</p><p>It basically creates generated PDF file from provided Latex file, it can be set in workflow file as given below: (- Note that this workflow runs on tagged commits which has a tag with *.*.* pattern -)</p><p>However, setting up only this job is not sufficient enough to have completed workflow, we require to more jobs which are <strong>Create Release</strong> and <strong>Upload Release</strong>. As you may guess from their name, first one will create the release and second one will upload provided file to releases page. It can be setup as following</p><p>The given workflow is completed version of what you might have at the end. In summary, it builds PDF from provided Latex file, creates release and upload file to release. For more details, you can check information on each action page.</p><h3>Proof of Concept</h3><p>Here is example repository to check completed version.</p><p><a href="https://github.com/mrturkmenhub/latex-on-ci-cd">https://github.com/mrturkmenhub/latex-on-ci-cd</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5ILkOvxM3e6bOyRn.png" /><figcaption>SS From Releases Page</figcaption></figure><p>Ahmet Turkmen © 2020</p><p><em>Originally published at </em><a href="https://mrturkmen.com/build-release-latex/"><em>https://mrturkmen.com</em></a><em> on October 26, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a24b0620995" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Universal gRPC client demonstration [Evans]]]></title>
            <link>https://mrturkmen.medium.com/universal-grpc-client-demonstration-evans-dba71ba90669?source=rss-83cc93a775d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/dba71ba90669</guid>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[demonstration]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Ahmet Türkmen]]></dc:creator>
            <pubDate>Sat, 08 Aug 2020 11:30:16 GMT</pubDate>
            <atom:updated>2020-08-08T11:30:16.441Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://mrturkmen.com/gRPC-calls-with-evans/">https://mrturkmen.com/gRPC-calls-with-evans/</a></p><p>In this post, I am going to write demo for a tool which I have just met, it is called <strong>Evans</strong>. It is basically universal gRPC client. What it means ? Basically when you have gRPC server and would like to test gRPC calls without creating client, you can test server side calls with <strong>Evans</strong>. It is known that gRPC is very common communication method between microservices, it can be used for internal and external communication. I do not have intention to explain what gRPC is in this post since it is not the purpose. If required <a href="https://grpc.io/docs/what-is-grpc/introduction/">documentation of gRPC</a> can be investigated.</p><h3>Create a simple gRPC server</h3><p>To demonstrate and see how <strong>evans</strong> works, a running gRPC should be exists, for this reason, I am going to provide a sample gRPC server. For this purpose, I will use Go programming language, however gRPC is supporting more <a href="https://grpc.io/docs/languages/">programming languages</a> which you may more familiar than Go.</p><p>gRPC server is basically an API endpoint where clients can make requests, since it is an API, first thing could be to define which methods will be used for this service.</p><p>For simplicity and purpose of this post, I have created a basic microservice which will has four calls namely, Add,Delete,List and Find. Since the purpose is to understand how <strong>evans</strong> works, the gRPC server does not need to be complex or includes lots of calls.</p><h3>Sample repository</h3><p>A sample microservice is created for demonstration purposes and all codes are available here : <a href="https://github.com/mrturkmencom/BookShelf">https://github.com/mrturkmencom/BookShelf</a></p><p>If you have already a running gRPC server, you can direcly pass to <a href="https://mrturkmen.com/gRPC-calls-with-evans/#demonstration-of-evans">demonstration of evans</a>, if not, you can clone <a href="https://github.com/mrturkmencom/BookShelf">https://github.com/mrturkmencom/BookShelf</a> repository and test <strong>evans</strong> out.</p><h3>Defining calls</h3><p>In my opinion, it is always nice to prepare <em>proto</em> file before hand, because it is like a contract which creates your main service. Let’s imagine you would like to add, delete, list and find the books that you have read or wish to read. For this purpose, microservice should have at least four different calls which are Add, Delete, List and Find. There is no limit to have more calls however in order to do not get out of topic, I am keeping it small.</p><p>Following proto file would be enough for BookShelf service.</p><pre>// it is important to declare syntax version<br>syntax = &quot;proto3&quot;;<br>service BookShelf {<br>    rpc AddBook(AddBookRequest) returns (AddBookResponse) {}<br>    rpc ListBook (ListBooksRequest) returns (ListBooksResponse) {}<br>    rpc DelBook (DelBookRequest) returns (DelBookResponse){}<br>    rpc FindBook (FindBookRequest) returns (FindBookResponse){}<br>}<br></pre><pre>message AddBookRequest {<br>    BookInfo book = 1;<br>    message BookInfo {<br>        string isbn =1;<br>        string name =2;<br>        string author=3;<br>        string addedBy=4;<br>    }</pre><pre>}</pre><pre>message AddBookResponse {<br>    string message = 1;<br>}<br>message ListBooksRequest {<br>// no need to have anything<br>// could be extended to list books based on category ...<br>}</pre><pre>message ListBooksResponse {<br>    repeated BookInfo books =1;<br>    message BookInfo {<br>        string isbn =1;<br>        string name =2;<br>        string author=3;<br>        string addedBy=4;<br>    }<br>}</pre><pre>message  DelBookRequest {<br>    string isbn =1;<br>}</pre><pre>message DelBookResponse {<br>    string message =1;<br>}<br>message FindBookRequest {<br>    string isbn =1;<br>}</pre><pre>message FindBookResponse {<br>    Book book = 1;<br>    message Book {<br>        string isbn =1;<br>        string name =2;<br>        string author=3;<br>        string addedBy=4;<br>    }<br>}</pre><p>Once <strong>proto</strong> file is declared, it becomes more easy to continue. For the demostration purposes, I will store information of books in memory. However, as you know, it is NOT acceptable for any production level application.</p><h3>Compile Proto file</h3><p><strong>proto</strong> files are great since once you have defined what you need, you can directly generate codes in available languages which are represented in gRPC <a href="https://grpc.io/docs/languages/">supported languages</a>. The generation of codes in your desired language is pretty straitforward, I am going to generate the code for Go programming language.</p><pre>$  protoc -I proto/ proto/bs.proto --go_out=plugins=grpc:proto</pre><p>It will generate ready to use Go source code for your rpc calls which are defined in proto file.</p><p>Afterwards, necessary piece of codes should be implemented, which are in memory store and book struct. For the aim of this post, I assumed that you have created all rest of the code as given in example gRPC server (-BookShelf-).</p><p><strong>NOTE</strong>: Generating source code through protoc requires to have protoc tool to be installed before hand. Installation of protoc is <a href="https://developers.google.com/protocol-buffers/docs/downloads">over here</a></p><h3>Run gRPC server</h3><p>The post is not covering all aspects of gRPC, proto buffers, Go language and those are not the intention of this post. Therefore, I am assuming that you had gRPC server and would like to test out and see whether your proto contract is running correctly without creating client side codes. Once it is confirmed that your gRPC calls are running without encouraging any unseen problems, then creating client side code will be much easy without any problem.</p><p>You can start gRPC server with:</p><pre>$ go run server/main.go<br> BookShelf gRPC server is running ....</pre><p>Once gRPC server is up and running, you can use <strong>evans</strong> tool for inspecting gRPC server for available inquires.</p><h3>Demonstration of EVANS</h3><p>Evans is an open source project which is available <a href="https://github.com/ktr0731/evans">at Github</a> and I found it pretty useful, in particular, for people who have no idea what kind of calls are available in proto file, as it states its explanation, it is universal gRPC client. Installation of evans and more information is given its <a href="https://github.com/ktr0731/evans/blob/master/README.md">readme file</a>.</p><p>It has plenty of features which are very handy to use for automating and testing some stuff on top of existing gRPC server or new one.</p><p>Let’s make a demo, when you are using <strong>evans</strong> your gRPC server should be up and running, in order to make communication with universal gRPC client — <strong>evans</strong>. I assumed that you have followed <a href="https://github.com/ktr0731/evans/blob/master/README.md">readme file</a> of <strong>evans</strong> and installed it correctly.</p><p><em>Note that port 9000 is given because it is port of gRPC server.</em></p><pre>❯ evans -r -p 9000</pre><pre>  ______<br> |  ____|<br> | |__    __   __   __ _   _ __    ___<br> |  __|   \ \ / /  / _. | | &#39;_ \  / __|<br> | |____   \ V /  | (_| | | | | | \__ \<br> |______|   \_/    \__,_| |_| |_| |___/</pre><pre> more expressive universal gRPC client</pre><pre>BookShelf@127.0.0.1:9000&gt; show services </pre><pre>+-----------+----------+------------------+-------------------+<br>|  SERVICE  |   RPC    |   REQUEST TYPE   |   RESPONSE TYPE   |<br>+-----------+----------+------------------+-------------------+<br>| BookShelf | AddBook  | AddBookRequest   | AddBookResponse   |<br>| BookShelf | ListBook | ListBooksRequest | ListBooksResponse |<br>| BookShelf | DelBook  | DelBookRequest   | DelBookResponse   |<br>| BookShelf | FindBook | FindBookRequest  | FindBookResponse  |<br>+-----------+----------+------------------+-------------------+</pre><pre>BookShelf@127.0.0.1:9000&gt;</pre><p>As you can observe all calls which are used in proto file can be used through <strong>evans</strong>, moreover its usage is pretty straitforward.</p><p>You can check demonstration video below.</p><p>⚠️ <strong><em>You may wish to change the video quality to 1080p60</em></strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FGnAUkPUXYCs%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DGnAUkPUXYCs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FGnAUkPUXYCs%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3cecb1ee136d1632a937a1d8336c14e/href">https://medium.com/media/f3cecb1ee136d1632a937a1d8336c14e/href</a></iframe><p>If you have any questions, fix, or something else, do not hesitate to contact with me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dba71ba90669" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NGINX Ingress Controller with HAProxy for k8s cluster]]></title>
            <link>https://mrturkmen.medium.com/nginx-ingress-controller-with-haproxy-for-k8s-cluster-3eb4e837b38c?source=rss-83cc93a775d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3eb4e837b38c</guid>
            <category><![CDATA[haproxy]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Ahmet Türkmen]]></dc:creator>
            <pubDate>Fri, 10 Jul 2020 22:33:49 GMT</pubDate>
            <atom:updated>2021-04-19T01:09:40.622Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Originally posted at</em></strong><a href="https://mrturkmen.com/posts/setup-ingress-controller/"><strong><em> https://mrturkmen.com/setup-ingress-controller</em></strong></a></p><p>In recent post, which is <a href="https://medium.com/@mrturkmen/setup-highly-available-kubernetes-cluster-with-external-haproxy-lb-1fb4d18cbc03?source=friends_link&amp;sk=f58d5b528fad5ec332a58aa21fee0654">Setup Highly Available Kubernetes Cluster with HAProxy</a> a highly available Kubernetes cluster is created. However, once I started to dig in and deploy some stuff to cluster, I realized that I am not able to connect any deployed application or services. For instance, when an web application is deployed using HAProxy load balancer (endpoint), and check from <em>kubectl</em> (on client side), its status is running. However, that application could not be reached from outside world although I re-patch an external IP address by following command</p><pre>$ kubectl patch svc &lt;application-name&gt; -n &lt;name-of-namespace&gt; -p ‘{“spec”: {“type”: “LoadBalancer”, “externalIPs”:[“&lt;haproxy-ip-address&gt;”]}}’</pre><p>After some searching and reading, I realized that worker nodes require their own ingress controllers in order to forward traffic between them in case of load. I will be giving more information of how I fix the issue, however let’s learn some basic terms and general information about ingress controller.</p><h3><strong>What is ingress controller ?</strong></h3><p>The best and simple explanation to this question is coming from Kubernetes official documentation over <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/">here</a>, as they are expressing that ;</p><blockquote>Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. Traffic routing is controlled by rules defined on the Ingress resource.</blockquote><blockquote>An [Ingress controller](https://kubernetes.io/docs/concepts/services-networking/ingress-controllers) is responsible for fulfilling the Ingress, usually with a load balancer, though it may also configure your edge router or additional frontend to help handle the traffic.</blockquote><p>Whenever you have services which are running inside a cluster and would like to access them, you need to setup ingress controller for that cluster. The missing part was having no ingress controller on worker nodes in my k8s cluster. Everything was working however there was no access to them from outside world, that’s why ingress controller should take place in cluster architecture.</p><p>In this post, I will go for <a href="https://kubernetes.github.io/ingress-nginx/">NGINX ingress controller </a>with its default setup, however there are plenty of different<a href="https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/#additional-controllers"> ingress controllers </a>which you may go for. I might change NGINX to Traefik in future but it depends on requirements yet for now, I will go with nginx ingress controller. The reason is that, it is super easy to setup, super rich with different features, included Kubernetes official documentation and fulfill what I am expecting for now.</p><h3><strong>Updates to cluster</strong></h3><p>Let’s briefly what I have explained in <a href="https://medium.com/@mrturkmen/setup-highly-available-kubernetes-cluster-with-external-haproxy-lb-1fb4d18cbc03?source=friends_link&amp;sk=f58d5b528fad5ec332a58aa21fee0654">previous post</a>;</p><ul><li>Create VMs</li><li>Setup SSH connection</li><li>Use KubeSpray to deploy cluster</li><li>Create HAProxy and establish SSH connection with all nodes.</li></ul><p>I have noticed that when deploying cluster, some add-ons should be enabled in order to use ingress controller from cluster with external HAProxy load balancer. Now, since cluster deployment was established with Ansible playbooks, it is not needed to setup everything from scratch. All modified configuration can be re-deployed without effecting any resource which is exists on cluster setup. It means that, I can enable required parts in configuration file and re-deploy cluster as I did on previous post.</p><ul><li><strong>Enable ingress controller from </strong><a href="https://github.com/kubernetes-sigs/kubespray/blob/master/inventory/sample/group_vars/k8s-cluster/addons.yml"><strong>inventory</strong></a><strong> file inside KubeSpray</strong></li></ul><pre>$ vim inventory/mycluster/group_vars/k8s-cluster/addons.yml<br># Nginx ingress controller deployment<br>ingress_nginx_enabled: false -&gt; true</pre><p>Once this configuration part is updated from existing KubeSpray configuration files, k8s cluster should be redeployed with same command in <a href="https://medium.com/@mrturkmen/setup-highly-available-kubernetes-cluster-with-external-haproxy-lb-1fb4d18cbc03?source=friends_link&amp;sk=f58d5b528fad5ec332a58aa21fee0654">previous post</a></p><p><em>*Assumption*</em> : previous configured KubeSpray settings are used.</p><pre>$ ansible-playbook -i inventory/mycluster/hosts.yaml — become — become-user=root cluster.yml</pre><p>It will take a while and update all necessary parts which are required.</p><ul><li><strong>Include Ingress API object to route traffic from external HAProxy server to internal services</strong></li></ul><p>To include Ingress API object, HAProxy configuration file should be modified, following lines should be added to <strong><em>/etc/haproxy/haproxy.cfg</em></strong> file.</p><pre>$ vim /etc/haproxy/haproxy.cfg</pre><pre>frontend kubernetes-ingress-http<br>bind *:80</pre><pre>default_backend kubernetes-worker-nodes-http<br>backend kubernetes-worker-nodes-http<br>balance leastconn<br>option tcp-check<br>server worker1 10.0.128.81:80 check fall 3 rise 2<br>server worker2 10.0.128.137:80 check fall 3 rise 2<br>server worker3 10.0.128.156:80 check fall 3 rise 2</pre><p>In given configuration balancing algorithm is `leastconn` which can be changed into any load balancer algorithm which is supported by HAProxy, however `leastconn` algorithm is fitting more to what I would like to achieve that’s why it is declared as `leastconn`. Note that this configuration addition is on top of added part on <a href="https://medium.com/@mrturkmen/setup-highly-available-kubernetes-cluster-with-external-haproxy-lb-1fb4d18cbc03?source=friends_link&amp;sk=f58d5b528fad5ec332a58aa21fee0654">previous post.</a></p><p>Once HAProxy configuration is updated, HAProxy should be restarted `<strong><em>systemctl restart haproxy</em></strong>`. It is all for HAProxy configuration, now let’s dive into setting up NGINX Ingress Controller.</p><ul><li><strong>Setup NGINX Ingress Controller</strong></li></ul><p>It is super simple to deploy and setting up NGINX ingress controller since it is well documented and explains required parts in detail. To setup NGINX Ingress Controller, I will follow official guideline which is exists on <a href="https://docs.nginx.com/nginx-ingress-controller/installation/">NGINX Ingress Controller Installation</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EYYAZDjhyCfeXxhAg56qwA.png" /><figcaption>NGINX Ingress Controller</figcaption></figure><p><em>Image is taken from </em><a href="https://www.nginx.com/products/nginx/kubernetes-ingress-controller/#resources">https://www.nginx.com/products/nginx/kubernetes-ingress-controller/#resources</a></p><p>In normal cases, the situation is as given figure above, however, since in existing k8s cluster, I am using HAProxy for communicating with clients, I need NGINX ingress controller inside worker nodes which will manage running applications/services by communicating with HAProxy and eventually, the services will be accessible from outside world.</p><p>If I summarize how overview diagram will look like in my case is like in given figure below.</p><figure><img alt="Overview of HA Kubernetes Cluster" src="https://cdn-images-1.medium.com/max/1024/1*-QhhSrmxPZpdX28BK30KHA.png" /><figcaption>Overview of HA k8s cluster</figcaption></figure><p>It can be observed that, in given k8s cluster overview, HAProxy is in front, it communicates with clients, afterwards transmitting request based on defined rule on HAProxy configuration. Each worker node has NGINX ingress controller, what exactly it means, whenever a request appear to cluster, worker nodes will agree between each other and response back to user without having any problem. Since NGINX ingress controller is capable of load balancing inside worker nodes as well.</p><p>There is also Ingress Resource Rules part inside cluster, what it does, is that all routing rules based on path forwarded given service, an example on this is given below.</p><h4><strong>Steps to create NGINX Ingress controller</strong></h4><p><em>All steps shown below for installation of NGINX Ingress Controller taken from </em><a href="https://docs.nginx.com/nginx-ingress-controller/installation/"><em>https://docs.nginx.com/nginx-ingress-controller/installation/</em></a></p><p><strong>Make sure that you are a client with administrator privilege, all steps related to NGINX ingress controller should be done through `kubectl` (on client computer/server)</strong></p><ul><li><strong>Clone Ingress Controller Repo</strong></li></ul><pre>$ git clone <a href="https://github.com/nginxinc/kubernetes-ingress/">https://github.com/nginxinc/kubernetes-ingress/</a><br>$ cd kubernetes-ingress</pre><ul><li><strong>Create a namespace and a service account for the Ingress controller</strong></li></ul><pre>$ kubectl apply -f common/ns-and-sa.yaml</pre><ul><li><strong>Create a cluster role and cluster role binding for the service account</strong></li></ul><pre>$ kubectl apply -f rbac/rbac.yaml</pre><ul><li><strong>Create a secret with a TLS certificate and a key for the default server in NGINX</strong></li></ul><pre>$ kubectl apply -f common/default-server-secret.yaml</pre><p>- <strong>**Create a config map for customizing NGINX configuration:**</strong></p><pre>$ kubectl apply -f common/nginx-config.yaml</pre><p>Afterwards, there are two different ways to run NGINX ingress controller deployment, which are as daemonset or as deployment. Main difference between those are summarized on official <a href="https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/">installation page</a> as;</p><blockquote><strong>Use a Deployment</strong>. When you run the Ingress Controller by using a Deployment, by default, Kubernetes will create one Ingress controller pod.</blockquote><blockquote><strong>Use a DaemonSet</strong>: When you run the Ingress Controller by using a DaemonSet, Kubernetes will create an Ingress controller pod on every node of the cluster.</blockquote><p>I will go with DaemonSet approach, the reason is that generally when you have background tasks which will run non-stateless then DaemonSet is more preferred way of running it.</p><pre>$ kubectl apply -f daemon-set/nginx-ingress.yaml</pre><p>Once it is applied as daemon set, the result could be checked with following command and result will be similar to given result below.</p><pre>$ kubectl get all</pre><pre>NAME READY STATUS RESTARTS AGE<br>pod/nginx-ingress-47z8r 1/1 Running 0 24h<br>pod/nginx-ingress-cmkfq 1/1 Running 0 24h<br>pod/nginx-ingress-ft5pv 1/1 Running 0 24h<br>pod/nginx-ingress-q554l 1/1 Running 0 24h<br>pod/nginx-ingress-ssdrj 1/1 Running 0 24h<br>pod/nginx-ingress-t9jml 1/1 Running 0 24h</pre><pre>NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE<br>daemonset.apps/nginx-ingress 6 6 6 6 6 &lt;none&gt; 24h</pre><h3><strong>Deploy Example Application</strong></h3><p>To test how an application will be exposed to externally from k8s cluster, an example applicaton could be deployed as given below. Note that the following example is simplest example for this context, hence, keep in mind that it might require more configuration and detailed approach then described here when you would like to deploy more complex applications.</p><ul><li><strong>Create a sample NGINX Web Server </strong>(Using provided example)</li></ul><p><strong><em>*nginx-deploy-main.yml*</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8350ioTW3TKau1VI1bPFmA.png" /><figcaption>Example NGINX Deployment</figcaption></figure><p><em>Taken from </em><a href="https://kubernetes.io/docs/tasks/run-application/run-stateless-application-deployment/">https://kubernetes.io/docs/tasks/run-application/run-stateless-application-deployment/</a></p><p>In given yaml deployment file above, two replicas of NGINX:1.14.2 will be deployed to cluster and it has name of `<em>nginx-deployment</em>`. The yaml explains itself very well.</p><p>It can be deployed either through directly from official link or from your local depends on your preferences.</p><pre>$ kubectl apply -f <a href="https://k8s.io/examples/application/deployment.yaml">https://k8s.io/examples/application/deployment.yaml</a></pre><pre>## or you can do same thing with local file as given below</pre><pre>$ kubectl apply -f nginx-deploy-main.yml</pre><p>Expose deployment:</p><pre>$ kubectl expose deploy nginx-deployment --port 80</pre><p>Once it is deployed to cluster and exposed, there is one step left for this simple counter example is that, exposing the service and creating ingress rule (resource) in yaml file, by specifiying kind as `Ingress`.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ILlUFSTvkddROblbMwjqeA.png" /><figcaption>Ingress Ruleset</figcaption></figure><p>The crucial part is `<strong><em>serviceName</em></strong>` and `<strong><em>servicePort</em></strong>` which are defining specifications of the services within cluster. The yaml specifications can be expanded as shown below, assume that you have wildcard record in your domain name server and have multiple services which are running in same port in a cluster, yaml file can be re-defined as given below.</p><p><strong><em>*nginx-ingress-resource.yml*</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UwzWyEEBTbFbrp33LKJGww.png" /><figcaption>Ingress rules for different services</figcaption></figure><p>Keep in mind that all given services should be deployed before hand otherwise when a request made to any path which is not deployed, it may return either 404 or 500. There are plenty of different options to define and update the components in a k8s cluster. Therefore, all yaml files should be changed according to requirements.</p><p><em>*Create ingress controller rules from provided yaml file*</em></p><pre>$ kubectl create -f nginx-ingress-resource.yml</pre><p>Now, the NGINX web server deployment is ready on given DNS record in yaml file and according to request paths different services can be called which are also running inside kubernetes cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JV_ctXUBm9LAQ9mDPn-nug.png" /><figcaption>Example NGINX Web Server Deployment Result</figcaption></figure><p>Note that, provided yaml files are just simple example of deploying NGINX web server without any certification, when certificates (HTTPS) enabled or any other type of deployment happened different configurations should be applied.</p><p>When everything goes without any problem, you will have a cluster which uses NGINX Ingress controller for internal cluster routing and HAProxy as communication endpoint for clients. Keep in mind that whenever a new service or deployment take place, required configuration should be enabled in HAProxy configuration as it is enabled for port 80 applications above. Different services will have different requirements therefore it is important to catch main logic in a setup. It is all done for this post.</p><p>Cheers !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3eb4e837b38c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup Highly Available Kubernetes Cluster with external HAProxy LB]]></title>
            <link>https://mrturkmen.medium.com/setup-highly-available-kubernetes-cluster-with-external-haproxy-lb-1fb4d18cbc03?source=rss-83cc93a775d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fb4d18cbc03</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[haproxy]]></category>
            <category><![CDATA[container-orchestration]]></category>
            <dc:creator><![CDATA[Ahmet Türkmen]]></dc:creator>
            <pubDate>Fri, 10 Jul 2020 21:25:30 GMT</pubDate>
            <atom:updated>2020-07-10T22:05:57.682Z</atom:updated>
            <content:encoded><![CDATA[<p>Originally posted at <a href="https://mrturkmen.com/install-ha-kubernetes-cluster/">https://mrturkmen.com/install-ha-kubernetes-cluster/</a></p><p>The main purpose of this blog post a simple walk through of setting up Kubernetes cluster with external <a href="http://www.haproxy.org/">HAProxy</a> which will be the endpoint where our kubectl client communicates over. Node specifications for this setup is given as shown in the table below. Keep in mind that all of them has access to each other with password and without password. The environment which Kubernetes cluster will stay is running on OpenStack. It means that once a configuration (ssh keys, hosts, and etc) is done for example master1 then all other nodes could be initialized through snapshot of master1. To be able to setup such a Kubernetes cluster easily, I will be using <a href="https://github.com/kubernetes-sigs/kubespray">KubeSpray</a> which is a repository where it has all required configuration and playbooks for setting up necessary cluster.</p><p>The intention of this walkthrough is that setting up your own Kubernetes cluster in your own servers, this post is not very useful for people who are already using cloud provider solutions.(Kubernetes cluster as a service). You can checkout following resources listed below : (few of them :) )</p><p><strong>Cloud Providers Solutions:</strong></p><ul><li><a href="https://azure.microsoft.com/en-us/services/kubernetes-service/">Azure Kubernetes Service — AKS</a></li><li><a href="https://cloud.google.com/kubernetes-engine">Google Kubernetes Engine — GKE</a></li><li><a href="https://www.digitalocean.com/products/kubernetes/">Managed Kubernetes on DigitalOcean</a></li><li><a href="https://aws.amazon.com/kubernetes/">Kubernetes on AWS</a></li></ul><h3>Node Specification</h3><p>Kubernetes cluster will be setup on following nodes in the table below, note that HAProxy will run on another node and all ansible playbooks and setting up Kubernetes cluster will be managed through HAProxy. Keep in mind that all nodes + HAProxy is under same subnet internally which means that we will only one external IP address where HAProxy use and kubectl clients communicate. All instances are running on<strong><em> ubuntu_18.04</em></strong>, it means that the instructions and steps may not work with another system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*tupLW_rtN5J20pvyo_Y-HQ.png" /><figcaption>Nodes Specifications</figcaption></figure><h3>Prerequisites</h3><ul><li>Nodes</li><li><a href="https://github.com/kubernetes-sigs/kubespray/blob/master/requirements.txt">Requirements</a> of KubeSpray</li><li>Setting up SSH Key Across Nodes</li><li>Getting snapshot ( -it is optional -)</li><li>Setting up login with password</li></ul><h3>General Overview</h3><p>The following sketch is general overview of how Kubernetes cluster will look like at the end of this walk through, the figure is super over viewed version of cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_5EFttycBfweNc9oyskXKw.png" /><figcaption>External HAPRoxy in front of cluster</figcaption></figure><p>In given figure above, nodes do not have any external IP adress however, including HAProxy, all of them in same subnet, only HAProxy has external IP address which will be reachable by kubectl clients.</p><p>Before moving installation step of Kubernetes cluster, we need to setup a sample master node (instance) with predefined configuration. Since we will have only one server which is open to outside world, we need to make sure that there is a connection between HAProxy and sample master node. I am currently calling it sample master node, it is because, preliminary configurations such as authentication with password, disabled swap area and ssh keys will be all configured. This sample master node should be started and accesible over HAProxy, which means that in order to access to sample master node, I should do following;</p><ul><li>SSH to HAProxy using SSH key (<strong>Password Login disabled</strong>) like ssh -i ~/.ssh/id_rsa &lt;username&gt;@&lt;ha-proxy-external-ip&gt;</li><li>Copy SSH Key to HAProxy, which let you in to sample master node</li><li>Then SSH to sample master node with same approach. (ssh ~/.ssh/masternode.pem &lt;username&gt;@&lt;master-node-ip&gt;</li></ul><p>After you are inside sample master node, now, some configurations and setting should be done. Afterwards, we can initialize other five nodes from snapshot of configured sample master node.</p><p>Steps:</p><ul><li><strong>Enable Password Login if not enabled already.</strong></li></ul><pre>$ echo &quot;PermitRootLogin yes&quot; &gt;&gt; /etc/ssh/sshd_config<br>$ sed -i -E &#39;s/PasswordAuthentication no/PasswordAuthentication yes/g&#39; /etc/ssh/sshd_config</pre><ul><li><strong>Specify Password for ROOT</strong></li></ul><pre>$ sudo su <br>$ passwd</pre><p>Given commands will ask new unix password for root user. Define the password and do not forget or lose it. Since we will gonna use snapshot of this configured machine, all settings will be same, I did like that to shortcut the process.</p><ul><li><strong>Disable swap area (RUN ALL COMMANDS AS ROOT)</strong></li></ul><pre>$ swapoff -a</pre><p>Afterwards, exit from sample master node, create snapshot of that node (it is called volume snapshot in OpenStack), once you have successfully created snaphot, all five other nodes should be initialized from snapshot of this sample master node. This way, there is no need to repeat same steps described above.</p><p>In case of not having possibility to create snapshot follow given steps (if and if only, you could NOT create snapshot and initialize other five nodes from the snapshot)</p><ul><li>Create all nodes (workers and masters)</li><li>Enable SSH connection to all nodes from HAPRoxy server.</li></ul><p>From HAProxy server, execute following steps. (-Make sure that you have configured SSH connection with ROOT priviledges and have access to all nodes from HAProxy node -)</p><p>Once you are sure that you have SSH access to all nodes from HAProxy through SSH, implement following steps.</p><ul><li><strong>Install parallel-ssh (-to run a command in parallel on nodes-) (run with ROOT priviledges)</strong></li></ul><pre>$ apt-get update &amp;&amp; apt-get install -y pssh</pre><ul><li><strong>Install HAProxy (as ROOT priviledges)</strong></li></ul><pre>$ apt-get install -y haproxy</pre><ul><li><strong>Modify </strong><strong>/etc/hosts (-For easy communication through nodes-)</strong></li></ul><p><em>Append worker and master node IPs to </em><em>/etc/hosts file</em></p><pre>$ vim /etc/hosts <br>10.0.128.156 worker3<br>10.0.128.137 worker2<br>10.0.128.81  worker1<br>10.0.128.184 master3<br>10.0.128.171 master2<br>10.0.128.149 master1</pre><ul><li><strong>Create </strong><strong>nodes text file on home directory</strong></li></ul><pre>$ cat nodes <br>worker3<br>worker2<br>worker1<br>master3<br>master2<br>master1</pre><p><em>Since IP addresses of them defined in </em><em>/etc/hosts file, system can now recognize and connect IPs of them through just by name</em></p><ul><li><strong>Generate and Copy SSH Key to all nodes</strong> (Required for easy communication)</li></ul><p>If there is already a SSH key (like in ~/.ssh/id_rsa), you can use it as well.If not, you can do following step</p><pre>$ ssh-keygen  # will prompt passphrase, you can leave empty , NOTE THAT IF YOU DO NOT HAVE SSH KEY, GENERATE IT.</pre><pre>$ for i in $(cat nodes); ssh-copy-id $i; done</pre><p>The for loop given as second command will copy ssh key to all nodes, then accesing any node without password will be flawless.Like given command below;</p><pre>$  ssh master1  # in defualt uses same username with terminal session</pre><ul><li><strong>Disable swap area on all nodes (Note that if you are using snapshot method, no need to do this step)</strong></li></ul><pre>$ parallel-ssh -h nodes -i &quot;swapoff -a&quot;</pre><p>Parallel SSH tool is handy to complete tasks in parallel for multiple hosts.</p><h3>KubeSpray Configuration</h3><p>KubeSpray is a repository to setup Kubernetes clusters with predefined configuration settings using Ansible playbooks. The usage of KubeSpray is pretty straightforward, as default settings, KubeSpray is using internal load balancers in each worker node, which means that when you setup a Kubernetes cluster using default values of KubeSpray, you will have following arch overview.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SnV2jRjyxHgv9EFD.png" /></figure><p>However, in this guide, external load balancer approach will be used to setup cluster, if you wish to leave everything as default with KubeSpray, you can skip this <a href="https://mrturkmen.com/install-ha-kubernetes-cluster/#external-load-balancer-setup">External Load Balancer Setup</a> part.</p><h3>External Load Balancer Setup (HAProxy)</h3><p>Modify configuration file of HAProxy to enable external LoadBalancer, copy this following configuration and append to /etc/haproxy/haproxy.cfg. (end of file)</p><pre>listen kubernetes-apiserver-https<br>  bind &lt;your-haproxy-internal-ip&gt;:8383<br>  mode tcp<br>  option log-health-checks<br>  timeout client 3h<br>  timeout server 3h<br>  server master1 &lt;your-master1-ip&gt;:6443 check check-ssl verify none inter 10000<br>  server master2 &lt;your-master2-ip&gt;:6443 check check-ssl verify none inter 10000<br>  server master3 &lt;your-master3-ip&gt;:6443 check check-ssl verify none inter 10000<br>  balance roundrobin</pre><p>Balance algorithm is roundrobin however you can change it from list of available <a href="https://cbonte.github.io/haproxy-dconv/configuration-1.4.html#4.2-balance">balance algorithms</a> provided by HAProxy. Once it is done, save and restart HAProxy service.</p><pre>$ systemctl restart haproxy</pre><h3>Setup KubeSpray Configuration</h3><p>Since external load balancer will be used, there is few things to be done to change default values in KubeSpray. Following steps will be done on HAProxy node.</p><ul><li><strong>Clone the project and prepare environment</strong></li></ul><pre>$ git clone https://github.com/kubernetes-sigs/kubespray<br>$ apt-get install -y python3-pip # install pip3 if not installed<br>$ cd kubespray</pre><ul><li><strong>Follow the guide on KubeSpray README.md file</strong></li></ul><p>Following instructions taken from <a href="https://github.com/kubernetes-sigs/kubespray">KubeSpray README.md</a></p><pre># Install dependencies from ``requirements.txt``<br>$ sudo pip3 install -r requirements.txt<br># Copy ``inventory/sample`` as ``inventory/mycluster``<br>$ cp -rfp inventory/sample inventory/mycluster<br># Update Ansible inventory file with inventory builder<br>$ declare -a IPS=(10.0.128.149 10.0.128.171 10.0.128.184 10.0.128.81 10.0.128.137 10.0.128.156)<br>$ CONFIG_FILE=inventory/mycluster/hosts.yaml python3 contrib/inventory_builder/inventory.py ${IPS[@]}</pre><ul><li><strong>Modify generate hosts YAML file</strong></li></ul><p>When you check inventory/mycluster/hosts.yaml file, you will notice that it created two master nodes, which we require three, add missing one properly to that list as shown below.</p><pre>all:<br>  hosts:<br>    master1:<br>      ansible_host: 10.0.128.149<br>      ip: 10.0.128.149<br>      access_ip: 10.0.128.149<br>    master2:<br>      ansible_host: 10.0.128.171<br>      ip: 10.0.128.171<br>      access_ip: 10.0.128.171<br>    master3:<br>      ansible_host: 10.0.128.184<br>      ip: 10.0.128.184<br>      access_ip: 10.0.128.184<br>    worker1:<br>      ansible_host: 10.0.128.81<br>      ip: 10.0.128.81<br>      access_ip: 10.0.128.81<br>    worker2:<br>      ansible_host: 10.0.128.137<br>      ip: 10.0.128.137<br>      access_ip: 10.0.128.137<br>    worker3:<br>      ansible_host: 10.0.128.156<br>      ip: 10.0.128.156<br>      access_ip: 10.0.128.156<br>  children:<br>    kube-master:<br>      hosts:<br>        master1:<br>        master2:<br>        master3:<br>    kube-node:<br>      hosts:<br>        master1:<br>        master2:<br>        master3:<br>        worker1:<br>        worker2:<br>        worker3:<br>    etcd:<br>      hosts:<br>        master1:<br>        master2:<br>        master3:<br>    k8s-cluster:<br>      children:<br>        kube-master:<br>        kube-node:<br>    calico-rr:<br>      hosts: {}</pre><p>Once it is done, the other thing which should be modified to use external load balancer HAProxy, is all.yaml file located under inventory/mycluster/group_vars/all/.</p><p>all.yml is general configuration file which specifies main configurations of your cluster, it uses Nginx load balancer by default which means that each worker node has its own local nginx load balancer as given second figure above. If not specified anything else.</p><ul><li><strong>Disable default load balancer</strong></li></ul><pre>$ vim inventory/mycluster/group_vars/all/all.yml<br>loadbalancer_apiserver_localhost: false</pre><ul><li><strong>Add external load balancer HAProxy.</strong></li></ul><pre>$ vim inventory/mycluster/group_vars/all/all.yml<br>## External LB example config<br>apiserver_loadbalancer_domain_name: &quot;&lt;domain-name-of-lb&gt;&quot;<br>loadbalancer_apiserver:<br>  address: 10.0.128.193<br>  port: 8383</pre><ul><li><strong>Initialize cluster deployment</strong></li></ul><pre># under kubespray/ directoy <br>$ ansible-playbook -i inventory/mycluster/hosts.yaml  --become --become-user=root cluster.yml</pre><p>It will take around 10–15 minutes which depens on your cluster and if everything goes well, at the end of deployment through Ansible you will not face with any problem. If so, you can test it by SSH to master node and try kubectl cluster-info.</p><pre>$ kubectl cluster-info<br>Kubernetes master is running at .....</pre><pre>To further debug and diagnose cluster problems, use &#39;kubectl cluster-info dump&#39;.</pre><p>It means that Kubernetes cluster with three master and three worker nodes available to use.</p><p>Note that the default configuration of cluster could be changed more however before attempting to change default configuration, make sure that you did correct research on what to change on KubeSpray default settings. Otherwise, there might be problems regarding to customized configuration settings.</p><p>For more information stay updated and watch <a href="https://github.com/kubernetes-sigs/kubespray">KubeSpray</a> regarding to issues, pitfalls and more.</p><p>Last step for this post is creating kubectl configuration for your personal/work computer to access the cluster. <a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/">Install kubectl</a> on your environment. Afterwards copy configuration from master node to your ~/.kube/ as config.</p><p>Since we have only one endpoint, configuration file should be copied to HAProxy Server then your computer, through rsync or scp</p><ul><li><strong>On HAProxy Server</strong></li></ul><pre>$ scp root@master1:/etc/kubernetes/admin.conf config  # will copy admin.conf as config <br>$ cp config /home/ubuntu/    # copy to a user home dir<br>$ chown ubuntu:ubuntu /home/ubuntu/config    # change owner of the file</pre><ul><li><strong>On your personal/work computer</strong></li></ul><pre>$ scp -i ~/.ssh/haproxy.pem ubuntu@&lt;ha-proxy-ip&gt;:/home/ubuntu/config  ~/.kube/</pre><p>Now, you should be able to get and dump your cluster information as in master nodes.</p><pre>$ kubectl cluster-info<br>Kubernetes master is running at .....</pre><pre>To further debug and diagnose cluster problems, use &#39;kubectl cluster-info dump&#39;.</pre><p>There are lots of configurations and different settings regarding to Kubernetes cluster environment and generally using Cloud Provider solutions are less painful or painless. However, sometimes it is less costly to setup your own environment and having full access to anything could be better for learning under the hood things or creating highly customized environments. It really depends on your situation therefore it is up to you to go and setup your own Kubernetes cluster or use it as service from cloud providers.</p><p>By the way, thanks for giving time to checkout the post 😉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fb4d18cbc03" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kendimize özel VPN kurulumu]]></title>
            <link>https://mrturkmen.medium.com/kendimize-%C3%B6zel-vpn-kurulumu-e28524545629?source=rss-83cc93a775d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e28524545629</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[vpn]]></category>
            <category><![CDATA[openvpn]]></category>
            <category><![CDATA[wireguard]]></category>
            <category><![CDATA[programlama]]></category>
            <dc:creator><![CDATA[Ahmet Türkmen]]></dc:creator>
            <pubDate>Wed, 01 Jul 2020 10:00:00 GMT</pubDate>
            <atom:updated>2021-04-19T01:22:49.917Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*sDy__UYn5RS7itMv-G89LQ.jpeg" /></figure><p>Bugün sizlere kendinize ait VPN sistemi nasıl kurulur, onu anlatmak istiyorum, daha önce İngilizce olarak, <a href="https://mrturkmen.com/setup-free-vpn/">yayınladım</a> fakat Türkçe bir kaynağın da faydalı olabileceğini düşündüm. Burada anlatılanlar, ubuntu ailesine (16.04,18.04) ait sunucular üzerinde test edilmiştir.</p><p>İlk olarak bulut hizmeti sağlayan bir şirketten bu DigitalOcean, Google Cloud, Microsoft Azure veya Amazon olabilir, sunucu kiralıyorsunuz, en ucuzu ve makul olanı DigitalOcean tarafından sunulan <a href="https://www.digitalocean.com/pricing/">aylık 5 dolar</a> olan sunucu diyebilirim. Sunucuyu kiraladıktan ve ssh bağlantısını sağladıktan sonra VPN kurulumuna geçebiliriz.</p><p>VPN hakkında tam bilgisi olmayan arkadaşlar için şu şekilde özetlenebilir, sizin için oluşturulmuş sanal bir bağlantı noktası gibi düşünebilirsiniz. Yani VPN’e bağlandıktan sonra bilgisayarınızdan çıkan ve bilgisayarınıza gelen ağ trafik şifrelenmiş olarak işlenir. Üçüncü parti yazılımların veya MITM gibi saldırıların önüne geçmiş olursunuz.</p><h3>Neden kendi VPN sistemi kurmalıyız ?</h3><p>Çünkü şu anda var olan bütün VPN sistemleri, ücretsiz olarak hizmet sağlasa dahi, sizin bilgilerinizin satılması, arşivlenmesi ve gerektiğinde ilgili birimlere aktarılması amacıyla kaydedilmektedir. Bunun ne gibi zararları olabilir gelin birlikte şöyle bir sıralayalım:</p><ul><li>Oltalama saldırılarına sadece sizin bilebileceğiniz bilgiler ile maruz kalma.</li><li>Ziyaret ettiğiniz siteler tarafından reklam bombardımanına maruz kalma.</li><li>Kişisel bilgilerinizin reklam veren ajanslara satılması, bu durum birçok kişi tarafından tam olarak anlaşılamıyor, yani şu şekilde anlaşılamıyor, internet üzerinden alışveriş yapan A kişisi, kendine ait bilgilerin, onun bilgilerini satacak kişiler tarafından değersiz olduğuna inanıyor ve hiçbir gizlilik sağlamadan internet kullanımına devam ediyor. Bu sonunda o kişiye zarar vermese bile o kişinin konuştuğu, görüştüğü veya birlikte çalıştığı arkadaşlara zarar verebiliyor.</li></ul><p>Burada sıralananlar sadece buzdağının görünen ucu bile diyemeyiz, günümüzde veri işleme teknikleri ve yaklaşımları öyle gelişmiştir ki siz bile kendinize ait olan bir şeyin varlığına farkında olmadan onlar işlemleri tamamlamış oluyor :).</p><p>Bu ve bunlardan çok daha fazla nedenden dolayı VPN kullanımı şart diyebilirim. Peki bunu nasıl yapacağız, bu kısımdan sonra sizin bir bulut sağlayıcısı tarafından sunucunu kiraladığınızı ve ssh bağlantısını sağladığınızı varsayıyorum.</p><p>Bu gönderide WireGuard VPN uygulaması kullanılacaktır. WireGuard VPN uygulaması açık kaynaklı bir uygulama olup, sağladığı imkanlar sayesinde diğer VPN uygulamalarına (OpenVPN ve diğerleri) kıyasla çok daha hızlı ve güvenilirdir.</p><h3>Sunucu Ayarları</h3><p><strong>VPN uygulamasını kiraladığımız sunucu üzerine kuralım.</strong></p><pre>$ sudo apt-get update &amp;&amp; sudo apt-get upgrade -y <br>$ sudo add-apt-repository ppa:wireguard/wireguard<br>$ sudo apt-get update <br>$ sudo apt-get install wireguard -y</pre><p><strong>Uygulamayı çekirdek güncellemeleri ile birlikte güncellemek için gerekli komutu girelim.</strong></p><pre>$ sudo modprobe wireguard</pre><p><strong>Aşağıda verilen komut girildiğinde beklenen sonuç.</strong></p><pre>$ lsmod | grep wireguard</pre><pre>wireguard             217088  0<br>ip6_udp_tunnel         16384  1 wireguard<br>udp_tunnel             16384  1 wireguard</pre><p><strong>Anahtarları üretelim.</strong></p><pre>$ cd /etc/wireguard<br>$ umask 077<br>$ wg genkey | sudo tee privatekey | wg pubkey | sudo tee publickey</pre><p><strong>VPN Konfigurasyon dosyasını </strong><strong>/etc/wireguard/wg0.conf ayarlayalım.</strong></p><pre>[Interface]<br>PrivateKey = &lt;daha-öncesinde-üretilen-gizli-anahtar&gt;<br>Address = 10.120.120.2/24<br>Address = fd86:ea04:1111::1/64<br>SaveConfig = true<br>PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o ens3 -j MASQUERADE; ip6tables -A FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -A POSTROUTING -o ens3 -j MASQUERADE<br>PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o ens3 -j MASQUERADE; ip6tables -D FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -D POSTROUTING -o ens3 -j MASQUERADE<br>ListenPort = 51820</pre><p>Burada önemli nokta ens3, ip tables komutu içerisinde yer alan en3, sunucudan sunucuya farklılık gösterebilir, bundan dolayı sizin sunucunuzda ne ise ağ kartının ismi onu girmelisiniz. ifconfig komutu sayesinde öğrenilebilir.</p><p>Bir diğer önemli nokta ise daha öncesinde 4. adımda üretilen privatekey, içeriğinin PrivateKey alanına girilmesidir.</p><p><strong>Ağ trafiğini yönlendirme</strong></p><p>/etc/sysctl.conf dosyası içerisine aşağıda verilen bilgileri girerek kaydediniz.</p><pre>net.ipv4.ip_forward=1<br>net.ipv6.conf.all.forwarding=1</pre><p><strong>Bilgiler gerekli dosyaya kaydedildikten sonra aşağıdaki komutlar sırası ile girilmelidir.</strong></p><pre>$ sysctl -p<br>$ wg-quick up wg0</pre><p><strong>Komutların girilmesi ve herhangi bir sorun görülmemesi durumda ve </strong><strong>wg komutu terminale girildikten sonra aşağıda verilen çıktıya benzer bir çıktı göreceksiniz.</strong></p><pre>$ wg<br>interface: wg0<br>  public key: loZviZQpT5Sy4gFKEbk6Vc/rcJ3bH84L7TUj4qMB918=<br>  private key: (hidden)<br>  listening port: 51820</pre><p>Eğer herhangi bir sorun ile karşılaşmazsanız bu adıma kadar, bu demek oluyor ki, sunucu tarafında işiniz şimdilik tamamlandı geriye sadece kendi bilgisayarımızı, telefonumuzu vs VPN sunucusuna bağlamak kaldı.</p><h3>Kullanıcı Ayarları</h3><p>Kullanıcıların kendi bilgisayar ortamlarında, telefonlarında, tabletlerinde veya diğer sunucularında kullanabileceği uygulamaları <a href="https://www.wireguard.com/install/">buradan</a> indirebilirsiniz.</p><p>Gerekli uygulamayı kendi ortamınıza indirdikten sonra tek yapmanız gereken, VPN sunucusu tarafında ayarladığımız VPN’e bağlanmak, bunun için gerekli olan sadece konfigurasyonları doğru girmek olacaktır.</p><p>Kullanıcı tarafında, uygulama üzerinden aşağıda verilen konfigurasyona benzer bir ayarı (kendi kurduğunuz VPN ayarlarına göre privatekey ve ip adressi değişiklik gösterecektir.) ayarlamanız gerekmektedir.</p><pre>[Interface]<br>Address = 10.120.120.2/32<br>Address = fd86:ea04:1111::2/128<br># note that privatekey value is just a place holder <br>PrivateKey = KIaLGPDJo6C1g891+swzfy4LkwQofR2q82pFR6BW9VM=<br>DNS = 1.1.1.1</pre><pre>[Peer]<br>PublicKey = &lt;sunucunuza-ait-public-anahtar&gt;<br>Endpoint = &lt;sunucunuzun-dış-ip-adresi&gt;:51820<br>AllowedIPs = 0.0.0.0/0, ::/0</pre><p>Gerekli işlemler kullanıcı tarafında da sağlandıktan sonra, sunucu tarafında bu kullanıcıya bağlantı izni vermek kalıyor, onuda aşağıda verilen komut ile sağlayabilirsiniz.</p><pre>$ wg set wg0 peer &lt;kullanici-public-anahtari&gt; allowed-ips 10.120.120.2/32,fd86:ea04:1111::2/128</pre><p>Sunucu tarafindan kullanicinin VPN baglantisi sağladığını aşağıda verilen komut ile teyit edebilirsiniz.</p><pre>$ wg</pre><pre>interface: wg0<br>  public key: loZviZQpT5Sy4gFKEbk6Vc/rcJ3bH84L7TUj4qMB918=<br>  private key: (hidden)<br>  listening port: 51820</pre><pre>peer: Ta9esbl7yvQJA/rMt5NqS25I/oeuTKbFHJu7oV5dbA4=<br>  allowed ips: 10.120.120.2/32, fd86:ea04:1111::2/128</pre><p>Daha sonrasinda, wireguard tarafından oluşturulan ağ kartını aktivate edelim.</p><pre>$ wg-quick up wg0</pre><h3>Güvenlik duvarı ayarları</h3><p>Bazen sunucu tarafında yapmanız gereken bazı güvenlik duvarı ayarları bulunmakta, bunlar VPN bağlantısını başarılı bir şekilde sağlamanız için kritik öneme sahiptir.</p><pre>$ ufw enable</pre><p><strong>VPN uygulamasına bağlanmamızı sağlayacak portu açıyoruz.</strong></p><pre>$ ufw allow 51820/udp</pre><p><strong>IP tabloları ile 51820 portu için bazı ayarlamalar yapıyoruz.</strong></p><pre>$ iptables -A INPUT -p udp -m udp --dport 51820 -j ACCEPT<br>$ iptables -A OUTPUT -p udp -m udp --sport 51820 -j ACCEPT</pre><p>Burada önemli olan kısımlardan biriside bütün komutlar ROOT, yani yönetici yetkisi ile yapılmalı, aksi takdirde hata verecektir.</p><p>Bu noktadan sonra, bilgisayarınıza, tabletinize veya telefonunuza kurduğunuz WireGuard uygulaması sayesinde sorunsuz ve güvenlikli bir şekilde internetinizi kullanabilirsiniz.</p><p>Ahmet Turkmen © 2020</p><p><em>Originally published at </em><a href="https://mrturkmen.com/vpn-kuralim/"><em>https://mrturkmen.com</em></a><em> on July 1, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e28524545629" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>