Consul Part 3: Key/Value store and Web UI - YouTube

Channel: unknown

[9]
hi i'm andre
[10]
and in the last two console videos we've
[13]
learned how to do a service discovery
[16]
using the http and dns api self-console
[19]
and we've learned how to use console
[21]
templates to make use of that
[23]
information to configure services
[26]
today i'd like to show you how you can
[28]
use
[30]
the key value store of console to
[33]
actually
[33]
coordinate or configure parts of your
[36]
services dynamically
[38]
and how to use the web uif console to
[40]
easily do so
[42]
as you can see the environment is about
[43]
the same as we left it after the last
[46]
video
[47]
we've got two constant lines one console
[49]
server
[50]
only thing i've done is i've updated all
[52]
of them to console.70
[56]
and in order to set an item in the key
[59]
value saw
[60]
you just use the http put methods
[64]
on the endpoint v1 kv for key value
[68]
and then you can think of a path
[69]
yourself in my case
[71]
i'm setting the number of web server
[74]
workers
[75]
for specific hosts so i'll be setting
[78]
calls or client one and workers to eight
[81]
and if i fetch the same value again you
[84]
can see
[85]
that console added some more information
[88]
to it
[101]
there you are you get a creation index
[105]
you can you could have set some flags
[110]
and of course you get the value itself
[113]
but it doesn't look like the number 8 we
[116]
put in there
[118]
that is because in order to be
[121]
encoding agnostic console will use
[125]
base64 encoding on your values
[127]
you get the same value out that you put
[129]
into it
[132]
now let's stop our console server we
[134]
already set the
[137]
client access id to be any ip on the
[140]
server so you can
[142]
have clients access the server from
[145]
anywhere in the network and we have the
[148]
dash ui option
[150]
so we'll have the web interface started
[152]
with the control server
[156]
now just to get rid of the error
[158]
messages
[159]
we'll also restart both of the clients
[161]
it's not really necessary but
[167]
there we are now let's start a web
[168]
browser go to our console server and it
[171]
will redirect you
[173]
to the ui portion of the url space
[178]
and there you are you can have a look at
[181]
different services in your network
[186]
you can have a look at your different
[187]
nodes in the network you also get some
[189]
information about the nodes can also
[198]
have it
[199]
within server centric view
[205]
and of course you can access the key
[207]
value store
[209]
there we are we just set the key for
[210]
console client 1 and the num worker
[212]
straight
[213]
let's use the ui to change it to 12
[217]
and when we fetch the value from any of
[220]
the console clients
[223]
we get a different base64 encoded value
[225]
and if we decode it
[228]
we get surprise surprise
[231]
the number 12 just as we entered it in
[234]
the web ui
[236]
but now let's put the original value of
[239]
8 back in
[250]
and you see it's back to the original
[252]
base
[253]
encoded value it's the same we had
[256]
before
[258]
so it's 8 again
[267]
just to make things a little more
[268]
interesting we'll add
[270]
a key for the second client
[274]
so we'll add the number of workers for
[276]
console client two
[279]
and we set it to a different value say 4
[283]
and we do it on the same note because
[287]
key value items in console are shared
[291]
among all the members of a cluster so
[293]
you can easily
[294]
set and access it from any of your
[297]
clients
[300]
and you cannot only configure your load
[303]
balancer weights with it
[304]
you could also coordinate things with it
[307]
you could
[308]
set a global maintenance flag for
[310]
example to have all your web servers
[313]
render out a maintenance page while
[314]
you're updating the web application in
[316]
the background
[318]
you could point all your web
[321]
web application servers to your central
[323]
database server
[325]
and have an easy time switching the
[327]
database server to
[329]
the other master master master replica
[331]
sets or something like that
[333]
now we'll go back to the console master
[335]
and
[336]
run console template to have our load
[338]
balancer config rendered out
[342]
and let's have a look at it
[348]
and you see it's still just rendering
[351]
the two servers as an upstream
[354]
it'll use the substream servers
[358]
to balance among them
[361]
any request it gets if we wanted to add
[364]
weights to it we would have to do this
[369]
just at weight equals well the actual
[372]
weight
[374]
but if we did this it would be
[377]
overwritten the next time
[378]
we run the console template daemon so
[381]
let's adjust the template
[384]
we don't want to add a static value we
[387]
actually want to use
[388]
the value start in the key value style
[393]
to do this
[397]
you can easily extend the templates
[401]
the go templates support
[404]
a function called key or default which
[407]
will either give you
[408]
the value of a specific key or if it
[410]
doesn't find that key
[411]
it will give it it will render out the
[414]
default value
[416]
so let's say the default will be one
[421]
but somehow our key names are
[425]
not very static they are dependent on
[428]
the hostname
[430]
and this is a bit of a nuisance in
[433]
golden templates because we would
[436]
we will actually have to print
[440]
the name of our notes
[444]
and the string of the item name
[449]
to have it fill in the actual
[454]
key name of hostname slash them workers
[459]
it feels a bit like a clutch but you can
[461]
get used to it it's
[463]
not that complicated and
[466]
now we rent out the template and have a
[468]
look at it
[472]
there we go we get the correct key
[476]
value for each server
[485]
and now let's delete the key for
[488]
console client 2 just to make things
[491]
interesting and to see that the
[493]
default value actually works
[498]
let's render the template again
[503]
and look into it and you will see that
[506]
now
[507]
contour client 2 has a weight of 1
[509]
because that's what we said as a default
[514]
and this concludes the planned parts of
[518]
my series about the console service
[520]
discovery demon
[521]
if you've got any further questions feel
[524]
free to leave a comment
[525]
if you like this sort of videos
[527]
subscribe to my channel
[530]
and for now thanks for watching and
[533]
have a nice day