0:00
hey everyone welcome back to our Channel
0:02
today we are going to learn how to
0:04
configure genkins to dynamically spin up
0:06
kubernetes ports as built
0:09
agents this setup will help you scale
0:11
your cicd pipeline efficiently and save
0:14
resources let's dive in before we start
0:17
make sure you have a running kubernetes
0:19
cluster genkins installed and running
0:22
kubernetes command line tool Cube Kettle
0:24
configured and admin access to both
0:27
Jenkins and kubernetes cluster we will
0:29
cover this process in four main steps
0:32
first step is to install kubernetes
0:34
plugin second getting cluster
0:36
credentials that is Cube config third we
0:39
will integrate the kubernetes cluster
0:41
with genkins master and Define code and
0:43
container template in the last we will
0:46
test our configuration with a simple job
0:49
all right without any delay let's Deep
0:51
dive into the step in order to integrate
0:54
kubernetes cluster with genkins Master
0:57
we must install kubernetes plugins on
1:00
so log to a genkins GUI navigate to
1:05
genkins and then click on
1:08
plugins select avable plugins search
1:16
kubernetes so install this
1:20
plugin select the plugin and click on
1:23
install choose this option restart Chen
1:26
kins with installation is complete and
1:32
it will take a minute or
1:35
two once the plug-in is installed login
1:41
GUI again navigate to manage
1:47
genkins this time select
1:50
security under the security we will have
1:53
agent section here select the first
1:56
option fixed that is TCB port for
1:59
inbound agents and specify the port by
2:03
default it is 50,000 so you can give the
2:14
save this 50,000 Port is commonly used
2:16
by genkins for jnlp traffic Java Network
2:20
launch protocol jenin uses jnlp to
2:23
stabilize communication between Jenkins
2:25
Master node that is controller and its
2:27
agents that is slaves that are running
2:31
machines now SSH your genkins master and
2:35
allow this port in your firewall in case
2:38
firewall is up and running I have
2:41
already taken the SSS session of my
2:45
master now run the command sud do
2:56
slcp H enter now reload the changes for
3:12
reload output confirms that we have
3:15
allowed 50,000 port on our genin Master
3:18
next get the cube config of your
3:20
kubernetes cluster I am already
3:23
connected to my control
3:26
plane so this Cube config will be used
3:29
while creating a credentials for our
3:33
cluster in my case Cube config is placed
3:43
config so copy this config file on your
3:47
system let's download
3:54
it now head back to the genkins GUI and
3:56
create the credentials for your
4:01
okay navigate to manage
4:03
genkins and then click
4:07
credentials to system Global
4:10
credentials click on ADD
4:14
credentials select the kind as secret
4:20
Global now select the config file that
4:27
downloaded give the name as Cube
4:36
create now add your kubernetes cluster
4:39
into the genkins as a cloud so again go
4:44
genkins and then under system
4:47
configuration click on
4:49
clouds and click on new
4:52
Cloud now specify the name of your Cloud
4:55
name let's say key it
5:02
kubernetes and then click
5:06
create now we need to get the kubernetes
5:09
URL now go back to your control
5:20
file so this is the kubernetes URL in my
5:32
here now scroll down under the
5:35
credentials section select the
5:38
credential that we have just created
5:40
just select config and click on test
5:47
connections output confirms that we are
5:49
able to connect our kubernetes
5:55
Save now select this cluster now we'll
5:58
Define the PO template template for this
6:00
cluster click on add a port
6:02
template under the name section specify
6:05
the name for your Port template let's
6:08
say it's key it as hyphen
6:11
agent and name space where the bo will
6:15
be created so it would be under
6:19
default label let's say KS hyph
6:26
agent under the uses select this options
6:33
scroll down a little bit and here you
6:38
get add a container template option so
6:45
template container name would be
6:52
jnlp container image will be pulled from
6:55
the repo genkins slash
7:04
agent and the working directory on the
7:07
agent would be/ home/
7:12
Jenkins keep this blank and argument
7:15
also is blank and leave the other
7:19
parameters as it is and then click on
7:22
create if you click on again this Cloud
7:27
here we will have one po template with
7:29
the name k s agent which will be using a
7:33
default name space and label is KS agent
7:37
under this P template we have one
7:38
container template container name is gnl
7:42
this is my Docker image that will be
7:44
used while spinning of the Pod and this
7:47
would be the home directory that will be
7:49
used by our Jenkins agent or we call or
7:53
the genin slaves all right now in order
7:56
to test this configurations let's create
7:59
a sample Pipeline and we will force that
8:02
pipeline to run on the this kuber port
8:09
isent click on plus new item let's
8:16
demo pipeline hyphen Kate hyphen isent
8:21
select the pipeline and then click
8:31
and use this sample pipeline code so if
8:34
you see in this pipeline we are
8:38
specifically mentioning that please run
8:42
this stage on the agent whose label is
8:49
agent and we have one stage with the
8:52
name test here we are executing two
8:54
commands first one is Eco from the kuber
8:57
port and then running a host name from
9:05
Save now try to run this pipeline click
9:22
now we can see the console output a p
9:26
has been created using the P template k
9:29
as agent Cod name is this this
9:37
executed the code under
9:40
the working directory SL home/ Jenkins
9:44
and it has executed uh Eco command hello
9:47
from kubernetes Sport and executed the
9:50
name this confirms that we have
9:53
successfully able to execute our
9:57
pipeline using our template which is
10:00
provision on our kubernetes Cloud that's
10:04
it you have successfully configured
10:05
genkins to use kuber Sports as build
10:09
agents if you have found this
10:11
useful hit the like button subscribe for
10:14
more devops tutorials drop a comment if
10:17
you have any questions thank you for
10:19
watching see you in the next video