Skip to content

Instantly share code, notes, and snippets.

@Madhuka
Last active June 14, 2023 06:05
Show Gist options
  • Save Madhuka/797cb9a04f65d27730beaf888aa8a383 to your computer and use it in GitHub Desktop.
Save Madhuka/797cb9a04f65d27730beaf888aa8a383 to your computer and use it in GitHub Desktop.
Kubectl commands
Description Command
List pods with nodes info kubectl get pod -o wide
List everything kubectl get all --all-namespaces
Get all services kubectl get service --all-namespaces
Show nodes with labels kubectl get nodes --show-labels
Validate yaml file with dry run kubectl create --dry-run --validate -f pod-dummy.yaml
kubectl run shell command kubectl exec -it mytest -- ls -l /etc/hosts
Explain resource kubectl explain pods | kubectl explain svc
Get pods kubectl get pods
Check pod environment variables kubectl exec wso2apim-pod env
Get services sorted by name kubectl get services –sort-by=.metadata.name
Get pods sorted by restart count kubectl get pods –sort-by=’.status.containerStatuses[0].restartCount’
Delete pod kubectl delete pod <pod-name> -n <my-namespace>
Delete pod by force kubectl delete pod <pod-name> --grace-period=0 --force
Delete pods by labels kubectl delete pod -l env=test
List all services kubectl get services
List service endpoints kubectl get endpoints
Scale out kubectl scale --replicas=3 deployment/nginx-app
Roll backup kubectl rollout app-v1 app-v2 --rollback
List rollout kubectl get rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment