0
0
Kubernetesdevops~30 mins

Pod lifecycle states in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Pod lifecycle states
📖 Scenario: You are managing a Kubernetes cluster and want to understand the lifecycle states of a Pod. Pods are the smallest deployable units in Kubernetes that run your containers. Knowing the Pod states helps you monitor and troubleshoot your applications effectively.
🎯 Goal: Learn how to create a Pod manifest, add a label selector, check the Pod's lifecycle state, and display the Pod status using kubectl.
📋 What You'll Learn
Create a Pod manifest YAML file named mypod.yaml with specific metadata and container details
Add a label app: demo to the Pod manifest
Use kubectl get pod with label selector to check the Pod's lifecycle state
Print the Pod's status phase to see its current lifecycle state
💡 Why This Matters
🌍 Real World
Kubernetes Pods run your application containers. Knowing their lifecycle states helps you monitor if your app is running, starting, or has errors.
💼 Career
DevOps engineers and site reliability engineers use Pod lifecycle states daily to ensure applications are healthy and troubleshoot issues quickly.
Progress0 / 4 steps
1
Create the initial Pod manifest
Create a YAML file named mypod.yaml with a Pod manifest that has apiVersion: v1, kind: Pod, metadata name mypod, and a single container named nginx using the image nginx:latest.
Kubernetes
Need a hint?

Remember to include apiVersion, kind, metadata with name, and spec with containers list.

2
Add a label to the Pod manifest
Add a label app: demo under the metadata section in mypod.yaml to help identify the Pod.
Kubernetes
Need a hint?

Labels go under metadata as a map with key and value.

3
Check Pod lifecycle state using label selector
Use the command kubectl get pod -l app=demo to list the Pod with label app=demo and observe its lifecycle state in the STATUS column.
Kubernetes
Need a hint?

The -l flag filters Pods by label.

4
Display the Pod's current lifecycle state
Use the command kubectl get pod mypod -o jsonpath='{.status.phase}' to print the current lifecycle state of the Pod named mypod.
Kubernetes
Need a hint?

The -o jsonpath= option extracts specific fields from the Pod JSON output.