{"id":15868576,"url":"https://github.com/oleonardorodrigues/cheatsheet-kubectl","last_synced_at":"2025-04-01T21:40:56.383Z","repository":{"id":189408104,"uuid":"680617035","full_name":"OLeonardoRodrigues/cheatsheet-kubectl","owner":"OLeonardoRodrigues","description":"Kubectl Cheatsheet (WIP)","archived":false,"fork":false,"pushed_at":"2023-08-21T00:29:50.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T14:15:25.158Z","etag":null,"topics":["cheatsheet","commands","devops","kubectl","kubectl-commands","kubernetes","utilities"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OLeonardoRodrigues.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-19T20:27:27.000Z","updated_at":"2023-08-19T21:13:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"f580798a-980d-4962-82bf-16ae5be80c6c","html_url":"https://github.com/OLeonardoRodrigues/cheatsheet-kubectl","commit_stats":null,"previous_names":["oleonardorodrigues/cheatsheet-kubectl"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OLeonardoRodrigues%2Fcheatsheet-kubectl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OLeonardoRodrigues%2Fcheatsheet-kubectl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OLeonardoRodrigues%2Fcheatsheet-kubectl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OLeonardoRodrigues%2Fcheatsheet-kubectl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OLeonardoRodrigues","download_url":"https://codeload.github.com/OLeonardoRodrigues/cheatsheet-kubectl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246716171,"owners_count":20822429,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cheatsheet","commands","devops","kubectl","kubectl-commands","kubernetes","utilities"],"created_at":"2024-10-06T00:01:10.685Z","updated_at":"2025-04-01T21:40:56.363Z","avatar_url":"https://github.com/OLeonardoRodrigues.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cheatsheet Kubectl\n\n1. Get Running Pods:\n\u003ccode\u003ekubectl get pods --field-selector=status.phase=Running -n [namespace]\u003c/code\u003e\n\n1. Get Failed or Errored Pods:\n\u003ccode\u003ekubectl get pods --field-selector=status.phase=Failed -n [namespace]\u003c/code\u003e\n\n1. Describe Deployment:\n\u003ccode\u003ekubectl describe deployment my-deployment -n [namespace]\u003c/code\u003e\n\n1. Tail Logs from Container in Pod:\n\u003ccode\u003ekubectl logs -f pod my-pod -c container-name -n [namespace]\u003c/code\u003e\n\n1. Access or Execute Command from Container:\n\u003ccode\u003ekubectl exec -it my-pod -n [namespace] --container container-name -- /bin/bash\u003c/code\u003e\n\n1. Edit ConfigMap:\n\u003ccode\u003ekubectl edit configmap my-configmap -n [namespace]\u003c/code\u003e\n\n1. Rollout Status:\n\u003ccode\u003ekubectl rollout status deployment my-deployment -n [namespace]\u003c/code\u003e\n\n1. Scale Deployment:\n\u003ccode\u003ekubectl scale deployment my-deployment --replicas=3 -n [namespace]\u003c/code\u003e\n\n1. Select Pods by Label:\n\u003ccode\u003ekubectl get pods -l app=my-app -n [namespace]\u003c/code\u003e\n\n1. Port Forward Pod so it is accessible from localhost:\n\u003ccode\u003ekubectl port-forward -n [namespace] pod my-pod 8080:80\u003c/code\u003e\n\n1. Get Resource Usage from Specific Pod:\n\u003ccode\u003ekubectl top pod my-pod -n [namespace]\u003c/code\u003e\n\n1. Apply Remote Manifest:\n\u003ccode\u003ekubectl apply -f https://url-to-resource.yaml -n [namespace]\u003c/code\u003e\n\n1. Explain Field:\n\u003ccode\u003ekubectl explain pod.spec.containers\u003c/code\u003e\n\n1. List Events Sorted by Timestamp:\n\u003ccode\u003ekubectl get events --sort-by=.metadata.creationTimestamp\u003c/code\u003e\n\n1. Annotate Deployment:\n\u003ccode\u003ekubectl annotate deployment my-deployment my-label=updated -n [namespace]\u003c/code\u003e\n\n1. Rollback Deployment:\n\u003ccode\u003ekubectl rollout undo deployment my-deployment -n [namespace]\u003c/code\u003e\n\n1. PVCs by Capacity:\n\u003ccode\u003ekubectl get pvc --sort-by=.spec.capacity.storage\u003c/code\u003e\n\n1. View Deployment Rollout History:\n\u003ccode\u003ekubectl rollout history deployment my-deployment -n [namespace]\u003c/code\u003e\n\n1. Label a Pod:\n\u003ccode\u003ekubectl label pod my-pod my-label=updated -n [namespace]\u003c/code\u003e\n\n1. Diff Manifests:\n\u003ccode\u003ekubectl diff -f https://url-to-new-resource.yaml\u003c/code\u003e\n\n1. Node Details:\n\u003ccode\u003ekubectl describe node my-node\u003c/code\u003e\n\n1. Get Services with Details:\n\u003ccode\u003ekubectl get services --all-namespaces -o wide\u003c/code\u003e\n\n1. Pause Rollout:\n\u003ccode\u003ekubectl rollout pause deployment my-deployment -n [namespace]\u003c/code\u003e\n\n1. Describe Ingress:\n\u003ccode\u003ekubectl describe ingress my-ingress -n [namespace]\u003c/code\u003e\n\n1. Force Delete Pod:\n\u003ccode\u003ekubectl delete pod my-pod --grace-period=0 --force -n [namespace]\u003c/code\u003e\n\n1. Decode Secret (Kubernetes Secrets are too easy to break):\n\u003ccode\u003ekubectl get secret my-secret -o jsonpath='{.data.username}' | base64 -d\u003c/code\u003e\n\n1. Resume Rollout:\n\u003ccode\u003ekubectl rollout resume deployment my-deployment -n [namespace]\u003c/code\u003e\n\n1. Export HPA:\n\u003ccode\u003ekubectl get hpa my-hpa -n [namespace] -o yaml \u003e hpa.yaml\u003c/code\u003e\n\n1. Taint a Node:\n\u003ccode\u003ekubectl taint node my-node key=value:NoSchedule\u003c/code\u003e\n\n1. Get Completed Jobs:\n\u003ccode\u003ekubectl get jobs -n [namespace] --field-selector=status.successful=1\u003c/code\u003e\n\n1. Drain a Node:\n\u003ccode\u003ekubectl drain my-node --ignore-daemonsets\u003c/code\u003e\n\n1. Service IPs:\n\u003ccode\u003ekubectl get endpoints my-service -n [namespace] -o jsonpath='{.subsets[0].addresses[*].ip}'\u003c/code\u003e\n\n1. Rollback by Revision:\n\u003ccode\u003ekubectl rollout history deployment my-deployment --revision=3\u003c/code\u003e\n\n1. Explain Replica Count:\n\u003ccode\u003ekubectl explain deployment.spec.replicas\u003c/code\u003e\n\n1. Replace Resource:\n\u003ccode\u003ekubectl replace -f https://url-to-updated-resource.yaml\u003c/code\u003e\n\n1. Restart Deployment:\n\u003ccode\u003ekubectl rollout restart deployment my-deployment\u003c/code\u003e\n\n1. Uncordon Node:\n\u003ccode\u003ekubectl uncordon my-node\u003c/code\u003e\n\n1. Pending CSRs:\n\u003ccode\u003ekubectl get csr --sort-by=.metadata.creationTimestamp\u003c/code\u003e\n\n1. Rollback with Revision:\n\u003ccode\u003ekubectl rollout undo deployment my-deployment --to-revision=2\u003c/code\u003e\n\n1. Cordon Node:\n\u003ccode\u003ekubectl cordon my-node\u003c/code\u003e\n\n1. CRD List:\n\u003ccode\u003ekubectl api-resources | grep CustomResourceDefinition\u003c/code\u003e\n\n1. DaemonSet Status:\n\u003ccode\u003ekubectl rollout status daemonset/my-daemonset\u003c/code\u003e\n\n1. Ingress Hostname:\n\u003ccode\u003ekubectl get ingress my-ingress -o jsonpath='{.spec.rules[0].host}'\u003c/code\u003e\n\n1. Debug Pod:\n\u003ccode\u003ekubectl run -it --rm --restart=Never debug-pod --image=busybox -- sh\u003c/code\u003e\n\n1. Label Value:\n\u003ccode\u003ekubectl get rs my-replicaset -o jsonpath='{.metadata.labels.app}'\u003c/code\u003e\n\n1. Create Secret:\n\u003ccode\u003ekubectl create secret generic my-secret --from-literal=username=admin --from-literal=password=pass\u003c/code\u003e\n\n1. Rollback DaemonSet:\n\u003ccode\u003ekubectl rollout undo daemonset/my-daemonset\u003c/code\u003e\n\n1. Namespace Deployments:\n\u003ccode\u003ekubectl get deploy -n my-namespace\u003c/code\u003e\n\n1. ConfigMap Data:\n\u003ccode\u003ekubectl get cm my-configmap -o jsonpath='{.data.key}'\u003c/code\u003e\n\n1. DaemonSet History:\n\u003ccode\u003ekubectl rollout history daemonset/my-daemonset\u003c/code\u003e\n\n1. Service Ports:\n\u003ccode\u003ekubectl explain svc.spec.ports\u003c/code\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foleonardorodrigues%2Fcheatsheet-kubectl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foleonardorodrigues%2Fcheatsheet-kubectl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foleonardorodrigues%2Fcheatsheet-kubectl/lists"}