DEV Community

SOVANNARO
SOVANNARO

Posted on

🕵️‍♂️ Dive Into Kubernetes: The Fun Way to Inspect Your Cluster Like a Pro!

Have you ever stood in front of your terminal, typed kubectl get something, and then felt a little lost? 😅

Don't worry—you’re not alone! Today, we're going to explore how to inspect and monitor your Kubernetes resources the easy, delightful way. Whether you're just getting started or want to sharpen your K8s skills, this guide is for you. Let’s turn “kubectl confusion” into “kubectl confidence”! 🚀


🔍 Getting Started: See It All with kubectl get all

Want to peek into your Kubernetes world? Run this command:

kubectl get all
Enter fullscreen mode Exit fullscreen mode

This shows everything running in your default namespace: Pods, Deployments, ReplicaSets, Services, and more.

If you don’t see your deployment my-apache, you can create it like this:

kubectl create deployment my-apache --image=httpd --replicas=2
Enter fullscreen mode Exit fullscreen mode

Now, let’s expand the view with more details:

kubectl get all -o wide
Enter fullscreen mode Exit fullscreen mode

And for everything in YAML format (perfect for deep-diving 🧠):

kubectl get deploy/my-apache -o yaml
Enter fullscreen mode Exit fullscreen mode

🏷️ Resource Labels: Why They Matter

Labels in Kubernetes help group and manage resources like family members with matching last names.

Here's how labels tie together:

  • Deployment with app: my-apache
  • ReplicaSet with app: my-apache, pod-template-hash: XYZ
  • Pod that also carries these labels

This label matching helps K8s keep everything connected and working smoothly—like a smart manager keeping track of who’s on which team. 💼


📖 Going Deeper with kubectl describe

kubectl get is great, but it can feel like reading just the headlines. Want the full story? Use kubectl describe.

kubectl describe deploy/my-apache
Enter fullscreen mode Exit fullscreen mode

This gives you:

  • A summary of your deployment
  • Linked ReplicaSets
  • Pod templates
  • Deployment events (like failed updates or restarts)

Want to check a specific Pod?

kubectl describe pod/my-apache-xxxx-yyyy
Enter fullscreen mode Exit fullscreen mode

Boom! Full breakdown.


🖥️ Let’s Talk Nodes

Sometimes, you need to zoom out and check the machines (nodes) running your Pods.

List all your cluster’s nodes:

kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

More detailed info about a specific node:

kubectl get node/docker-desktop -o wide
Enter fullscreen mode Exit fullscreen mode

Even deeper:

kubectl describe node/docker-desktop
Enter fullscreen mode Exit fullscreen mode

This is like checking your house’s foundation—strong nodes mean a strong cluster. 🏡


👀 Real-Time Watching with -w

Want to watch your cluster in real-time, like a Kubernetes security camera? 🎥

kubectl get pods -w
Enter fullscreen mode Exit fullscreen mode

Now try deleting a pod in another terminal:

kubectl delete pod/my-apache-xxxx-yyyy
Enter fullscreen mode Exit fullscreen mode

Watch the magic as Kubernetes automatically recreates it. 💫

Want to monitor events?

kubectl get events --watch-only
Enter fullscreen mode Exit fullscreen mode

So satisfying to watch your cluster react in real-time!


📝 Viewing Container Logs

Trouble with a pod? It’s log time!

Start simple:

kubectl logs deploy/my-apache
Enter fullscreen mode Exit fullscreen mode

To follow logs and see the latest line:

kubectl logs deploy/my-apache --follow --tail=1
Enter fullscreen mode Exit fullscreen mode

For specific containers:

kubectl logs pod/my-apache-xx-yy -c httpd
Enter fullscreen mode Exit fullscreen mode

Want all containers in a pod?

kubectl logs pod/my-apache-xx-yy --all-containers=true
Enter fullscreen mode Exit fullscreen mode

To level-up your logging game, check out stern on GitHub—it’s a log-tastic tool! 🐶


🧹 Clean-Up Time

Done with your testing? Clean up with:

kubectl delete deployment my-apache
Enter fullscreen mode Exit fullscreen mode

Just like tidying your desk after a great project. ✨


🎁 Bonus: YAML Spec of a Pod

Here’s a quick peek at how Kubernetes defines your pod under the hood:

apiVersion: v1
kind: Pod
metadata:
  name: my-apache-abc123
  labels:
    app: my-apache
spec:
  containers:
  - name: httpd
    image: httpd
    imagePullPolicy: Always
Enter fullscreen mode Exit fullscreen mode

Isn’t that beautiful? Clean, declarative, and powerful.


💬 Final Words: You’re Now a Kubernetes Detective! 🕵️‍♀️🕵️‍♂️

Kubernetes might seem like a mysterious world full of YAML spells and terminal magic, but with tools like kubectl get, describe, and logs, you're more than ready to investigate, monitor, and master your cluster!

Keep experimenting, keep learning—and most of all, have fun. Because learning Kubernetes doesn’t have to be boring. It can be joyful. 💙

Top comments (0)