►
From YouTube: How to automate the setup of a Kubernetes cluster on GCP
Description
Using Ansible to install, setup, and configure a Google Kubernetes Cluster (GKE) on Google Cloud Platform (GCP). Infrastructure as Code (IaC) is paramount to maintain consistency across different environments. IaC resolves the environment drift issue where each environment has unique configurations that are not reproducible automatically. Ansible is the tool of choice to implement this tutorial. It helps us to create the necessary code to provision a basic Kubernetes cluster on GCP (GKE) automation.
A
Hello,
everyone
welcome
to
the
inaugural
kubernetes
community
day,
africa.
I
hope
you
are
enjoying
the
event
so
far.
Let
me
introduce
myself.
My
name
is
rafael
natali
and
I
will
be
talking
about
kubernetes,
ansible
automation,
infrastructure
as
code
and
how
all
they
work
together.
A
little
bit
about
myself.
I
am
currently
a
senior
devops
engineer
at
marionette
consulting.
A
A
Also,
I
am
an
aws
and
gcp
certified
professional
and
more
relevant
for
today's
topic.
I
am
a
certified
kubernetes
administrator.
Okay,
so
let's
get
started.
Infrastructure
is
code.
Infrastructures
code
is
an
intrinsic
part
of
the
devops
culture
and
best
practices.
The
goal
is
to
guarantee
configuration,
consistency
and
traceability
across
environments.
A
A
A
A
Where
I
define
my
zone,
my
region,
I
will
define
my
project
id
my
service
accounts
and
also
a
section
where
I
will
be
defining
some
variables
for
our
kubernetes
cluster.
So,
for
example,
the
name
I
can
say
kcd
africa
and
the
number
of
nodes.
Let's
create
that
cluster,
with
three
nodes
with
400
gigabytes
of
disk,
solid
state
and
machine
type,
n1
standard,
two:
okay,
those
are
the
variables
that
we
are
going
to
be
using
through
out.
A
We
will
see
when
you
start
to
go
with
the
rows
where
we're
going
to
be
using
that
okay.
So
as
for
the
inventory
file,
I
will
be
using
a
file
that
I
created
beforehand
just
for
security
reasons.
I
will
not
be
showing
here,
but
has
the
the
same
variables
that
I
show
in
the
example
before.
A
A
A
A
So
here
we
can
see
in
the
documentation
all
the
parameters
that
I
can
use
in
case.
In
the
case
for
the
network,
we
have
an
example
which
is
pretty
much
the
same,
that
we're
using
here
and
all
the
return
values.
So
when
we
create
the
gcp
network,
we
can
return.
We
can
register
this
in
firewall,
for
example,
the
name
as
we
are
going
to
see
here
in
in
the
row.
A
Okay.
So
the
module
is
a
piece
of
code
that
ansible
knows
what
you
do
in
the
gcp.
I
will
come
back
to
to
the
rows
to
the
tasks
later
on.
Before
that
I
will
just
create
another
row
for
kubernetes
cluster.
A
A
And
now
I
will
have
two
ansible
modules:
okay,
so,
in
order
to
create
a
kubernetes
cluster
in
gcp,
I
need
to
use
two
ansible
modules.
I
need
to
use
the
google
cloud
gcp
container
cluster
and
after
I
need
to
use
the
google
cloud
gcp
container
notebook
to
create
a
notebook
inside
of
the
kubernetes
cluster.
A
A
And
the
playbook
the
ansible
playbook
is
created
is
a
file
that
we
create
to
execute.
The
rows
is
a
ordered
list
of
tasks,
or
that's
in
that
case
rows
that
we
use
to
execute
the
same
code
every
time.
The
same
way,
the
same
manner
is
important
to
highlight
that,
as
I
mentioned,
is
an
order,
at
least
so.
A
A
A
So
ansible
knows
that
you
need
to
use
this
ansible
module
the
google
cloud
gcp
compute
network
to
create
the
network,
so
it
will
use
the
name
network
dash
cluster
name.
You
can
see
here.
This
is
a
jinja
2
type
of
variable,
and
I
replace
this
value
cluster
name
with
the
name
of
the
cluster
name
that
I
specified
previously
in
the
inventory
file.
Remember
I
put
kcd
africa,
so
ansible
will
ask
gcp
to
create
a
network
called
network
dash
kcd
dash
africa.
A
It
will
create
all
the
sub
networks
automatically,
because
I
set
this
to
true
in
the
project
id
project
again
ginger,
true
type,
it's
going
to
replace
with
the
project
id
that
I
specify
in
the
inventory
file
with
the
credential
file
again
that
I
use
in
the
inventory
file.
Okay,
the
state
the
state
for
this
task
is
to
be
present,
which
means
that
I'm
telling
ansible
that
whenever
it
runs
it
needs
to
ensure
that
the
network
exists.
A
A
So
that's
why
it's
changed:
okay,
because
previous
it
doesn't
exist
and
now
it
exists
if,
for
whatever
reason,
this
network
is
removed,
it's
deleted
and
we
run
this
ansible
again.
It
will
recreate
okay
and
if
we
run
danceable
again
and
then
symbol
see
that
the
network
already
exists,
it
doesn't
do
anything,
it
doesn't
recreate
or
delete
or
do
anything
you
just
say:
okay,
the
the
state
is
present.
So
I
I'm
okay
with
that
in
this.
Using
this
keyword
register,
I
am
registering
all
the
outcomes
of
the
this
module.
A
A
A
Okay,
as
you
can
see,
a
lot
of
things,
so
what
I
did
here,
I
used
the
name,
which
is
the
same
name
that
I
specify
in
the
adventure
file
the
kcd
africa.
The
number
of
nodes
that
I
want
this
tree,
the
location
is
the
zone.
A
A
I
use
the
variable
network
with
the
return
value
name
to
create
this
kubernetes
cluster.
So
I
associating
my
kubernetes
cluster
with
my
network.
If
I
don't
specify
anything
it
will
create
in
the
default
network,
but
I
don't
want
that.
My
project
id
is
coming
from
the
inventory
file.
I'm
authenticating
using
the
service
account
again
that
I
specify
in
the
eventual
file
the
state
is
present,
so
if
forever,
if
for
any
reason,
this
cluster
is
deleted.
A
A
A
For
the
network
you
see
is
creating
in
the
network
that
we
specified
previously
that's
great
now.
The
second
part
is
the
notebook.
So
this
this
module
only
creates
the
cluster,
but
doesn't
have
any
nodes.
A
In
the
same
way,
there
are
several
parameters
you
can
specify.
I
just
choose
a
couple
ones
for
this
presentation
for
simplicity,
so
the
name
is
node
pool
and
the
cluster
name.
The
initial
node
count
is
the
same
that
is
specified
before,
and
the
cluster
which
cluster
I
am
going
to
associate
my
notebook,
I'm
going
to
associate
with
the
cluster
that
I
create
in
the
step
before
the
kubernetes
cluster,
okay
and
I
will
create,
with
the
disk
size
of
100
gigabytes,
ssd,
the
machine
and
102
and
again
present.
A
So
I
I
want
this
to
be
present
okay,
so
we
can
see
here
in
the
terminal
that
it
already
run
so
it
already
created
the
kubernetes
cluster.
It
already
creates
the
kubernetes
node
pull
so
two
here.
Okay,
three
are
changed.
A
A
Now
all
the
resources
that
we
want
already
exists,
so
I
don't
want
ansible
to
do
anything
you
see.
So
when
we
rerun
this
with
this
information
and
ansible
checks
that
everything
already
exists
in
gcp,
you
just
say:
okay,
okay,
okay,
so
everything's,
okay,
because
all
these
states
are
true,
so
I
have
a
cluster.
I
have
the
node
poll.
I
have
the
network,
so
everything's,
okay,
ansible
doesn't
need
to
do
any
change
in
the
environment.
A
Notes-
and
here
they
are
the
same
three
notes
that
we
saw
in
the
console
before.
If
I
do
ctl
get
namespaces,
I
can
see
all
the
default
namespaces
get
parts
and
exam
group
system
do
we
have
anything
that
could
assist
in
rainy?
Oh,
we
have
great.
Let's
go
that's
good
from
this
point
on.
You
can
manage
the
kubernetes
cluster
with
kubctl
no
problems
at
all.
A
A
So
that's
what
I
wanted
to
show
to
you
today.
This
presentation
was
just
to
demonstrate
the
use
of
infrastructure
as
code
to
install
setup
and
configure
a
simple
kubernetes
cluster
on
google
cloud
platform
and
also
to
show
some
essential
concepts
from
ansible
like
rows
and
playbooks,
and
how
to
configure
and
structure
them
to
provision
resources
in
the
cloud.
A
Much
much
more
is
possible
with
ansible
gcp
kubernetes.
Obviously
this
is
just
a
starting
point
to
you
be
able
to
organize
your
kubernetes
configuration
such
as
namespace
deployments
and
policies
as
code
okay.
So
thank
you
very
much
for
being
with
me
today
and
continue
to
join
the
kubernetes
community
africa
bye.