Learning Library

← Back to Library

Kubernetes Deployments: YAML, Rolling Updates, Debugging

Key Points

  • A pod is the smallest deployable unit in Kubernetes, and deployments manage pods using a YAML‑defined resource that specifies metadata, replica count, selectors, and pod templates.
  • Applying the deployment YAML with kubectl creates a Deployment object, which in turn generates a ReplicaSet to maintain the desired number of healthy pod copies.
  • Updating the deployment (e.g., changing replica count or container image) triggers Kubernetes to create a new ReplicaSet and perform a rolling update, ensuring zero downtime.
  • The same YAML can be used to delete the deployment, and common debugging tools like kubectl logs (and the --previous flag) help diagnose issues with pod containers.

Full Transcript

# Kubernetes Deployments: YAML, Rolling Updates, Debugging **Source:** [https://www.youtube.com/watch?v=Sulw5ndbE88](https://www.youtube.com/watch?v=Sulw5ndbE88) **Duration:** 00:03:54 ## Summary - A pod is the smallest deployable unit in Kubernetes, and deployments manage pods using a YAML‑defined resource that specifies metadata, replica count, selectors, and pod templates. - Applying the deployment YAML with kubectl creates a Deployment object, which in turn generates a ReplicaSet to maintain the desired number of healthy pod copies. - Updating the deployment (e.g., changing replica count or container image) triggers Kubernetes to create a new ReplicaSet and perform a rolling update, ensuring zero downtime. - The same YAML can be used to delete the deployment, and common debugging tools like kubectl logs (and the --previous flag) help diagnose issues with pod containers. ## Sections - [00:00:00](https://www.youtube.com/watch?v=Sulw5ndbE88&t=0s) **Understanding Kubernetes Deployment YAML** - Sai Vennam explains what pods are, walks through the structure of a Kubernetes Deployment manifest, and shows how to apply it with kubectl to create and manage replica sets. - [00:03:08](https://www.youtube.com/watch?v=Sulw5ndbE88&t=188s) **Debugging Kubernetes Deployments: Key Techniques** - The speaker outlines three primary methods—examining kubectl describe events, SSHing into pods to run diagnostics like ps aux, and inspecting pod file systems for logs—to troubleshoot deployment issues. ## Full Transcript
0:00Hi everyone, my name is Sai Vennam with the IBM Cloud team. 0:03Today, I want to talk about Kubernetes deployments. 0:06Deploying your applications to Kubernetes 0:08doesn't have to be difficult, 0:09but first, let's introduce what a pod is. 0:12A pod is the smallest logical unit 0:14that you can deploy into a Kubernetes cluster. 0:17However, to really harness the power of Kubernetes, 0:20you need to deploy those pods 0:22using the Kubernetes deployment resource. 0:25Kubernetes resources are managed using YAML. 0:28And here, we've got some YAML that defines 0:30how to deploy a sample application into Kubernetes. 0:34Taking a look at the YAML, 0:36starting at the top, we can see things like 0:38the kind of resource that it is 0:40- so we see that it's a deployment. 0:42In addition, we define some metadata 0:44and the name for this artifact. 0:46Going a little bit lower, 0:48we can see that we define the number of replicas 0:50that we want this Kubernetes deployment to manage 0:52as well as a match selector, 0:54which connects the pods to this deployment resource. 0:58Finally, at the bottom, we see the template. 1:01This is the most important part of a Kubernetes deployment 1:04and defines the pod that it will be deploying. 1:07In here, we can see things like the name of the image 1:10as well as things like the port that it will listen on 1:12and various configuration like environment variables. 1:15We'll take this YAML, 1:17and using kubectl, a CLI tool, 1:19we'll deploy that YAML into a Kubernetes cluster, 1:23at which point Kubernetes will create a deployment resource, 1:26which, in turn, creates a ReplicaSet. 1:29A ReplicaSet is simply there to manage identical copies of a pod, 1:33and to make sure they're running and healthy. 1:36Next, let's talk about updating that deployment. 1:39So, we'll go back to the YAML, 1:40and let's say that we want to up the number of replicas 1:42from two to three, and we will also change the image. 1:46Maybe we'll go from v1 of the application to v2. 1:50After we make the changes to the YAML file, 1:52we'll deploy it using kubectl, 1:54at which point Kubernetes recognizes the change to that deployment 1:58and creates a new ReplicaSet 2:00with that new image and the number of replicas. 2:03Kubernetes will then do a rolling update 2:05to make sure no downtime is happening 2:07while those pods are being updated 2:09to the new version of that image. 2:11Finally, what about deleting a deployment? 2:14With Kubernetes, 2:15using the same YAML that you used to actually create that resource, 2:18you can also delete those same resources. 2:21By using another kubectl command, 2:23you can pass that deployment YAML in 2:25and delete those resources from Kubernetes. 2:28Life is good when all of your applications are working, 2:31but let's talk about some key debugging techniques 2:34to figure out when things go wrong. 2:36The first one I like to use is kubectl logs. 2:39You can pass in the ID of a pod that was created by that deployment 2:43and find logs from the containers running within it. 2:46In fact, you can even use the "- - previous" flag 2:50to find logs from a previously crashed container, 2:53which is generally the case if you're trying to debug 2:55something wrong with your containers. 2:58Next, I like to use the "kubectl describe" command, 3:01along with the pod, to find any events that have been thrown 3:05to help you figure out what went wrong. 3:08The "kubectl describe" command has a lot of output, 3:10but at the bottom, by taking a look at these events, 3:13you can figure out exactly what happened. 3:15For example, maybe the wrong port was defined, 3:17or the wrong image has been pulled. 3:20If neither of those techniques work for you, 3:22you can also SSH directly into a pod in Kubernetes 3:26and run things like "ps aux" 3:27to make sure that the right processes are running. 3:30You can also check out the file system 3:32to identify any logs that might be coming out 3:34from the processes running within that pod. 3:37I think those are 3 major ways that can help you debug any issue 3:41with your Kubernetes deployments. 3:43Thanks for joining me today 3:44this was a quick overview of Kubernetes deployments. 3:47If you have any questions or feedback 3:49feel free to drop a comment below, 3:50and stay tuned to subscribe for more videos like this in the future.