Skip to content

Instantly share code, notes, and snippets.

@edib
Created September 25, 2023 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edib/6044631585e399b1cf52b46277caec0f to your computer and use it in GitHub Desktop.
Save edib/6044631585e399b1cf52b46277caec0f to your computer and use it in GitHub Desktop.

Some Importants

Basic Interactions:

    kubectl version: Display the client and server versions.

    kubectl help: Display help documentation.

Cluster Information:

    kubectl cluster-info: Display cluster information.

    kubectl get nodes: List all nodes in the cluster.

Pod Management:

    kubectl get pods: List all pods in a namespace.

    kubectl describe pod [POD_NAME]: Show detailed information about a pod.

    kubectl run [NAME] --image=[IMAGE_NAME]: Run a particular image on the cluster.

    kubectl delete pod [POD_NAME]: Delete a pod.

Configuration:

    kubectl config view: View Kubernetes configuration.

    kubectl config use-context [CONTEXT_NAME]: Switch to another context (cluster).

Workloads:

    kubectl get deployments: List all deployments.

    kubectl describe deployment [DEPLOYMENT_NAME]: Describe a specific deployment.

    kubectl create -f [CONFIG_FILE.yaml]: Create a resource from a file.

    kubectl delete -f [CONFIG_FILE.yaml]: Delete a resource described in a file.

    kubectl scale deployment [DEPLOYMENT_NAME] --replicas=[NUM]: Scale a deployment.

Service Management:

    kubectl get svc: List all services.

    kubectl expose: Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service.

Namespace:

    kubectl get namespaces: List all namespaces.

    kubectl create namespace [NAMESPACE_NAME]: Create a new namespace.

    kubectl delete namespace [NAMESPACE_NAME]: Delete a namespace.

Logs and Debugging:

    kubectl logs [POD_NAME]: Retrieve logs from a pod.

    kubectl exec -it [POD_NAME] -- /bin/sh: Execute a command on a running pod (usually for debugging).

Resource Management:

    kubectl get [RESOURCE_TYPE]: e.g., services, pods, configmaps, secrets, etc.

    kubectl describe [RESOURCE_TYPE] [RESOURCE_NAME]: Get detailed information about a specific resource.

    kubectl apply -f [CONFIG_FILE.yaml]: Apply changes to a resource using a file.

    kubectl delete [RESOURCE_TYPE] [RESOURCE_NAME]: Delete a resource.

Storage:

kubectl get pv: List all Persistent Volumes.

kubectl get pvc: List all Persistent Volume Claims.

Advanced:

kubectl rollout: Manage a resource rollout (commonly used with deployments).

kubectl port-forward: Forward traffic from local machine to a pod.

kubectl proxy: Start a proxy to the Kubernetes API server.

Autoscaling:

kubectl autoscale: Automatically scale the set of pods.

Plugin Management:

kubectl plugin list: List available kubectl plugins.

Alias:

While not a kubectl command directly, many users define aliases for common kubectl commands to reduce typing. For example: alias k='kubectl'.

This list covers many of the commonly used kubectl commands. However, there are many more commands and flags available, and the exact capabilities can vary based on the version of Kubernetes you're working with. Always refer to the official Kubernetes documentation or use kubectl help to dive deeper into specific commands and their usages.

@edib
Copy link
Author

edib commented Sep 25, 2023

kubectl run -it alpine --image alpine -- ash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment