<?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 Victor Oliveira on Medium]]></title>
        <description><![CDATA[Stories by Victor Oliveira on Medium]]></description>
        <link>https://medium.com/@victor.oliveira.comp?source=rss-a571c287e041------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*L3x9MyKjdE0ywCOoo7scrA.png</url>
            <title>Stories by Victor Oliveira on Medium</title>
            <link>https://medium.com/@victor.oliveira.comp?source=rss-a571c287e041------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 14:01:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@victor.oliveira.comp/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[Production-ready Kubernetes PaaS in 10 steps.]]></title>
            <link>https://medium.com/@victor.oliveira.comp/production-ready-kubernetes-paas-in-a-couple-of-easy-steps-iaas-included-174fe64be881?source=rss-a571c287e041------2</link>
            <guid isPermaLink="false">https://medium.com/p/174fe64be881</guid>
            <dc:creator><![CDATA[Victor Oliveira]]></dc:creator>
            <pubDate>Fri, 14 Feb 2020 12:37:39 GMT</pubDate>
            <atom:updated>2020-02-25T08:12:52.116Z</atom:updated>
            <content:encoded><![CDATA[<p>IaaS included</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IOSCSjje0Hurd1aIGw_WCg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@dianamia?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">C Dustin</a> on <a href="https://unsplash.com/s/photos/cloud?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Yeah, this isn’t a clickbaity title, it’s 10 steps. And no, this isn’t a Kubespray or kubeadm tutorial.</p><p>Easy, straightforward and can be performed by anyone with a basic understanding of production systems (read: <em>basic</em>).</p><p>But, my advice <strong>IF</strong> (&lt;- big if) you want to use these steps on your infrastructure, adapt them to your needs.</p><p>At the very least you’ll have a place to start without having to spend countless hours, doing research… drinking more than what anyone would consider a healthy amount of coffee. And/or having to work out what articles out there are compatible with what or which aren’t.</p><blockquote>Tech writers need to start specifying software versions on their articles to prevent this from happening.</blockquote><p>I’ve written other articles about how to streamline the deployment for VMs using virtualization platforms such as <a href="https://www.proxmox.com/en/">Proxmox</a> and automation tools like <a href="https://www.ansible.com/">Ansible</a>.</p><p>This step-by-step can and will deal with some of these technologies without too much customization. You could also adapt it to use some other alternatives to the tools used here.</p><p>Enough preamble, let’s go for it.</p><h3>Step 1: Get some hardware</h3><p>Take your pick. Whether it’s a very low-cost decommissioned desktop PC from an office or a laptop with a broken screen.</p><blockquote>You can get a lot of good deals on ebay for decommissioned hardware, either tower PCs or “old” servers.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/0*ttY3LjR1iuDB713Z.jpg" /></figure><p>Or a US$ 20,000 latest-generation server with the latest and greatest hardware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/207/0*8KqCP_BBoh0c6_nF.jpg" /></figure><p>It’s your call. I can’t determine how much load will your platform have but these steps should help you choose. So, please, adapt it to your needs.</p><h3>Step 2: Let’s set up a Cloud-ish environment.</h3><p>Let’s say you don’t have a lot of bare-metal machines or, maybe, you do. In my case I’ve had an issue with the bare-metal servers I have available to me. They’re too big.</p><p><em>Note: Yes, I know, this example can be set up with </em><em>virsh. This is how I decided to do it, there’s a million ways to do it, this one’s easier for me :)</em></p><p>As in, 512 Gigs of RAM each. Now, Kubernetes’ workloads don’t usually go well with huge servers, there’s a pod limit to each node. Kernel limitations won’t help either. So I’ve decided to go with a Proxmox cluster environment that will host a few VMs with different VM models on it.</p><p>This is how the Proxmox deployment will look like after it’s done:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*SSvaM1GObrbW7V8z2SVn-A.png" /><figcaption>Proxmox Infrastructure</figcaption></figure><p>This example uses a 3 node Proxmox cluster. The setup for the cluster just needs you to install 3 machines with Proxmox, it can be Proxmox 5 or 6, your call. It makes no difference.</p><p>After you have installed the Proxmox distro on the machines, just create a cluster.</p><h4>Create the Proxmox Cluster</h4><p>In this example I’m going to reserve the following IPs for the installation (they’re also stated on the image above):</p><pre>192.168.1.2 node1<br>192.168.1.3 node2<br>192.168.1.4 node3</pre><p>The cluster creation is pretty well documented on Proxmox’s documentation <a href="https://pve.proxmox.com/wiki/Cluster_Manager#pvecm_create_cluster">here</a>. On the newer versions, it can also be done with the GUI. I’m proceeding with the installation on Proxmox 6.1.</p><p>These steps should create a cluster pretty painlessly, let’s name it <em>cloudish. </em>Just log in via SSH to any of the nodes, in this case node1, and execute the following command:</p><pre>node1:~# pvecm create cloudish</pre><p>Then login into the other nodes and run the join command on each one of them:</p><pre>node2:~# pvecm add 192.168.1.2</pre><pre>node3:~# pvecm add 192.168.1.2</pre><p>The <em>pvecm</em> command will ask you for the node1 credentials, input them and you’re good to go.</p><h4>Step 3: Create a bare-metal controller</h4><p>To control and deploy the nodes I’m using <a href="https://maas.io/">MaaS</a> (Metal as a Service), a bare metal controller that allows you to present the VMs you are going to create, or even bare metal servers to a cloud orchestrator such as Terraform or JuJu.</p><p>MaaS uses two elements:</p><ul><li>A region Controller that handles: DNS, NTP, Syslog, and Squid Proxy</li><li>A rack Controller that handles: PXE, IPMI, NTP, TFTP, iSCSI, DHCP</li></ul><p>Both of these elements can be deployed to the same machine.</p><p>In case you want/need high availability these components can be separated and installed in different machines, it’s well documented and straightforward, more info <a href="https://maas.io/docs/high-availability">here</a>.</p><p>In our case, we’re going to use the same machine for both things.</p><p>The deployment will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*Je7wRTSL6uqVYD5sD8LAxA.png" /><figcaption>MaaS Deployment</figcaption></figure><p>Download an Ubuntu Server ISO from the Ubuntu website and install it on a VM created on the Proxmox cluster, in this case, Ubuntu 18.04 LTS.</p><p>The bare minimum MaaS deployment needs one machine with 1 core and 2 Gigs of RAM. This should suffice for a very small deployment with a couple of machines.</p><p>Lets amp that up and go all the way to 4 cores and 8 Gigs of RAM!</p><p>For this example the MaaS machine will have the following IP:</p><pre>MaaS --- 192.168.1.10</pre><p>After you’ve installed the OS on the VM, go ahead and install the MaaS Controller, in our case MaaS 2.6.2:</p><pre>maas:~# sudo add-apt-repository ppa:maas/2.6<br>maas:~# sudo apt update<br>maas:~# sudo apt install maas<br>maas:~# sudo maas init</pre><p>After the initialization is done you’ll see a URL on the terminal. Go ahead and log into it using your favorite browser and finally, proceed with the configuration stage. Read more <a href="https://maas.io/install">here</a>.</p><p>Please remember to set up your DHCP service, by going on the MaaS interface and setting up the range you want.</p><p>To use MaaS DHCP you need it to be the only DHCP service on the network. <strong>This is very important</strong>. Also, reserve the ranges for the IPs you’re going to use elsewhere or the ones you’ve already used.</p><h4>Step 4: Create VMs.</h4><p>Yes, create Virtual Machines for Proxmox, a lot of them. I advise going with a <em>for</em> loop on the terminal using <em>qm create </em>so the process doesn’t get tedious, remember to check what requirements you need.</p><p>For this project, we’re going to create the bare minimum that Canonical recommends for a charmed Kubernetes deployment with HA, 10 machines.</p><p>Also the 3 VMs for JuJu.</p><p>The setup is as follows:</p><pre><strong>VM1</strong>    2 CPU Cores | 2 GB RAM | 20 GB HDD   tags=master<br><strong>VM2    </strong>2 CPU Cores | 2 GB RAM | 20 GB HDD   tags=master<br><strong>VM3    </strong>2 CPU Cores | 2 GB RAM | 20 GB HDD   tags=loadbalancer<br><strong>VM4    </strong>2 CPU Cores | 2 GB RAM | 20 GB HDD   tags=easyrsa<br><strong>VM5    </strong>2 CPU Cores | 2 GB RAM | 20 GB HDD   tags=etcd<br><strong>VM6    </strong>2 CPU Cores | 2 GB RAM | 20 GB HDD   tags=etcd<br><strong>VM7    </strong>2 CPU Cores | 2 GB RAM | 20 GB HDD   tags=etcd<br><strong>VM8    </strong>4 CPU Cores | 4 GB RAM | 20 GB HDD   tags=worker<br><strong>VM9    </strong>4 CPU Cores | 4 GB RAM | 20 GB HDD   tags=worker<br><strong>VM10   </strong>4 CPU Cores | 4 GB RAM | 20 GB HDD   tags=worker<br><strong>VM11   </strong>1 CPU Cores | 3 GB RAM | 20 GB HDD   tags=juju-controller<br><strong>VM12   </strong>1 CPU Cores | 3 GB RAM | 20 GB HDD   tags=juju-controller<br><strong>VM13   </strong>1 CPU Cores | 3 GB RAM | 20 GB HDD   tags=juju-controller</pre><p>After you create the VMs you need to add them to MaaS, make sure they’re set up for <strong>Network</strong> boot first and <strong>HDD</strong> second, like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*RS6DfPD2KsIXNQvoL4nXMQ.png" /><figcaption>VM Boot order</figcaption></figure><p>Then boot them up so they go through the process to be added to MaaS.</p><h4>Step 5: Configure MaaS</h4><p>For MaaS to be able to control Proxmox VMs like if they were a bare-metal machine it needs a driver.</p><p>Luckily a guy by the name of <a href="https://launchpad.net/~enter2608">Wojtek Rakoniewski</a> wrote one for all of us to use and posted it on launchpad. It works with what I’ve tested: Proxmox 5.1, 6.1 and everything in between since it uses the Proxmox API.</p><p>I’ve taken the liberty of hosting it on a public Github repo with credits for him all around, just in case the guys from launchpad decide to archive the bug tracker.</p><p>You can download it <a href="https://raw.githubusercontent.com/galdorork/proxmox-maas/master/proxmox.py"><strong>here</strong></a><strong>.</strong></p><p>Or using wget:</p><pre>wget <a href="https://raw.githubusercontent.com/galdorork/proxmox-maas/master/proxmox.py">https://raw.githubusercontent.com/galdorork/proxmox-maas/master/proxmox.py</a></pre><p>After you download it you need to put the file on this route on the MaaS Region controller:</p><pre>/usr/lib/python3/dist-packages/provisioningserver/drivers/power/</pre><p>And register the driver on the registry.py located here:</p><pre>/usr/lib/python3/dist-packages/provisioningserver/drivers/power/registry.py</pre><p>You need to edit the entry so it looks like this:</p><pre><strong>## Add this to the import headers</strong><br>from provisioningserver.drivers.power.proxmox import ProxmoxPowerDriver</pre><pre><strong>## The <em>ProxmoxPowerDriver</em> is the entry to be added</strong><br>power_drivers = [<br>     ProxmoxPowerDriver(),<br>     ...<br> ]</pre><p>Then install the proxmoxer python package so the driver knows what to use when talking to the Proxmox API:</p><pre>apt install python3-proxmoxer</pre><p>Finally, restart the maas-regiond service to take the changes into account, systemctl restart maas-regiond should work.</p><p>Unfortunately even using this driver MaaS doesn’t know how to auto-detect the hardware controller for the machine, but it’s easily done manually on the VM’s config.</p><p>To do this you need to create a PVE user on the Proxmox GUI that has the VM.Audit and VM.PowerMgmt permissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*-aSAUQugofcW0NG-2tdn-Q.png" /><figcaption>User Definition</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*s4BNG-cUEoMH4veBD7g7Yg.png" /><figcaption>Group Definition</figcaption></figure><p>Then configure the VM on MaaS so the region controller knows how to use it’s power capabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*HX6qwwXCXSuHriAqgouyWg.png" /><figcaption>MaaS power type configuration</figcaption></figure><p>Input here the PVE user you have created, it’s password, one of the proxmox nodes’ IPs and the VM id.</p><h4>Step 6: Commission the VMs</h4><p>MaaS works with this workflow:</p><p><em>The machine is added →Machine needs to be commissioned → Machine is deployed.</em></p><p>The workflow makes sense since no machine can be formatted or deployed accidentally by being present on the same network and being pxe-booted.</p><p>When you boot up your proxmox VMs the first time, they will be added to MaaS as <em>new</em> machines:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/159/1*ata67e6yJ6kxQAwtEeEs-w.png" /><figcaption>New machine added</figcaption></figure><p>Then you need to commission them, this means it gets booted from MaaS (remember to configure the power type) and some tests are run on the machine, as well as defining an inventory for that specific machine, parsing CPU info, RAM info, Storage info, etc.</p><p>After it’s commissioned it’ll be shown as ready:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RRzSLwuQHSkvXk8eyeK2mg.png" /><figcaption>MaaS VM in ready state</figcaption></figure><p>This means the VM is ready to be used by either a controller or being manually deployed by either using the MaaS GUI or the MaaS API or, maybe even JuJu.</p><p>Let’s go for JuJu.</p><p><strong>DO NOT FORGET: </strong>JuJu needs “tags” to identify MaaS nodes, else it grabs them at random, please set up tags with the VM usage so you can use them as constraints later on:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*ZkbnglfLkgS_xFaOMvJCBA.png" /><figcaption>MaaS VM Tag configuration</figcaption></figure><h4>Step 7: Create your JuJu controller VMs.</h4><p>This implementation requires a JuJu controller. For this example, we’re going to use 2.7.1-eoan-amd64.</p><p>We’re going to use a single machine for it. The VM needs at least 1 core and 3 GB of RAM.</p><p>You don’t need to install it, just set it up to boot from Network and the VM will boot up using iPXE. After it boots with the Ubuntu image it will download some of the packages it needs to check the resources the VM has and show it to the MaaS controller.</p><p>Afterward, commission it and you’re all set, you can commission your first machine from JuJu. This will be done from your PC.</p><p>On your PC, execute the following command:</p><pre>yourawesomelaptop:~$ sudo snap install juju --classic</pre><p>Now, add the MaaS cloud to your JuJu environment:</p><pre>yourawesomelaptop:~$ juju add-cloud --local</pre><p>The output will be as follows (I’ve bolded the entries you need to input):</p><pre>Cloud Types<br>  lxd<br>  maas<br>  manual<br>  openstack<br>  vsphere</pre><pre>Select cloud type: <strong>maas</strong></pre><pre>Enter a name for your maas cloud: <strong>my-amazing-bare-metal-cloud</strong></pre><pre>Enter the API endpoint url: <a href="http://192.168.1.10:5240/MAAS"><strong>http://192.168.1.10:5240/MAAS</strong></a></pre><pre>Cloud &quot;my-amazing-bare-metal-cloud&quot; successfully added</pre><pre>You will need to add credentials for this cloud (`juju add-credential my-amazing-bare-metal-cloud`)<br>before creating a controller (`juju bootstrap my-amazing-bare-metal-cloud`).</pre><p>Your JuJu installation needs to be able to connect to the API, it has the URL, now it needs the credentials:</p><pre>yourawesomelaptop:~$ juju add-credential maas-cloud</pre><p>It’ll ask for the MaaS secret, get it from the MaaS GUI. Click on your username on the top right corner and it’s the first field, copy and paste when it asks for <em>maas-oauth</em>:</p><pre>Enter credential name: <strong>my-amazing-bare-metal-cloud-credentials</strong></pre><pre>Using auth-type &quot;oauth1&quot;.</pre><pre>Enter maas-oauth:</pre><pre>Credentials added for cloud my-amazing-bare-metal-cloud.</pre><p>You can check the added credentials with:</p><pre>yourawesomelaptop:~$ juju credentials --local</pre><p>And finally create the main JuJu controller, using the JuJu tags and constraints:</p><pre>yourawesomelaptop:~$ juju bootstrap --bootstrap-constraints tags=juju-controller my-amazing-bare-metal-cloud maas-controller</pre><p>You’re done with JuJu for now.</p><p>If you want High Availability you can scale the controller and let it have more machines, 3 is advised for any production environment (remember to create the VMs first on Proxmox) for this example we’re doing it:</p><pre>yourawesomelaptop:~$ juju enable-ha</pre><h4>Step 8: JuJu the hell out of that MaaS instance</h4><p>Once the empty VMs are ready, the MaaS controllers are ready and the JuJu controller is ready you’re all set.</p><p>You can even do these steps on a nice graphical interface using JuJu Gui. Don’t worry, you can still use the terminal to adjust some of it, or even customize the charm bundle so it adapts to your machines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FovHpBRZtMSEWENpEYV_ow.png" /><figcaption>Charmed Kubernetes Bundle</figcaption></figure><p>In this case, we’re going to edit some of the constraints, so next to where it says untitled-model you can click on export and download the YAML descriptor file. On this file you need to focus on the machine descriptors at the end of the file and add the constraints to each one, depending on their need. E.g:</p><pre>machines:<br>  &#39;0&#39;:<br>    constraints: tags=easyrsa<br>  &#39;1&#39;: <br>    constraints: tags=etcd<br>  &#39;2&#39;: <br>    constraints: tags=etcd<br>  &#39;3&#39;: <br>    constraints: tags=etcd<br>  &#39;4&#39;: <br>    constraints: tags=loadbalancer<br>  &#39;5&#39;: <br>    constraints: tags=master<br>  &#39;6&#39;: <br>    constraints: tags=master<br>  &#39;7&#39;: <br>    constraints: tags=worker<br>  &#39;8&#39;: <br>    constraints: tags=worker<br>  &#39;9&#39;: <br>    constraints: tags=worker</pre><p>Make sure the machine IDs match with the descriptions present at the beginning of each service definition. Then import it to your GUI and let it process.</p><p>Then commit the changes. You should add your ssh public key on this step. Remember you can always add it later on.</p><p>Then relax, get a cup of coffee, or tea, or a beer, maybe all of them. Depending on the hardware you have available this could take a while, from 15 mins on. In the meantime, you can see the deployment status on the GUI.</p><p>If you decide to use the terminal the bundle can also be deployed like this:</p><pre>yourawesomelaptop:~$ juju deploy myawesomekubernetescluster.yaml</pre><h4>Step 9: Get your Kubernetes config file</h4><p>After the provisioning is done you just need to get your Kubernetes config file from the juju deployment:</p><pre>yourawesomelaptop:~$ juju scp kubernetes-master/0:config ~/.kube/config</pre><p>And connect to the deployment using kubectl, in case you need to install kubectl on your machine I’ve written an article about it <a href="https://medium.com/@victor.oliveira.comp/set-up-your-machine-to-use-kubectl-316e6c33fe56">here</a>, it has instructions for the main OSs out there.</p><p>There, you’re all set. Optionally you can set up MetalLB as a way to expose the services or even use nfs-client provisioner or whichever persistent storage you might want to use.</p><h4>Step 10: Scale it away</h4><p>Yes, this platform can be scaled vertically, using more VMs present on MaaS for this task.</p><p>From JuJu you can extend each of the cluster roles from your choosing, an example for a Kubernetes worker would be:</p><pre>juju add-unit kubernetes-worker</pre><p>Scale it A LOT? (take caution, this will add <strong>16</strong> worker nodes):</p><pre>juju add-unit kubernetes-worker -n 16</pre><p>Or scale it down (removing the second worker):</p><pre>juju remove-unit kubernetes-worker/2</pre><p>The same applies to all of the other cluster roles.</p><p>Et voilá, it’s all set up, now you can focus on developing the next million-dollar idea without having to worry about the platform you have, and without paying premiums on cloud platforms that can be replicated on-site or maybe use hardware you already have laying around.</p><p>If you’re going to use this article as a base to deploy your own PaaS solution, don’t forget that it can be extended a lot, using JuJu for vertical scaling as well as Kubernetes autoscaling for horizontal scaling (pod replica scaling).</p><p>If you need any extra help you can get in touch with me using the comments on this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=174fe64be881" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recovering an overwritten script that’’s still in execution from memory]]></title>
            <link>https://medium.com/swlh/recovering-an-overwritten-script-that-s-still-in-execution-from-memory-b5ab445b1e6c?source=rss-a571c287e041------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5ab445b1e6c</guid>
            <category><![CDATA[gdb]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Victor Oliveira]]></dc:creator>
            <pubDate>Tue, 14 Jan 2020 14:24:43 GMT</pubDate>
            <atom:updated>2020-01-14T14:24:43.463Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LC59Fva-gXh9p6moI2S8kA.jpeg" /></figure><p>Recently I had a co-worker do an <em>oopsie</em> on a server he was running a script on. He, actually wisely, executed a script on a screen within his terminal while connected to a production server. Now, this is all standard, what isn’t standard is that he somehow managed to overwrite the script (while in execution) on another terminal with a one-liner.</p><p>This script took a while to run so it was still running after he reported the issue to me. This is at least 2 days of work from him, a guy that actually knows what he’s doing (unlike me :D ).</p><p>So I remembered from my old days that you could output a script from memory using GDB as debugger, so after a few `man` searches and a few hairs pulled out of my head (maybe a few from his head) and found a very useful command from within GDB to help us with this.</p><p>I can’t give you the actual script recovery, however I can replicate it.</p><h3>Testing script</h3><p>Assuming you have GDB we can replicate this procedure, if you don’t, you’re dead on the water. Just kidding, you can install it on whatever distro with the package gdb.</p><p>Let’s start with a <em>very</em> simple script within a screen:</p><pre>#!/bin/bash<br>while true; do<br> sleep 1; echo “Running…”<br>done</pre><p>In the meantime we can leave the screen with <strong>Ctrl+A+D</strong> and then proceed to do some process debugging.</p><h3>PIDs everywhere</h3><p>Let’s start with getting the PID for the process:</p><p>ps -ef | grep bash</p><p>In this case we find the following output:</p><p>root 436 410 0 19:14 pts/0 00:00:00 /bin/bash ./while.sh</p><h3>Debugging our way into the script</h3><p>We want the PID number which is *436*, so we attach ourselves to the process with our favorite open source debugger:</p><p>gdb -p 436</p><p>Now what we’re attached we enter the gdb prompt that will pause the process execution while we’re attached, take this into account as it prevents a lot of stress thinking the process is going to end and lose everything we’re trying to rescue. Also, generate a core file:</p><p>(gdb) generate-core-file</p><p>Which will generate, you guessed it, a *core file*, with the output: `Saved corefile core.436`. This core file has everything in-memory regarding the process in execution, including our bash script. However we don’t want to suddenly stop the execution of the process so we *detach* from it using the command (insert obviousness here):</p><p>(gdb) detach</p><p>And we exit the debugger:</p><p>(gdb) quit</p><h3>Analizing</h3><p>This output is a binary file that isn’t stored as clear text, if we try to use cat to output it’s contents the system will say something like `cat: write error: Input/output error` so we use *strings* to make it usable as clear text (don’t have it? install it):</p><p>strings core.436 &gt; rescuescript.sh</p><p>And within the dump we can find our script in clear text, however don’t be so hopeful and happy yet, core files can have a **lot** of data that isn’t useful for us, so be patient!. Anyway here’s the script we found on the core file (on line 10509, hence the need for patience):</p><pre>#!/bin/bash<br>while true; do<br> sleep 1; echo “Running…”<br>done</pre><p>Et voilà!</p><p>Hope you don’t <em>ever</em> need to use this. Good luck if you do!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5ab445b1e6c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/recovering-an-overwritten-script-that-s-still-in-execution-from-memory-b5ab445b1e6c">Recovering an overwritten script that’’s still in execution from memory</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Retiring a Proxmox cluster node the right way]]></title>
            <link>https://medium.com/@victor.oliveira.comp/retiring-a-proxmox-cluster-node-the-right-way-f88d4b1f192d?source=rss-a571c287e041------2</link>
            <guid isPermaLink="false">https://medium.com/p/f88d4b1f192d</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[virtualization]]></category>
            <category><![CDATA[corosync]]></category>
            <category><![CDATA[proxmox]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Victor Oliveira]]></dc:creator>
            <pubDate>Tue, 14 Jan 2020 14:24:09 GMT</pubDate>
            <atom:updated>2020-02-10T09:09:21.388Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pnDOXfVP7q6-t-HgXx09GQ.jpeg" /></figure><p>When retiring a Proxmox cluster node from a cluster you need to take into account several things.</p><p>Not very often you find yourself with the opportunity to retire a server and install a new one. Especially a new, shiny one with all the best bells and whistles a provider can give. Or you can find yourself finding that a node has broken down and it’s not worth it to fix it, might as well replace it.</p><p>In case one of these machines belongs on a Proxmox Cluster you need to retire it. Leaving it presented on the cluster might cause a ton of issues we won’t go into on this article, trust me, Murphy’s law applies.</p><h3>Is the proxmox node on?</h3><p>If the Proxmox Node is online you need to migrate all the Virtual Machines (VMs) to another Node. Since Proxmox 5 migrating VMs has never been easier. You can just right click and click on Migrate, whether it has local or shared storage is transparent for the operator/sysadmin/you.</p><p>After the migration finishes (in the case that you don’t use shared storage and you use local storage this might take a while) you can proceed to shutoff the node.</p><p>Non-recoverable hardware failures on nodes don’t need to go through this step. There are ways to recover the VMs if the storage was locally based but, due to time constrains I won’t cover it here.</p><h3>Make sure the node is no longer on</h3><p>When the node has been shutdown <strong>DO NOT START IT UP AGAIN</strong>. This will cause problems with the corosync services. Preferably unplug the network connection, either physically or through the OS configuration.</p><h3>Verify it!</h3><p>In the case described on this post we’re using a 9 node cluster, something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*ZOljJT-d14XGDf8IyFgYAw.png" /></figure><p>You need to check the Node name from the Proxmox Custer Manager CLI, this is as easy as opening an SSH console or going through the Proxmox GUI -&gt; Shell and issuing the command:</p><p>pvecm nodes</p><p>It should give you an output like this:</p><pre>Membership information<br> — — — — — — — — — — — <br> Nodeid Votes Name<br> 9 1 proxmox9<br> 8 1 proxmox8<br> 3 1 proxmox3<br> 4 1 proxmox4<br> 7 1 proxmox7<br> 6 1 proxmox6<br> 5 1 proxmox5<br> 1 1 proxmox1 (local)<br> 2 1 proxmox2</pre><h3>Get down to it, and get the node down too</h3><p>Let’s say we want to remove the node with id 2 (proxmox2). <em>Ensure you’ve shut it off </em>and issue the command:</p><p>pvecm delnode proxmox2<br><br>There won’t be any output to this command unless something goes wrong. What this command does is remove all of the configuration files from the pve file system that control the cluster. It does NOT, however, completely clean all of the corosync entries, hence the “If it’s out, it stays out”, the cluster will basically look like this afterwards:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*jfiZDZIJFNDIfa-i5XKsSA.png" /></figure><p>Et voilá!</p><p>You’ve successfully removed a Proxmox Node from a running cluster and with zero (hopefully) downtime on the VMs themselves.</p><p>Now go and add a brand new shiny machine to the Cluster. Maybe a few more than one!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f88d4b1f192d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reusing TCP ports for fun, profit, and lack of headaches]]></title>
            <link>https://levelup.gitconnected.com/reusing-tcp-ports-for-fun-profit-and-lack-of-headaches-cd57e7859dbb?source=rss-a571c287e041------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd57e7859dbb</guid>
            <category><![CDATA[hadoop]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[debian]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[kernel]]></category>
            <dc:creator><![CDATA[Victor Oliveira]]></dc:creator>
            <pubDate>Tue, 14 Jan 2020 07:08:14 GMT</pubDate>
            <atom:updated>2020-01-21T12:46:31.228Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JHo4lBEDaC-3M6tIUrobMA.jpeg" /></figure><p>Last week I was checking out some old issues in the issue tracking system that hadn’t been solved since way before my time. While browsing them, I noticed an unsolved ticket that had a lot of updates from both the sysadmins that came before me and the developers from an application that ran a few times per day but always had issues running.</p><p>The errors that were thrown by the application (which was programmed in Java of all things) were like this:</p><p>java.net.NoRouteToHostException: Can’t assign requested address (Address not available)</p><h3>Possible causes</h3><p>All of the updates regarding this issue “pointed” towards the database cluster that was being called in order for the application to store its output (the quotes serve a purpose, by the way, just wait and read). Now, I could see a year’s worth of interactions from both teams discussing the error and possible solutions but somehow they all managed to “point” the error towards the database cluster.</p><p>Please take into account that this is a Percona cluster that could handle tens of thousands of connections, not counting the concurrency. Real beefy stuff. That had been configured by a co-worker which I <em>know</em> can do his job competently, but since the ticket had my attention I decided to take a crack at it.</p><h3>Troubleshooting</h3><p>The first few steps of the troubleshooting I had to do were to eliminate all obvious conclusions (year’s worth of work, remember?) my co-workers came to; which pointed me towards the Percona cluster. Since this is a production system I wasn’t able to really stress it since I knew my testing would get unwanted attention from developers and managers that start yelling wolf as soon as they see something that’s not expected on their metrics. So I just threw around 30k concurrent sessions to the cluster and it didn’t break a sweat.</p><p>So, next steps it is. After checking out the whole error log from Java I noticed the error and decided to SSH into the application server from where the app was being deployed and as soon as I connected to it I received a Slack message asking me not to play with since it was on production!!!</p><p>Naturally I did what every sysadmin does at least once (a day), ignore the developer and started checking out every log I could get my hands on and noticed something specific to those machines, they weren’t reusing TCP connections. As you can see it didn’t “point” to a database issue. These kinds of database clusters are designed to run with HUGE workloads.</p><h3>Possible solutions</h3><p>At this point it was painfully obvious that the machine was running out of internal ports for the application that was deployed on it, in order to check this I just reviewed the kernel parameters in execution with the following command:</p><p>sysctl -a | grep range</p><p>And the reusability of the ports:</p><p>sysctl -a | grep reuse</p><h3>A more permanent solution</h3><p>Both of those commands gave me what I needed, the port range was ok:</p><p>net.ipv4.ip_local_port_range = 15000 65000</p><p>Which is expected since it’s a default behavior, but the reuse flag wasn’t enabled, so we just changed it on the kernel config on the file:</p><p>/etc/sysctl.conf</p><p>And added the entry:</p><p>net.ipv4.tcp_tw_reuse = 1</p><p>Applied it live:</p><p>sysctl -p<br><br>And, done.</p><p>Et voilà!</p><h3>Final thoughts</h3><p>As soon as I had finished the changes, I went to the developers desk and described my solution and the horror face he made when I told him I needed to change a kernel parameter was priceless. He kept rambling about how it needed to be scheduled since it needed a reboot and this is a production system that had to approved by the higher-ups and bla bla bla bla bla (Good thing those types of changes don’t require a reboot). I just told him it was done and added a simple “Please run the application again, it won’t fail now”.</p><p>Hope it doesn’t :p</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd57e7859dbb" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/reusing-tcp-ports-for-fun-profit-and-lack-of-headaches-cd57e7859dbb">Reusing TCP ports for fun, profit, and lack of headaches</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Updating a Proxmox Cluster from 4.4 to 5.4 the safe way]]></title>
            <link>https://medium.com/@victor.oliveira.comp/updating-a-proxmox-cluster-from-4-4-to-5-4-the-safe-way-f893aac4393f?source=rss-a571c287e041------2</link>
            <guid isPermaLink="false">https://medium.com/p/f893aac4393f</guid>
            <category><![CDATA[debian]]></category>
            <category><![CDATA[it]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[proxmox]]></category>
            <category><![CDATA[virtualization]]></category>
            <dc:creator><![CDATA[Victor Oliveira]]></dc:creator>
            <pubDate>Fri, 10 Jan 2020 11:09:43 GMT</pubDate>
            <atom:updated>2020-01-10T11:09:43.650Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*glPnx3fKMLyOaEW_ipxiOw.jpeg" /></figure><p><em>Disclaimer: I know that Proxmox 6 is out, but most production systems and more importantly the people that make decisions don’t precisely like to work with the latest releases because they can be prone to bugs (no matter the company or community behind it).</em></p><p>Most of us have had instances where a production virtualization cluster can’t be updated for whatever reasons: stability, fear of screwing up, orders from above, or scared co-workers that might think that once it’s in production you shouldn’t (just don’t) touch anything that might hinder the intended behavior of a system.</p><p>However, there are some things that do need to be upgraded, especially in cases where a bug that has been pestering you has been fixed on a newer version or a new functionality has been added. Now, I’m not one of those guys that likes to have absolute bleeding-edge software on production servers (obvious reasons might include: it just hasn’t been tested long enough), but having software on production that might soon reach End Of Life or that isn’t behaving up to current standards, that, I have a problem with.</p><p>I started to work on a new company not long ago and I came to work on the first day to see a few Proxmox clusters running on 4.4, which isn’t that bad (don’t touch production servers remember?), so I tested the functionality and I came to see bugs I hadn’t seen in years (including issues with the no-vnc connections to the VMs) and decided to do something about it. So I convinced my manager to upgrade the clusters.</p><p>At the time of writing this article the current version of Proxmox is 6.0. I’ve had bad experiences upgrading to the first major version of Proxmox before so I decided to upgrade to 5.4 at least until a more polished version of Proxmox comes around.</p><p>The procedure is pretty simple, if you have classical shared storage (NFS, iSCSI disks, etc.).</p><blockquote><strong>Beware CEPH Users</strong></blockquote><blockquote>This article doesn’t cover the steps for a CEPH upgrade, so please be careful</blockquote><blockquote><strong>Beware CEPH Users</strong></blockquote><p>So, we start with a cluster. We need to balance our the whole cluster so we can get an empty node. That means migrating all the VMs to other nodes, all while making sure the target nodes don’t run out of RAM and in my case making sure the CPU load wasn’t topping out (production servers remember?).</p><p>The migration procedure is pretty straightforward:</p><blockquote>Right click on a VM -&gt; Migrate -&gt; Select the target node -&gt; Get a cup of coffee</blockquote><p>After you finish this process you can go ahead and upgrade the node.</p><p>First off, start with a check from the terminal so we can make sure there’s no VMs running on the node:</p><p>qm list</p><p>Once we make sure there are no running VMs and we’re sure the node is empty (go ahead, check again.) we can proceed.</p><p>First step is to do an update on the repos with:</p><p>apt update</p><p>Then we can upgrade and reboot the current system with the newest kernel for 4.4:</p><p>apt upgrade -y; reboot</p><p>Once the node comes back up we need to add-in the new repos for the upgrade, as well as the GPG signatures for the repos:</p><pre>sed -i ‘s/jessie/stretch/g’ /etc/apt/sources.list<br>sed -i ‘s/jessie/stretch/g’ /etc/apt/sources.list.d/pve-enterprise.list<br>wget <a href="http://download.proxmox.com/debian/proxmox-ve-release-5.x.gpg">http://download.proxmox.com/debian/proxmox-ve-release-5.x.gpg</a> -O /etc/apt/trusted.gpg.d/proxmox-ve-release-5.x.gpg</pre><p>Then we proceed with updating the repository on APT:</p><p>apt update</p><p>Now, this is <strong>very</strong> important, we need to remote sysv-rc, openrc, etc from the system so we’re able to get the latest systemd gracefulness on the system<strong> DO NOT REBOOT THE SYSTEM</strong>:</p><p>apt purge insserv sysv-rc initscripts openrc</p><p><strong>DO NOT REBOOT THE SYSTEM</strong> Seriously, unless you wanna spend hours fixing the system or just formatting it and adding it as a new node. (which in hindsight isn’t such a bad idea)</p><p>After the removal is done we can finally upgrade the node to the 5.4 version of Proxmox:</p><p>apt-get dist-upgrade</p><p>This step can take a while, and it’s going to prompt you for answers a couple of times regarding configuration files, you can leave them as-is or you can upgrade them, up to you. I leave them as-is in case I need to recover anything.</p><p>Finally, you can reboot the system:</p><p>reboot</p><p>Et voilà!</p><p>Now you can migrate the VMs back to the node and start all over again with another node. This process can take a while and you might be able to automate it, however I’ve heard some stories both from RL and online from people that have had some bad luck with automating it and end up screwing up the cluster in some way or another.</p><p>Good Luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f893aac4393f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kernel mishaps on the network stack]]></title>
            <link>https://medium.com/@victor.oliveira.comp/kernel-mishaps-on-the-network-stack-3eada9447cc3?source=rss-a571c287e041------2</link>
            <guid isPermaLink="false">https://medium.com/p/3eada9447cc3</guid>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[kernel]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[debian]]></category>
            <dc:creator><![CDATA[Victor Oliveira]]></dc:creator>
            <pubDate>Fri, 10 Jan 2020 11:06:13 GMT</pubDate>
            <atom:updated>2020-02-10T09:07:03.570Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1evchsgq4qm4tLwHKnqeRw.jpeg" /></figure><p>For a couple of months we’ve had some issues with the one of our servers, the issue was summarized as follows:</p><blockquote><strong>Dev</strong>: I can’t connect to the server right now</blockquote><blockquote><strong>Ops</strong>: What do you mean?</blockquote><blockquote><strong>Dev</strong>: Connections timeout</blockquote><blockquote><strong>Ops</strong>: I can connect, we can connect, everyone can connect. Stop messing with your OS settings.</blockquote><blockquote><strong>Dev</strong>: …</blockquote><blockquote>Half an hour passes</blockquote><blockquote><strong>Ops</strong>: Oh $h*t I can’t connect now.</blockquote><blockquote><strong>Dev</strong>: :)</blockquote><p>Now this incident happened a few times over the course of a few months, but since this was only happening from our offices and the server was located at the collocation site we thought it was something between the office and the datacenter. We could, however, connect to the server by jumping from any other server at the datacenter. This, of course, was not optimal but we managed to push the issue onto backlog since we had several other critical incidents to take into account.</p><p>After checking everything on the network we noticed something was off about the server. We couldn’t reproduce the issue on any server, including this one, totally intermittent and it didn’t point towards anything else other than the server.</p><h3>Getting down to it</h3><p>One day, I had some time to kill so I decided to take a kick at it. Note that this isn’t the best way to “kill time”, you’ll end up trying to kill the guys next to you after a few hours of nothing making sense.</p><p>So, I connected to the server via SSH, via mysql remote connection (port 3306), http, https, and a few others and couldn’t reproduce the issue.</p><p>Checked it on a few other pc’s, Windows, Linux, Mac, a Solaris VM I carry around, nothing under the sun or above it could not connect. Wait it is.</p><p>After a few hours one of the computers failed to be able to connect, mine (praise the luck gods). So I started checking for everything within that machine, connected via another machine on the Datacenter’s network.</p><p>Now, this machine had a few kernel parameters set up since it needed to use a few thousand connections every few hours due to some hadoop processes that were supposed to run on it.</p><h3>Searching, searching, searching…</h3><p>Then our almighty friend Google came in, then it’s less mighty friend DuckDuckGo, then (yes, I know) Bing, then I was there looking at my screen with a few dozen tabs open with nothing to show for it and a light headache.</p><p>So I started looking at the networking stack within Linux and checking the network statistics recorded by the kernel itself. You can check these with:</p><p>netstat -s</p><p>The output for the netstat -s command left me with more questions than answers but something stood out of the terminal staring straight to my face:</p><p>35544811584 SYNS to LISTEN sockets dropped<br><br>This can happen since the Linux network stack is designed to avoid SYN floods by default and this counter is almost never zero because of false positives, however this doesn’t hinder the performance or the usability of the system. In case you want to learn more about SYN Flood attacks <a href="https://www.cloudflare.com/learning/ddos/syn-flood-ddos-attack">read here</a></p><h3>The culprit</h3><p>Other than the SYNS to LISTEN sockets dropped I noticed another couple entries:</p><pre>7008728 invalid SYN cookies received<br>10703 packets collapsed in receive queue due to low socket buffer</pre><p>These entries looked strange to me, I know this is a server but those numbers looked way too high for a server that wasn’t exposed to external networks.</p><p>After checking a lot more documentation than I should have about those entries which, by the way, is like reading a legal book with it’s own technical language that no one but kernel developers seem to understand. I decided to go back to the kernel config at:</p><p>/etc/sysctl.conf</p><p>And noticed this (this was copied verbatim straight from the server):</p><pre>vm.overcommit_memory = 1<br>net.ipv4.tcp_fin_timeout=30<br>vm.swappiness=1<br>#net.core.somaxconn = 1024<br>#fs.file-max = 1311072<br>net.ipv4.tcp_max_syn_backlog = 16192<br>net.core.somaxconn = 4096<br>vm.nr_hugepages=512<br>net.ipv4.tcp_tw_recycle = 1<br>net.ipv4.tcp_tw_reuse = 1<br>net.netfilter.nf_conntrack_tcp_timeout_established=600<br></pre><p>The entry for net.ipv4.tcp_tw_reuse = 1 was added by me because of another incident I can’t describe on this post but these other entries don’t match what I was expecting for this server to have configured. However, these sounded familiar and I decided to up the scale on some of them, including the tcp_max_syn_backlog and the somaxconn, adapting them to the memory quantities this server has, not outdated numbers for 4GB systems (this node has 512GB of RAM and averages 200GB free RAM, it can afford to give a few megs to the kernel)</p><p>But one other entry popped right at my eyes, after hours and hours of searching and watching for logs, and command outputs:</p><p>net.ipv4.tcp_tw_recycle = 1</p><h3>Fixing the issue</h3><p>Let me explain. tcp_tw_reuse and tcp_tw_recycle should be used when server and client timestamps are enabled, by default they are.</p><p>tcp_tw_reuse only works for the client.</p><p>tcp_tw_recycle works for both the client and the server, it reclaims the socket after 3.5*RTO (RTO=Retransmission timeout, if you want to read more about RTO, <a href="https://tools.ietf.org/html/rfc6298">check this out</a> after opening the connection.</p><p>In the case of LANs the re-transmission is really fast since there’s basically no delay on the network so the server tries to recycle connections faster than they can be used, hence the no connection after a while.</p><p>Basically the server says “Nope, you already connected, I’m recycling your connection for something else”. But what else? …</p><p>The solution, after months, turns out to be disabling the entry. Just comment it out altogether from the sysctl.conf file.</p><p>net.ipv4.tcp_tw_recycle = 0</p><p>And reload it with a:<br><br>sysctl -p</p><p>Yeap, a few hours wasted, buuuuuuuuut. Now I know how the Linux network stack works, I’ll have a future article about it soon.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3eada9447cc3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How jq can save your job in simple ways]]></title>
            <link>https://levelup.gitconnected.com/how-jq-can-save-your-job-in-simple-ways-341c27ede1b9?source=rss-a571c287e041------2</link>
            <guid isPermaLink="false">https://medium.com/p/341c27ede1b9</guid>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[jq]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Victor Oliveira]]></dc:creator>
            <pubDate>Thu, 09 Jan 2020 11:19:45 GMT</pubDate>
            <atom:updated>2020-01-09T11:19:45.238Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Programming" src="https://cdn-images-1.medium.com/max/1024/1*XXI-kg18liPn4XcfZmoqQQ.jpeg" /></figure><p>While checking the ticketing system for my company I noticed there was a new reply for a ticket that had been in hiatus for quite a while (hiatus as in it was opened and no one checked it for whatever reason, maybe someone was too busy and no it wasn’t on the backlog queue). The new message said something like: ‘Hey guys? is this happening? ever?’</p><p>So, I had some free time and decided to act on it. An API needed to be monitored. The API had several endpoints defined, all of which gave crucial information about the application instance that was deployed on the server. The information is presented on a JSON format and has the `value` entry defined with the values that needed monitoring.</p><p>Now, I’m not an expert on JSON, however the format isn’t too hard to understand and after checking some documentation and a couple of google searches it’s easily manageable. With a general understanding about the works on Bash, and a general understanding that’s basically summarized in two words -&gt; google-fu (as 99% of sysadmins I know are too afraid to admit this publicly, I will).</p><h3>Analizing</h3><p>After checking the API’s URL with `curl` I could tell there were some endpoints presented. All of the endpoints the developers needed to be monitored in fact.</p><blockquote>Note: If you don’t want an explanation for this and just wanna see the script, it’s posted at the end of this article</blockquote><p>To do this all you need to use is a one-liner on the terminal such as this:</p><blockquote>curl -s <a href="http://amazingapi.local/api">http://amazingapi.local/api</a><br><br>Note: you could use curl with any URL, be it with a domain name or an IP without DNS, if you need to get some more instructions about it feel free to consult the man pages for the command using man curl</blockquote><h3>Working with JSON</h3><p>After checking the output from the curl command we get something like this:</p><pre><br>curl -s <a href="http://amazingapi.local/api">http://amazingapi.local/api</a></pre><pre>{“names”:[“jvm.memory.max”,”jdbc.connections.active”,”process.files.max”,”jvm.gc.memory.promoted”,”tomcat.cache.hit”,”system.load.average.1m”,”tomcat.cache.access”,”jvm.memory.used”,”jvm.gc.max.data.size”,”jdbc.connections.max”,”jdbc.connections.min”,”jvm.gc.pause”,”jvm.memory.committed”,”http.server.requests”,”system.cpu.count”,”tomcat.global.sent”,”jvm.buffer.memory.used”,”tomcat.sessions.created”,”jvm.threads.daemon”,”system.cpu.usage”,”jvm.gc.memory.allocated”,”tomcat.global.request.max”,”hikaricp.connections.idle”,”hikaricp.connections.pending”,”tomcat.global.request”,”tomcat.sessions.expired”,”hikaricp.connections”,”jvm.threads.live”,”jvm.threads.peak”,”tomcat.global.received”,”hikaricp.connections.active”,”hikaricp.connections.creation”,”process.uptime”,”tomcat.sessions.rejected”,”process.cpu.usage”,”tomcat.threads.config.max”,”jvm.classes.loaded”,”hikaricp.connections.max”,”hikaricp.connections.min”,”jvm.classes.unloaded”,”tomcat.global.error”,”tomcat.sessions.active.current”,”tomcat.sessions.alive.max”,”jvm.gc.live.data.size”,”tomcat.servlet.request.max”,”hikaricp.connections.usage”,”tomcat.threads.current”,”tomcat.servlet.request”,”hikaricp.connections.timeout”,”process.files.open”,”jvm.buffer.count”,”jvm.buffer.total.capacity”,”tomcat.sessions.active.max”,”hikaricp.connections.acquire”,”tomcat.threads.busy”,”process.start.time”,”tomcat.servlet.error”]}</pre><p>Not many people will read the entire output, first of all because even though it’s on a JSON format, it’s minimized so it’s not as easy to follow, however this is where our new best friend when it comes to JSON comes in: jq. If you pipe the output from the curl command into jq we can see something like this:</p><pre><br>curl -s <a href="http://amazingapi.local/api">http://amazingapi.local/api</a> | jq<br>{<br> “names”: [<br> “jvm.memory.max”,<br> “http.server.requests”,<br> “jdbc.connections.active”,<br> “process.files.max”,<br> “jvm.gc.memory.promoted”,<br> “tomcat.cache.hit”,<br> “system.load.average.1m”,<br> “tomcat.cache.access”,<br> “jvm.memory.used”,<br> “jvm.gc.max.data.size”,<br> “jdbc.connections.max”,<br> “jdbc.connections.min”,<br> “jvm.gc.pause”,<br> “jvm.memory.committed”,<br> “system.cpu.count”,<br> “tomcat.global.sent”,<br> “jvm.buffer.memory.used”,<br> “tomcat.sessions.created”,<br> “jvm.threads.daemon”,<br> “system.cpu.usage”,<br> “jvm.gc.memory.allocated”,<br> “tomcat.global.request.max”,<br> “hikaricp.connections.idle”,<br> “hikaricp.connections.pending”,<br> “tomcat.global.request”,<br> “tomcat.sessions.expired”,<br> “hikaricp.connections”,<br> “jvm.threads.live”,<br> “jvm.threads.peak”,<br> “tomcat.global.received”,<br> “hikaricp.connections.active”,<br> “hikaricp.connections.creation”,<br> “process.uptime”,<br> “tomcat.sessions.rejected”,<br> “process.cpu.usage”,<br> “tomcat.threads.config.max”,<br> “jvm.classes.loaded”,<br> “hikaricp.connections.max”,<br> “hikaricp.connections.min”,<br> “jvm.classes.unloaded”,<br> “tomcat.global.error”,<br> “tomcat.sessions.active.current”,<br> “tomcat.sessions.alive.max”,<br> “jvm.gc.live.data.size”,<br> “tomcat.servlet.request.max”,<br> “hikaricp.connections.usage”,<br> “tomcat.threads.current”,<br> “tomcat.servlet.request”,<br> “hikaricp.connections.timeout”,<br> “process.files.open”,<br> “jvm.buffer.count”,<br> “jvm.buffer.total.capacity”,<br> “tomcat.sessions.active.max”,<br> “hikaricp.connections.acquire”,<br> “tomcat.threads.busy”,<br> “process.start.time”,<br> “tomcat.servlet.error”<br> ]<br>}</pre><p>If you need to install jq, it’s as simple as: apt install jq -y on Debian based distros or yum install jq -y on RHEL based distros.</p><p>This is A LOT easier to understand, and we start finding a small issue, there’s a lot of endpoints. There’s a few ways to create a script to monitor an API, most of them involve creating a single script for a single API, however there’s many APIs to be monitored in both this company’s infrastructure or whichever we want to explore.</p><h3>Reasoning</h3><p>In this specific case a few developers told me that not all of the APIs had the same endpoints but most of them didn’t need credentials since they were filtered by IPs, so it made the task a lot easier. I won’t go on details on how to do this against an authenticated API, maybe on another article; but implementing a token based authentication or a credentials based authentication on the script shouldn’t take more than a couple of lines.</p><p>Back to the API. As you and I can see, there’s a lot of endpoints and we don’t know if those are going to change any day, some deleted, some added. We need to make a script that can adapt and be set up within our monitorization tool to take into account the new changes. Also, this API is served from a Tomcat application, this doesn’t need to be the case always.</p><p>Since we can get the Endpoint list from the curl command we executed earlier, we can also check for a specific endpoint. In the case of the first entry: jvm.memory.max we can do this:</p><h3>Selecting values</h3><pre>curl -s <a href="http://amazingapi.local/api/jvm.memory.max">http://amazingapi.local/api/jvm.memory.max</a> | jq<br>{<br> “name”: “jvm.memory.max”,<br> “description”: “The maximum amount of memory in bytes that can be used for memory management”,<br> “baseUnit”: “bytes”,<br> “measurements”: [<br> {<br> “statistic”: “VALUE”,<br> “value”: 33096204287<br> }<br> ],<br> “availableTags”: [<br> {<br> “tag”: “area”,<br> “values”: [<br> “heap”,<br> “nonheap”<br> ]<br> },<br> {<br> “tag”: “id”,<br> “values”: [<br> “Compressed Class Space”,<br> “PS Survivor Space”,<br> “PS Old Gen”,<br> “Metaspace”,<br> “PS Eden Space”,<br> “Code Cache”<br> ]<br> }<br> ]<br>}</pre><p>Awesome, we see the value that the API provides as well as a few extra data that doesn’t serve much purpose for our needs right now and we won’t delve on it too much. The main attribute we want from the JSON output is the VALUE entry, which belongs on the measurements array:</p><pre> “measurements”: [<br> {<br> “statistic”: “VALUE”,<br> “value”: 33096204287<br> }<br> ],</pre><h3>Options for jq</h3><p>With jq we can get an array from within an object with single quotes and the brackets to denote an array, like this:</p><pre>curl -s <a href="http://amazingapi.local/api/jvm.memory.max">http://amazingapi.local/api/jvm.memory.max</a> | jq ‘.measurements[]’<br>{<br> “statistic”: “VALUE”,<br> “value”: 33096204287<br>}</pre><p>In case we want to get a specific entry from the array we can go further in and get the specific value we need:</p><pre><br>curl -s <a href="http://amazingapi.local/api/jvm.memory.max">http://amazingapi.local/api/jvm.memory.max</a> | jq ‘.measurements[]’ | jq ‘.value’</pre><pre>33096204287</pre><p>That number that outputs from the command is “The maximum amount of memory in bytes that can be used for memory management” as stated by the previous query we did against the API. This number can be converted a bunch of different ways from the script, however we won’t because we need the script to be as frugal as possible so it can be used with many APIs and many endpoints.</p><p>Now, we know how to get a specific value from an endpoint using *curl*, we just need to script it into something that can be used by monitoring software. Since most monitoring software allows bash scripts or sh or ksh or whichever shell is installed on the monitoring software’s host machine we’ll just use Bash.</p><h3>Scripting</h3><p>Please note that this script relies on some text manipulation that can be understood using the man pages on your Linux console. This script might look kinda hard to read at first (sorry, not sorry) but it’s pretty simple once you actually go line through line.</p><p>Lets start with the first segment:</p><pre><br>#!/bin/bash<br>if [[ -z $1 ]] ; then<br> echo “This script has to be used with two parameters”<br> echo “Usage:”<br> echo “check_api.sh &lt;api_url&gt; &lt;endpoint&gt;”<br> echo “e.g.:”<br> echo “ check_api.sh <a href="http://exampleurl.com/api">http://exampleurl.com/api</a> cpu.sys.util”<br> exit 1<br>fi</pre><p>We just initialize the script and put in a description, if the script doesn’t receive the parameters it expects on startup its going to show some help message and an example.</p><p>Afterwards we define a couple of variables to be used:</p><pre><br>url=$1<br>probe=$2<br>endpoints=$`curl -s $1 | \<br>jq ‘.names[]’| awk -F\” ‘{print $2}’|cut -c 1-`</pre><p>These variables do simple jobs. The first two are set up to receive the parameters from the script execution, the third one is the command that gets the enpoint list from the API server (like we discovered earlier).</p><p>Then we input the endpoint list onto an array defined as: <em>endpointsarray</em>:</p><pre>endpointsarray=( $endpoints )</pre><p>And finally the actual magic:</p><pre>for i in “${endpointsarray[@]}”<br>do<br> specs=`curl -s $1$i | \<br> jq ‘.measurements[]’ | jq ‘.value’`<br> echo $i $specs |grep $probe | cut -d “ “ -f2-<br>done</pre><p>This for loop just goes through the array and gets the value from the endpoint. It has some text manipulation due to the fact that the script is going to throw out some information that’s not needed, in case you wanna see some of it you’re free to experiment with the script, try seeing what the *cut* command does on it.</p><p>Hopefully this has thrown some light onto some things that may need some light. Full script as follows.</p><h3>Final Script</h3><p>TL;DR: Script that gets all endpoints from an API and gets the values from a single endpoint:</p><pre><br>#!/bin/bash<br>if [[ -z $1 ]] ; then<br> echo “This script has to be used with two parameters”<br> echo “Usage:”<br> echo “check_api.sh &lt;api_url&gt; &lt;endpoint&gt;”<br> echo “e.g.:”<br> echo “ check_api.sh <a href="http://exampleurl.com/api">http://exampleurl.com/api</a> cpu.sys.util”<br> exit 1<br>fi</pre><pre>url=$1<br>probe=$2</pre><pre>endpoints=$`curl -s $1 | \<br>jq ‘.names[]’| awk -F\” ‘{print $2}’|cut -c 1-`</pre><pre>endpointsarray=( $endpoints )</pre><pre>for i in “${endpointsarray[@]}”<br>do<br> specs=`curl -s $1$i | \<br> jq ‘.measurements[]’ | jq ‘.value’`<br> echo $i $specs |grep $probe | cut -d “ “ -f2-<br>done</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=341c27ede1b9" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/how-jq-can-save-your-job-in-simple-ways-341c27ede1b9">How jq can save your job in simple ways</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[S(z)etting up your private networks with ZeroTier]]></title>
            <link>https://medium.com/@victor.oliveira.comp/s-z-etting-up-your-private-networks-with-zerotier-a0540f936d2b?source=rss-a571c287e041------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0540f936d2b</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[privacy]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[zerotier]]></category>
            <dc:creator><![CDATA[Victor Oliveira]]></dc:creator>
            <pubDate>Thu, 09 Jan 2020 11:11:09 GMT</pubDate>
            <atom:updated>2020-01-09T11:11:09.777Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Rope Network" src="https://cdn-images-1.medium.com/max/1024/1*oGoUT4CZ9CQlQOi5TfCsZw.jpeg" /></figure><p>I’ve had the privilege of setting up, maintaining and running different systems ranging from home-labs, to full-blown multinational production systems that our staff works on during office hours (sometimes beyond office hours). Along with my co-workers and friends, I’ve tested and use daily different ways to connect to private infrastructures, usually through a VPN connection.</p><p>This is where ZeroTier comes in, being a SD-WAN (Software Defined Wide Area Network) it doesn’t depend on new hardware, it can just be set up using whatever you already have, as long as you have more than one machine. Take into account that your phone counts :). This is basically a P2P network that only your devices can access.</p><p>ZeroTier’s virtual networks are defined by it’s creators as:</p><blockquote>ZeroTier virtual networks are like chat rooms for machines. Just create virtual networks, join them from your devices and systems, approve authorization for the things you’ve added, and you’re done! Advanced features like our network rules engine help you manage your networks like a pro, and automatic end-to-end encryption keeps everything private and secure.</blockquote><h3>Registering</h3><p>To be able to use ZeroTier you need to register on their website, this is so you can control the P2P network: (<a href="https://zerotier.com/">https://zerotier.com</a>). Click on Login and then Register:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*-KIj8zzM4vjahKd0QmAw9w.png" /><figcaption>Registration site</figcaption></figure><p>After you register and confirm your email, you could purchase a subscription since the service doesn’t allow more than 100 devices on the free plan, also there’s no support if you’re not paying. That’s just how the world works, even though the service is free, people need to be paid for their work.</p><p>Let’s get started.</p><h3>Creating Networks</h3><p>You need to create a network for your machines (and phone) to connect, click on ‘Networks’ and then on ‘Create a Network’. Take into account that even using the <em>free plan</em> you still get to be able to create unlimited networks here.</p><p>The network creation is immediate, it comes with a Network ID and a random name:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h29oOwU4l2conI8prqAAUQ.png" /></figure><p>This network can be <em>Private</em> or <em>Public</em>.</p><p>Private networks are the safest way to go around, but also mean you have to make a couple of clicks per machine you add to the network.</p><p>Public networks allow anyone with the network ID to connect to it and be authorized.</p><p>Afterwards, you can set up the actual network.</p><h3>Setting up the network</h3><p>IPv4 ranges can be selected from the network control panel, it comes with the *Auto-Assign from range* option pre-selected and a random range selected too. Note that all of these ranges are private IPs, you can’t see them outside of your ZeroTier network. Since you’re using the free plan there’s no actual reason to use anything more than a /24 range, select one, in this case: 192.168.195.x:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gYqS-GxQ7kPbjHNvozUqfg.png" /></figure><p>These ranges also come with an established route, if you would like to change them you could do so as well.</p><p>In the case of IPv6 you can also Auto-Assign the IPs, depending on what you need you could use:</p><blockquote>- ZeroTier RFC4193 (/128 for each device)<br>- ZeroTier 6PLANE (/80 routable for each device)<br>- Auto-Assign from Range</blockquote><p>Now to the machines:</p><h3>Setting up our peers</h3><p>Lets use a couple of examples here so you can see how to set up different machines on different OS’s, although ZeroTier’s documentation is pretty complete about it:</p><h4>Linux machine</h4><p>Make sure you have curl and gpg installed. Most modern distros come with gpg, but not always curl. Depending on your linux distro just use your package manager to install these. Once installed run this command:</p><pre>curl -s ‘<a href="https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/doc/contact%40zerotier.com.gpg&#39;">https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/doc/contact%40zerotier.com.gpg&#39;</a> | gpg — import &amp;&amp; if z=$(curl -s ‘<a href="https://install.zerotier.com/&#39;">https://install.zerotier.com/&#39;</a> | gpg); then echo “$z” | sudo bash; fi</pre><p>There’s another method to install the client, daemon services, and repository but it doesn’t check for cryptographic signatures and relies fully on SSL, just a simple script:</p><p>curl -s <a href="https://install.zerotier.com/">https://install.zerotier.com</a> | sudo bash</p><p>After the script is done just join the node with the zerotier-cli using your network ID:</p><p>zerotier-cli join d3ecf5726d62e220</p><p>And finally, authorize it from your control panel by checking on the checkbox that appears on your panel with the node ID (This node ID is shown on the terminal when the installation process finishes)</p><h4>Android phone</h4><p>Yes, I’m including this because not everyone has more than one machine and not everyone wants to create VMs and some people need a connection straight to their laptops or desktop machines from their phones:</p><p>Go on the Play Store and search for ZeroTier, install it and join a network, pretty easy, pretty straightforward.</p><p>Oh and don’t forget to authorize the phone.</p><h3>Final set up</h3><p>There’s no final set up, just go ahead and connect to your devices, doesn’t matter if you’re on the same Wifi or on a different country, as long as the machine as an internet connection you should be able to get to it.</p><p>Don’t forget to fill the names and/or description fields on the control panel for the machines, else you’re gonna have a bad time after it gets to more than a couple machines.</p><p>Good Luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0540f936d2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Set up your machine to use kubectl]]></title>
            <link>https://medium.com/@victor.oliveira.comp/set-up-your-machine-to-use-kubectl-316e6c33fe56?source=rss-a571c287e041------2</link>
            <guid isPermaLink="false">https://medium.com/p/316e6c33fe56</guid>
            <category><![CDATA[mac]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[kubectl]]></category>
            <dc:creator><![CDATA[Victor Oliveira]]></dc:creator>
            <pubDate>Thu, 09 Jan 2020 10:59:16 GMT</pubDate>
            <atom:updated>2020-01-09T10:59:16.347Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Programmer Laptop" src="https://cdn-images-1.medium.com/max/1024/1*yAy78IwsgFvSGVnCwpupXw.jpeg" /></figure><p>Most of the infrastructure I use on a daily basis is currently tied to K8s in one way or another. As a result this means that our machines have to be set up for K8s in one way or another to be able to perform different tasks on it. If you decide to run, test or become proficient on K8s you need to have kubectl set up on your environment.</p><p>K8s allows you to have different permissions and roles depending on your role regarding the cluster, whichever it may be: admin, maintainer, operator, developer, tester, etc.</p><p>This article won’t go into detail on RBAC (Role-Based Access Control), if you want to learn more about it go to: <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/">https://kubernetes.io/docs/reference/access-authn-authz/rbac/</a>)</p><p>For whatever task you need to perform on the cluster you do need some sort of way to interact with the cluster.</p><h3><strong>Enter kubectl</strong></h3><p>kubectl is a CLI tool that allows you to run commands that interact with K8s clusters. Whether it may be getting information from a specific pod, deployment, service, etc. to editing a definition for an instance.</p><p>It can be installed in different ways, lets focus on the ones that can be maintained easily, for instance from the OS’s package manager.</p><p>After you install kubectl you need to configure it. Just scroll down, you’ll get there. Above all, take into account the freedom of choice.</p><h3>Linux</h3><p>The easiest to install, just copy and paste these commands on the terminal for each of the distros.</p><p><em>Please take into account that you should check the contents of the repo file as well as the URLs, just to be safe</em></p><p>You’re going to use package management, snaps and straight binary download for the sake of completeness (<strong>JUST USE ONE OF THESE</strong>)</p><h4>Debian/Ubuntu/other derivatives that use .deb</h4><pre>sudo apt-get update &amp;&amp; sudo apt-get install -y apt-transport-https<br>curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -<br>echo “deb https://apt.kubernetes.io/ kubernetes-xenial main” | sudo tee -a /etc/apt/sources.list.d/kubernetes.list<br>sudo apt-get update<br>sudo apt-get install -y kubectl</pre><h4>CentOS/RHEL/Fedora/other derivatives that use .rpm</h4><pre>cat &lt;&lt;EOF &gt; /etc/yum.repos.d/kubernetes.repo<br>[kubernetes]<br>name=Kubernetes<br>baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64<br>enabled=1<br>gpgcheck=1<br>repo_gpgcheck=1<br>gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg<br>EOF<br>yum install -y kubectl</pre><h4>Snap</h4><p>sudo snap install kubectl — classic</p><h4>Straight binary</h4><p>Download the latest release from google:</p><pre><br>curl -LO <a href="https://storage.googleapis.com/kubernetes-release/release/%60curl">https://storage.googleapis.com/kubernetes-release/release/`curl</a> -s <a href="https://storage.googleapis.com/kubernetes-release/release/stable.txt%60/bin/linux/amd64/kubectl">https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl</a><br></pre><p>Give it executable permissions</p><p>chmod +x ./kubectl<br><br>And move it to your binary path</p><p>sudo mv ./kubectl /usr/local/bin/kubectl<br><br>Make sure it works!</p><p>kubectl version</p><h3>Windows</h3><p>In the case of Windows you can decide to use a few tools including but not limited to WSL (Windows subsystem for linux), PowerShell, Chocolatey, etc.</p><h4>WSL</h4><p>Just use the same procedures for linux on your WSL console</p><h4>PowerShell</h4><h4>PSGallery</h4><p>You can use PSGallery:</p><pre><br>Install-Script -Name install-kubectl -Scope CurrentUser -Force<br>install-kubectl.ps1 [-DownloadLocation $PATH]<br></pre><p>You should change: $PATH for whichever path you want to choose for the download</p><h4>Curl</h4><p>Pure PowerShell allows you to run kubectl as well:</p><pre><br>curl -LO <a href="https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/windows/amd64/kubectl.exe">https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/windows/amd64/kubectl.exe</a><br></pre><p>Don’t forget to add the <em>.exe</em> to your path, else you’ll have to navigate to the download path all the time or use an absolute route for the binary.</p><h4>Chocolatey</h4><p>choco install kubernetes-cli</p><h3>Mac</h3><p>The number of systems and devops engineers that use Mac either grows or diminishes every year (depends on who you ask, to each their own. I don’t judge). However there’s a lot our there that use it daily. In the same way that Linux and Windows users have a few ways to install it.</p><h4>Homebrew</h4><p>For Homebrew it’s a simple one-liner:</p><p>brew install kubectl</p><h4>Macports</h4><p>Same with Macports</p><p>sudo port selfupdate; sudo port install kubectl</p><h4>Straight binary on MAC</h4><p>The binary method for MAC is basically the same as for Linux but with a different binary package:</p><pre><br>curl -LO “<a href="https://storage.googleapis.com/kubernetes-release/release/$(curl">https://storage.googleapis.com/kubernetes-release/release/$(curl</a> -s <a href="https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl">https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl</a>&quot;<br></pre><p>Give it executable permissions</p><p>chmod +x ./kubectl<br><br>And move it to your binary path</p><p>sudo mv ./kubectl /usr/local/bin/kubectl</p><p>Make sure it works!</p><p>kubectl version</p><h3>Configuration</h3><p>After the installation is done you need to add the config file for kubernetes on your $PATH for kubectl to be able to work against your cluster.</p><p>On Linux, MAC and WSL this can be done by copying your config file on the following route:</p><p>~/.kube/config<br>In the case of Windows the file should be copied on the following route:</p><p>%USERPROFILE%/.kube/config</p><h4>Checking that everything works</h4><p>You can test that kubectl has access to the cluster by issuing the command:</p><p>kubectl version</p><p>If the connection works you’ll see an output like this:</p><pre>Client Version: version.Info{Major:”1&quot;, Minor:”17&quot;, GitVersion:”v1.17.0&quot;, GitCommit:”70132b0f130acc0bed193d9ba59dd186f0e634cf”, GitTreeState:”clean”, BuildDate:”2019–12–10T03:03:57Z”, GoVersion:”go1.13.5&quot;, Compiler:”gc”, Platform:”linux/amd64&quot;}<br>Server Version: version.Info{Major:”1&quot;, Minor:”16&quot;, GitVersion:”v1.16.3&quot;, GitCommit:”b3cbbae08ec52a7fc73d334838e18d17e8512749&quot;, GitTreeState:”clean”, BuildDate:”2019–11–13T11:13:49Z”, GoVersion:”go1.12.12&quot;, Compiler:”gc”, Platform:”linux/amd64&quot;}</pre><p>Where the ‘Client Version’ is the kubectl binary version and the ‘Server Version’ is the Cluster version.</p><h3>Final words</h3><p>This tutorial should help you configure kubectl for your machine, it can also be used to set up a control server (just a simple virtual machine that has access to the same network as the K8s cluster)</p><p>In case you need any help you can type in a comment, we try to answer them ASAP.</p><p>Good Luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=316e6c33fe56" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>