Kubernetes command line

Kubernetes provides a powerful command-line interface (CLI) called kubectl that allows you to interact with Kubernetes clusters. Here are some commonly used kubectl commands:

Cluster Information:

  1. View Cluster Information:kubectl cluster-info
  2. Display Nodes:kubectl get nodes

Pods:

  1. List Pods:kubectl get pods
  2. Pod Details:kubectl describe pod <pod_name>
  3. Create Pod:kubectl apply -f pod.yaml

Deployments:

  1. List Deployments:kubectl get deployments
  2. Scale Deployment:kubectl scale deployment <deployment_name> --replicas=3
  3. Rollout History:kubectl rollout history deployment <deployment_name>

Services:

  1. List Services:kubectl get services
  2. Service Details:kubectl describe service <service_name>

ConfigMaps and Secrets:

  1. List ConfigMaps:kubectl get configmaps
  2. List Secrets:kubectl get secrets

Logs and Exec:

  1. Pod Logs:kubectl logs <pod_name>
  2. Run Command in Pod:kubectl exec -it <pod_name> -- /bin/sh

Namespaces:

  1. List Namespaces:kubectl get namespaces
  2. Switch Namespace:kubectl config set-context --current --namespace=<namespace_name>

Contexts and Configuration:

  1. List Contexts:kubectl config get-contexts
  2. Switch Context:kubectl config use-context <context_name>

Deleting Resources:

  1. Delete Pod:kubectl delete pod <pod_name>
  2. Delete Deployment:kubectl delete deployment <deployment_name>
  3. Delete Service:kubectl delete service <service_name>

More Resources:

Remember to replace <pod_name>, <deployment_name>, <service_name>, etc., with the actual names of your Kubernetes resources.

These are just a few examples, and kubectl provides a wide range of commands for managing various aspects of Kubernetes clusters. Always refer to the official Kubernetes documentation for detailed information and options.

Leave a comment