Kubernetes is a defacto tool for any enterprise application to manage containerized applications in production. I would like to share some important commands which I use daily work.


Context & Configurations

  • To view configuration of the k8s
                kubectl config view  
  • To display list of contexts
              kubectl config get-contexts
  • To display current context
            kubectl config current-context
  • To set the default context to specific <my-cluster-name>
            kubectl config use-context my-cluster-name

Viewing & Finding Services

  • To display all the pods
            kubectl get pods
  • To get Pod's yaml file
            kubectl get pod my-pod -o yaml
  • To display pod's yaml without cluster specific information
            kubectl get pod my-pod -o yaml --export
  • Show labels for all pods (or any other K8s object that supports lebelling)
            kubectl get pods --show-labels

To Interact with Running Pods

  • To display logs of a pod
           kubectl logs my-pod
  • To display logs of pods with a specific label name
            kubectl logs -l name=my-label
  • To display logs of a container
           kubectl logs my-pod -c my-container
  • To stream pod logs
          kubectl logs -f my-pod
  • To stream pod container logs
          kubectl logs -f my-pod -c my-container
  • To stream pod previous container logs 
          kubectl logs -f my-pod -c my-container --previous

  • To know complete details every pod
           kubectl describe pods





Post a Comment

Previous Post Next Post