kubectl most common commands

kubectl most common commands

Here are some of the most common kubectl commands :

  1. Cluster Status:

    • kubectl cluster-info: Displays cluster info.

    • kubectl get nodes: Lists nodes in the cluster and their status.

    • kubectl get pods --all-namespaces: Lists all pods in all namespaces.

    • kubectl get deployments: Lists all deployments in the cluster.

    • kubectl get services: Lists all services in the cluster.

  2. Application Deployment and Management:

    • kubectl create deployment <name> --image=<image>: Creates a new deployment.

    • kubectl expose deployment <name> --port=<port>: Exposes a deployment as a service.

    • kubectl scale deployment <name> --replicas=<number>: Scales a deployment to increase or decrease the number of replicas.

    • kubectl set image deployment/<name> <container-name>=<new-image>: Updates the image of a container in a deployment.

  3. Debugging and Monitoring:

    • kubectl logs <pod-name>: Displays logs of a specific pod.

    • kubectl describe pod <pod-name>: Provides details about a specific pod.

    • kubectl top nodes: Shows resource usage metrics for nodes.

    • kubectl top pods: Shows resource usage metrics for pods.

  4. Configuration Management:

    • kubectl create configmap <name> --from-file=<file>: Creates a ConfigMap from a file.

    • kubectl create secret generic <name> --from-literal=<key>=<value>: Creates a secret from literal values.

    • kubectl apply -f <file.yaml>: Applies configuration from a YAML file.

  5. Resource Deletion:

    • kubectl delete <type> <name>: Deletes a specific resource.

    • kubectl delete -f <file.yaml>: Deletes resources defined in a YAML file.

    • kubectl delete pod --all: Deletes all pods in the cluster.