List of kubectl Commands with Examples

List of kubectl Commands with Examples

Kubectl is a command-line tool that is used for managing Kubernetes clusters. It provides a way to interact with Kubernetes API and allows developers to deploy, inspect, and manage their applications. In this article, we will discuss a list of kubectl commands with examples that will help you to get started with Kubernetes.

Basic Commands

  1. kubectl version - This command is used to check the version of kubectl that is installed on your system.
    Example:
kubectl version
  1. kubectl cluster-info - This command is used to display the cluster information.
    Example:
kubectl cluster-info
  1. kubectl get - This command is used to list the resources in a particular namespace.
    Example:
kubectl get pods
  1. kubectl describe - This command is used to get detailed information about a particular resource.
    Example:
kubectl describe pod my-pod
  1. kubectl create - This command is used to create a new resource from a file or standard input.
    Example:
kubectl create -f my-deployment.yaml
  1. kubectl delete - This command is used to delete a particular resource.
    Example:
kubectl delete pod my-pod
  1. kubectl edit - This command is used to edit a particular resource.
    Example:
kubectl edit pod my-pod
  1. kubectl apply - This command is used to apply changes to a resource.
    Example:
kubectl apply -f my-deployment.yaml
  1. kubectl exec - This command is used to execute a command in a container.
    Example:
kubectl exec my-pod ls
  1. kubectl logs - This command is used to get the logs of a container.
    Example:
kubectl logs my-pod

Advanced Commands

  1. kubectl rollout - This command is used to manage rollouts of a deployment.
    Example:
kubectl rollout status my-deployment
  1. kubectl autoscale - This command is used to automatically scale a deployment based on CPU usage.
    Example:
kubectl autoscale deployment my-deployment --cpu-percent=50 --min=1 --max=10
  1. kubectl label - This command is used to add or remove labels from a resource.
    Example:
kubectl label pod my-pod app=myapp
  1. kubectl annotate - This command is used to add or remove annotations from a resource.
    Example:
kubectl annotate pod my-pod description='This is my pod'
  1. kubectl proxy - This command is used to create a proxy server between your machine and Kubernetes API server.
    Example:
kubectl proxy --port=8080

Kubectl is a powerful tool that allows developers to manage their Kubernetes clusters from the command line. In this article, we have discussed a list of kubectl commands with examples that will help you to get started with Kubernetes. Whether you are a beginner or an experienced Kubernetes user, these commands will help you to be more productive and efficient in managing your Kubernetes clusters.

Related Searches and Questions asked:

  • How to Install Minikube on CentOS 7
  • How to Install Minikube on CentOS 8
  • How to Install Minikube on Ubuntu 20.04
  • How to Install Minikube on Ubuntu 22.04
  • That's it for this post. Keep practicing and have fun. Leave your comments if any.

    Post a Comment

    0 Comments