Press "Enter" to skip to content

LONGEST KUBERNETES SHENANIGANS! – FunFunFunction #26


good Monday morning I am mpj and this is

fun fun function you know today I’m

going to the cypher in fire side five

fair in a couple of hours so I need to

record an episode before that so we’re

going to do are going to continue the

decoding project the communities

shenanigans project where I write try to

make this nobody where I try to make

this little body come on focus interact

with a server deployed on kubernetes and

a lot of people have asked me why do you

do this on kubernetes why do you do this

on Heroku well because I wanna I could

you know just have some person of the of

the internet do this code for me and

build it or I could just buy a buy an

egg timer and use that for Pomodoro

timer instead but you know it’s fun to

do things if you haven’t watched the

previous week and shenanigans videos you

can watch them there I have not touched

this project for I think two weeks which

means that I have forgotten everything

about it so that is why it’s really good

and that is why it’s very important to

keep a work log to remember where you

were and I have okay last time we did

this we want to press the button and

have the server log out the number of

the button that was pressed okay I don’t

think that I have I think I deleted the

cluster we need this cluster last time

so I’m gonna spin that up no no I need

to create it

take a while come on I’m going to while

that is doing its job I’m going to go to

the window and look at something in the

in the distance because my optician have

taught me that as you watch a screen at

this distance your eyes cramp up and be

that is how you gradually your your eye

eyesight is gradually being detrimental

and watching something in the distance

every 20-30 minutes or so will relax

your eye muscles and we’re done

excellent let’s create a it’s the ploy

Kyrene let’s create a doctor Quick Start

what I’m doing now is kind of annoying

every time I do this thing I spin up a

cluster on the cloud and I don’t want to

keep that running in the two weeks where

I don’t do this project so I spin this

thing again and every time I do that I

have to remember all these commands and

I should really us create a deploy

script for this application I’m not sure

if I should be doing that yet because at

poi script is it’s kind of you know it’s

one of those things that is alluring

it’s you feel like wow this would be so

great if you I could automate it but

it’s gonna take you time to automate it

and you will probably change it a lot so

the time you spend automating it is

probably not gonna be a good time

investment either way I try to you know

just apply a little bit of inertia upon

myself before I before I start creating

the poi scripts and automating that kind

of thing before you know about things I

you don’t want this is a mess I am gonna

be doing this every time and I am going

to make the goal of this episode to make

a deploy script we want an automated

deploy of Kyrene to Benitez now on

Google container we’re spending a lot of

time just getting the server up but you

know development is like that sometimes

you just find yourself with struggling

with just one aspect or but getting your

application deployed and it’s usually

not a hard programming problem it’s

usually some kind of

configuration thing that you just can’t

figure out and that’s the way it is some

parts are going to move very slowly

some parts are going to move very very

fast and that’s the way it is so let’s

first create a deployed no we’re gonna

call it we just control it scripts

directory in this know it wanna scripts

file that’s wrong come on create new not

file I’m stupid scripts folder cool and

this is going to have deploy so we’re

gonna have one deploy script that

creates the cluster from scratch and

deploys the server and one that creates

like updates the existing an existing

server we’re going to begin by having a

next step is that we want to build image

probably gonna do this at the top

because if if you’re not in the docker

terminal this is going to fail and we

don’t want to do anything otherwise you

will this will not fail in the docker

tournament terminal and that means that

the the deploy script will have this

super annoying long thing and then it

will fail at the second step by the way

I want to figure out how to hold bash

all right so we want to create the

cluster and then what’s next we want to

deploy it now we want to wanna upload

the docker image to VM we want to upload

I’m kinda short this tank that we try

checking out Stack Exchange dating in

documentation but it might also be you

know organizational archaeology you

digging around in old code that people

have written or just going around the

office asking who knows about this I

think that we all would like our jobs to

be of coding and stuff but in reality

that is a very small part of the job the

main part of the job is figuring out

am so it’s this in break the replication

control thank that this needs wonder

where do we run this from Dom and oh

crap it’s creating it’s generating this

dynamically because the next command

that we need to do is to actually expose

expose replication controller and these

things and these things you know here

it’s being generated and this it’s not

how do we do this can we perhaps can we

perhaps give the replication controller

a label and expose by label and we do

aha

we’re gonna do a new we’re gonna call it

service JSON Kyrene service ports utter

one word ports this is its 3000 target

for a thousand maybe a selector service

name Korean right because Karina’s

that’s we’re defining a service name

label here

no no here and the in this specification

file for the main replication controller

and the service will be using that to

select it for this world cube CTL create

file service in Bali Kashyap beginning

ah this let’s see if they work cube CTL

I get service yes

okay let’s copy this I P know we don’t

have an external IP yet let’s there

particle IO dashboard right no it’s not

the dashboard it’s the build thing I

think it’s this right right right right

okay but this is just publishing events

well does my code look like we have

looked at code yet so alright because we

have a because this publish where that

goes it’s going it’s going to go to

centrally to the build up particle IO

service there cloud and then we’re gonna

have a service hoc Jason that sets this

up to post to this IP which is our old

server so that won’t work

hmm this is a bit tricky because this

lalalalala

next step we generate a particle of JSON

file from the ip3 turned from from

kubernetes or keep CTL this is a bit

tricky because the cube CTL command like

running cube CTL and get services ah

this thing here first of all this is a

table and the external IP that’s not

gonna appear immediately when we first

run this command this is gonna be empty

so it’s going to have to either wait a

little while or poll so we will be using

node to do this deploy script or at

least parts of it so we won’t be using

bash because Bash is quite possibly the

worst programming language invented of

all time so I think the first step is to

write a reg X that will match this do we

have the output where the thing did not

exist yes so I’m writing this to my

so this is what it looks like when there

isn’t one and this is what it looks like

when there is one so we’re gonna do this

with a regular expression since my Ruby

days I

this was my standard go-to thing I

really like this one is and we want like

any whitespace character and we want

would capture here we want digits any

digit and we want dots and we need to

escape the dots now we want some digits

and we want to escape the dot because

they have a special meaning in regular

expressions IP is always gonna be

formatted like this it really won’t

because this one is like it won’t work

with ipv6 I guess I don’t even know how

an ipv6 address looks like are we

escaping these correctly regular

expressions as the hardest thing ever to

there that’s sort of an IP ah

yes for ipv6 reasons I’m going to know

they might so for supporting ipv6 we’re

gonna change this to word okay and that

will work I thing okay that works for

capturing the the happy path however we

also have the sad path which is when it

looks like this I’m gonna try just make

sure that it works when I do this to all

right wait the other one was actually

wrong it’s the second IP address that we

want so I’m just gonna copy this and

we’re gonna white space here

and then we’re gonna capture and we

don’t care about this right so now it’s

matching second one and let’s see the

non happy path case okay it’s not

matching that’s actually good that’s

actually good our regular expression

works okay so we have a regular

expressions for extracting the the IP

out of the cube CTL it services the next

step is to create a little script

that extracts that out and shoves that

into a Jason for the particle web cooked

and right snap down to disk and then

uses that file to create a new web hook

this is very convoluted but I’m having a

lot of fun this is turning into some

kind of kubernetes DevOps Internet of

Things series I’m going to the sci-fi

fair now I’m going to be continuing this

later in the day or in the evening I

guess and we’ll see where if we can

ah screw it we’ll do this with

JavaScript

haha I tried to extract that with grep

no shell script I don’t remember how to

do this it’s found you see let’s see

this will do nicely

damn install don’t say – ljs gotcha

how does this work this is just magic

syntax because there globally injecting

all these things I’m not sure I like it

but that’s the way chill shell EAS does

it so so how do you just execute a

command o here x ik so I just exact what

square oh right I have to make it

executable or we can’t run it as a Oh

– script okay cool it runs it but we

want to get that as or so as this art

works hello no no do you know what I

want to do oh I have no idea of this

gonna work does this work yes okay but I

got a zero for some reason here what is

this oh okay this is yes this is the

result code you don’t want that say that

let’s try it yes yes so the output is

here cool now let’s just match it to the

Reg X that we made before copy that and

STD out dot match X X X

oh no I lost the poop emoji I should

have this

some kind of hotkey no copy don’t know

why it doesn’t copy online first when

the first time I press it blocked okay I

have to use use strict all right so the

match is okay so this is the match it’s

okay alright the first the first array

of the match is the full string and then

the second one is the actual the first

match so I need to do this to get the IP

so vehicle it let the Const first no ii

ii IP second IP you reg ex yes the red x

i think there we go and then we call

this match ii vipera X matches the

public IP we’re gonna not bulik public

and we’re gonna call that is the matches

one cool let’s just check that that is

okay that

all right cool we’re now extracting the

IP what we wanna do now is to read in

the service hook JSON the particle hook

definition for the particle web hook and

read that in as a sort of template and

replace this IP here with the IP that to

get from service we are going to call

this service of the template instead and

we are going to invent a new IP a new

templating system here I’m not really

mad but I server IP address okay so how

node documentation ain’t nobody got time

for that

this looks good it’s a bit messy okay so

this is the read file we want to read

the serve this

for template JSON file I’m just gonna

log this out and see if it behaves yes

it behaves cool we see here that the

take the log down here is the template

file we and we want to replace the I

server IP address with the public IP we

want to call this new contents sorry

right

new contents not to date are because

there is no date anymore and now we have

replaced the IP that went faster than I

imagined sometimes things go easy okay

we did something I have forgotten what

we were doing and gonna check the work

log ok generate the particle to JSON

file from the IP return from cube CT I

will almost on that what we need to

write this two disc as well so that we

can pass it to the particle web hook

command how do I write to know arrive to

via lol no jest if the words the spot

and Google still figures it out isn’t

this amazing we live in the future

writing father OH

did you notice I have been googling this

before these are purple purple file and

it’s not gonna be called template it’s

gonna be just called service of calling

particle service I’m gonna call a

particle web hook that’s better and we

are going to bind to the one part of me

here wants to turn this into pretty

promises but that is one of those things

that might turn into a distraction that

takes over like the entire task so might

do that in the future might not but I

think it’s always really important to

focus on the end goal before you allow

yourself to tidy things up too much

let’s write a console.log successfully

route to output fun let’s see what that

does

unexpected end of input oh I’m not

ending this properly right all right I

don’t want this to be echoed out I think

yes

let’s make this there okay so we now

have a little script that it when you

run it you know script test that is a

horrible name we’re gonna talk it’s

gonna be Jenna we’re gonna call it

generate web.config like that when we

run generate webhook config that is

going to generate a particle whether

jason with fresh IP picked from the from

communities by running the cubes et al

get services command so what we did was

had a cube City organ services and it’s

gone to via reg Alex it’s going to

extract this string here and it’s going

to hurt put it there but that’s not the

same string no no no it’s complete that

one sorry this one and put it there so I

want to put this in the deploy command

we are going to we’re going to generate

webhook con

web.config and then we are going to

particle weather creamy I think that is

just particle where book JSON right try

that yes yes that works okay we have a

thousand web books now I need to delete

some pool now this was create this won’t

work out of the box because this command

will take a little bit of time not a lot

of time like if we want to be fancy or

we could extend this thing to wait and

pull for it I am too lazy to do that as

I think that I just want a sleep command

bash sleep okay right to sleep for 5

seconds use 5 that was the most

unnecessary copy/paste ever delays it to

write sleep ah ok

X

posing we’ll say while so let’s sleep 20

seconds you know this might be it I’m

going to go and delete my cluster again

ah where is my Google cloud here so this

is my go claw I’m gonna delete this

container cluster here yes I want to

meet Kareem but if I’m pom pom pom pom

pom pom pom from home we’re deleting

it’s deleted ok I am not yet confident

enough to run this on its own so I’m

gonna run ranked line by line just make

this nice and clean okay first command

building the docker image ok successful

build that worked create the cluster

copy paste great oh this would take some

found a bit of old parrots in the

kitchen

you just gotta finish itself because I’m

gonna get carrot in my teeth

and everybody’s gonna screech up at that

worked

push the try pushing the image worked

rating the replication controller it’s

created at work and we are going to

expose no this won’t work because this

is this generator right oh but we

resolve this before we are going to this

is gonna be cube CTL create bow service

yes yes it’s gonna beat that I think

this looks sensible yes okay now we’re

gonna wait 30 seconds what’s this 30

I don’t think 30 seconds is gonna be

enough the way it is there oh yeah now

30 seconds is definitely not enough I’m

gonna use it I’m just gonna go crazy and

do 120 seconds I know I’m just gonna

delete this to make sure that it’s

actually generating it and then we’re

gonna do particle webhook particle jet

trick Jason okay cool I think everything

worked so yes let me do cube CT I’ll get

pods to see what service is running this

is running now so let’s see if we’re

gonna tell the logs of this little

bugger logs do you do to do follow and

if this works now I think yes haha

awesome I’m going to do that again I’m

gonna do that again but I’m going to use

other camera and I’m going to press the

button here and it’s going to update and

I gotta press other buttons I’m just

gonna say for and it’s gonna say to you

and it’s kind of oh yes I have created

life so this works now it’s tiny things

up a bit because everything is really

kubernetes top JSON is a bit of as

misnomer this is actually the

configuration for the replication

this is looking pretty good we’re

spending a lot of time on this and and

and it’s actually pretty stupid for for

a hack but or no nothing is stupid for a

hack and hack is what it is a

side-project is what it is what it’s

whatever you want it to be but for a

real application it’s very very good to

have you know a very simple deploy

process where all these things are

solved in one place and you can do it in

a simple way and you know that it’s

gonna work you don’t need to remember to

put your servers into a certain state to

deploy the app you don’t have to

remember to yeah we have to install this

on this server and you have to

remember to do this before you do that

if you have a process to take care of

that things are going to be a lot easier

for you because this kind of will

take up so much of your time otherwise

our you know some to not watch the

screen yes this means that we have

accomplished our mission we want an

automated deploy of Kyrene on Google

commit message it’s for a master yep and

it’s it’s pushed and you can check it

out here if you are interested in

reading any of this blabber bladder as

usual with these episodes we didn’t get

very far the only thing that we did was

an automate to deploy of our server on

Google cloud what we accomplished what

we set out to do I think it’s very

important to celebrate every little step

along the way because no matter how big

your application is it’s going to be

made up of these small small individual

steps towards a bigger goal and if you

if you focus too much on the end goal

and forget about focusing on the

individual parts and feeling the sense

of progress that you’re making with each

individual part you’re going to feel

you’re going to feel bad you’re gonna

feel like oh I’m not getting to my goal

and eventually if you don’t feel that

sense of progress it’s going to hurt

your motivation so much that you just

don’t have the stamina to each reach

your end goal and this is especially

important when you are working with your

own projects where nobody is telling you

what to do and pushing you so in those

cases you have to think about your

motivation a lot how did you like this

episode how do you like this format did

you feel that this episode improved over

the last episodes is there anything that

you would like to see different do you

like the length or are you actually a

cat and you’re just writing comments on

the internet and you you post as a human

and you want to confess that write a

comment below or write a comment below

write a comment below

or if you don’t feel like that hit like

that’s also good or maybe even hit

subscribe I make a new episode of fun

fun function every Monday and

subscribing will make sure that you

don’t miss out on them if you don’t feel

like waiting and you want more fun fun

function right now you can check out

this episode

perhaps it’s nuts I am mpj this is fun

fun function until next Monday morning stay curious

Please follow and like us: