‫I'll be honest.
‫Back when I first saw Kubernetes YAML, I
‫was really intimidated.
‫It seemed way more complex than Compose format.
‫That's for good reason.
‫It adds tons of flexibility, tons
‫more things you can do with it. But, that comes at a price.
‫That is getting over the hump of learning the basics and
‫how to make these files. When you first started looking at
‫these files, there's so much to it that I wasn't even sure
‫what was going on when I first held these files.
‫Totally understand
‫if you are feeling a little bit confused about this as we
‫go through it, just try to rewatch these videos because I'm
‫going to try to break this down in a way that I think is
‫best for learning Kubernetes YAML.
‫First up is we could write this technically
‫in JSON, but YAML tends
‫to be easier for humans to manipulate and read, and JSON's
‫better for computers.
‫What's happening in the background is the standard for
‫us humans is to write the YAML and then it's going to
‫convert that into JSON. You technically could write the
‫JSON, but the standard with Kubernetes for
‫humans to write is YAML.
‫Like I said before, you can mix or match these
‫files. You can have many different resources in
‫a single file and then do the opposite of that where
‫you have a single file per resource.
‫Doesn't really matter. It's up to you.
‫The commands work the same way.
‫We're calling these manifests.
‫The full description of a resource is
‫a manifest, and that manifest has requirements.
‫You'll see those requirements as for root keys
‫inside the YAML file.
‫Root meaning they're at the very beginning of the line.
‫That starts with API
‫version. There's kind.
‫There's metadata. And there's spec.
‫So, you have to see those in every file for these
‫resources to work. And Let's just look at some quick
‫examples from the command line.
‫If you're in your Docker Mastery repo, you will see a
‫k8s-yaml directory where I've put
‫some of these examples in here.
‫If you don't see that directory, then you
‫may need to do a git-pull to get the latest updates to
‫the repo. If you've made some changes in the repo from
‫taking this course, that's fine.
‫You can either use a git-stash to stash those changes away
‫temporarily and then do the git-pull.
‫Or, you can just copy it down into
‫a different directory. Just clone it in a different
‫location for this part of the course, because this
‫Kubernetes stuff is newer than the original stuff.
‫So, some of you may be coming back at this later
‫and don't have the latest updates.
‫The first example here is just a simple pod.
‫This is probably the simplest YAML we can create.
‫Like I said earlier in this course, you won't be making
‫that many pods because that's just creating like
‫a docker run.
‫That's not really something you're going to want to do.
‫It doesn't have rolling updates. It's not a deployment,
‫right. If you ever need to troubleshoot, or you just need
‫to run something simple locally, you could do this.
‫You'll notice it has the same four requirements.
‫The API version, the kind, the
‫metadata, and the spec.
‫We'll talk about what those are in the next lecture.
‫For now, I
‫just want you to see how this kind is pod. Then metadata
‫has the name attribute.
‫That key is the required key of all
‫YAML objects.
‫They all have to have that name, just like docker run has
‫to have a name. All Docker objects have to have a name.
‫Same with Kubernetes. The spec here is the meat.
‫We'll get to that in a moment. Let's take another look at a
‫deployment.
‫Here is a single deployment with two
‫replicas of that same container. It's probably twice the
‫size but for good reason.
‫Because if you think about it, you're creating that
‫deployment resource, and then that is creating the
‫ReplicaSet. Then that's creating the pods.
‫The spec area gets a
‫little bit more complex because it's doing more things that
‫we have to define. You'll notice also that our API version
‫is slightly different because
‫that's related to the kind, and the kind in this case is a
‫deployment. It's kind of such that means resource.
‫And the API version is the version
‫of the API for that kind. The rest here makes hopefully
‫a little sense to you.
‫It looks a little bit similar to Compose files but
‫obviously the format is different.
‫So, I understand it can be confusing, especially if you're
‫working back and forth between Compose and Kubernetes.
‫In this example, I have combined the
‫service and the deployment, for
‫that same type of deployment, into a single file.
‫This is how you would have multiple manifests in a single
‫file as you use the
‫three dashes to break those two apart. That is sort of a
‫YAML thing that will tell Kubernetes hey, this
‫object is unique. Then the next part is
‫a new object. You can have as many as you want in here
‫until it gets so unruly that you just have to break it out.
‫You'll see with this first part, the API version
‫is V1 of the service resource kind.
‫The word kind here probably could just be resource,
‫but they've called it kind.
‫Metadata here again. Got to have a name.
‫The spec and that's going to be totally different
‫based on which resource you're creating.
‫Then a similar deployment to what we had earlier, which
‫this case I have three replicas and it's
‫got a slightly different name, but other than that, it's
‫the same Nginx.
‫Just by looking at that, you're thinking, wow. I must need
‫templates that I'm going to store so I know how to start
‫because this seems quite complex.
‫There is no single docs page that spells all this
‫out for all the different dozens and dozens of resource
‫types, and how each one needs to be set up.
‫That's unfortunately something that we got with Compose
‫where it was a nice single, although long.
‫web page on the Docker docs for the entire Compose
‫format. In this case, we don't get that with Kubernetes
‫simply because there's too much complexity, and it's not
‫all in one place.
‫It's not even one app. You can actually add more resource
‫types by adding more things called CRDs
‫that we'll talk about later.
‫We can get into that. That basically means you can extend
‫Kubernetes with more resource types.
‫More third party stuff, which would even add more options
‫to this YAML. That's unique to Kubernetes.
‫Swarm and Docker doesn't allow for that.
‫Their format is set where this one's
‫quite extensible, depending on what's installed in your
‫cluster.