YouTube2Text

Kubernetes Crash Course for Absolute Beginners [NEW] — Transcript

by TechWorld with Nana · 10,204 words · 1,713 segments · language en · Watch on YouTube

Full transcript

  1. 0:00hello and welcome to the kubernetes
  2. 0:03crash course where i will teach you
  3. 0:05everything you need to know to get
  4. 0:07started with kubernetes in one hour
  5. 0:10i am nana and i have taught hundreds of
  6. 0:13thousands of people how to advance their
  7. 0:15devops skills through my youtube channel
  8. 0:18online courses and the devops
  9. 0:20educational program
  10. 0:21if you're new here be sure to subscribe
  11. 0:24because i upload new videos all the time
  12. 0:27now let's look at an overview of what
  13. 0:29you will learn
  14. 0:30first of all we'll see what is
  15. 0:32kubernetes and why do we need it and why
  16. 0:34did it become so popular
  17. 0:37second we will go through the kubernetes
  18. 0:38architecture and you will see how
  19. 0:40kubernetes actually works in the
  20. 0:42background
  21. 0:43after that we will cover main kubernetes
  22. 0:46components that you need to learn to
  23. 0:48work efficiently with kubernetes and
  24. 0:51finally we will do a hands-on demo
  25. 0:53project to get your first practical
  26. 0:56experience with kubernetes now
  27. 0:58kubernetes is a very popular but also a
  28. 1:01very complex technology so this crash
  29. 1:04course will help you get your first
  30. 1:06experience to get started with
  31. 1:08kubernetes but if by the end of the
  32. 1:10video you decide to deepen your
  33. 1:12knowledge in kubernetes and are thinking
  34. 1:15about a career as a kubernetes
  35. 1:17administrator my new complete kubernetes
  36. 1:20administrator course will be a great
  37. 1:22resource for you where you will learn
  38. 1:24how to build configure and manage
  39. 1:26kubernetes clusters from scratch
  40. 1:29the course is also dedicated to help you
  41. 1:32pass the cka exam from linux foundation
  42. 1:35to become a certified kubernetes
  43. 1:37administrator now we have a lot to cover
  44. 1:40in this video so let's jump right into
  45. 1:43it
  46. 1:44so let's jump in right into the
  47. 1:45definition what is kubernetes
  48. 1:48so kubernetes is an open source
  49. 1:49container orchestration framework which
  50. 1:52was originally developed by google so on
  51. 1:54the foundation it manages containers be
  52. 1:57docker containers or from some other
  53. 1:59technology which basically means that
  54. 2:02kubernetes helps you manage applications
  55. 2:05that are made up of hundreds or maybe
  56. 2:08thousands of containers and it helps you
  57. 2:11manage them in different environments
  58. 2:13like physical machines virtual machines
  59. 2:16or cloud environments or even hybrid
  60. 2:19deployment environments
  61. 2:23so what problems does kubernetes solve
  62. 2:26and what are the tasks of a container
  63. 2:29orchestration tool actually so to go
  64. 2:32through this chronologically
  65. 2:34the rise of microservices caused
  66. 2:36increased usage of container
  67. 2:38technologies because the containers
  68. 2:40actually offer the perfect host for
  69. 2:43small
  70. 2:44independent applications like
  71. 2:46microservices
  72. 2:48and the rise of containers and the micro
  73. 2:50service technology actually resulted in
  74. 2:53applications they're now comprised of
  75. 2:55hundreds or sometimes maybe even
  76. 2:57thousands of containers managing those
  77. 3:00loads of containers across multiple
  78. 3:02environments using scripts and self-made
  79. 3:06tools can be really complex
  80. 3:08and sometimes even impossible so that
  81. 3:11specific scenario actually caused the
  82. 3:14need for
  83. 3:15having container orchestration
  84. 3:17technologies
  85. 3:21so what those orchestration tools like
  86. 3:23kubernetes do is
  87. 3:25actually guarantee following features
  88. 3:28one is high availability in simple words
  89. 3:32high availability means that the
  90. 3:34application has no downtime so it's
  91. 3:36always accessible by the users a second
  92. 3:40one is scalability which means you can
  93. 3:43scale your applications fast when you
  94. 3:46have more load on it and more users are
  95. 3:49trying to access it and the same way you
  96. 3:51can easily scale it down when the load
  97. 3:53goes down
  98. 3:55so it makes your application more
  99. 3:56flexible to adjust to the increasing or
  100. 3:59decreasing load and the third one is
  101. 4:03disaster recovery which basically means
  102. 4:05that if an infrastructure has some
  103. 4:06problems like data is lost or the
  104. 4:09servers explode or something bad happens
  105. 4:11with the service center the
  106. 4:12infrastructure has to have some kind of
  107. 4:14mechanism to back up the data and to
  108. 4:16restore it to the latest state so that
  109. 4:19application doesn't actually lose any
  110. 4:21data and the containerized application
  111. 4:23can run from the latest state after the
  112. 4:26recovery
  113. 4:27and all of these are functionalities
  114. 4:29that
  115. 4:30container orchestration technologies
  116. 4:32like kubernetes offer so how does the
  117. 4:34kubernetes basic architecture actually
  118. 4:36look like
  119. 4:37the kubernetes cluster is made up with
  120. 4:40at least one master node
  121. 4:43and then connected to it you have
  122. 4:45a couple of worker nodes where each node
  123. 4:49has a cubelet process running on it and
  124. 4:52cubelet is actually a kubernetes process
  125. 4:55that makes it possible for the cluster
  126. 4:58to talk to each other to communicate to
  127. 5:00each other and actually execute some
  128. 5:03tasks on those nodes like running
  129. 5:05application processes
  130. 5:07each worker node has containers of
  131. 5:10different applications deployed on it so
  132. 5:12depending on how the workload is
  133. 5:15distributed you would have different
  134. 5:17number of docker containers running on
  135. 5:20worker nodes and worker nodes are where
  136. 5:23the actual work is happening so here is
  137. 5:25where your applications are running so
  138. 5:28the question is what is running on
  139. 5:30masternode
  140. 5:31masternode actually runs several
  141. 5:34kubernetes processes that are absolutely
  142. 5:37necessary
  143. 5:38to run and manage the cluster properly
  144. 5:41one of such processes is an api server
  145. 5:44which also is a container an api server
  146. 5:47is actually the entry point to the
  147. 5:49kubernetes cluster so this is the
  148. 5:51process
  149. 5:52which the different kubernetes clients
  150. 5:54will talk to like ui if you're using
  151. 5:56kubernetes dashboard an api if you're
  152. 5:59using some scripts and automating
  153. 6:02technologies and a command line tool so
  154. 6:05all of these will talk to the api server
  155. 6:07another process that is running on
  156. 6:09master node is a controller manager
  157. 6:12which basically keeps an overview of
  158. 6:14what's happening in the cluster whether
  159. 6:16something needs to be repaired or maybe
  160. 6:19if a container died and it needs to be
  161. 6:21restarted etc
  162. 6:23and another one is
  163. 6:25scheduler which is basically responsible
  164. 6:27for scheduling
  165. 6:29containers on different nodes based on
  166. 6:31the workload and the available server
  167. 6:34resources on each node so it's an
  168. 6:37intelligent
  169. 6:38process that decides on which worker
  170. 6:41node the next container should be
  171. 6:44scheduled on based on the available
  172. 6:46resources on those worker nodes and the
  173. 6:48load that that container needs and
  174. 6:51another very important component of the
  175. 6:53whole cluster is actually an etcd key
  176. 6:56value storage which basically holds at
  177. 6:59any time the current state of the
  178. 7:02kubernetes cluster so it has all the
  179. 7:04configuration data inside
  180. 7:06and all the status data of each node and
  181. 7:09each container inside of that node and
  182. 7:12the backup and restore that we mentioned
  183. 7:14previously is actually made from these
  184. 7:16etcd snapshots because you can recover
  185. 7:20the whole cluster state using that etcd
  186. 7:24snapshot and last but not least also a
  187. 7:26very important component of kubernetes
  188. 7:29which enables those nodes worker nodes
  189. 7:32masternodes talk to each other is the
  190. 7:34virtual network that spans all the nodes
  191. 7:37that are part of the cluster and in
  192. 7:39simple words virtual network actually
  193. 7:42turns
  194. 7:43all the nodes inside of a cluster into
  195. 7:46one powerful machine that has the sum of
  196. 7:50all the resources of individual nodes
  197. 7:53one thing to be noted here is that
  198. 7:55worker knows because they actually have
  199. 7:58most load because they are running the
  200. 8:01applications on inside of it usually are
  201. 8:04much bigger and have more resources
  202. 8:07because they will be running hundreds of
  203. 8:08containers inside of them whereas master
  204. 8:11node will be running just a handful of
  205. 8:14master processes like we see in this
  206. 8:16diagram so it doesn't need that many
  207. 8:18resources however as you can imagine
  208. 8:20masternode is much more important than
  209. 8:23the individual worker nodes because if
  210. 8:25for example you lose a masternode access
  211. 8:29you will not be able to access the
  212. 8:31cluster anymore and that means that you
  213. 8:34absolutely have to have a backup of your
  214. 8:36master at any time so in production
  215. 8:39environments usually you would have at
  216. 8:41least two masters inside of your
  217. 8:44kubernetes cluster but in more cases of
  218. 8:46course you're going to have multiple
  219. 8:48musters where if one muster node
  220. 8:51is down the cluster continues to
  221. 8:54function smoothly because you have other
  222. 8:56masters available
  223. 8:59in this video we're going to learn about
  224. 9:01the main kubernetes components that we
  225. 9:04as kubernetes administrators or users
  226. 9:07will be working with most of the time to
  227. 9:10make it easier to understand all these
  228. 9:12components i'm gonna build a simple use
  229. 9:14case of a web application with a simple
  230. 9:17database and i'm gonna show you step by
  231. 9:20step how each component in kubernetes
  232. 9:23helps you deploy such an application
  233. 9:25setup and what is the role of each of
  234. 9:27these components
  235. 9:31so let's start with the basic setup of a
  236. 9:34worker node or in kubernetes terms a
  237. 9:37node
  238. 9:38which is a simple server a physical or
  239. 9:41virtual machine and the basic component
  240. 9:43or the smallest unit of kubernetes is a
  241. 9:47pod so what pod is is basically an
  242. 9:50abstraction over a container so if
  243. 9:52you're familiar with docker containers
  244. 9:55or container images so basically what
  245. 9:57pod does is it creates this running
  246. 10:00environment or a layer on top of the
  247. 10:03container
  248. 10:04and the reason is because kubernetes
  249. 10:06wants to abstract away the container
  250. 10:09runtime or container technologies so
  251. 10:11that you can replace them if you want to
  252. 10:14and also because you don't have to
  253. 10:16directly work with docker or whatever
  254. 10:19container technology you use in a
  255. 10:21kubernetes so you only interact with the
  256. 10:23kubernetes layer so we have an
  257. 10:25application pod which is our own
  258. 10:27application and that will maybe use a
  259. 10:30database pod with its own container and
  260. 10:32this is also an important concept here
  261. 10:35pod is usually meant to run one
  262. 10:38application container inside of it you
  263. 10:41can run multiple containers inside one
  264. 10:43pod but usually it's only the case if
  265. 10:45you have one main application container
  266. 10:48and the helper container or some side
  267. 10:51service that has to run inside of that
  268. 10:54pod
  269. 10:55and as you see this is nothing special
  270. 10:57you just have one server and two
  271. 10:58containers running on it with a
  272. 11:00abstraction layer on top of it so now
  273. 11:02let's see how they communicate with each
  274. 11:04other in kubernetes world so kubernetes
  275. 11:07offers out of the box a virtual network
  276. 11:09which means that each
  277. 11:10pod gets its own ip address not the
  278. 11:14container the pod gets the ip address
  279. 11:16and each pod
  280. 11:18can communicate with each other using
  281. 11:20that ip address which is an internal ip
  282. 11:22address obviously it's not the public
  283. 11:24one so my application container can
  284. 11:27communicate with database using the ip
  285. 11:30address however pod components in
  286. 11:33kubernetes also an important concept are
  287. 11:36ephemeral which means that they can die
  288. 11:39very easily
  289. 11:40and when that happens for example if i
  290. 11:42lose a database container because the
  291. 11:45container crashed because the
  292. 11:47application crashed inside or because
  293. 11:50the nodes the server that i'm running
  294. 11:53them on
  295. 11:54ran out resources the pod will die
  296. 11:57and a new one will get created in its
  297. 11:59place and when that happens it will get
  298. 12:02assigned a new ip address which
  299. 12:04obviously is inconvenient if you are
  300. 12:07communicating with the database using
  301. 12:08the ip address because now you have to
  302. 12:10adjust it every time pod restarts and
  303. 12:13because of that another component of
  304. 12:16kubernetes called service is used
  305. 12:21so service is basically a static ip
  306. 12:24address or permanent ip address that can
  307. 12:27be attached so to say to each pod so my
  308. 12:31app will have its own service and
  309. 12:32database pod will have its own service
  310. 12:35and the good thing here is that the life
  311. 12:38cycles of service and the pod are not
  312. 12:41connected so even if the pod dies
  313. 12:44the service and its ip address will stay
  314. 12:48so you don't have to change that
  315. 12:51endpoint anymore
  316. 12:52so now obviously you would want your
  317. 12:55application to be accessible through a
  318. 12:57browser right and for this you would
  319. 12:59have to create an external service so
  320. 13:01external services a service that opens
  321. 13:04the communication from external sources
  322. 13:07but obviously you wouldn't want your
  323. 13:09database to be open to the public
  324. 13:12requests and for that you would create
  325. 13:14something called an internal service so
  326. 13:17this is a type of a service that you
  327. 13:20specify when creating one however if you
  328. 13:23notice the url of
  329. 13:26the external service is not very
  330. 13:29practical so basically what you have is
  331. 13:32an http protocol with a node ip address
  332. 13:36so of the node not the service and the
  333. 13:39port number of the service which is
  334. 13:42good for test purposes if you want to
  335. 13:44test something very fast but not for the
  336. 13:46end product so usually you would want
  337. 13:48your url to look like this if you want
  338. 13:50to talk to your application with a
  339. 13:53secure protocol and a domain name and
  340. 13:56for that
  341. 13:57there is another component of kubernetes
  342. 14:00called ingress so instead of service the
  343. 14:03request goes first to ingress and it
  344. 14:05does the forwarding then to the service
  345. 14:08so now we saw some of the very basic
  346. 14:10components of kubernetes and as you see
  347. 14:12this is a very simple setup we just have
  348. 14:14a one server and a couple of containers
  349. 14:17running and some services nothing really
  350. 14:21special where kubernetes advantages or
  351. 14:24the actual cool features really come
  352. 14:26forward but we're gonna get there step
  353. 14:28by step so let's continue
  354. 14:34so as we said pods communicate with each
  355. 14:36other using a service so my application
  356. 14:39will have a database endpoint let's say
  357. 14:42called mongodb service that it uses to
  358. 14:45communicate with the database but
  359. 14:48whether you configure usually this
  360. 14:50database url or endpoint usually you
  361. 14:53would do it in application properties
  362. 14:55file or as some kind of external
  363. 14:58environmental variable but usually it's
  364. 15:00inside of the built image of the
  365. 15:03application so for example if the
  366. 15:06endpoint of the service or service name
  367. 15:08in this case changed to mongodb you
  368. 15:11would have to adjust that url in the
  369. 15:13application so usually you'd have to
  370. 15:16rebuild the application with a new
  371. 15:18version and you have to push it to the
  372. 15:20repository and now you'll have to
  373. 15:23pull that new image in your pod and
  374. 15:26restart the whole thing so a little bit
  375. 15:28tedious for a small change like database
  376. 15:32url so for that purpose kubernetes has a
  377. 15:35component called config map so what it
  378. 15:38does is it's basically your external
  379. 15:40configuration to your application so
  380. 15:43config map would usually contain
  381. 15:45configuration data like urls of a
  382. 15:48database or some other services that you
  383. 15:50use and in kubernetes you just connect
  384. 15:53it to the pod so that pod actually gets
  385. 15:56the data that config map contains
  386. 15:59and now if you change the name of the
  387. 16:01service the endpoint of the service you
  388. 16:03just adjust the config map and that's it
  389. 16:06you don't have to build a new image and
  390. 16:08have to go through this whole cycle now
  391. 16:11part of the external configuration can
  392. 16:13also be database username and password
  393. 16:16right which may also change in the
  394. 16:19application deployment process but
  395. 16:21putting a password or other credentials
  396. 16:24in a config map in a plain text format
  397. 16:27would be insecure even though it's an
  398. 16:29external configuration so for this
  399. 16:31purpose kubernetes has another component
  400. 16:34called secret
  401. 16:36so secret is just like config map but
  402. 16:39the difference is that it's used to
  403. 16:41store secret data credentials for
  404. 16:44example and it's stored not in a plain
  405. 16:46text format but in base 64 in encoded
  406. 16:50format but of course basics before
  407. 16:52encoding a secret doesn't make it
  408. 16:53automatically secure
  409. 16:55the secret components are meant to be
  410. 16:58encrypted
  411. 16:59using third-party tools in kubernetes
  412. 17:02because kubernetes doesn't encrypt them
  413. 17:04out of the box
  414. 17:05and there are tools for that from cloud
  415. 17:07providers or separate third-party tools
  416. 17:10that you can
  417. 17:11deploy on kubernetes to encrypt your
  418. 17:13secrets and that will make secrets
  419. 17:16secure
  420. 17:17so secret would contain things like
  421. 17:20credentials and of course i mean
  422. 17:22database user you could also put in
  423. 17:23config map but what's important is the
  424. 17:26passwords certificates things that you
  425. 17:29don't want other people to have access
  426. 17:31to would go in the secret and just like
  427. 17:34config map you just connect it to your
  428. 17:36pod so that pod can actually see those
  429. 17:38data and read from the secret you can
  430. 17:41actually use the data from configmap or
  431. 17:44secret inside of your application pod
  432. 17:47using for example environmental
  433. 17:49variables or even as a properties file
  434. 17:52so now let's see another very important
  435. 17:54concept generally which is data storage
  436. 17:58and how it works in kubernetes
  437. 18:00so we have this database pod that our
  438. 18:02application uses and it has some data or
  439. 18:04it generates some data with this setup
  440. 18:06that you see now if the database
  441. 18:09container or the pod gets restarted
  442. 18:12the data would be gone and that's
  443. 18:15problematic and inconvenient obviously
  444. 18:18because you want your database data or
  445. 18:20log data to be persisted reliably long
  446. 18:24term
  447. 18:25and the way you can do it in kubernetes
  448. 18:27is using another component of kubernetes
  449. 18:30called volumes
  450. 18:32and how it works is that it basically
  451. 18:34attaches a physical storage on a hard
  452. 18:37drive to your pod and that storage could
  453. 18:40be either on a local machine meaning on
  454. 18:42the same server node where the pod is
  455. 18:45running or it could be on a remote
  456. 18:47storage meaning outside of the
  457. 18:49kubernetes cluster it could be a cloud
  458. 18:52storage or it could be your own premise
  459. 18:54storage which is not part of the
  460. 18:56kubernetes cluster so you just have an
  461. 18:59external reference on it so now when the
  462. 19:01database pod or container gets restarted
  463. 19:04all the data will be there persisted
  464. 19:07it's important to understand the
  465. 19:08distinction between the kubernetes
  466. 19:10cluster and all of its components and
  467. 19:13the storage
  468. 19:14regardless of whether it's a local or
  469. 19:17remote storage think of a storage as an
  470. 19:20external hard drive plugged in into the
  471. 19:23kubernetes cluster because the point is
  472. 19:26kubernetes cluster explicitly doesn't
  473. 19:28manage any data persistence which means
  474. 19:31that you as a kubernetes user or an
  475. 19:33administrator are responsible for
  476. 19:36backing up the data replicating and
  477. 19:38managing it and making sure that it's
  478. 19:40kept on a proper hardware etc because
  479. 19:43it's not taking care of kubernetes
  480. 19:50so now let's see everything is running
  481. 19:51perfectly and a user can access our
  482. 19:53application through a browser
  483. 19:56now with this setup what happens if my
  484. 19:59application pod dies right crashes or i
  485. 20:02have to restart the pod because i built
  486. 20:06a new container image
  487. 20:08basically i would have a downtime where
  488. 20:11a user can reach my application which is
  489. 20:14obviously a very bad thing
  490. 20:16if it happens in production and this is
  491. 20:19exactly the advantage of distributed
  492. 20:21systems and containers
  493. 20:23so instead of relying on just one
  494. 20:25application part and one database part
  495. 20:28etc
  496. 20:29we are replicating everything
  497. 20:32on multiple servers
  498. 20:34so we would have another node where a
  499. 20:37replica or clone of our application
  500. 20:40would run which will also be connected
  501. 20:43to the service so remember previously we
  502. 20:45said the service is like a persistent
  503. 20:48static ip address with a dns name so
  504. 20:51that you don't have to
  505. 20:53constantly adjust the end point when a
  506. 20:56pod dies
  507. 20:57but service is also a load balancer
  508. 20:59which means that the service will
  509. 21:01actually catch the request and forward
  510. 21:03it to whichever part is least busy so it
  511. 21:05has both of these functionalities
  512. 21:08but in order to create the the second
  513. 21:10replica of the my application pod you
  514. 21:13wouldn't create a second part but
  515. 21:15instead you will define a blueprint for
  516. 21:18a my application pod and specify how
  517. 21:20many replicas of that pod you would like
  518. 21:23to run and that component or that
  519. 21:25blueprint is called deployment which is
  520. 21:28another component of kubernetes and in
  521. 21:31practice you would not be working with
  522. 21:33pods or you would not be creating pods
  523. 21:36you would be creating deployments
  524. 21:38because there you can specify how many
  525. 21:40replicas and you can also scale up or
  526. 21:43scale down the number of replicas of
  527. 21:46pots that you need so with pot we said
  528. 21:48that pot is a layer of abstraction on
  529. 21:51top of containers
  530. 21:53and deployment is another abstraction on
  531. 21:56top of pots which makes it more
  532. 21:58convenient to interact with the pods
  533. 22:00replicate them and do some other
  534. 22:02configuration
  535. 22:04so in practice you would mostly work
  536. 22:06with deployments and not with pods so
  537. 22:09now if one of the replicas of your
  538. 22:11application pod would die the service
  539. 22:13will forward the requests to another one
  540. 22:17so your application would still be
  541. 22:18accessible for the user so now you're
  542. 22:20probably wondering what about the
  543. 22:22database pod because if the database
  544. 22:25part died your application also wouldn't
  545. 22:27be accessible so we need a
  546. 22:30database replica as well however we
  547. 22:32can't replicate database using a
  548. 22:35deployment and the reason for that is
  549. 22:37because database has a state which is
  550. 22:41its data
  551. 22:42meaning that if we have clones or
  552. 22:44replicas of the database they would all
  553. 22:47need to access the same
  554. 22:50shared
  555. 22:50data storage and there you would need
  556. 22:53some kind of mechanism that manages
  557. 22:56which parts are currently writing to
  558. 22:58that storage or which pods are reading
  559. 23:01from the storage in order to avoid data
  560. 23:04inconsistencies and that mechanism
  561. 23:08in addition to replicating feature is
  562. 23:11offered by another kubernetes component
  563. 23:14called statefulset so this component is
  564. 23:17meant specifically for applications like
  565. 23:20databases so mysql mongodb
  566. 23:24elasticsearch or any other stateful
  567. 23:27applications or databases
  568. 23:30should be created using stateful sets
  569. 23:32and not deployments
  570. 23:34it's a very important distinction
  571. 23:36and stateful said just like deployment
  572. 23:39would take care of
  573. 23:40replicating the pots and scaling them up
  574. 23:44or scaling them down but making sure the
  575. 23:46database reads and writes are
  576. 23:48synchronized so that no database
  577. 23:51inconsistencies are offered however i
  578. 23:54must mention here that deploying
  579. 23:56database applications using stateful
  580. 23:59sets
  581. 24:00in kubernetes cluster can be somewhat
  582. 24:03tedious so it's definitely more
  583. 24:05difficult than working with deployments
  584. 24:08where you don't have all these
  585. 24:09challenges that's why it's also a common
  586. 24:12practice to host database
  587. 24:14applications outside of the kubernetes
  588. 24:17cluster and just have the deployments or
  589. 24:20stateless applications
  590. 24:22that replicate and scale with no problem
  591. 24:24inside of the kubernetes cluster and
  592. 24:27communicate with the external database
  593. 24:29so now that we have two replicas of my
  594. 24:31application pod and two replicas of the
  595. 24:34database and they're both load balanced
  596. 24:36our setup is more robust which means
  597. 24:39that now even if node one the whole node
  598. 24:42server was actually rebooted or crashed
  599. 24:46and nothing could run on it we would
  600. 24:48still have a second node with
  601. 24:50application and database pods running on
  602. 24:53it and the application would still be
  603. 24:55accessible by the user until these two
  604. 24:58replicas get recreated so you can avoid
  605. 25:01downtime
  606. 25:04so to summarize we have looked at
  607. 25:07the most used kubernetes components we
  608. 25:10start with the pods and the services in
  609. 25:12order to communicate between the parts
  610. 25:14and the ingress component which is
  611. 25:16used to route traffic into the cluster
  612. 25:19we've also looked at external
  613. 25:21configuration using config maps and
  614. 25:23secrets and data persistence using
  615. 25:26volumes and finally we've looked at pod
  616. 25:30blueprints with replicating mechanisms
  617. 25:33like deployments and stateful sets where
  618. 25:36stateful set is used specifically for
  619. 25:38stateful applications like databases
  620. 25:41just using these core components you can
  621. 25:44actually build pretty powerful
  622. 25:46kubernetes clusters
  623. 25:48before moving on i want to give a shout
  624. 25:50out to castin who made this video
  625. 25:52possible
  626. 25:54kessen's k10 is the data management
  627. 25:57platform for kubernetes
  628. 25:59k10 basically takes off most of the load
  629. 26:02of doing backup and restore in
  630. 26:04kubernetes from the cluster
  631. 26:06administrators it has a very simple ui
  632. 26:09so it's super easy to work with and has
  633. 26:12an intelligent logic which does all the
  634. 26:14heavy lifting for you and with my link
  635. 26:17you can download k10 for free and get 10
  636. 26:20nodes free forever to do your kubernetes
  637. 26:23backups so make sure to check out the
  638. 26:25link in the video description and now
  639. 26:27let's continue
  640. 26:28so now that we have seen the basic
  641. 26:30concepts of kubernetes how do we
  642. 26:32actually create those components like
  643. 26:34pods and services to configure the
  644. 26:37kubernetes cluster
  645. 26:41all the configuration in kubernetes
  646. 26:43cluster actually goes through a master
  647. 26:46node with the process called api server
  648. 26:48which we mentioned briefly earlier so
  649. 26:51kubernetes clients which could be a ui a
  650. 26:54kubernetes dashboard for example or an
  651. 26:56api which could be a script or a curl
  652. 26:59command
  653. 27:00or a command line tool like cubectl they
  654. 27:03all talk to the api server and they send
  655. 27:05their configuration requests to the api
  656. 27:08server which is the main entry point or
  657. 27:10the only entry point into the cluster
  658. 27:12and these requests have to be either in
  659. 27:15yaml format or json format and this is
  660. 27:18how example configuration in yaml format
  661. 27:21actually looks like so with this we are
  662. 27:23sending a request to kubernetes to
  663. 27:26configure a component called deployment
  664. 27:29which is basically a template or a
  665. 27:31blueprint for creating pods and in this
  666. 27:33specific configuration example we tell
  667. 27:36kubernetes to create two replica pods
  668. 27:39for us called my app with each pod
  669. 27:43replica having a container based on my
  670. 27:46image running inside in addition to that
  671. 27:49we
  672. 27:50configure what the environment variables
  673. 27:52and the port configuration of this
  674. 27:54container inside of the pod should be
  675. 27:57and as you see
  676. 27:58the
  677. 27:59configuration requests in kubernetes are
  678. 28:02declarative form so we declare what is
  679. 28:04our desired outcome from kubernetes
  680. 28:07and kubernetes tries to meet those
  681. 28:10requirements meaning for example since
  682. 28:12we declare we want two replica parts of
  683. 28:15my app deployment to be running in the
  684. 28:18cluster and one of those parts dies the
  685. 28:21controller manager will see that the
  686. 28:23ease and shoot states now are different
  687. 28:26the actual state is one part our desired
  688. 28:29state is 2 so it goes to work to make
  689. 28:32sure that this desired state is
  690. 28:35recovered automatically restarting the
  691. 28:38second replica of that pod
  692. 28:42so here i have examples of a deployment
  693. 28:45and service configuration files side by
  694. 28:48side so the first thing is that every
  695. 28:51configuration file in kubernetes has
  696. 28:54three parts the first part is where the
  697. 28:57metadata of that component that you're
  698. 29:00creating resides and one of the metadata
  699. 29:03is obviously name of the component
  700. 29:05itself the second part in the
  701. 29:08configuration file is specification so
  702. 29:11each component's configuration file will
  703. 29:14have a specification where you basically
  704. 29:16put every kind of configuration that you
  705. 29:19want to apply for that
  706. 29:21component the first two lines here as
  707. 29:24you see is just
  708. 29:25declaring what you want to create here
  709. 29:28we are creating deployment and here
  710. 29:30we're creating a service
  711. 29:32and this is basically you have to look
  712. 29:34up for each component there's a
  713. 29:36different api version
  714. 29:37so now inside of the specification part
  715. 29:40obviously the attributes will be
  716. 29:44specific to the kind of a component that
  717. 29:47you're creating so deployment will have
  718. 29:50its own attributes
  719. 29:52that only apply for deployment and the
  720. 29:54service will have its own stuff but i
  721. 29:57said there are three parts of a
  722. 29:58configuration file and
  723. 30:01we just see metadata and the
  724. 30:03specification so where's the third part
  725. 30:06so the third part will be a status but
  726. 30:09it's going to be automatically generated
  727. 30:12and edit by kubernetes so the way it
  728. 30:15works is that kubernetes will always
  729. 30:17compare what is the desired state and
  730. 30:20what is the actual state or the status
  731. 30:22of that component and if the status and
  732. 30:24desired state do not match then
  733. 30:27kubernetes knows there's something to be
  734. 30:29fixed there so it's gonna try to fix it
  735. 30:32and this is the basis of the
  736. 30:35self-healing feature that kubernetes
  737. 30:37provides for example here you specify
  738. 30:40you want two replicas of nginx
  739. 30:43deployment so when you apply this when
  740. 30:46you actually create the deployment using
  741. 30:48this configuration file that's what
  742. 30:50apply means kubernetes will add here the
  743. 30:52status of your deployment and it will
  744. 30:56update that state continuously so for
  745. 30:59example if a status at some point will
  746. 31:01say just one replica is running then
  747. 31:04kubernetes will compare that status with
  748. 31:07the specification and we'll know there
  749. 31:09is a problem there another replica needs
  750. 31:12to be created sap now another
  751. 31:14interesting question here is
  752. 31:16where does kubernetes actually get the
  753. 31:18status data to automatically add here or
  754. 31:22update continuously that information
  755. 31:24comes from the icd remember the cluster
  756. 31:27brain one of the master processes that
  757. 31:30actually stores the cluster data so it
  758. 31:33cd holds at any time the current status
  759. 31:37of any kubernetes component and that's
  760. 31:40where the status information comes from
  761. 31:46so as you see the format of the
  762. 31:48configuration files is yemel
  763. 31:51that's why the extension here and
  764. 31:54generally it's pretty straightforward to
  765. 31:56understand it's a very simple format but
  766. 31:58yaml is very strict about the
  767. 32:00indentations so for example if you have
  768. 32:04something wrongly indented here your
  769. 32:06file will be invalid but other than that
  770. 32:09it's pretty simple another thing is
  771. 32:11where do you actually store those
  772. 32:13configuration files a usual practice is
  773. 32:16to store them with your code because
  774. 32:19since the deployment and service is
  775. 32:22going to be applied to your application
  776. 32:24it's a good practice to store these
  777. 32:26configuration files in your application
  778. 32:28code so usually it will be part of the
  779. 32:31whole infrastructure as a code concept
  780. 32:34or you can also have its own git
  781. 32:37repository just for the configuration
  782. 32:39files
  783. 32:41so in this video i'm going to show you
  784. 32:43what mini cube and cube ctl are and how
  785. 32:46to set them up
  786. 32:47so first of all let's see what is mini
  787. 32:49cube usually in kubernetes world when
  788. 32:52you are setting up a production cluster
  789. 32:55it will look something like this so you
  790. 32:57would have multiple masters at least two
  791. 32:59in a production setting and you would
  792. 33:01have multiple worker nodes
  793. 33:03and master nodes and the worker nodes
  794. 33:06have their own separate responsibility
  795. 33:09so as you see on the diagram you would
  796. 33:10have actual separate virtual or physical
  797. 33:13machines that each represent a note
  798. 33:17now if you want to test something on
  799. 33:19your local environment or if you want to
  800. 33:22try something out very quickly for
  801. 33:23example deploying new application or new
  802. 33:27components and you want to test it on
  803. 33:29your local machine obviously setting up
  804. 33:31a cluster like this will be pretty
  805. 33:33difficult or maybe even impossible if
  806. 33:35you don't have enough resources like
  807. 33:37memory and cpu etc and exactly for the
  808. 33:41use case
  809. 33:42there's this open source tool that is
  810. 33:44called a mini cube so what a mini cube
  811. 33:46is is basically one node cluster where
  812. 33:50the master processes and the worker
  813. 33:52processes both run on one node and this
  814. 33:56node will have a docker container
  815. 33:58runtime pre-installed so you will be
  816. 34:01able to run the containers or the pods
  817. 34:03with containers on this node
  818. 34:07so now that you have this virtual node
  819. 34:10on your local machine that represents
  820. 34:12mini cube you need some way to interact
  821. 34:15with that cluster so you need a way to
  822. 34:17create pods
  823. 34:18and other kubernetes components on the
  824. 34:20node and the way to do it is using
  825. 34:23cubectl which is a command line tool for
  826. 34:26kubernetes cluster so let's see how it
  827. 34:28actually works remember we said that
  828. 34:30minicube runs both master and work
  829. 34:32processes so one of the master processes
  830. 34:35called api server is actually the main
  831. 34:38entry point into the kubernetes cluster
  832. 34:40so if you want to do anything in the
  833. 34:42kubernetes if you want to configure
  834. 34:44anything create any component you first
  835. 34:46have to talk to the api server and the
  836. 34:48way to talk to the api server is through
  837. 34:50different clients so you can have a ui
  838. 34:52like a dashboard you can talk to it
  839. 34:54using kubernetes api
  840. 34:56or a command line tool which is cubectl
  841. 35:00and cubectl is actually the most
  842. 35:02powerful of all the three clients
  843. 35:04because with cube cdl you can basically
  844. 35:06do
  845. 35:07anything in the kubernetes that you want
  846. 35:09and throughout this video tutorials
  847. 35:11we're going to be using cube ctl mostly
  848. 35:14so once the cube ctl submits commands to
  849. 35:16the api server to create components
  850. 35:18delete components etc the work processes
  851. 35:22on minicube node will actually make it
  852. 35:25happen so they will be actually
  853. 35:27executing the commands to create the
  854. 35:29parts to destroy the parts to create
  855. 35:31services etc so this is the mini cube
  856. 35:34setup and this is how cubectl is used to
  857. 35:37interact with the cluster an important
  858. 35:39thing to note here is that kipctl isn't
  859. 35:42just for minikube cluster if you have a
  860. 35:44cloud cluster or a hybrid cluster
  861. 35:47whatever cube ctl is the tool to use to
  862. 35:51interact with any type of kubernetes
  863. 35:53cluster setup so that's important to
  864. 35:55note here so now that we know what mini
  865. 35:57cube and cube ctl are let's actually
  866. 35:59install them to see them in practice
  867. 36:04now let's see how to install and run
  868. 36:07mini cube there are many different ways
  869. 36:10depending on your operating system and
  870. 36:12its architecture so the best way is to
  871. 36:15reference the official documentation and
  872. 36:17here as you see minicube can run either
  873. 36:20as a container or a virtual machine and
  874. 36:24these are the resource requirements to
  875. 36:26run minicube on your machine so make
  876. 36:29sure you have enough resources for
  877. 36:31installation you just select the correct
  878. 36:34data for your machine in my case it's
  879. 36:36going to be mac os with a home homebrew
  880. 36:39installation
  881. 36:41and with one simple brew installed mini
  882. 36:43cube command i can basically install
  883. 36:46mini cube
  884. 36:48like this and as you see the latest mini
  885. 36:51cube version has been installed once
  886. 36:53minicube is installed we want to
  887. 36:55actually start or create a mini cube
  888. 36:58cluster
  889. 36:58which is also super easy as you see
  890. 37:01we simply execute a mini cube start
  891. 37:04command
  892. 37:05however as i mentioned
  893. 37:07minicube must start either as a
  894. 37:09container or a virtual machine so we
  895. 37:12need either a container or a virtual
  896. 37:14machine tool installed on our laptop to
  897. 37:17run mini cube and this is going to be
  898. 37:19the driver for mini cube and opening the
  899. 37:22drivers page
  900. 37:23you see the list of supported drivers
  901. 37:27for linux mac os and windows and you see
  902. 37:31that docker is actually the preferred
  903. 37:34driver for running mini cube on all
  904. 37:36operating systems now this may be a
  905. 37:38little bit confusing because as you know
  906. 37:41inside the kubernetes cluster we run
  907. 37:44docker containers and it's important to
  908. 37:46note here that mini cube insulation
  909. 37:49actually comes with docker already
  910. 37:51installed to run those containers but
  911. 37:54docker as a driver from minicube means
  912. 37:58that we are hosting minicube on our
  913. 38:01local machine as a docker container
  914. 38:03itself so we have two layers of docker
  915. 38:06mini cube running is a docker container
  916. 38:08and inside mini cube we have docker
  917. 38:12packaged in minikube to run our
  918. 38:14application containers and for hosting
  919. 38:17minicube on our machine we can use
  920. 38:19docker so if you have docker already
  921. 38:21installed on your machine you're all set
  922. 38:24up to start a mini cube cluster
  923. 38:26if not also not a problem you can easily
  924. 38:29install it from here
  925. 38:31so clicking on install docker link this
  926. 38:34will take me to docker hub where i have
  927. 38:37docker desktop installation for windows
  928. 38:40and mac
  929. 38:42so i'm simply going to click in
  930. 38:44in my case docker desktop for mac and
  931. 38:47i'm gonna download and install docker
  932. 38:50and once downloaded just install it
  933. 38:55drag and drop into the applications
  934. 38:57folder
  935. 38:59and now we can start the docker daemon
  936. 39:01from the applications
  937. 39:04and as you see docker is starting up so
  938. 39:07the download and installation may take
  939. 39:09some time but once docker is installed
  940. 39:12and running we can switch back to the
  941. 39:14terminal and start the mini cube cluster
  942. 39:17using mini cube
  943. 39:19start command passing docker as a driver
  944. 39:23option
  945. 39:23using the driver flag with docker value
  946. 39:27and let's execute
  947. 39:29and this may also take a while when
  948. 39:32you're running it first time because it
  949. 39:34needs to actually create the cluster and
  950. 39:36download all the necessary images and
  951. 39:38components so the next time you do mini
  952. 39:40cube start it should actually go faster
  953. 39:43and as you see this command created a
  954. 39:45local kubernetes cluster on our machine
  955. 39:49with the latest kubernetes version
  956. 39:511.22 and now we can check the status of
  957. 39:54the cluster using minicube
  958. 39:57status command
  959. 39:58and we see that all the components
  960. 40:00inside are running and everything is
  961. 40:02configured and now start to actually
  962. 40:06interact with our cluster using
  963. 40:09command line tool and cubectl actually
  964. 40:12gets installed as a dependency when we
  965. 40:15install minicube
  966. 40:18which you see right here installing
  967. 40:20dependencies for minicube and kubernetes
  968. 40:23cli is actually cube ctl
  969. 40:26and that means we already have that
  970. 40:28available we don't have to install it so
  971. 40:31now i can do cube ctl get node
  972. 40:35and this will display all the nodes in
  973. 40:37the cluster in our case we just have one
  974. 40:39node which is control plane and the
  975. 40:41worker node at the same time
  976. 40:43and we see information for each node
  977. 40:46like the status the kubernetes version
  978. 40:49that it's running as well as when it was
  979. 40:51added to the cluster so with this we now
  980. 40:54have an actual kubernetes cluster
  981. 40:56running locally on our machine and we
  982. 40:59can start deploying applications in it
  983. 41:01so from this point on we are going to be
  984. 41:03interacting with the mini cube cluster
  985. 41:05using cubectl command line tool so
  986. 41:08minicube is basically just for the
  987. 41:10startup and for deleting the cluster but
  988. 41:13everything else configuring we're going
  989. 41:15to be doing through cubectl now we have
  990. 41:18enough knowledge to deploy a very simple
  991. 41:20but realistic application setup in a
  992. 41:23kubernetes cluster we will deploy a
  993. 41:25mongodb database and a web application
  994. 41:29which will connect to the mongodb
  995. 41:32database using external configuration
  996. 41:35data from config map and the secret and
  997. 41:38finally we will make our web application
  998. 41:42accessible externally from the browser
  999. 41:45so let's get right in so i have two
  1000. 41:47resources here we're going to reference
  1001. 41:49the kubernetes documentation to create
  1002. 41:51our components which is a realistic way
  1003. 41:53of working with kubernetes and also a
  1004. 41:56docker hub where i have
  1005. 41:58the web application image that i created
  1006. 42:00which is publicly accessible so you can
  1007. 42:02also pull it directly from the docker
  1008. 42:05hub in your kubernetes cluster so first
  1009. 42:08let's go ahead and create
  1010. 42:10all the kubernetes configuration files
  1011. 42:13that we need for deploying our
  1012. 42:16application setup and for that i'm going
  1013. 42:18to go to visual studio code where i have
  1014. 42:21a kubernetes demo folder open and in
  1015. 42:24this folder we're going to create four
  1016. 42:26kubernetes configuration files that we
  1017. 42:28need we're going to create a config map
  1018. 42:31with mongodb
  1019. 42:32database endpoint we're going to create
  1020. 42:35a secret with username and password for
  1021. 42:38mongodb and then we're going to create a
  1022. 42:41configuration file for deploying a
  1023. 42:42mongodb application
  1024. 42:44and its service and then we're going to
  1025. 42:46create kubernetes configuration file for
  1026. 42:49deploying our simple demo app
  1027. 42:52application with its service
  1028. 42:57so the first file will be called
  1029. 43:00config.yml
  1030. 43:03and creating a config map in kubernetes
  1031. 43:05is super simple for the syntax we can
  1032. 43:08reference kubernetes documentation
  1033. 43:13so i'm going to copy the first part here
  1034. 43:16paste it in
  1035. 43:17and that's basically the main syntax
  1036. 43:19we're starting from
  1037. 43:21let's call our config map
  1038. 43:24config
  1039. 43:28so we have the metadata and then we have
  1040. 43:30the actual
  1041. 43:31contents of this config map within the
  1042. 43:34data attribute we have all the key value
  1043. 43:37pairs that we define as external
  1044. 43:40configuration within this config map in
  1045. 43:42our case we just have one which we're
  1046. 43:44going to call
  1047. 43:46url as a key and of course we need a
  1048. 43:49value for the mongodb url and the value
  1049. 43:53will be the service that we're going to
  1050. 43:56create for mongodb application and we're
  1051. 43:59going to call that service
  1052. 44:01service
  1053. 44:02and in a couple of minutes you're going
  1054. 44:04to see how to create this service
  1055. 44:07and that will be basically all the
  1056. 44:09configuration we need for creating
  1057. 44:11config map
  1058. 44:15so that one is done let's now go ahead
  1059. 44:17and create secret
  1060. 44:20dot
  1061. 44:21yaml which will hold the username and
  1062. 44:24password for mongodb application again
  1063. 44:28to reference
  1064. 44:29documentation
  1065. 44:33i'm going to take this one and let's
  1066. 44:35actually copy the whole thing
  1067. 44:37so we have the secret kind instead of
  1068. 44:40config map let's call this secret
  1069. 44:44we have type opaque which is the generic
  1070. 44:47type for defining secret data basically
  1071. 44:51and we have the same data attribute here
  1072. 44:54and let's actually create our own values
  1073. 44:56let's call this
  1074. 44:58[Music]
  1075. 44:59user
  1076. 45:00and
  1077. 45:03password
  1078. 45:06and as you already learned the values in
  1079. 45:09secret are base64 encoded so we can just
  1080. 45:12set the values plain text we have to
  1081. 45:15encode them first and encoding values is
  1082. 45:18super easy we're just gonna do echo
  1083. 45:21and let's call it user
  1084. 45:24and
  1085. 45:25base 64. encode it
  1086. 45:28and the same way let's do
  1087. 45:31password
  1088. 45:36and
  1089. 45:38paste those values
  1090. 45:44and this will be our secret
  1091. 45:46configuration and now when we create
  1092. 45:49deployments for our applications we can
  1093. 45:51reference
  1094. 45:52any of the values defined in the secret
  1095. 45:55or config map so let's see how that
  1096. 45:57works
  1097. 46:01again let's create a new file and let's
  1098. 46:03call this dot yaml this is going
  1099. 46:07to be a configuration file where
  1100. 46:09we're going to create deployment and
  1101. 46:12service for mongodb you can have
  1102. 46:15separate files for them but it's a very
  1103. 46:17common thing to put them together
  1104. 46:19because all the deployments need
  1105. 46:21services so you have them grouped in one
  1106. 46:24yaml file
  1107. 46:25and again
  1108. 46:26let's reference the documentation for
  1109. 46:31the deployment example syntax
  1110. 46:34and we can then adjust the values as we
  1111. 46:36need
  1112. 46:37and as you see deployment configuration
  1113. 46:39file looks a little bit more complex
  1114. 46:42than configmap or a secret so let's go
  1115. 46:45through the configuration and understand
  1116. 46:47all these attributes so we have the
  1117. 46:49metadata section
  1118. 46:51and the specification and these are
  1119. 46:53basically deployment specific
  1120. 46:56configuration that we have in the
  1121. 46:58specification section and let's start
  1122. 47:01with the main part of the deployment
  1123. 47:02which defines the blueprint for the pots
  1124. 47:06and that blueprint is defined as a
  1125. 47:08template so template
  1126. 47:11basically is a configuration of the part
  1127. 47:15within the configuration of deployment
  1128. 47:18and you see that template section has
  1129. 47:20its own metadata and own spec or
  1130. 47:24specification just like deployment has
  1131. 47:26its metadata and specification right so
  1132. 47:29this part actually configures the pod
  1133. 47:33within a deployment and in the
  1134. 47:35specification of the pod we have the
  1135. 47:37definition of containers so this is a
  1136. 47:40list of containers as you learned you
  1137. 47:42can have multiple containers in a pot
  1138. 47:45but mostly one main application per pot
  1139. 47:49and this is where we define which image
  1140. 47:52will be used to create this pod in our
  1141. 47:55case this is going to be a mongodb image
  1142. 47:58and if we
  1143. 48:00search for
  1144. 48:01in docker hub
  1145. 48:04that's basically the image name and you
  1146. 48:07can find all the text
  1147. 48:09in the text section and we're going to
  1148. 48:11use the tag 5.0
  1149. 48:14so one go
  1150. 48:175.0 that's where we define the image
  1151. 48:20of the container within the pot we can
  1152. 48:22name this
  1153. 48:23mongodb this is just the name of the
  1154. 48:26container and we also have the port
  1155. 48:28where the container will listen and
  1156. 48:30let's check our image and as you see
  1157. 48:33mongodb starts at this port so we can
  1158. 48:35just copy it and paste it in here so
  1159. 48:38this basically
  1160. 48:40just configures our deployment to create
  1161. 48:43pods with a mongodb image version
  1162. 48:465.0 so that's the core of a deployment
  1163. 48:50now let's see what is all this other
  1164. 48:51stuff here first of all we have this
  1165. 48:54labels attribute in the metadata section
  1166. 48:58and then we also have match labels
  1167. 49:00attribute so what is this about in
  1168. 49:03kubernetes you can give any component
  1169. 49:06a key value pair labels so you can label
  1170. 49:10anything from pod to deployment to
  1171. 49:12configmap etc and labels basically are
  1172. 49:16additional identifiers of the components
  1173. 49:18in addition to the name for example
  1174. 49:21so you can
  1175. 49:22identify and address specific components
  1176. 49:26using their labels
  1177. 49:27now why do we need them first of all
  1178. 49:30when we have multiple replicas of the
  1179. 49:32same part
  1180. 49:34each part will get a unique
  1181. 49:36name however
  1182. 49:38they can share the same label so we can
  1183. 49:41identify all the part replicas of the
  1184. 49:43same application using a specific label
  1185. 49:47that all of them share and that's why in
  1186. 49:49the metadata of the pod we always have
  1187. 49:52this label so for pods labels is a
  1188. 49:55required field for other components like
  1189. 49:58deployment configmap etc labels is
  1190. 50:01optional but it is a good practice to
  1191. 50:04set them
  1192. 50:05now
  1193. 50:06when we create pod replicas how does
  1194. 50:08deployment know which parts actually
  1195. 50:11belong to it or how does kubernetes know
  1196. 50:13which pods belong to which deployments
  1197. 50:16and that is defined using
  1198. 50:19this part right here so
  1199. 50:21selector match labels is in the
  1200. 50:23specification of the deployment as you
  1201. 50:25see and this defines
  1202. 50:27that all the parts that match
  1203. 50:30this label belong to
  1204. 50:33this deployment so that's why we have
  1205. 50:36match labels here
  1206. 50:38so this
  1207. 50:39selector will match the pods created
  1208. 50:42with this configuration
  1209. 50:44because they have label app engine x now
  1210. 50:47are these labels
  1211. 50:48given or can you select any key value
  1212. 50:51pairs well these are totally up to you
  1213. 50:53you can call it whatever you want
  1214. 50:55you can call it my key
  1215. 50:58my value it doesn't really matter
  1216. 51:00however the standard and a common
  1217. 51:02practice in kubernetes is to use app
  1218. 51:06key in the labels when labeling your
  1219. 51:08applications and the value will
  1220. 51:10obviously be whatever application you
  1221. 51:12have so let's actually change and set
  1222. 51:15the values
  1223. 51:17to instead of nginx
  1224. 51:19because that's our application and of
  1225. 51:21course we want to match label app
  1226. 51:25and let's also change
  1227. 51:27this one right here
  1228. 51:29to deployment and finally last
  1229. 51:32attribute we have here is replicas which
  1230. 51:35is super simple and straightforward this
  1231. 51:38just defines how many pods you want to
  1232. 51:40create using this blueprint in our case
  1233. 51:43let's do just one replica because it's a
  1234. 51:46database and as you learned if you want
  1235. 51:48to scale databases in kubernetes you
  1236. 51:50should use stateful set and not a
  1237. 51:52deployment to keep everything simple
  1238. 51:54we're going to stick to one replica and
  1239. 51:57that basically configures our mongodb
  1240. 52:00deployment
  1241. 52:01and the pod blueprint now let's add a
  1242. 52:04service configuration because every
  1243. 52:06application needs a service in
  1244. 52:07kubernetes and
  1245. 52:10that's going to be a separate
  1246. 52:12yaml
  1247. 52:13unit or yaml section and we're going to
  1248. 52:15separate it using
  1249. 52:17three dashes which is basic yaml syntax
  1250. 52:20nothing specific to kubernetes and again
  1251. 52:23let's
  1252. 52:25grab a service example
  1253. 52:34and adjust it as we need now service
  1254. 52:36configuration is much easier than the
  1255. 52:38deployment as you see first let's change
  1256. 52:41the name let's call it service and
  1257. 52:44remember this is the end point
  1258. 52:47which
  1259. 52:48we will use to access and that's
  1260. 52:50what we defined right here so this is
  1261. 52:53the name of the service
  1262. 52:57and in the specification we have
  1263. 53:00service specific attributes first of all
  1264. 53:03we have the selector attribute which you
  1265. 53:06already know from here now why do we
  1266. 53:08need a selector in service because as
  1267. 53:11you know service needs to forward the
  1268. 53:14request that it gets to
  1269. 53:17its endpoint pods how does service know
  1270. 53:20which pods belong to it and which ones
  1271. 53:23it should forward the requests to well
  1272. 53:25using the same label selector as we saw
  1273. 53:29on deployment so this should match
  1274. 53:32the label
  1275. 53:33of the pods that will belong to the
  1276. 53:36service which is
  1277. 53:37and that's how service and pods
  1278. 53:41will find each other and then we have
  1279. 53:43the ports configuration which is also
  1280. 53:46super simple service is accessible
  1281. 53:48within the cluster using its own ip
  1282. 53:52address and the port and we define its
  1283. 53:55port right here
  1284. 53:56and this can be any port that we decide
  1285. 53:58on this could be 80 8080 doesn't really
  1286. 54:01matter
  1287. 54:02and we have the target port which is the
  1288. 54:06port of the pods that belong to the
  1289. 54:09service and logically enough the target
  1290. 54:12port should always be the same as the
  1291. 54:15container port because that's where the
  1292. 54:17application in the pod is accessible
  1293. 54:20that's where the service should forward
  1294. 54:23the request to so again very important
  1295. 54:26port attribute sets the port of the
  1296. 54:29service and target port tells service
  1297. 54:33to which port it should forward the
  1298. 54:36request to the pods and this should be
  1299. 54:39same as the container port port and
  1300. 54:41target port values can be different or
  1301. 54:44again it's a common standard
  1302. 54:46to
  1303. 54:47select the same port for the service as
  1304. 54:49well just to keep things simple so let's
  1305. 54:52save this and that's our configuration
  1306. 54:55for mongodb deployment and service
  1307. 55:00now i'm going to copy this whole thing
  1308. 55:03and
  1309. 55:04create
  1310. 55:05a deployment in service for web
  1311. 55:08application for our kubernetes demo
  1312. 55:11application and let's call this webapp
  1313. 55:14dot yaml
  1314. 55:16paste
  1315. 55:17everything in
  1316. 55:19and we can just adjust all these
  1317. 55:22values
  1318. 55:30in the service
  1319. 55:31and deployment
  1320. 55:33all the labels and label selectors of
  1321. 55:35course
  1322. 55:36and right here we of course need the
  1323. 55:39correct image of our web application
  1324. 55:42going back to our docker hub
  1325. 55:44this is
  1326. 55:45the name of my image and again this is
  1327. 55:48publicly accessible so you can use it as
  1328. 55:51well
  1329. 55:52and
  1330. 55:53the tag is v
  1331. 55:551.0
  1332. 55:57and there you go so this is a very
  1333. 55:59simple node.js application which starts
  1334. 56:02on port 3000 so that's why we need to
  1335. 56:05define container port on 3000 and
  1336. 56:08container port is same as target port
  1337. 56:11on the service and we can set the
  1338. 56:13service port to the same value and this
  1339. 56:16will configure
  1340. 56:17deployment
  1341. 56:19and
  1342. 56:20service for our web application
  1343. 56:23so this is
  1344. 56:24the basic configuration for deployment
  1345. 56:27and service for any application in
  1346. 56:30kubernetes cluster
  1347. 56:34but we have one more thing to configure
  1348. 56:37in our deployment components for both
  1349. 56:40and web app which is we need to
  1350. 56:43pass the data defined in the config and
  1351. 56:47secret components
  1352. 56:48first of all when starting a mongodb
  1353. 56:51application we need to set user name and
  1354. 56:54password so when mongodb application
  1355. 56:56starts it will automatically generate
  1356. 56:58username and password for mongodb and we
  1357. 57:00can then use that to access it in our
  1358. 57:03cluster
  1359. 57:04now how do we know
  1360. 57:06how username and password can be
  1361. 57:08configured in a mongodb on startup well
  1362. 57:11we go to the image documentation and
  1363. 57:14right here we see the environment
  1364. 57:16variable names
  1365. 57:18for username and password and these are
  1366. 57:21actually required fields in most of the
  1367. 57:23databases we have to set them otherwise
  1368. 57:26we won't be able to access them so the
  1369. 57:28next question is how do we configure
  1370. 57:30environment variables in a container
  1371. 57:33configuration so how do we pass
  1372. 57:35environment variables to this
  1373. 57:37application running inside the container
  1374. 57:40well that's also very easy we have n
  1375. 57:44attribute for that
  1376. 57:46which is a list of environment variables
  1377. 57:49with names
  1378. 57:50and
  1379. 57:52values that's it
  1380. 57:54so
  1381. 57:55very simple so name is the environment
  1382. 57:58variable name and value is
  1383. 58:00the environment variable value so let's
  1384. 58:03copy the name
  1385. 58:05so this is the environment variable name
  1386. 58:07that mongodb expects and we have to set
  1387. 58:10a value whatever we want the username to
  1388. 58:13be now we can directly set
  1389. 58:16the username right here like this
  1390. 58:19or in our case we're going to reference
  1391. 58:21them from secret and config
  1392. 58:24components
  1393. 58:26how do we do that also pretty simple we
  1394. 58:28do value from
  1395. 58:31and we want to reference it
  1396. 58:32from the secret so we do secret
  1397. 58:36key
  1398. 58:38ref
  1399. 58:40and under that we have the name of the
  1400. 58:42secret
  1401. 58:43which we called secret
  1402. 58:46and the key
  1403. 58:50which is user
  1404. 58:53so kubernetes will basically find a
  1405. 58:55secret with this name
  1406. 58:57and get the value set for this key and
  1407. 58:59substitute it as a value for this
  1408. 59:02environment variable and the same way
  1409. 59:04we're gonna
  1410. 59:06configure
  1411. 59:08a password
  1412. 59:09so let's take the password that's the
  1413. 59:12name of the environment variable
  1414. 59:14same secrets
  1415. 59:16component
  1416. 59:19this time with a different key
  1417. 59:22and that's it
  1418. 59:23so our mongodb configuration file is
  1419. 59:26complete
  1420. 59:28and when it starts a user with these
  1421. 59:30credentials will be created
  1422. 59:35when our web application starts it will
  1423. 59:38need to connect to the database so we
  1424. 59:40need to give this web application
  1425. 59:43information about the database endpoint
  1426. 59:46where can it access the database
  1427. 59:49and which username and password to use
  1428. 59:52to authenticate with the database and i
  1429. 59:54have already configured this application
  1430. 59:57inside to expect all these values as
  1431. 1:00:00environment variables with specific
  1432. 1:00:03names so we're going to pass
  1433. 1:00:05these three pieces of data as
  1434. 1:00:07environment variables
  1435. 1:00:09to the web app application so let's do
  1436. 1:00:13that
  1437. 1:00:16again
  1438. 1:00:17the name of the environment variable the
  1439. 1:00:18first one i actually called username
  1440. 1:00:22and we can actually copy
  1441. 1:00:25the same configuration and paste it here
  1442. 1:00:28and you already see an advantage of
  1443. 1:00:30using
  1444. 1:00:31configuration from secret or config
  1445. 1:00:34because if you need the same information
  1446. 1:00:37in 10 different applications you create
  1447. 1:00:39it once and reference it 10 times
  1448. 1:00:43the second
  1449. 1:00:44environment variable is for password
  1450. 1:00:49and i called this one user pwd
  1451. 1:00:53and finally our application needs
  1452. 1:00:56the database endpoint which
  1453. 1:01:01will be db url
  1454. 1:01:04and this value is not in the secret
  1455. 1:01:07but in configmap and how do we access
  1456. 1:01:10value from config map very similar as
  1457. 1:01:14the secret so we have the same value
  1458. 1:01:16from
  1459. 1:01:19and instead of secret key ref we have
  1460. 1:01:21config
  1461. 1:01:23map
  1462. 1:01:24kirev
  1463. 1:01:25or key reference
  1464. 1:01:27and then we have
  1465. 1:01:28name which we called config
  1466. 1:01:33and key
  1467. 1:01:36which is the name of the key
  1468. 1:01:39and that's it so we don't have any of
  1469. 1:01:41the configuration values hard coded in
  1470. 1:01:44our
  1471. 1:01:45kubernetes configuration files we only
  1472. 1:01:48have references which makes our
  1473. 1:01:50configuration way cleaner so if
  1474. 1:01:52something changes or the values change
  1475. 1:01:54here we don't have to adjust anything in
  1476. 1:01:57our deployments
  1477. 1:02:01so connectivity with the database is
  1478. 1:02:03configured and there is one last thing
  1479. 1:02:06missing in our web application
  1480. 1:02:08configuration before we deploy all this
  1481. 1:02:10which is making it accessible from the
  1482. 1:02:13browser we want to be able to type in
  1483. 1:02:16some url and access our web application
  1484. 1:02:19from the browser right and as you
  1485. 1:02:22learned we have external services for
  1486. 1:02:24that so we will need to adjust
  1487. 1:02:27the service configuration a little bit
  1488. 1:02:29right now
  1489. 1:02:30these service configurations both of
  1490. 1:02:32them are internal services
  1491. 1:02:35so to make it external
  1492. 1:02:37all we need to do is
  1493. 1:02:40set a type which is by default cluster
  1494. 1:02:43ip
  1495. 1:02:45so that's the default type if we don't
  1496. 1:02:47specify the type but we're going to set
  1497. 1:02:49it to
  1498. 1:02:50node port
  1499. 1:02:52so node port is an external service type
  1500. 1:02:55and it requires a third port which is
  1501. 1:02:58called
  1502. 1:02:59a node port
  1503. 1:03:03so what is a node port port
  1504. 1:03:05this is a port which will open on the
  1505. 1:03:08kubernetes nodes on which the
  1506. 1:03:11application will be accessible so on the
  1507. 1:03:14node ip address in node port combination
  1508. 1:03:17we will be able to access
  1509. 1:03:20this service which will then access
  1510. 1:03:24the pods behind it and node port range
  1511. 1:03:27is actually defined in kubernetes so we
  1512. 1:03:29can't just type anything we want here
  1513. 1:03:34like this it has to be within the range
  1514. 1:03:36of thirty thousand and thirty two
  1515. 1:03:38thousand seven hundred sixty seven so
  1516. 1:03:42anything within this range is fine as a
  1517. 1:03:44value so we can do 30 000 or 30
  1518. 1:03:48100 doesn't really matter
  1519. 1:03:51so let's set this as a value and this
  1520. 1:03:54completes the web app configuration file
  1521. 1:03:59now we have a very simple but also
  1522. 1:04:02pretty realistic
  1523. 1:04:04configuration
  1524. 1:04:05for deploying an application with its
  1525. 1:04:07database
  1526. 1:04:09with external configuration in the
  1527. 1:04:11cluster so as a final step we're just
  1528. 1:04:14gonna create all these components one by
  1529. 1:04:16one in kubernetes so i'm gonna open a
  1530. 1:04:19terminal and we already have a mini cube
  1531. 1:04:22cluster running
  1532. 1:04:27but there are no components inside so
  1533. 1:04:30first we need to create the external
  1534. 1:04:32configurations because
  1535. 1:04:34they need to be there when we create
  1536. 1:04:36mongodb and web application deployments
  1537. 1:04:40because they reference those
  1538. 1:04:41configurations so let's create
  1539. 1:04:44config and secret first to do that
  1540. 1:04:47we have cube ctl apply command with
  1541. 1:04:50minus f which stands for file which
  1542. 1:04:53takes a kubernetes configuration file as
  1543. 1:04:55an input
  1544. 1:04:57like this
  1545. 1:04:58and creates whatever is defined inside
  1546. 1:05:01and as you see config was created
  1547. 1:05:04now let's create longer secret
  1548. 1:05:08next we're gonna create a database
  1549. 1:05:10because our web application depends on
  1550. 1:05:12it
  1551. 1:05:14so it should start first
  1552. 1:05:16and again let's do cube ctl apply
  1553. 1:05:19with mongo.yaml as an input and as you
  1554. 1:05:23see deployment
  1555. 1:05:24and service were created and finally
  1556. 1:05:28let's deploy our web application and
  1557. 1:05:30there you go so everything seems fine
  1558. 1:05:33but of course we want to check all the
  1559. 1:05:35parts and all the components
  1560. 1:05:37that were created in the cluster
  1561. 1:05:42so for that i'm going to actually switch
  1562. 1:05:44to command line so that we can see it
  1563. 1:05:46better
  1564. 1:05:47and first we're going to do cube ctl get
  1565. 1:05:51all
  1566. 1:05:52which gives you all the components
  1567. 1:05:54created in the cluster which includes
  1568. 1:05:56deployments
  1569. 1:05:58the pods
  1570. 1:05:59behind the deployment and all the
  1571. 1:06:01services and as you see we have
  1572. 1:06:04deployment and web app deployment parts
  1573. 1:06:07each one with one replica running and we
  1574. 1:06:10have the services for
  1575. 1:06:13mongodb and web app
  1576. 1:06:15and web app service is of node port type
  1577. 1:06:18which means we can access it externally
  1578. 1:06:20however we don't see configmap and
  1579. 1:06:22secret here we can get them using
  1580. 1:06:25kubectl get config map
  1581. 1:06:28and cubectl get
  1582. 1:06:30secret commands so as you see displaying
  1583. 1:06:33any component is pretty easy using cube
  1584. 1:06:35ctl you just do kubectl get and the name
  1585. 1:06:38of the component like pod and you get
  1586. 1:06:42a list of those components
  1587. 1:06:44with some additional data
  1588. 1:06:46and cubesatl is actually a very powerful
  1589. 1:06:49tool and it has a bunch of sub-commands
  1590. 1:06:52so as a natural documentation for
  1591. 1:06:54cubectl to basically have an overview
  1592. 1:06:57and see what you can do with it you can
  1593. 1:07:00always use cubectl
  1594. 1:07:03help as a documentation which lists all
  1595. 1:07:06the sub-commands you can use with it one
  1596. 1:07:09of them which we already used
  1597. 1:07:11get and for each sub-command
  1598. 1:07:14like cube ctl get you can also get some
  1599. 1:07:17help
  1600. 1:07:18and basically see all the examples
  1601. 1:07:20plus all the available options so you
  1602. 1:07:23can navigate all the options you have
  1603. 1:07:25here so cube ctl get is obviously the
  1604. 1:07:28most common command you're going to use
  1605. 1:07:30to list all the components
  1606. 1:07:33if you want to see more details about a
  1607. 1:07:35certain component
  1608. 1:07:37you can use cube ctl describe command
  1609. 1:07:40for it a name of the component like a
  1610. 1:07:42service for example
  1611. 1:07:44and the actual instance of that
  1612. 1:07:47component like web app service and this
  1613. 1:07:50will give you more detailed output about
  1614. 1:07:52that specific component same way you can
  1615. 1:07:55also do cube ctl describe pod and then
  1616. 1:07:59name of the pod
  1617. 1:08:02like this one
  1618. 1:08:05and this will give you details about
  1619. 1:08:08your pot including the status of how the
  1620. 1:08:11pod was scheduled
  1621. 1:08:13the container configuration
  1622. 1:08:16labels etc
  1623. 1:08:18and finally
  1624. 1:08:22of course when you have applications
  1625. 1:08:24running in your cluster you want to
  1626. 1:08:26check the logs to troubleshoot debug or
  1627. 1:08:29just make sure that everything is fine
  1628. 1:08:31within the pod and you can do that very
  1629. 1:08:34easily using kubectl locks command
  1630. 1:08:37and just specifying name of the pot like
  1631. 1:08:42this
  1632. 1:08:42this gives you
  1633. 1:08:44logs of the container inside
  1634. 1:08:46and you can even stream the logs using
  1635. 1:08:49minus f option
  1636. 1:08:54so the final step we want to validate
  1637. 1:08:56that our application is also accessible
  1638. 1:08:58from the browser and for that we
  1639. 1:09:01actually configured the service and we
  1640. 1:09:03can actually get the service using
  1641. 1:09:05service or svc
  1642. 1:09:08comment so how do we access this service
  1643. 1:09:11from the browser because this is the
  1644. 1:09:13port we're going to use to access it but
  1645. 1:09:15which ip address is it accessible at
  1646. 1:09:18well the node port service is always
  1647. 1:09:20accessible at the ip address of the
  1648. 1:09:23cluster node so all the work nodes that
  1649. 1:09:26the cluster has in our case we just have
  1650. 1:09:28one which is the mini cube so we need
  1651. 1:09:30the ip address of the mini cube to get
  1652. 1:09:33that
  1653. 1:09:34we just do mini cube ip
  1654. 1:09:37or using kubernetes we can also get
  1655. 1:09:40get node which gives you mini cube
  1656. 1:09:44and
  1657. 1:09:45a white output
  1658. 1:09:47or a longer output than what you see
  1659. 1:09:49here
  1660. 1:09:50which will give you
  1661. 1:09:51the ip address
  1662. 1:09:54of the node which is the same as this
  1663. 1:09:57one right here and by the way you can
  1664. 1:09:59use the all white option for any other
  1665. 1:10:02get command for services pods etc to get
  1666. 1:10:06some additional information like this
  1667. 1:10:09so let's grab the mini cube ip address
  1668. 1:10:12and access the application at this port
  1669. 1:10:18which is 30
  1670. 1:10:20100
  1671. 1:10:22and there you go this is our web
  1672. 1:10:24application which is connected to
  1673. 1:10:27mongodb and we can also validate that by
  1674. 1:10:30editing something
  1675. 1:10:36and saving because this request goes to
  1676. 1:10:39database
  1677. 1:10:40and if we refresh
  1678. 1:10:42the changes should still be there
  1679. 1:10:45awesome so we deployed an application
  1680. 1:10:47with its database in kubernetes which is
  1681. 1:10:50a blueprint configuration for most
  1682. 1:10:53common application
  1683. 1:10:54setups you're gonna have plus you also
  1684. 1:10:56learn a couple of cubesitl commands as
  1685. 1:10:59well as how to reference the kubernetes
  1686. 1:11:01official documentation to help you
  1687. 1:11:04configure and create all the components
  1688. 1:11:07i hope i helped you learn a lot about
  1689. 1:11:09kubernetes with this crash course and
  1690. 1:11:11you feel much more confident with
  1691. 1:11:13kubernetes now if you're serious about
  1692. 1:11:16learning kubernetes in depth i actually
  1693. 1:11:18have two more resources for you
  1694. 1:11:20as i mentioned at the beginning if you
  1695. 1:11:22want to really become an expert in
  1696. 1:11:24kubernetes and learn how to build and
  1697. 1:11:27administer a cluster from scratch then
  1698. 1:11:30my complete kubernetes administrator
  1699. 1:11:32course will be a perfect resource for
  1700. 1:11:34you but if your goal is rather to become
  1701. 1:11:37a devops engineer then our complete
  1702. 1:11:39devops educational program will be the
  1703. 1:11:42best fit for you where during a
  1704. 1:11:44six-month program you learn all the
  1705. 1:11:47necessary concepts and technologies
  1706. 1:11:49including kubernetes which you need to
  1707. 1:11:52get started in devops or cloud
  1708. 1:11:54engineering
  1709. 1:11:55if you're interested you can find the
  1710. 1:11:57links in the video description below and
  1711. 1:11:59with that
  1712. 1:12:00thank you for watching and see you in
  1713. 1:12:02the next video

About this transcript

This page contains the full transcript of Kubernetes Crash Course for Absolute Beginners [NEW] by TechWorld with Nana, generated from the public captions YouTube serves with the video. The transcript has 10,204 words across 1,713 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.