Kubernetes Commands
kubectl commands and Kubernetes resource management.
Cluster Info
kubectl cluster-infoDisplay cluster information
kubectl versionShow client and server version
kubectl get nodesList all nodes in cluster
kubectl get nodes -o wideList nodes with additional info
kubectl describe node node-nameShow detailed node information
kubectl top nodesShow node resource usage
Pods
kubectl get podsList pods in current namespace
kubectl get pods -AList pods in all namespaces
kubectl get pods -o wideList pods with additional details
kubectl describe pod pod-nameShow detailed pod information
kubectl logs pod-nameView pod logs
kubectl logs -f pod-nameFollow pod logs in real-time
kubectl logs pod-name -c container-nameView logs from specific container
kubectl exec -it pod-name -- /bin/bashExecute shell in pod
kubectl delete pod pod-nameDelete a pod
kubectl top podsShow pod resource usage
Deployments
kubectl get deploymentsList deployments
kubectl describe deployment deployment-nameShow deployment details
kubectl create deployment name --image=nginxCreate deployment
kubectl scale deployment name --replicas=3Scale deployment to 3 replicas
kubectl set image deployment/name container=image:tagUpdate deployment image
kubectl rollout status deployment/nameCheck rollout status
kubectl rollout history deployment/nameView rollout history
kubectl rollout undo deployment/nameRollback to previous version
kubectl delete deployment nameDelete deployment
Services
kubectl get servicesList services
kubectl get svcList services (short)
kubectl describe service service-nameShow service details
kubectl expose deployment name --port=80 --type=LoadBalancerExpose deployment as service
kubectl delete service service-nameDelete service
kubectl get endpointsList service endpoints
ConfigMaps & Secrets
kubectl get configmapsList ConfigMaps
kubectl describe configmap nameShow ConfigMap details
kubectl create configmap name --from-file=file.txtCreate ConfigMap from file
kubectl get secretsList secrets
kubectl describe secret nameShow secret details
kubectl create secret generic name --from-literal=key=valueCreate secret from literal
kubectl delete configmap nameDelete ConfigMap
kubectl delete secret nameDelete secret
Namespaces
kubectl get namespacesList all namespaces
kubectl get nsList namespaces (short)
kubectl create namespace nameCreate new namespace
kubectl delete namespace nameDelete namespace
kubectl config set-context --current --namespace=nameSet default namespace
kubectl get pods -n namespace-nameList pods in specific namespace
Resources & YAML
kubectl apply -f file.yamlApply configuration from file
kubectl delete -f file.yamlDelete resources from file
kubectl get allList all resources
kubectl get pod pod-name -o yamlExport pod as YAML
kubectl get pod pod-name -o jsonExport pod as JSON
kubectl explain podsShow resource documentation
kubectl api-resourcesList all resource types
Context & Config
kubectl config viewView kubeconfig
kubectl config get-contextsList contexts
kubectl config current-contextShow current context
kubectl config use-context context-nameSwitch to context
kubectl config set-context name --cluster=cluster --user=userCreate new context
Labels & Selectors
kubectl get pods -l app=nginxFilter pods by label
kubectl get pods --show-labelsShow pod labels
kubectl label pods pod-name env=productionAdd label to pod
kubectl label pods pod-name env-Remove label from pod
Troubleshooting
kubectl get eventsList cluster events
kubectl get events --sort-by=.metadata.creationTimestampList events sorted by time
kubectl describe pod pod-nameDebug pod issues
kubectl logs pod-name --previousView logs from previous pod instance
kubectl port-forward pod-name 8080:80Forward local port to pod
kubectl cp pod-name:/path/file ./fileCopy file from pod
kubectl debug pod-name -it --image=busyboxDebug pod with ephemeral container