‫Similar to Docker Swarm in, it using
‫replicas as the term for the different containers
‫running and deciding how to scale up and
‫scale down using the number of replicas, and also the scale
‫command. We had that similar experience with
‫Kubernetes. Let's check out the kubectl command line
‫and how that's going to work.
‫First we're going to need to start a new Deployment.
‫So, let's go back and do a kubectl run
‫my-apache.
‫-- image httpd.
‫Unlike Nginx, we're going to run an Apache web server this
‫time, mostly just because it does give us some default
‫logging out-of-the-box so we can at least look at logs.
‫We can check that all those objects have been deployed with
‫another get all.
‫Once your desired and current are ready
‫to go on your ReplicaSet, as well as the pod,
‫then we know we're ready to do the next command.
‫This default run gives us a single
‫pod or replica.
‫Let's scale that up to 2.
‫Notice that I typed --replicas 2 here with the scale
‫command. I also put in
‫the type of object.
‫In other words, a Deployment, and then the name of that
‫Deployment. But there's a different format you noticed I've
‫used here. I've used a deploy rather than Deployment,
‫and I've used a forward slash rather than a space.
‫This goes into a little discussion around the flexibility
‫of the Kubernetes command line.
‫You'll notice that a lot of commands have short versions of
‫the command itself.
‫Different parts of the command can be abbreviated or
‫substituted in various ways like a slash versus a space.
‫Stuff like that. In this case, the scale
‫deploy / my-apache would be the same as
‫scale space deployment space my-apache.
‫Those would be the same equivalent.
‫You can basically in a lot of places where you would
‫see the Deployment option, you might be able to specify
‫deploy, deployment or deployments in the plural
‫state. You'll notice that this is sometimes
‫similar in other parts of the command line where plural or
‫singular work just as well.
‫Or, sometimes you can abbreviate part of the command.
‫Honestly, over the years, this has changed.
‫So, it's not so obvious which parts you can abbreviate or
‫put in a slash for a space.
‫But, I think once you get used to your own way of doing
‫things, that'll just work for you.
‫Now, if we do a quick kubectl get all again.
‫You'll notice that we have two pods now.
‫You'll see that the ReplicaSet at the bottom has a desired
‫state of two and two are running.
‫In the general concept here, this is exactly
‫what Swarm services do. They scale up and down replicas
‫based on your requirements.
‫In this case, we're just talking about pods
‫rather than tasks.
‫When we did the scale command, let me give you the basics
‫of what went on in the background.
‫Because we have extra levels of abstraction, we
‫need to understand how these levels react to each other.
‫When we typed the scale command, we were technically
‫updating the Deployment spec.
‫In Kubernetes, everything has a spec.
‫This spec for the Deployment changed the
‫ReplicaSet to a set of two replicas.
‫Then that ReplicaSet controller decided to change it
‫to two pods, and there would be one pod
‫for each replica.
‫Then the control plane makes a decision about which nodes,
‫in this case you've only got one node, but which nodes
‫would get assigned those pods.
‫Then if you had a multi-node setup, the kubelet
‫agent would then get assigned that pod and would
‫take that for execution to create the container on his
‫local Docker Engine.
‫While it seems like this is a lot of work going on the
‫background simply to start another container, it actually
‫happens really fast. In fact, it happens almost as fast
‫as Swarm. Generally, we're talking about
‫a second, two seconds, something like that when you're
‫talking about a single machine.
‫With Swarm, one of the advantages it has is that everything
‫is in the single binary.
‫So, it happens a lot quicker because it's really just
‫happening inside the same process including the launching
‫of the container itself.
‫With Kubernetes, we get these additional layers of
‫abstraction. That does introduce
‫a slight delay compared to maybe something you would do
‫Docker or Swarm.
‫But really, in most cases, it's negligible.
‫The tradeoff is we get much more flexibility and control
‫with these different layers of abstraction.
‫Oh! Don't clean up on this one.
‫We're going to use these Apache containers in
‫the next lecture when we do some inspecting of what's going
‫on in Kubernetes.