"Master Kubernetes: Cheat Sheet with Practical Examples"

Mastering Kubernetes: A Comprehensive Cheat Sheet with Examples

Kubernetes, often referred to as K8s, is an open-source container orchestration platform that automates application deployment, scaling, and management. Whether you're a seasoned Kubernetes user or just starting your journey, this cheat sheet will serve as a handy reference for common tasks and commands.

Kubernetes Basics and Setup

Before diving into the cheat sheet, ensure you have a running Kubernetes cluster. You can set up a local cluster using Minikube or use a managed Kubernetes service like Amazon EKS, Azure Kubernetes Service, or Google Kubernetes Engine.

Checking Kubernetes Version and Cluster Info

  • Check the client version:

Kubernetes Commands Cheat Sheet | Pods, Services, Deployments & YAML Guide
Kubernetes Commands Cheat Sheet | Pods, Services, Deployments & YAML Guide

kubectl version
  • Check the server version and cluster info:

  • kubectl cluster-info

    Kubernetes Objects and Commands

    Kubernetes uses various objects to manage resources. Here are some essential commands to work with these objects.

    Pods

    • List all pods in all namespaces:

    a diagram with the words how to learn kubernets on it and an image of
    a diagram with the words how to learn kubernets on it and an image of

    kubectl get pods
  • Describe a specific pod:

  • kubectl describe pod <pod-name>
  • Delete a pod:

  • kubectl delete pod <pod-name>

    Deployments

    • List all deployments:

    Kubernes Cheat Sheet
    Kubernes Cheat Sheet

    kubectl get deployments
  • Scale a deployment:

  • kubectl scale deployment <deployment-name> --replicas=<number-of-replicas>
  • Rollout a new version of a deployment:

  • kubectl set image deployment <deployment-name> <container-name>= <new-image:tag>

    Services

    • List all services:

    kubectl get services
  • Expose a deployment as a service:

  • kubectl expose deployment <deployment-name> --type=<service-type> --port=<port>

    Namespaces

    • List all namespaces:

    kubectl get namespaces
  • Switch to a specific namespace:

  • kubectl config set-context $(kubectl config current-context) --namespace=<namespace-name>

    Kubernetes Configuration and Contexts

    Kubernetes uses config files to store cluster information and credentials. Here's how to manage these configurations.

    Viewing and Managing Contexts

    • List all contexts:

    kubectl config view --minify --output 'jsonpath={..contexts[].name}'
  • Use a specific context:

  • kubectl config use-context <context-name>

    Managing Kubeconfig File

    • View the kubeconfig file:

    kubectl config view --minify
  • Merge kubeconfig files:

  • kubectl config view --minify --output 'jsonpath={..clusters}'

    Troubleshooting Kubernetes

    When encountering issues, use the following commands to diagnose problems.

    Checking Node and Pod Status

    Command Description
    kubectl get nodes List all nodes and their status
    kubectl get pods --all-namespaces List all pods in all namespaces

    Viewing Events and Logs

    • View events for a specific pod:

    kubectl get events --sort-by=.metadata.creationTimestamp -w <pod-name>
  • View logs for a specific pod:

  • kubectl logs <pod-name>

    This cheat sheet provides a solid foundation for working with Kubernetes. As you gain more experience, you'll find that many tasks can be automated using scripts, config maps, and secrets. Happy orchestrating!

    the kubernets services chat sheet is shown in four different languages, including one for
    the kubernets services chat sheet is shown in four different languages, including one for
    the ultimate kubernets command cheatet is displayed in this screenshote
    the ultimate kubernets command cheatet is displayed in this screenshote
    a blue and white poster with the words kubernets heat sheet
    a blue and white poster with the words kubernets heat sheet
    a blue and white poster with the words kubernets written in different languages
    a blue and white poster with the words kubernets written in different languages
    how kubernets works end - to - end with the blueprinting application
    how kubernets works end - to - end with the blueprinting application
    #devops #kubernetes | Aswin Vijayan
    #devops #kubernetes | Aswin Vijayan
    an image of a document with the words, fundamentnal kubernets concept
    an image of a document with the words, fundamentnal kubernets concept
    the roadmap for kubernets is shown in this graphic, which shows how
    the roadmap for kubernets is shown in this graphic, which shows how
    the kubernets basics diagram with several different types of service and services in it
    the kubernets basics diagram with several different types of service and services in it
    an info sheet describing the different types of kubernets and what they are used
    an info sheet describing the different types of kubernets and what they are used
    a poster with the words kubernets network and other information on it's side
    a poster with the words kubernets network and other information on it's side
    ☕︎‧₊kubernetes٠࣪⋆💻₊˚ᵎ Devops
    ☕︎‧₊kubernetes٠࣪⋆💻₊˚ᵎ Devops
    the kubernets explanation diagram is shown in this graphic above it's description
    the kubernets explanation diagram is shown in this graphic above it's description
    the kubernets concept is depicted in this graphic above it's description
    the kubernets concept is depicted in this graphic above it's description
    a poster with instructions on how to use kubernets
    a poster with instructions on how to use kubernets
    a poster with the words kubernets and an arrow pointing to each other
    a poster with the words kubernets and an arrow pointing to each other
    Chiranjeeb Dash on LinkedIn: 🚀 Mastering Kubernetes: The Ultimate Roadmap for 2024! ☸️ Kubernetes has…
    Chiranjeeb Dash on LinkedIn: 🚀 Mastering Kubernetes: The Ultimate Roadmap for 2024! ☸️ Kubernetes has…
    an info sheet with instructions on how to use the advanced kubernets system
    an info sheet with instructions on how to use the advanced kubernets system
    the kubernets interview chart is shown
    the kubernets interview chart is shown
    Kubernetes Cheat Sheet
    Kubernetes Cheat Sheet
    #kubernetes #devops #cloudcomputing #containers #k8s #techguide | puneet mehra
    #kubernetes #devops #cloudcomputing #containers #k8s #techguide | puneet mehra
    the kubectl cheat sheet is full of information for all kinds of items
    the kubectl cheat sheet is full of information for all kinds of items
    A few things I've learned about Kubernetes
    A few things I've learned about Kubernetes