good Monday morning I’m MP J and this is
fun fun function today’s episode is
going to be a little bit different
because I have gotten this this thing is
a particle internet button there’s
really no way that I will be sitting
around doing a video about something
else when I have a new toy this is not a
sponsored video by the way
this thing is just cool so what is it
let me just put you on a tripod particle
doesn’t like their main business isn’t
making these buttons it’s actually
making this thing that is inside the
button but focus
they make these tiny super cheap
computers I think they’re like 20 bucks
this thing and it has a Wi-Fi chip and
basic processor and it’s compatible with
order II knew like devices it’s fitted
up with this button which has a four-way
for right clicky button and multicolored
lens around this thing so today I’m
going to hack away this thing I will try
to make an attempt to produce an
interesting video of me doing it we’ll
see how well that goes never done
something like that before what I’m
gonna make with this button is a
Pomodoro timer if you don’t know what
the Pomodoro Technique is it’s a it’s a
method of working where you work for 25
minutes completely interrupted you turn
off your cell phone and you don’t check
email you just work on one thing for 25
minutes and after the your alarm rings
you take a five minute break and you do
things like check email or go grab a cup
of coffee or yours just look out the
window you also track your progress a
lot so you check that Oh I now completed
a successful Pomodoro or if you got
interrupted by say a colleague that came
over and asked you something or you
interrupted yourself and got that coffee
anyway during this Pomodoro that
Pomodoro is void and you put al
interruption check more so you keep
track of your progress it’s one of the
few productivity techniques that you
know actually works for me either way
let’s get started for a channel that is
named fun fun function and is about
programming I I know I do an awful lot
of talking and a lot of people they they
complain about that they say that oh I
miss when you work when you were doing
coding and but the thing is that in my
experience coding is a really really
small part of the success of a software
development project it I mean it’s
important but it is it’s a tiny part
software development step one steel
sharpie from girlfriend all right by the
way this is this week’s board game tip
pandemic legacy okay I haven’t played it
yet
bye it seems so the photon it has a
bunch of multicolored legs it has these
four bottles when say this button is
pressed I want this to start lining up
like a clock and until it reaches twenty
five minutes this level features that I
would like to have on this day if you
have seen the Martian you know that
being an engineer is about solving one
tiny problem at a time the photon it
runs I see I think it’s a seed dialect
I’m not sure if it’s actual C but either
way it’s in a language that nobody
really wants to program at least not me
so what we’re gonna do is we’re gonna
have a a node.js server that controls
this thing so the internet button will
basically just be a dumb terminal it
doesn’t it won’t know anything about
Pomodoro’s it will simply send like when
I press this button it will yell
an event to the nodejs server and it
will subscribe to events from the nodejs
server such as lights LED one at you
know some colorful stuff so before we do
anything else this event thingamabob
that is what we are going to set i’m
trying way too many new things at once
today but you know that’s the charm of
it let’s do it okay first we are going
to create a project make dear what I’m
going to call this so whenever I do
project I spend way too much time on
taking names so what I do is I go to the
list of Intel code names on Wikipedia
and I pick one at random whenever I do
any project so ah crow points okay no
that sucks
um hmm gross what again right no creek
Kyrene currying that’s that’s that’s a
co name for our project let’s close this
you’re not a an NPM in it I mean one one
one description leave that empty in
extra chairs works for me haha no no
keyboard out of batteries board the Xbox
controller will suffer for your sake I’d
set up a github repository our Kai
it’s gonna be an old project and now
let’s do an MIT license copy that out of
there
key words no author I like writing my
get remote add mpj monk get police VJ
master oh sorry
JSON yeah and get push don’t push get
push em pj a mess I stress that this is
not a tutorial this is just Q watching
me code really wow we have a git
repository on a package.json that cause
for celebration we should get some
coffee cop in Swedish caffeinated I’m
using Express and oh I’m I’m gonna use
save Express so using the the save flag
here will actually automatically add the
the dependency to to your package JSON
creative web server index of juniors
tutorial so nice and all but I don’t do
them because they grow stale like in no
time at all this is just me doing
something that might inspire you to make
something of your own
how does Express work copy/paste
programming we’re now running okay much
later I’m out of coffee
but we’ve made some progress this is now
a working notes
I’m just gonna run it to show you what
it does in index OJ’s example up
listening on port 3000 there and we’re
gonna switch to another terminal window
if I remember how to do that there so
we’re just gonna do a parallel where we
send some JSON here we post it and we’re
here like hello world and we’re posting
it to localhost 3000 event and enter
okay it doesn’t give any response but it
like sends out here body world and that
is because we have this over here and it
will parse it as JSON and it will echo
out the hello part of the JSON here I
want to deploy this on the internet so
that I can call it from the the internet
button next I’m gonna do that using
docker on the Google cloud container
engine because I feel like it whoops my
battery ran out of juice if you don’t
know what docker is it’s um it’s sort of
a it’s a way of packaging your
applications into small Linux containers
and it’s really nice because it allows
you to run a little basically a little
Linux cluster on your computer and have
an try your apps out in an environment
that looks very much the same as the the
one on the server because you will
deploying will be deploying this little
Linux container with all of its
dependencies and it will always be the
same thing locally and on the server so
doc rising a node app is really easy
this is the the docker file here
authorizing a node app is super easy I
have a file here the docker file this is
the only file that we need to do this
what the doctor file describes is
dependencies in this case the only thing
that we need on the
the Linux Linux container is note and
node provides an official docker image
actually for you so all we need to do to
get node into our docker container is
just this from node 5 5 0 and I’ve added
slim because I want it to be next up is
here we want to create the app directory
what we do is that we only remember that
this is on a virtual Linux machine so it
will create a directory here and then it
will switch the work directory to that
directory and it will then take our
package JSON from or from our
application and copy it to that
directory on the Linux Linux machine and
it will then run npm install after that
it will copy the rest of the app into
the the app directory on the server it
will expose the the 3 their port 3000 so
that we can access it from outside the
links container because from by default
nothing is exposed for security reasons
and then it just runs NPM start an NPM
start is by the way I’ve defined that in
the package.json here as basically just
node running the index dot JSP
now how do we use this well – first of
all we have to start the docker terminal
after you installed docker it will
create this thing for you the docker
QuickStart terminal
and it will run and it will look like
this and then you just since we are in
the directory that has the the docker
file we just go docker build oh sorry
dr. build this directory and this will
take some time the first time but I have
all this stuff cached and it will build
a image for us it doesn’t qur’anic yet
we have to do that too so we’re gonna do
docker run dot T for terminal so let me
see what’s going on and paste is the
image name and it boom runs so now we
see that okay it’s running on for 3000
okay let’s try that curl thing again
alright this will fail to connect
because we are no longer on our local
computer anymore like the server is
running on this little Linux cluster and
that that Linux lustre has assigned it
an IP on our local machine so we need to
check out kite magic here which is an
application that comes with docker and
it’s going to show us that we the Linux
container has been given this IP here
and like we see here that 3000 X is
exposed from the inside but it’s not
actually connected on the on the surface
we need to add 3000 here as well and
then hit save here now we can take this
IP here and paste this in here and this
should not work
maybe yes it looks like it does actually
all right let’s see if we’re not
attached to this docker containers you
need to see what docker containers are
running
we have this container right here that
is running I’m gonna copy that and I am
going to write docker logs and it works
next up I want to deploy this thing on
Google cloud first of all we need a
little cluster on Google cloud we need
some servers we do G cloud container
clusters create Kyrene our project name
and then we specify our machine type g1
small on head enter whoopsie it wants a
sone as well they have to do g-cloud
compute so list
oh I haven’t set that up in my project
yet let’s see I will have to go into my
cloud console and we’re gonna go to the
API
whoops good to the API manager and
compute engine API and we click enable
API here and now we can call g-cloud
compute sounds list no oh it’s still
enabling that prompts me to get some
lunch
Wow that’s that Sun okay we’ll go to a
very fancy place for lunch Wow I’m
walking there I want to talk about some
things I mentioned earlier that I think
that development is not all that much
about coding really it’s much more about
just having this attitude of you know
figuring things out getting into this
mode of yes solving one problem after
the other sometimes that is coding
related but sometimes it’s just related
to figuring out just doing research on
what tool is appropriate perhaps you
need to formulate your problem a bit
clearer in order to understand it
sometimes you just get stuck your brain
does not process information so you need
to just go play ping pong or figure out
some way of getting you yourself unstuck
sometimes the problem is that your your
colleagues don’t understand how
something works and
your relationship with them doesn’t
function often it’s just fiddling around
with weird configuration files but what
it all comes down to is having this
process for problem solving and I think
that the most important thing that you
can do to become better as an engineer
and as a creative professional is to you
know cultivate cultivate your own
creative process I started thinking
about this a lot ever since I watched
the Martian which is a movie and more
importantly a book that you really
should read if you have any kind of
creative professions without spoiling it
too much I think that the Martian is
basically a book about being a creative
professional but it’s set in a Mars
survival setting the core of engineering
is that you are stuck with this huge
huge problem in this case you’re stuck
on Mars alone and how how how to deal
with that how to eat an elephant that
big and of course the answer is one
piece at a time you break one tiny bit
of the problem off you solve that and
then you break another part of the
so anyway this is not a tutorial video
then ah I uh I I think I kind of have
some problem with tutorials they’re fine
I watch tutorials they’re handy to get a
sense of how something works but
tutorials also give this give you this
idea that development is more neat than
it really is
I mean development is essentially being
stuck on Morris with with the
environment trying to kill you well it’s
not it’s not really that but it’s kind
of like a mild variant but like the
universe isn’t an ordered thing and
development isn’t an ordered thing that
you it is up to you the developer to
make it an ordered thing that’s your job
that is what it means to do development
I think this is the core of being a good
creative professional or an engineer
that you construct a very clear image of
where you want to go and then you look
at what the problem looks like what is
preventing you from getting there and
then you break a tiny bit away from that
problem and you deal with that and that
gets you a bit of the way and then you
break off another part and deal with
that and so on maybe hundreds of
thousands of times until you solve this
big ass problem and that’s what I think
it means to be an engineer
oh by the way this is the fancy
we’re back from lunch let’s see if the
Google API has updated yes it has okay
the API is enabled you can’t use it in
your project into the crate credentials
okay I didn’t need to do that to do this
either a region Europe West one see that
or maybe it’s the Google container
engine API that I need to okay let’s try
that
oh this worked
Oh so Google cloud is now spinning up a
Linux cluster for me which is pretty
cool it is done okay so we have a little
cluster running in Europe
oMG one small machine type so what we
want to do now is to build our docker
with a special tag so it looks like this
so we’re gonna do a docker built just
like we did before but we are going to
build it with this tag so we’re gonna do
it with the this Google cloud container
repository and we are going to use my
project name this is my project name on
Google Cloud and then we’re gonna have a
name for the container and we’re gonna
have a version tag here I’m just gonna
start with one but this can be any
string I mean a metaphoric site I tend
to use a gate hash here and finally we
have the the dot which means that we
want to build the docker file in the
current directory oh and I’m doing this
in the in the wrong terminal we need to
do this in the the docker terminal which
i think is this why right and we have
gnostics her successfully built this
container that’s nice so now we want to
push this image that we are built up to
the Google Cloud container repository
and we do this by calling G cloud
dr. push and paste in the the image that
we as created and it will push it up
hopefully you know what Fiddlesticks
okay found the problem after like half
an hour I it turns out that I thought
and my project ID was this but that’s
just my project name a project ideas you
so I need this one so we need to rebuild
the image BAM and now we should push
this to dr. cloud registry and it’s come
on
push so now it’s time to get our cluster
running this image and to do that we
need to use kubernetes which is Google’s
system for managing clouds of docker
containers and to do this we need to
create a replication controller a
kubernetes replication controller and a
replication controller is a thing in
your cluster that contained controls
pots and pots are basically your virtual
servers so let’s say that a virtual a
pod goes down it is the job of the
replication controllers you monitor that
and bring that back up the replication
controller also keeps tabs on how many
servers you need some rubber the
replication controller is also
responsible for load balancing and and
it stuffs either way we’re gonna start a
replication controller and you do that
by defining a kubernetes dot JSON which
we have here and here down here it’s our
docker image this is the same as the
docker image that we just built and this
defines that the the pods are going to
be using that image we’re exposing port
3000 here and we are we don’t really
need this and now to create our
replication controller we simply run
simply this complicated stop create dot
F kubernetes dot JSON and bam we have
now a replication controller going and I
can just go view kubernetes control
I get RC to see that okay we have a
kubernetes container and while we were
talking
it had the kubernetes controller the
replication controller will have created
a pod right but we have an error so
let’s see what’s up cube city all this
scribe I mean cube CTL described pod all
right right right right right
because we’re doing the same mistake as
before we need this they’re not doing it
okay cool so what I’m gonna do now since
I created the replication controller
wrong I’m going to cube CTL get
replication controller I’m gonna pick
this one I’m gonna go cube CTL the leads
replication controller crying delete
that and let’s do this again now that we
have a correct kubernetes JSON with this
thing correct here I can find it in my
history test division cube CTL create
file kubernetes top JSON and now it’s
created cube CTL RC cool and Ricardo
cube CT now get Pio and it’s running
good now I can actually read the logs
from this and I can go cube Jubilee this
controller logs
oh ok ok so now we have a a note server
running in the Google Cloud so our node
server is running but it’s not exposed
to the internet yet and to do that we
need to grab the replication controller
so cube CTL
yeah RC repre controller here I’m gonna
copy that
and we are going to run cube CTL expose
replication controller and paste that in
and we’re gonna assign it as a load
balancer M service carrying queue blah
blah blah exposed let’s see what it
exposed because it’s now creating a
services cool
so it’s haven’t assigned the external IP
yet and while it does that I’m gonna
explain what has happened pods in
kubernetes and is their ephemeral right
they will die for various reasons behave
perhaps that google pulls the service
out of their racks in the space in the
data data center and the replication
controller will recreate them so they
they are ephemeral right they have new
IPs all the time and they move around so
but you don’t want end-users to to know
about that so you want to expose an IP
like that is permanent and that it’s not
tied to the pods and you you want to
have something that just takes that IP
and redirects it to whatever pod is
available and that is what services are
they we just spun up here that it has
this check again all right
so now it’s gotten this external IP
address and whenever that is accessed we
that will be redirected to a pod with
the label service name Kyrene and this
is what the the labels that are in the
in the in the kubernetes jason father
are for so that stuff like services can
find the ports even though they have
different IPS and
all the time this should be available
soon arias copy/paste is let’s see we’re
gonna do this thing with the JSON post
again but I’m going to paste the
external IP cool and now hope for the
best
enter okay cool right we never send any
response so that is why nothing is
happening but let’s check the logs now
of that pod again I cube CTL I get pods
right that’s our pod it’s still running
it hasn’t crashed that’s good so he’s on
a cube CTL yeah at logs
no not yet logs just lost and we paste
in the port and body world you know what
that’s it fortunately we didn’t get a
bothers working really but at least we
gonna have a a new node server running
in the running in the cloud so that’s
some progress you saw one a little
better at a time you might not always
get a lot of progress every time this
was a weird episode I know it was a
weird episode but I felt like
experimenting a bit perhaps we learned
something at least I did I am mvj this
is fun fun function until next Monday morning stay curious