‫You've heard me say before in this part of
‫the course about Kubernetes that it's rather unopinionated.
‫Which means it gives us a set of tools and commands,
‫but it doesn't really prescribe one way to do things.
‫I guess the more ways you could do something, the more
‫you might say it's unopinionated because you can just
‫choose whichever path you'd like.
‫We've talked about, in the previous section, about
‫three major ways to do
‫Kubernetes or to manage your Kubernetes workloads,
‫right. The third one, the declarative, the fully
‫declarative way, is the one that I want this
‫whole section to be about.
‫Which means we're going to be mostly focusing on YAML
‫and how that works in Kubernetes.
‫The reason I want this whole section to be about
‫the declarative way is because it's more of
‫the DevOps style.
‫It's more conducive to the infrastructure as
‫code, and the new term on the block, git-ops, which
‫is all about storing your YAML and configurations
‫in git repositories and using git-commits to change
‫your infrastructure. I don't get too much into git-ops
‫here but really it's just about applying the automation
‫style of DevOps to your configurations.
‫What better way to do that in Kubernetes by using
‫YAML. The nice thing is there's very few commands you
‫have got to learn here. Really, all the focus is going to
‫be learning the different YAML formats.
‫Here, we're using the kubectl apply command with
‫a -f to tell it here's the file I want to give
‫you, and that's the command.
‫That's the command you use to create something.
‫That's the command you use to update something, or to edit
‫a configuration, or to change the image, or whatever you
‫want to do. That's the same command.
‫In that way, it's very much like stack deploy in Swarm
‫where you're just constantly giving it the same command
‫with updated YAML.
‫For this section, we're going to skip that middle
‫type of deployment which has the kubectl create,
‫and the edit, and the replace, and those commands
‫because they're not really a good way to
‫manage production infrastructure anymore.
‫They don't have a good solid DevOps structure to
‫them, and this course is all about DevOp style containers.
‫That's why we want to strive to.
‫So, do realize, as a disclaimer in this slide, that surely
‫you can use those commands if you want, but that's not
‫really the primary way I think you should be using
‫Kubernetes.
‫Just because this is the way I recommend it doesn't mean
‫that there isn't a lot of other possibilities out there.
‫Let me just throw you some quick examples of different ways
‫you can use the apply command.
‫You've seen that we can just tell it a YAML file
‫and it will apply something that's in there.
‫Maybe it's a deployment. Maybe it's just a pod.
‫Maybe it's a service, or a job, or
‫a cron job, or some other resource.
‫That -f will work on a whole directory so
‫you could have a bunch of different objects, or resources,
‫sort of spread out in different files, maybe one file
‫per resource. You could put all those in a directory.
‫You could just point it to that directory and it would
‫bring in all of those.
‫Of course, one YAML file can have multiple resources
‫in it, and I'll show you how that looks in a minute.
‫Another interesting option here is kubectl apply
‫with a URL.
‫We give it that -f, but the file is technically
‫a URL there. The way it knows that is through the HTTP
‫protocol. In my case, I've created a
‫domain that has a couple of examples.
‫There is a pod.yaml file there and so technically
‫if you ran that command, it would work.
‫It would deploy a single pod.
‫Just be careful of these files because you know it's one
‫thing to pull something down over the Internet and download
‫it. It's a whole other thing to one line run
‫a YAML file in Kubernetes. This is kind of the equivalent
‫of cURLing something into shell
‫and thus allowing it to run on your system without even
‫looking at the file, right. You really don't want to do
‫that. We don't want to be randomly running stuff and that's
‫kind of what Kubernetes does, right.
‫It runs stuff. You might want to cURL that if you have cURL
‫locally. If you're on a Windows PowerShell, then
‫you can use that command to open it up in your browser.
‫In the next lecture, let's start looking at YAML
‫formatting and how we're going to create these objects.