Kubectl notes

   |   2 minute read   |   Using 350 words

kubectl is a command-line tool for Kubernetes, a powerful system for managing containerized applications.

Here are some of the most useful kubectl commands that are essential for interacting with a Kubernetes cluster

  1. kubectl get: Fetches a list of resources. For example, kubectl get pods lists all pods in the namespace, and kubectl get services lists all services.

  2. kubectl describe: Shows detailed information about a specific resource, such as kubectl describe nodes my-node.

  3. kubectl create: Used to create a resource from a file or stdin. For example, kubectl create -f my-resource.yaml creates the resources defined in the my-resource.yaml file.

  4. kubectl apply: Applies a configuration to a resource from a file or stdin. It’s used for applying changes to your resources. For instance, kubectl apply -f deployment.yaml updates the deployment defined in deployment.yaml.

  5. kubectl delete: Deletes resources either by filenames, stdin, resources and names, or by resources and label selector. For example, kubectl delete -f ./pod.json deletes a pod based on the type and name specified in pod.json.

  6. kubectl exec: Executes a command in a container. For example, kubectl exec -it my-pod -- /bin/bash opens a bash shell in my-pod.

  7. kubectl logs: Retrieves logs from a container. Useful for troubleshooting, e.g., kubectl logs my-pod.

  8. kubectl port-forward: Forwards one or more local ports to a pod. This is useful for accessing a service locally, e.g., kubectl port-forward my-pod 5000:6000.

  9. kubectl run: Runs a particular image on the cluster. For example, kubectl run my-nginx --image=nginx runs an nginx pod.

  10. kubectl config: Used to modify kubeconfig files. Commands like kubectl config view or kubectl config use-context my-cluster-name are frequently used.

  11. kubectl rollout: Manages the rollout of a resource (e.g., deployments). You can use kubectl rollout status deployment/my-deployment to check the status of a deployment.

  12. kubectl scale: Scales a resource like a Deployment or ReplicaSet. For instance, kubectl scale deployment my-deployment --replicas=3 changes the number of replicas to 3.

  13. kubectl top: Displays resource usage statistics. For example, kubectl top pod shows the usage of resources by pods.

  14. kubectl label: Updates the labels on a resource, which can be used for organizing and selecting subsets of objects.



denis256 at denis256.dev