Kubectl-Commands-05

Kubectl Commands

General Information

  • kubectl can be replaced with k by using an alias.
  • kubectl makes calls to the kube-apiserver behind the scenes.

Get or List Resources

  • List all K8s objects:
  • List nodes:
  • List pods:
  • List pods with additional info:
  • List services: or
  • List deployments:
  • List replica sets:
  • List replica sets with additional information:
  • List deployments in another namespace:
  • List pods in all namespaces:
  • List service accounts:
  • List pods with a label filter:
  • Get pods with multiple label filters:
  • List all jobs:
  • List all cron jobs:
  • List all network policies:
  • List all ingress resources:
  • List persistent volumes:
  • List persistent volume claims:
  • List all DaemonSets:
  • List cluster events:
  • Get which node each pod is deployed on:

Describe Resources

  • Describe a pod:
  • Describe a deployment:
  • Describe a service account:
  • Describe an ingress:
  • Describe a DaemonSet:

Create Resources

  • Create a pod from an image:
  • Apply a K8s config.yaml file (declarative):
  • Create a namespace:
  • Create a service account:

Delete Resources

  • Delete a pod:
  • Delete a replica set:
  • Delete a deployment:
  • Delete a K8s resource from a config file:

View Logs

  • View logs of a pod:
  • View live logs of a pod:
  • View logs of a container in a multi-container pod:
  • View logs of the previous container if the pod failed:

Rollouts and Updates

  • View the status of rollout for a deployment:
  • View the history of rollouts for a deployment:
  • View the history of a specific rollout revision:
  • Rollback a deployment:
  • Rollback a deployment to a specific revision:

Node Commands

  • Cordon a node (mark it unschedulable):
  • Un-cordon a node (mark it schedulable):
  • Drain a node of all the pods:
  • Drain a node of all the pods except DaemonSets:

Auth Commands

  • View roles:
  • View role bindings:
  • Check if you have access to perform an operation:
    • Create deployments:
    • Delete nodes in dev namespace:
  • Check if another user has access to perform an operation:
    • Create deployments:
    • Delete nodes in dev namespace:
  • Check if a service account has access to perform an operation:

Config Commands

  • List all clusters:
  • Set context for a cluster:

Certificates Commands

  • List all CSRs:
  • View a CSR in YAML format:
  • Delete a CSR:
  • Approve a CSR:
  • Deny a CSR:

Output Formats

  • – JSON output
  • – Only the resource name
  • – Extra info in plain text
  • – YAML output

Useful Imperative Commands

  • Create a pod:
  • Create a deployment:
  • Create a service for a deployment:
  • Create a service for a pod:
  • Edit a deployment (in memory):
  • Scale a deployment:
  • Update the image in a deployment:
  • Create resources from a config file:
  • Update resources from a config file:
  • Delete and recreate resources from a config file:
  • Edit a deployment (doesn’t work for pods as they require recreation):

Handy Commands

  • Get the config YAML of a pod:
  • Get the config YAML of a deployment:
  • Create a sample config YAML file for a pod:
  • Create a sample config YAML file for a deployment:
  • Create a sample config YAML file for a service:

JSON Path in Kubectl

  • Get images of all the pods:

Metrics Commands

  • Get top nodes by memory:
  • Get top nodes by CPU for a context:

Leave a Reply

Your email address will not be published. Required fields are marked *