<?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 Matthew Caspento on Medium]]></title>
        <description><![CDATA[Stories by Matthew Caspento on Medium]]></description>
        <link>https://medium.com/@mrcaspento?source=rss-879fbf683afb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*taPKjl5X21KlGWiW</url>
            <title>Stories by Matthew Caspento on Medium</title>
            <link>https://medium.com/@mrcaspento?source=rss-879fbf683afb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 20:22:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mrcaspento/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[How to Build a Kubernetes Server on a Raspberry Pi cluster]]></title>
            <link>https://awstip.com/how-to-build-a-kubernetes-server-on-a-raspberry-pi-cluster-43cce9931753?source=rss-879fbf683afb------2</link>
            <guid isPermaLink="false">https://medium.com/p/43cce9931753</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[home]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Matthew Caspento]]></dc:creator>
            <pubDate>Wed, 03 Aug 2022 17:54:19 GMT</pubDate>
            <atom:updated>2022-10-17T11:21:05.619Z</atom:updated>
            <content:encoded><![CDATA[<p>Part 3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bonbdo5KM7LZXP4VrXh6jw.jpeg" /></figure><h3><strong>Create a Kubernetes Cluster:</strong></h3><p>Before we create a Kubernetes Cluster, you will need to do a couple of things first.</p><p>One of the Raspberry Pis will need to be assigned as the control plane node, and the remaining nodes will be assigned as the worker nodes. You will need to pick a network CIDR that the pods will use in the cluster. This is important to have because the CIDR value is utilized by the container network interface(CNI) when we are making deployments.</p><p>I’m gonna use WeaveNet when initializing the control plane and worker nodes. Note the CIDR can’t overlap with any current CIDR that your home network uses already.</p><p>To start the process run of creating the control plane run the following:</p><pre>sudo kubeadm init --apiserver-advertise-address&lt;ip-address-of-pi&gt;</pre><p>The process will take a minute or two but it’s creating a whole bunch of things. From the coreDNS to the api-server for Kubernetes. Be patient. It’s important to install the CNI before because without it the CoreDNS will not start up.</p><p>To make kubectl work for a non-root user you can run:</p><pre>mkdir -p $HOME/.kube<br>sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config<br>sudo chown <strong>$(</strong>id -u<strong>)</strong>:<strong>$(</strong>id -g<strong>)</strong> $HOME/.kube/config</pre><p>Once you have the control plane node initialized you will want to join the worker nodes to the cluster. We start by printing the token join command. You can do that with the following command:</p><pre>sudo kubeadm token create -–print-join-command</pre><p>Example:</p><pre>kubeadm join 10.103.3.100:6443 — token ecl8em.qr2o44k3i4l7obn3 — discovery-token-ca-cert-hash sha256:47e29da64f820e2947d47f6c1bd085f8f4a36b6e9fe421f48d3b823ab58b8731 –apiserver-advertise-address&lt;ip-address-of-pi&gt;</pre><p>With that it should give you an output that you can copy and paste on the command line of the worker node you want to add.</p><p>So all you need to do is SSH into the worker nodes and paste the copied join command and the output should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*LE-VsSpxypPXCHhYqMyjog.jpeg" /></figure><p>You can now test if everything is working by creating a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/">Deployment</a>.</p><p>At the worker node you can run the command:</p><pre>kubectl create deployment nginx –image=nginx</pre><p>You can check if it’s running with:</p><pre>kubectl get pods</pre><p>Pictured below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VnlFt6XOrLJJf0TWUg5ERg.jpeg" /></figure><h3><strong>Conclusion:</strong></h3><p>At first glance, making a home server seems scary and complicated. Almost as mysterious as that second sock you are always losing when doing laundry. (Hell, it still is, there is a lot I need to still learn and everyday new things are being added to the ever growing list of cloud infrastructure tools &amp; tech.) Mostly network security still evades my expertise, but I got all the time in the world.</p><p>Now that you have a home server setup, the real fun begins. Further tutorials to be made on how to annoy your spouse/roommate with automation and home applications. I always like to say if you’re not getting under their skin, make sure to use that elbow grease to loosen up the pores.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43cce9931753" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/how-to-build-a-kubernetes-server-on-a-raspberry-pi-cluster-43cce9931753">How to Build a Kubernetes Server on a Raspberry Pi cluster</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a Kubernetes Server on a Raspberry Pi cluster]]></title>
            <link>https://medium.com/@mrcaspento/how-to-build-a-kubernetes-server-on-a-raspberry-pi-cluster-fa0ffa95c004?source=rss-879fbf683afb------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa0ffa95c004</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[home]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Matthew Caspento]]></dc:creator>
            <pubDate>Tue, 02 Aug 2022 11:46:32 GMT</pubDate>
            <atom:updated>2022-08-02T11:46:32.420Z</atom:updated>
            <content:encoded><![CDATA[<p>Part 2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bonbdo5KM7LZXP4VrXh6jw.jpeg" /></figure><h3><strong>Installing Docker Engine:</strong></h3><p>Part 2 is as simple as it gets. Unless you’re me and spent a couple days debugging only to realize I was using the wrong OS (Ubuntu Server 21(RPI3/4/400)) Don’t use it because it caused some bridging issue that prevented the CNI from starting. Like they always say you can save yourself 10 mins of reading Documentation with 2 days worth of debugging. Now to start.</p><p>You will want to start by setting up the repository with commands:</p><pre>sudo apt-get update<br>sudo apt install docker.io</pre><p>After installing Docker on your pi’s you will want to modify the default cgroups drivers to systemd. Kubernetes uses this method as it ensures system stability, having only one cgroup manager. Do this by modifying the docker daemon.</p><pre>sudo cat &gt; /etc/docker/daemon.json &lt;&lt;EOF<br>{<br>“exec-opts”: [“native.cgroupdriver=systemd”],<br>“log-driver”: “json-file”,<br>&quot;log=opts&quot;: {<br>},<br>“storage-driver”: “overlay2”<br>}<br>EOF</pre><p>Then you need to restart Docker for the changes to take effect.</p><pre>sudo systemctl enable docker<br>sudo systemctl daemon-reload<br>sudo systemctl restart docker</pre><p>We can now move on to installing the cream of the crop: Kubernetes. We are gonna be using kubeadm as it’s a great installation tool.</p><h3><strong>Installing Kubelet, Kubectl, &amp; Kubeadm:</strong></h3><p>I learned to code one year ago, and after the bootcamp I was in, I stumbled upon K8’s and became a huge Kubernetes fan. Seeing the demand for cloud engineers, I decided to become one. I set a personal goal to achieve my CKA, and I am glad to say I have reached that goal and am now working for Zaloni as a Cloud Operations Engineer.</p><p>In this section, I’ll go over everything you’ll need if you plan to use the `kubeadm` method of creating a cluster. It comes with it’s own advantages: one is that it can pass the <a href="https://kubernetes.io/blog/2017/10/software-conformance-certification">Kubernetes Conformance tests</a>. It gets us the minimum viable cluster up and running with the actions it takes for running the command `kubeadm init`.</p><p>On the master node and worker node we need to install <strong><em>kubeadm</em></strong>, <strong><em>kubelet</em></strong>, and <strong><em>kubectl</em></strong>.</p><p>Kubeadm is how we will bootstrap the cluster, and kubectl is the command we will use to tell the cluster to do whatever we want.</p><p>Example:</p><pre>kubectl get pods</pre><p>This will get me a list of pods that have been created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*swfcCcj5fcZNvld1eyto8A.jpeg" /></figure><p>Now the Kubelet is one of the most important parts. Think of it as an OS: without it you won’t be able to create containers or pods.</p><p><strong>Letting Ip tables See Bridged Traffic</strong></p><p>First, before we get started, we want to make sure that the br_netfilter module is loaded. To do that, follow the steps below:</p><pre>lsmod | grep br_netfilter</pre><pre>sudo modprobe br_netfilter</pre><pre>cat &lt;&lt;EOF | sudo tee /etc/modules-load.d/k8s.conf<br>br_netfilter <br>EOF</pre><pre>cat &lt;&lt;EOF | sudo tee /etc/sysctl.d/k8s.conf<br>net.bridge.bridge-nf-call-ip6tables = 1<br>net.bridge.bridge-nf-call-iptables = 1<br>EOF<br>sudo sysctl --system</pre><p>Since we are using Ubuntu as the OS, and because it’s a Debian-based distribution, we will use `apt-get`. First update the apt packages needed for Kubernetes.</p><pre>sudo apt-get update<br>sudo apt-get install -y apt-transport-https ca-certificates curl</pre><p>Then we download a Google Cloud public key, so that the apt repo will be trusted.</p><pre>sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg <a href="https://packages.cloud.google.com/apt/doc/apt-key.gpg">https://packages.cloud.google.com/apt/doc/apt-key.gpg</a></pre><p>The next step is to add the Kubernetes apt repo:</p><pre>echo “deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] <a href="https://apt.kubernetes.io/">https://apt.kubernetes.io/</a> kubernetes-xenial main” | sudo tee /etc/apt/sources.list.d/kubernetes.list</pre><p>The final step is to install the Kubernetes apt repo::</p><pre>sudo apt-get update<br>sudo apt-get install -y kubelet kubeadm kubectl<br>sudo apt-mark hold kubelet kubeadm kubectl</pre><p>Once the installation is completed, you need to check if everything is correctly installed by checking the versions of <strong><em>kubeadm</em></strong> and <strong><em>kubelet</em></strong>. Once done make sure to repeat these steps with each node.</p><p>If satisfied, we can continue by creating the cluster and adding the worker nodes to the cluster with part 3.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa0ffa95c004" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create an AWS Lambda EC2 AutoStart Function]]></title>
            <link>https://medium.com/zaloni-engineering/how-to-create-an-aws-lambda-ec2-autostart-function-c0b22d5f8e5c?source=rss-879fbf683afb------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0b22d5f8e5c</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[amazon-ec2]]></category>
            <dc:creator><![CDATA[Matthew Caspento]]></dc:creator>
            <pubDate>Thu, 23 Jun 2022 13:35:46 GMT</pubDate>
            <atom:updated>2022-06-23T13:54:25.998Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*wk7vSfIS7G1dRXOHDKNDqQ.jpeg" /></figure><p>Automation is a wonderful thing, especially if you’re lazy and don’t want to spend more than 3 minutes doing something. In this case, I hated getting up early each morning to start my environment. So I decided to automate my morning.</p><h3><strong>Use Case:</strong></h3><p>The use case we’ll be covering in this blog is automating the start of environments in order to enable an engineer to start the work day without delay. When an engineer starts their day, they have to authenticate to AWS. Once authenticated they need to switch regions and roles to where the EC2 instance resides. Then they have to start the instance after navigating to the EC2 Management Console. Once started, an engineer would have to wait for the instance to start. In total, the engineer would have spent 3 minutes or more.</p><p>Calculated yearly, each engineer wastes about 21 hours starting their environment.</p><p>Think of the cost of an employee who is earning $60K a year working124,800 minutes. That employee is making $.48 cents per minute, so each day the employee’s wasted time is $1.44 multiply that by 260 work days you get $375.</p><p>For each employee, there&#39;s an opportunity cost of $375 a year per engineer to spend 3 mins a day to start an instance. It’s something I know a lot of us do and it’s usually in the morning getting ready for work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UvjM2RtyUPYl0XRgF_PfTw.jpeg" /></figure><p>Currently, we have 35 instances that were manually started from 1/23/2022 at 7 pm EST to 1/24/2022 at 9 am EST. With that in mind if those are instances just being started that comes out to be an opportunity cost of $13,125 a year. As a company grows, so will the number of employees thus increasing that cost.</p><p>Currently, I have an array of holiday dates for India &amp; the United States. A script will check if today is in the array if so, it would skip the autoStart command. I have it set to run Monday-Friday once an hour on the hour from 12 am to 8 pm GMT. So I can limit the number of invocations from the lambda function to save on costs.</p><h3><strong>Documentation:</strong></h3><p>How to use the function: Just add the tags to the desired instance. The following syntax is required to work.</p><h4>Tags Required</h4><pre>start_auto: True/False, 1/0, Off/On (Default to False if Tag not present)</pre><pre>start_time: Should be 4 digits in hhmm format representing the</pre><pre>hour and minute to start the EC2 instance</pre><pre>hour is 24 hour time format<br>start_tz: Timezone to use for when interpreting start_time<br>Valid Time Zones from<br><a href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones">https://en.wikipedia.org/wiki/List_of_tz_database_time_zones</a><br>For US East use “America/New_York”<br>For India use “Asia/Calcutta”<br>start_lastdt:<br>Left blank for the script to update and patch<br>EC2 Instances will be started when all of the following are true:<br>- Instance is not running<br>- start_auto Tag is set to True (or equivalent)<br>- start_tz is a valid timezone<br>- current time hhmm &gt;&gt; start_time with current time converted to<br>start_tz timezone<br>AWS Permissions are assumed by the role assigned to the Lambda function<br>Requires ec2:DescribeInstances and ec2:StartInstances</pre><h4>EventBridge</h4><blockquote>Cronjob expression is: <strong>cron(0 0–20/1 ? * MON-FRI *)</strong></blockquote><h4>IAM Role</h4><blockquote>New role &amp; custom policy to start the instances</blockquote><h3><strong>Step One:</strong></h3><p>Before creating the lambda function, you will want to create a new IAM role with a custom permission policy. Start by making your way to the policies list located in the IAM dashboard sidebar and create a new policy.</p><p>You can use this JSON template, just replace the region and account Id.</p><pre>{<br>“Version”: “2012–10–17”,<br>“Statement”: [<br>{<br>“Effect”: “Allow”,<br>“Action”: [<br>“logs:CreateLogGroup”<br>],<br>“Resource”: “arn:aws:logs:&lt;currentRegion&gt;:&lt;accountID&gt;:*”<br>},<br>{<br>“Effect”: “Allow”,<br>“Action”: [<br>“logs:CreateLogStream”,<br>“logs:PutLogEvents”<br>],<br>“Resource”: “arn:aws:logs:&lt;currentRegion&gt;:&lt;accountID&gt;:log-group:/aws/lambda/run_autoStart:*”<br>},<br>{<br>“Action”: [<br>“ec2:StartInstances”,<br>“ec2:CreateTags”,<br>“ec2:DescribeInstances”<br>],<br>“Resource”: “*”,<br>“Effect”: “Allow”<br>}]<br>}</pre><p>Review the policy:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mzjBs243htfkzp27YcYhsg.jpeg" /></figure><p>Once the policy is created. We can now create an IAM role. Switch over to the <strong><em>Roles</em></strong> list and create a new role and attach the newly created policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*2zlDO9JSVjMnpyeE6YgxuA.jpeg" /></figure><p>Now we can create a lambda function. When doing so make sure you change the execution role to use an existing role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0o_EAY4Qoy-sX_RBYgr0Jg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jAW8-gkABtC2ZhmX613-Cg.jpeg" /></figure><p>Once created, we can build a trigger event rule. Just add a trigger and select the EventBridge(CloudWatch Events).</p><p>Make sure you add the expression in <strong><em>cron()</em></strong>.</p><pre>cron(0 3–20/1 ? * MON-FRI *)</pre><p>Now before we move on to adding the code. Save yourself a headache later and edit the runtime settings. Replace the first part of the handler with whatever you named the function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AUDnpo7ivj_RuR90PaNzeQ.jpeg" /><figcaption>Use the name of the function you created</figcaption></figure><p>Once this is done we can create the function.<strong> BUT</strong> first, we need to download a <strong><em>pytz </em></strong>package so we can differentiate between timezones. You can use:</p><pre>$ pip3 install pytz</pre><p>You will find the package in the python folder. Make a copy of the package and export it to an empty folder where we’ll eventually make it a zip as that’s the only way to import an app. When at the folder, open a code editor so you can create a new file that will contain all the logic for the function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*urG9_WdYsyZ8UQUUzT1XeQ.jpeg" /></figure><p>Make sure the folder is structured like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/215/1*qkeO1bzmZOj_bG7OyfwDug.jpeg" /></figure><p>For the script you can use this:</p><pre>###################################################################################<br>##  Name: autoStart.py<br>##  Purpose: to automatically start EC2 instances at a specific time<br>##           each day that are tagged appropriately<br>##<br>##  Tags Required:<br>##    start_auto:  True/False, 1/0, Off/On (Default to False if Tag not present)<br>##<br>##    start_time:  Should be 4 digits in hhmm format representing the<br>##                    hour and minute to start the EC2 instance<br>##                    hour is 24 hour time format<br>##<br>##    start_tz:    Timezone to use for when interpreting start_time<br>##                    Valid Time Zones from <br>##                      <a href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones">https://en.wikipedia.org/wiki/List_of_tz_database_time_zones</a><br>##                    For US East use &quot;America/New_York&quot;<br>##                    For India use &quot;Asia/Calcutta&quot;<br>##<br>##  EC2 Instances will be started when all of the following are true:<br>##     - Instance is not running<br>##     - start_auto Tag is set to True (or equivalent)<br>##     - start_tz is a valid timezone<br>##     - current time hhmm &gt;&gt; start_time with current time converted to <br>##                            start_tz timezone<br>##<br>##  AWS Permissions are assumed by the role assigned to the Lambda function<br>##      Requires ec2:DescribeInstances and ec2:StartInstances<br>##<br>##  Python Dependencies:<br>##    Package pytz must be installed locally and then uploaded into Lambda<br>##    using the zip upload option.<br>##    From same directly as this source file use:<br>##      install --target ./package pytz --system<br>##<br>##   This install the pytz package locally.  Again from the same directory<br>##   as this source file use:<br>##     zip -r9 lambda_package.zip . --exclude *.yml<br>##   The resulting zip can be uploaded into Lambda<br>##<br>####################################################################################</pre><pre>import json<br>import os<br>import boto3<br>import datetime<br>from datetime import datetime, date<br>from dateutil.parser import parse<br>import sys<br>sys.path.append(r&#39;./package&#39;)<br>import pytz</pre><pre>#############################################################################<br>##  sts_assume_role<br>##  Function only required if running locally for debug purposes<br>#############################################################################<br>def sts_assume_role( sess, arn, sessionName ):</pre><pre>sts_connection = sess.client(&#39;sts&#39;)<br>  assume_role_object = sts_connection.assume_role(RoleArn=arn, RoleSessionName=sessionName, DurationSeconds=3600)<br>  ## sess.credentials = assume_role_object[&#39;Credentials&#39;]<br>  tmp_access_key = assume_role_object[&#39;Credentials&#39;][&#39;AccessKeyId&#39;]<br>  tmp_secret_key = assume_role_object[&#39;Credentials&#39;][&#39;SecretAccessKey&#39;]<br>  security_token = assume_role_object[&#39;Credentials&#39;][&#39;SessionToken&#39;]</pre><pre>boto3_session = boto3.session.Session( aws_access_key_id=tmp_access_key,<br>                                        aws_secret_access_key=tmp_secret_key, <br>                                        aws_session_token=security_token  )<br>  return boto3_session</pre><pre>############################################################################<br>## compare date to Zaloni holidays<br>##<br>############################################################################<br>zaloni_holidays = [<br>&quot;2022-01-02&quot;,<br>&quot;2022-01-14&quot;,<br>&quot;2022-01-16&quot;,<br>&quot;2022-01-26&quot;,<br>&quot;2022-03-18&quot;,<br>&quot;2022-04-01&quot;,<br>&quot;2022-04-15&quot;,<br>&quot;2022-05-03&quot;,<br>&quot;2022-05-30&quot;,<br>&quot;2022-06-20&quot;,<br>&quot;2022-07-04&quot;,<br>&quot;2022-07-11&quot;,<br>&quot;2022-08-15&quot;,<br>&quot;2022-08-31&quot;,<br>&quot;2022-09-05&quot;,<br>&quot;2022-10-04&quot;,<br>&quot;2022-10-05&quot;,<br>&quot;2022-10-24&quot;,<br>&quot;2022-11-24&quot;,<br>&quot;2022-11-25&quot;,<br>&quot;2022-12-23&quot;,<br>&quot;2022-12-03&quot;,<br>&quot;2022-12-26&quot;<br>  ]<br>today = date.today().isoformat()<br>print(&quot;Is today a Holiday for Zaloni Employees?&quot;)<br>print(today in zaloni_holidays)<br>holiday_skip_day = today in zaloni_holidays</pre><pre>#############################################################################<br>## start_instances_for_region<br>##<br>#############################################################################<br>def start_instances_for_region( region ):</pre><pre>utc_now = pytz.utc.localize(datetime.utcnow())<br> <br>  ## master_session = boto3.session.Session( &quot;TBD KEY ID&quot;, &quot;TBD KEY SECRET ID&quot;)<br>  ## mysession = sts_assume_role( master_session, &quot;arn:aws:iam::&lt;accountID&gt;:role/cross-account-admin&quot;, &quot;tempSession1&quot; )<br> <br>  <br>  ec2_client = boto3.client(&quot;ec2&quot;, region_name=region)<br>  instances = ec2_client.describe_instances( MaxResults=800)<br>  # print( instances )<br>  i=0<br>  for x in instances[&#39;Reservations&#39;]:<br>    for instance in x[&#39;Instances&#39;]:<br>      i+=1<br>      InstanceId = instance[&#39;InstanceId&#39;] <br>      InstanceState = instance[&#39;State&#39;][&#39;Name&#39;]<br>        <br>      start_auto = False<br>      start_time = &quot;&quot;<br>      start_tz = &quot;&quot;<br>      start_lastdt = &quot;&quot;<br>      InstanceName = &quot;&quot;<br>      if &#39;Tags&#39; in instance:<br>        for tag in instance[&#39;Tags&#39;]:<br>          <br>          if ( tag[&#39;Key&#39;] == &#39;start_auto&#39; ):<br>            start_auto = tag[&#39;Value&#39;]<br>            if ( str(start_auto).lower() in (&quot;1&quot;, &quot;on&quot;, &quot;true&quot;) ):<br>              start_auto = True<br>            else:<br>              start_auto = False</pre><pre>if ( tag[&#39;Key&#39;] == &#39;start_time&#39; ):<br>            start_time = tag[&#39;Value&#39;]<br>          if ( tag[&#39;Key&#39;] == &#39;start_tz&#39; ):<br>            start_tz = tag[&#39;Value&#39;]<br>          if ( tag[&#39;Key&#39;] == &#39;start_lastdt&#39; ):<br>            start_lastdt = tag[&#39;Value&#39;]<br>          if ( tag[&#39;Key&#39;] == &#39;Name&#39; ):<br>            InstanceName = tag[&#39;Value&#39;]</pre><pre>if ( start_auto == True and InstanceState == &quot;stopped&quot;):<br>        print( &quot;Found EC2 %s (%s) in state %s and tags [%s, %s, %s]...&quot;%( InstanceName, InstanceId, InstanceState, start_auto, start_time, start_tz))<br>      <br>      if ( InstanceState == &quot;stopped&quot; and start_auto == True and start_time.isdigit() and len(start_time) == 4):<br>        print(&quot;..Instance %s (%s) is stopped and tagged for automatic start&quot;%( InstanceName, InstanceId ))</pre><pre>#############################################################<br>        ## Convert UTC_NOW to localized now so we can compare times<br>        ## and see if we need to start this machine<br>        #############################################################<br>        if ( start_tz != &quot;&quot;):<br>          if ( start_tz not in pytz.all_timezones ):<br>            print(&quot;..ERROR: Invalid Timezone String (%s) Specified in start_tz Tag for Instance %s&quot;%( start_tz, InstanceId ))<br>          else:<br>            localized_now = utc_now.astimezone(pytz.timezone( start_tz ))<br>            localized_time = ( localized_now.hour * 100 ) + localized_now.minute</pre><pre>last_start_dt = None<br>            try:<br>              if ( start_lastdt != &quot;&quot;):<br>                last_start_dt = datetime.strptime( start_lastdt, &quot;%Y-%m-%d %H:%M:%S&quot; )<br>            except ValueError as ve:<br>              print(&quot;Error parsing last start date/time: %s&quot;%( str(ve) ))<br>            except:<br>              print(&quot;Error parsing last start date/time&quot;)</pre><pre>print( &quot;..Localized Time=%s&quot;%( localized_time ))<br>            print( &quot;..Start Time=%s&quot;%( start_time ))<br>            print( &quot;..Last Start Time=%s&quot;%( start_lastdt))</pre><pre>skip_autostart = False<br>            if ( last_start_dt != None ):<br>              print( &quot;..%s %s | %s %s | %s %s&quot;% ( last_start_dt.year, localized_now.year, last_start_dt.month, localized_now.month, last_start_dt.day, localized_now.day))<br>              if ( last_start_dt.year == localized_now.year and last_start_dt.month == localized_now.month and last_start_dt.day == localized_now.day ):<br>                print(&quot;..instance already started once today, skipping auto start...&quot;)<br>                skip_autostart = True<br>          if(holiday_skip_day == False):<br>            if ( localized_time &gt;= int(start_time) and skip_autostart == False):<br>              print(&quot;..Starting instance %s (%s)...&quot;% (InstanceName, InstanceId) )<br>              response = ec2_client.start_instances( InstanceIds=[ InstanceId ] )<br>              print( response )<br>              localized_now_str = localized_now.strftime( &quot;%Y-%m-%d %H:%M:%S&quot; )<br>              print(&quot;..setting start_lastdt tag value to %s&quot;%( localized_now_str))<br>              ec2_client.create_tags(Resources=[ InstanceId], Tags=[{&#39;Key&#39;:&#39;start_lastdt&#39;, &#39;Value&#39;:localized_now_str}])</pre><pre>else:<br>        print(&quot;Skipping instance %s in state %s and start_auto=%s...&quot;%( InstanceId, InstanceState, start_auto ))</pre><pre>#############################################################################<br>##  lambda_handler<br>#############################################################################<br>def lambda_handler(event, context):<br>    <br>  #regions = [&#39;us-east-1&#39;, &#39;us-east-2&#39;, &#39;ap-south-1&#39;]<br>  regions = os.environ[&#39;region_list&#39;].replace(&quot; &quot;,&quot;&quot;).split(&quot;,&quot;)<br>  print(&quot;==============\nEnvironment regions %s...&quot;%( regions))</pre><pre>for region in regions:<br>    print(&quot;==============\nChecking region %s...&quot;%( region))<br>    start_instances_for_region( region )</pre><pre>return {<br>      &#39;statusCode&#39;: 200,<br>      &#39;body&#39;: json.dumps(&#39;Successful&#39;)<br>  }</pre><pre>## Uncomment when debugging locally<br># lambda_handler( None, None )</pre><p>You should notice 4 tags that contain <strong><em>start</em></strong> ; these tags are required on the desired EC2 instance to autoStart.</p><p>Once you create the file add it to the folder:</p><p>Once added, the next step is to zip the folder so you can upload it to the lambda function.</p><p>Make sure to review the code and everything else before proceeding. Add tags to the function itself as it is good practice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qAMOjplr1j3RZxXXW7BijQ.jpeg" /></figure><p>Now it’s time to test by adding tags to instances.</p><p>Example of the tags on my instance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HrX6zU_q1Ni7o5b3170ahA.jpeg" /></figure><p>Leave the <strong><em>start_lastdt</em></strong> tag blank as that will be updated by the function.</p><p>Currently the function will be invoked once an hour. For testing, I recommend changing the expression to every minute. Other than that you’re finished.</p><p>Congrats you can now officially be 3 mins lazier each day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SJm-iLuUIfTdbnOff_uTiQ.jpeg" /></figure><h3><strong>Future Goals:</strong></h3><p>My future goal is to have a policy set for tagging these. Possibly creating a resource group to house the tags so we can only let a specific account tag EC2’s with the group to allow autoStart. Another goal would be to implement the BambooHR API to check if employees are on PTO or out that day, or even no longer work at the company. And if true, it would not start the instance with their name. That also means you need to implement strict requirements on instance tagging, such as requiring the owner tag for id. We can clean up the instances that are not assigned as they are not being used daily. As a company gets bigger and bigger it will need to cover all the potential losses.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0b22d5f8e5c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zaloni-engineering/how-to-create-an-aws-lambda-ec2-autostart-function-c0b22d5f8e5c">How to Create an AWS Lambda EC2 AutoStart Function</a> was originally published in <a href="https://medium.com/zaloni-engineering">Zaloni Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a Kubernetes Server on a Raspberry Pi cluster Part 1]]></title>
            <link>https://medium.com/zaloni-engineering/how-to-build-a-kubernetes-server-on-a-raspberry-pi-cluster-part-1-d10033ae0d55?source=rss-879fbf683afb------2</link>
            <guid isPermaLink="false">https://medium.com/p/d10033ae0d55</guid>
            <category><![CDATA[vpn]]></category>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[kubernetes-cluster]]></category>
            <dc:creator><![CDATA[Matthew Caspento]]></dc:creator>
            <pubDate>Thu, 21 Apr 2022 14:59:13 GMT</pubDate>
            <atom:updated>2022-04-21T14:59:13.492Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bonbdo5KM7LZXP4VrXh6jw.jpeg" /></figure><p>This blog will serve as a tutorial and guide for the minimum requirements a user would need to host in the Arena platform or with a Kubernetes cluster.</p><h3><strong>Use Case Overview:</strong></h3><p>Some of the benefits of having a home server is that you can host small applications, create smart home applications, and even websites, but it’s important to ensure that you have a high upload speed to do that. Additionally, you may want to avoid the costs of using a cloud provider by using a home server. I know I’m guilty of forgetting to delete an instance and racking up quite the bill. In my case, I’m building a home server so I can practice not only my IT, but also my CloudOps skills. And the best part, I can destroy and create as much as my server can handle without worrying about the monthly cost.</p><p>If you ever watched the movie Flubber with Robin Williams, you know the movie starts with this opening scene where this rube-goldberg-like machine makes his breakfast every morning. When I was a kid I thought that was absolutely crazy, and when I grew up, I wanted something like that too. Well, I’ve grown up, and now, I want to fulfill my childhood dreams. I eventually will need to get a 3D printer, but we’ll save that for a future post.</p><p>I have a goal to create an environment so that when I have children, they will be able to engineer and create whatever they dream of. Having this server is a start to it and I welcome you to follow this engineering journey.</p><h4><strong>List of Requirements:</strong></h4><pre>3 x Raspberry Pi 4 Model B 8GB | $82.84 | <a href="https://thepihut.com/collections/raspberry-pi/products/raspberry-pi-4-model-b?variant=31994565689406">Find Here</a> | <br>2 x Cluster Case for Raspberry Pi(with fans)*| $11.27 | <a href="https://thepihut.com/collections/raspberry-pi-cases/products/cluster-case-for-raspberry-pi">Find Here</a> |<br>3 x Micro SD Cards 128Gb* | $21.79 | <a href="https://www.amazon.com/SanDisk-128GB-Extreme-microSD-Adapter/dp/B07FCMKK5X/ref=sxin_15_ac_d_mf_rf?ac_md=2-1-MTI4IEdC-ac_d_mf_rf_rf&amp;crid=STNH6CB2PTUM&amp;cv_ct_cx=micro+sd+card&amp;keywords=micro+sd+card&amp;pd_rd_i=B07FCMKK5X&amp;pd_rd_r=0687926d-6c20-4483-b8e5-100ecd6e7fe5&amp;pd_rd_w=wptzP&amp;pd_rd_wg=lN6fI&amp;pf_rd_p=a096e525-a495-453a-86b7-b8874baad0af&amp;pf_rd_r=1A93Q2YD6QFEQKQH50DF&amp;psc=1&amp;qid=1641309201&amp;sprefix=micro%2Caps%2C88&amp;sr=1-2-1db1fce3-1628-43df-a6c6-84620ba4aaaa">Find Here</a> |<br>3 x Mini PoE Expansion HAT | $27.79 | <a href="https://thepihut.com/products/mini-power-over-ethernet-poe-expansion-board-for-raspberry-pi-4-no-fan">Find Here</a> |<br>1 x USB keyboard*<br>1 x HDMI to microHDMI cable*| $3.38 | <a href="https://thepihut.com/collections/raspberry-pi-cables/products/hdmi-to-micro-hdmi-adapter-cable-160mm">Find Here</a><br>3 x Ethernet Cat6 cords* | $1.69 | <a href="https://thepihut.com/collections/raspberry-pi-ethernet-cables/products/rj45-cat5e-ethernet-lan-cable-2m-red">Find Here</a> | #EthernetCables.jpg<br>1 x TP-Link AC1900 Smart WiFi Router| $59.99 | <a href="https://www.amazon.com/dp/B08C3YBBHM?psc=1&amp;ref=ppx_yo2_dt_b_product_details">Find Here</a> |<br>1 x TP-link 5-Port Gigabit PoE Switch | $42.89 | <a href="https://www.amazon.com/gp/product/B076HZFY3F/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&amp;psc=1">Find Here</a> |</pre><pre>*optional</pre><pre>Total cost may vary depending on the optional choices you make on this build*</pre><pre>Shipping prices are not included*</pre><pre>Total: $556.48</pre><pre>Having a home server to automate breakfast: Eggcellent</pre><h3><strong>Building the Raspberry Pi Cluster:</strong></h3><p>You’re gonna want to start with building the cluster case. The build should take 30 mins.</p><p><strong>WARNING: DO NOT BUILD OVER A CARPET.</strong></p><p>These bolts are tiny! This warning was in every tutorial I followed. Unfortunately for me, I ignored the documentation and ended up taking a comb to my carpet as if I were one of the troopers in “Spaceballs” combing the desert.</p><p>You can follow along with the provided pictures to assemble the ClusterCase with Pi’s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ie_FcX7wIx5kevejWNEzgQ.jpeg" /></figure><p>You’re gonna want to make sure the round nuts are on top and not the bottom so the case does not slide around.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-BowPF4Ibfut9As5JerVMA.jpeg" /></figure><p>Add the first pi to the glass stand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Va-G_da8lkh7o22IIcWcsQ.jpeg" /></figure><p>Add the new glass level, but this time, include the fan and attach it to the pi.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vSnaALKdriXnVmqsyJUV6w.jpeg" /></figure><p>Once you have the new level and have added it to the case, finish by attaching another raspberry pi to the case and the top level with the attached fan.</p><p>Once the case and Pis are set up, we move to the next step by installing the operating system. In this blog, we will be using Ubuntu.</p><p>First, you will want to download the Raspberry Pi Imager; you can go can use one of the following to do so:</p><ul><li>Go to ubuntu and use <a href="https://ubuntu.com/tutorials/how-to-install-ubuntu-on-your-raspberry-pi#1-overview">this link</a> to follow their instructions Download one of the following:</li><li><a href="https://downloads.raspberrypi.org/imager/imager_latest_amd64.deb">Raspberry Pi Imager for Ubuntu</a></li><li><a href="https://downloads.raspberrypi.org/imager/imager_latest.exe">Raspberry Pi Imager for Windows</a></li><li><a href="https://downloads.raspberrypi.org/imager/imager_latest.dmg">Raspberry Pi Imager for macOS</a></li><li>Use:</li></ul><pre>$ sudo snap install rpi-imager</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0uRmyLJ8vVmMj2miumfgsA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y8B-clc48WAt3WeZpSdRNQ.jpeg" /><figcaption>(I’m using the Ubuntu Server 20.04.3 LTS(RPI3/4/400) OS)</figcaption></figure><h3><strong>Reserving Static Addresses:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HNpNgTOexMzEjWVJsbnpLg.jpeg" /></figure><p>Before we address the raspberry pi’s, you will need to set up the router and PoE switchboard to utilize the PoE HATS. If you don’t want to use the HATS use the power supply plugs. Plugin the router to your ISP router that is already connected to the internet, find the connection and connect to it. The next step is to go to the address <a href="http://tplinkwifi.net/">http://tplinkwifi.net</a> and create a new login to sign in. You can skip the quick setup and go to the console where you will find the advanced settings and the network tab where we will do most of the editing.</p><p>To start, let’s first configure the LAN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N9hTPaQc67C4IDWqkP215g.jpeg" /><figcaption>Make sure you are on router mode.</figcaption></figure><pre>LAN</pre><pre>Ip Address: 10.204.4.1</pre><pre>SubnetMask: 255.255.255.0</pre><p>Next, if you go to the Internet tab, you will see a drop-down for the Internet Connection Type and choose <strong><em>Dynamic IP.</em></strong> Since you have connected the router to your ISP router, it dynamically sets the parameters requested.</p><p>With that step done, we will now focus on the DHCP server. Make sure that the DHCP server is enabled and the Raspberry Pis are on and connected to the switchboard connected to the router. By doing so, the router will automatically identify the Raspberry Pis and they will be visible on the DHCP Client List. Note the MAC address as you will need that later to set the static IP addresses for the Pi’s. You can use this as an example of how it should look.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*cbbWlujShOLnCDNllDDSHg.jpeg" /></figure><p>Once completed, you can check the internet connection by going to any website and making sure it loads.</p><p>Now, to set the static IP addresses, the <strong><em>Address Reservation </em></strong>section on the page<strong><em> </em></strong>is where we will assign the IP address of the RaspberryPis:</p><pre>Device Name| Mac Address| Reserved Ip Address|</pre><pre>Kube-master| R7–3J-95–8H-KL-Y2| 10.204.4.101|</pre><pre>Kube-worker-1| R7–3J-95–9U-T4-X1| 10.204.4.100|</pre><h4><strong>Setting up the Pi Kernel:</strong></h4><p>Once you install the OS to the correct SD card, transfer them to the pi’s and plug in the power supply, micro HDMI, and keyboard. Give it 2 to 3 mins to load, but when you see the insert username, wait until it has more scripts run. If you were able to set a static IP address, another way you can access the Pi’s is by adding the SSH into them from your local computer.</p><pre>$ ssh ubuntu@10.204.4.100</pre><p>Once that is finished, you can use these credentials:</p><pre>Username: ubuntu</pre><pre>Password: ubuntu</pre><p>Once logged in, you will be prompted to change your password. Use any password of your choosing.</p><p>Once you have officially logged into your raspberry pi, we will start running it.</p><pre>$ sudo dhclient eth0</pre><p>The next step would be to determine the IP address of the Raspberry Pi’s so you can SSH into them later.</p><p>On Ubuntu, you can run:</p><pre>$ arp -na | grep -i “b8”</pre><p>Note, if you don’t have arp installed, you can run:</p><pre>$ sudo apt install net-tools</pre><p>You can now SSH into that board from any terminal.</p><p>Open a terminal and run:</p><pre>$ ssh ubuntu@&lt;RASBERRYPI-IP-ADDRESS&gt;</pre><p>Confirm you want to connect.</p><p>You will have officially connected to the Pi when the connection is confirmed. You can now add your SSH key if you want to save time for future SSH attempts:</p><p>Now, you will need to enable cgroups limit support. You will want to add these to the <strong><em>/boot/firmware/cmdline.txt</em></strong> file</p><p>Run the following command:</p><pre>$ sudo vim /boot/firmware/cmdline.txt</pre><p>Then add the following to the file:</p><pre>cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V2o2EG0jgv9YMBvXlIZLSQ.jpeg" /></figure><p>After doing so you will need to restart the kernel for the changes to take effect, so run the following:</p><pre>$ sudo reboot</pre><p>Make sure you follow the same steps for each board as they all need to be running an Ubuntu Server image.</p><p>Now if you’re like me and have recently gotten their <a href="https://www.cncf.io/certification/cka/">CKA</a>, you want to flex those muscles and utilize everything Kubernetes offers. With that in mind, I’ll be using Kubeadm to set up the clusters and for the second part of the tutorial I will be creating &amp; installing the infrastructure to host Arena Concourse, something I’ll be making a tutorial later in the year.</p><p>*In the next tutorial I will also add a factor of any new additional costs for any of the new infrastructure based on energy costs.</p><p>Before we start installing kubernetes we will need a Docker engine to do so. I’ll catch you in part 2.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d10033ae0d55" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zaloni-engineering/how-to-build-a-kubernetes-server-on-a-raspberry-pi-cluster-part-1-d10033ae0d55">How to Build a Kubernetes Server on a Raspberry Pi cluster Part 1</a> was originally published in <a href="https://medium.com/zaloni-engineering">Zaloni Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>