Chuleta de kubectl
NUEVOChuleta de kubectl para Kubernetes: contextos, get y describe, apply, logs, exec, port-forward, rollout, scale, secretos, depuración y formatos de salida. Los comandos están en inglés.
Funciona al 100 % en tu navegador — lo que introduces nunca se sube ni se guarda en nuestros servidores.
95 entradas en 11 secciones
Context & config
kubectl config get-contextsList the contexts (cluster, user, namespace) in your kubeconfig.
kubectl config current-contextShow the context you are using now.
kubectl config use-context <name>Switch to another context.
kubectl config set-context --current --namespace=<ns>Set the default namespace of the current context.
kubectl config view --minifyShow the kubeconfig settings of the current context only.
kubectl cluster-infoShow the addresses of the control plane and core services.
kubectl versionShow client and server versions.
Get & describe
kubectl get podsList pods in the current namespace.
kubectl get pods -AList pods in all namespaces.
kubectl get pods -o wideList pods with node and IP columns.
kubectl get pods -wWatch pods and print changes as they happen.
kubectl get pods -l app=webFilter by label.
kubectl get allList the common resource types (pods, services, deployments, ...).
kubectl get deploy,svc,ingList several resource types at once.
kubectl describe pod <name>Show details and recent events of a pod.
kubectl get events --sort-by=.lastTimestampList recent events, oldest first.
kubectl explain deployment.spec.strategyShow the documentation of a field in a resource.
Create, apply & delete
kubectl apply -f manifest.yamlCreate or update resources from a file.
kubectl apply -f ./dir/Apply every manifest in a folder.
kubectl apply -k <dir>Apply a Kustomize directory.
kubectl apply -f manifest.yaml --dry-run=serverValidate against the cluster without changing anything.
kubectl diff -f manifest.yamlShow what would change if you applied the file.
kubectl create deployment web --image=nginxCreate a deployment from the command line.
kubectl create namespace <name>Create a namespace.
kubectl run web --image=nginxStart a single pod.
kubectl expose deployment web --port=80Create a service in front of a deployment.
kubectl edit deployment <name>Edit a live resource in your editor.
kubectl delete -f manifest.yamlDelete the resources defined in a file.
kubectl delete pod <name>Delete a pod (a controller will usually recreate it).
Logs, exec, port-forward & cp
kubectl logs <pod>Show a pod's logs.
kubectl logs -f <pod>Follow the log.
kubectl logs <pod> -c <container>Logs of one container in a multi-container pod.
kubectl logs <pod> --previousLogs of the previous container instance, useful after a crash.
kubectl logs -l app=web --tail=50Last 50 lines from every pod matching a label.
kubectl exec -it <pod> -- shOpen a shell in a pod (use bash if available).
kubectl exec <pod> -- envRun one command in a pod.
kubectl port-forward <pod> 8080:80Forward local port 8080 to port 80 of the pod.
kubectl port-forward svc/<name> 8080:80Forward a local port to a service.
kubectl cp <pod>:/path/file ./fileCopy a file from a pod (needs tar in the container).
kubectl cp ./file <pod>:/path/fileCopy a local file into a pod.
Rollout & scale
kubectl rollout status deployment/<name>Wait for a rollout and report its progress.
kubectl rollout history deployment/<name>List the revisions of a deployment.
kubectl rollout undo deployment/<name>Go back to the previous revision.
kubectl rollout restart deployment/<name>Restart all pods of a deployment one by one.
kubectl set image deployment/<name> <container>=<image>:<tag>Change the image of a container and trigger a rollout.
kubectl scale deployment/<name> --replicas=3Set the number of replicas.
kubectl autoscale deployment <name> --min=2 --max=10 --cpu-percent=80Create a horizontal pod autoscaler.
Namespaces
kubectl get namespacesList namespaces.
kubectl get pods -n <namespace>Run a command against a specific namespace.
kubectl delete namespace <name>Delete a namespace and everything inside it.
kubectl get all -n <namespace>List common resources in a namespace.
kubectl api-resources --namespaced=trueList resource types that live inside namespaces.
Nodes
kubectl get nodesList nodes and their status.
kubectl describe node <name>Show capacity, allocated resources and conditions of a node.
kubectl top nodesCPU and memory use per node (needs metrics-server).
kubectl cordon <node>Mark a node as unschedulable.
kubectl drain <node> --ignore-daemonsetsEvict pods from a node before maintenance.
kubectl uncordon <node>Allow scheduling on a node again.
kubectl taint nodes <node> key=value:NoScheduleAdd a taint so pods without a matching toleration are not scheduled.
Secrets & ConfigMaps
kubectl create configmap app-config --from-literal=KEY=valueCreate a ConfigMap from a key and value.
kubectl create configmap app-config --from-file=config.propertiesCreate a ConfigMap from a file.
kubectl create secret generic db-pass --from-literal=password=<value>Create a generic secret.
kubectl get secret db-pass -o yamlShow a secret. Values are base64-encoded, not encrypted.
kubectl get secret db-pass -o jsonpath='{.data.password}' | base64 -dRead and decode one secret value.
kubectl create secret docker-registry regcred --docker-server=<host> --docker-username=<user> --docker-password=<pass>Create credentials for pulling private images.
Debugging
kubectl get pods --field-selector=status.phase!=RunningFind pods that are not running.
kubectl get events --field-selector involvedObject.name=<pod>Events for one pod: pull errors, scheduling issues, probe failures.
kubectl top podsCPU and memory use per pod (needs metrics-server).
kubectl debug -it <pod> --image=busybox --target=<container>Attach a temporary debug container to a pod.
kubectl run tmp --rm -it --image=busybox --restart=Never -- shStart a throwaway pod with a shell and remove it on exit.
kubectl auth can-i create deploymentsCheck whether you are allowed to do something.
kubectl get endpoints <service>Check which pod IPs back a service; empty means no ready pods match.
Output formats
kubectl get pod <name> -o yamlFull resource as YAML.
kubectl get pod <name> -o jsonFull resource as JSON.
kubectl get pods -o nameOnly resource names, like pod/web-1.
kubectl get pods -o jsonpath='{.items[*].metadata.name}'Extract fields with JSONPath.
kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'JSONPath loop: one node name per line.
kubectl get pods -o custom-columns=NAME:.metadata.name,NODE:.spec.nodeNamePick your own columns.
kubectl get pods --sort-by=.metadata.creationTimestampSort by a field.
kubectl get pods --show-labelsAdd a column with all labels.
Resource short names
Use these in place of the full type name, e.g. kubectl get po.
popods
svcservices
deploydeployments
rsreplicasets
dsdaemonsets
stsstatefulsets
cmconfigmaps
nsnamespaces
nonodes
pvpersistentvolumes
pvcpersistentvolumeclaims
ingingresses
hpahorizontalpodautoscalers
cjcronjobs
saserviceaccounts
Ejemplos rápidos
Entradas típicas y los resultados que produce esta herramienta.
Descripción general
kubectl es la herramienta de línea de comandos para hablar con un clúster de Kubernetes. Esta chuleta de kubectl reúne lo que usas a diario: cambiar de contexto y de espacio de nombres, get y describe, apply y delete, logs, exec y port-forward, rollouts y escalado, nodos, secretos y ConfigMaps, y depuración.
Una sección sobre formatos de salida muestra -o yaml, JSONPath y columnas personalizadas, y una tabla de nombres cortos de recursos (po, svc, deploy y otros) te ahorra escribir. Los comandos que modifican o eliminan cosas, como delete y drain, se describen con claridad.
Los comandos, las opciones y sus descripciones breves se muestran en inglés; solo la interfaz y el texto de la página están traducidos. Filtra la lista, copia un comando y sustituye los marcadores como <pod>. Todo se ejecuta en tu navegador y nada de lo que escribes se sube.
¿Por qué usar esta herramienta?
- Consulta la sintaxis de kubectl en segundos
- Comandos de depuración agrupados
- Ejemplos de JSONPath y custom-columns
- Nombres cortos de los recursos habituales
- Copia cualquier comando con un clic
Funciones
Contextos
Lista, cambia y fija el espacio de nombres predeterminado de un contexto.
Apply y delete
Manifiestos, simulaciones, diff y Kustomize.
Logs y exec
Sigue los logs, abre una shell, redirige puertos y copia archivos.
Rollouts
Estado, historial, undo, restart, set image y escalado.
Depuración
Eventos, top, contenedores de depuración y pods desechables.
Nombres cortos
Una tabla rápida: po, svc, deploy, ing, pvc y otros.
Cómo se usa
Elige una sección
Desplázate hasta Rollout, Debugging, Output formats o el tema que necesites (los títulos de sección están en inglés).
O filtra
Escribe una palabra como «logs» o «jsonpath» en el cuadro «Filtrar esta chuleta».
Lee la descripción
Cada comando tiene una explicación breve, en inglés, de lo que cambia o muestra.
Copia y ejecuta
Pulsa Copiar, pega en tu terminal y sustituye los marcadores como <pod>.