惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LINUX DO - 最新话题
A
Arctic Wolf
I
Intezer
V
Vulnerabilities – Threatpost
C
Cisco Blogs
MyScale Blog
MyScale Blog
NISL@THU
NISL@THU
Y
Y Combinator Blog
C
CERT Recently Published Vulnerability Notes
P
Privacy International News Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
Recorded Future
Recorded Future
云风的 BLOG
云风的 BLOG
S
SegmentFault 最新的问题
Microsoft Security Blog
Microsoft Security Blog
L
LangChain Blog
博客园 - 聂微东
博客园 - 叶小钗
F
Fortinet All Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Recent Announcements
Recent Announcements
C
Cyber Attacks, Cyber Crime and Cyber Security
Latest news
Latest news
Simon Willison's Weblog
Simon Willison's Weblog
P
Palo Alto Networks Blog
S
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Hacker News
The Hacker News
博客园 - 司徒正美
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LINUX DO - 热门话题
罗磊的独立博客
K
Kaspersky official blog
Last Week in AI
Last Week in AI
Know Your Adversary
Know Your Adversary
小众软件
小众软件
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
D
DataBreaches.Net
Scott Helme
Scott Helme
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
博客园 - 三生石上(FineUI控件)
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Full Disclosure

Learn Cloud Native

Agentgateway rate limiting for agents | Learn Cloud Native Local development with coding agents on Kubernetes using Signadot | Learn Cloud Native cuenv: one typed file for your whole project | Learn Cloud Native Preflight: AI Code Review Before You Push Anatomy of AI Agents Accessing Google Drive from Next.js Deploying to Fly.io using Dagger and Github Top Cloud-Native & Kubernetes Certifications [2026 Guide] Rapid microservices development with Signadot How to prepare for Istio certified associate exam (ICA) Global Rate Limiting in Istio with Envoy Rate Limit Service My Journey with Istio: From Incubation to Graduation Cilium Network Policy Tutorial: Secure Kubernetes Step by Step Kubernetes Networking: How kube-proxy and iptables Work Istio ServiceEntry: DNS vs. STATIC Resolution & Endpoints Explained Apply an Istio DestinationRule Globally (Mesh-Wide) Istio Rate Limiting: Configure a Local Rate Limiter in Envoy How to expose custom ports on Istio ingress gateway Portainer Tutorial: A Web UI for Kubernetes & Containers Traefik Proxy 2.x and TLS 101 Kubernetes CLI (kubectl) tips you didn't know about Setting up SSL certificates with Istio Gateway ArgoCD Best Practices You Should Know 在 OCI Ampere A1 计算实例上运行 AI Running AI On OCI Ampere A1 Instance How to Deploy Traefik Proxy Using Flux and GitOps Principles Firebase Emulators with Next.js: Local Setup Guide Running Hugo on free Ampere VM (Oracle Cloud Infrastructure) How to use kwatch to detect crashes in Kubernetes clusters Continuous profiling in Kubernetes using Pyroscope Monitoring containers with cAdvisor Creating a Kubernetes cluster in Google Cloud (LAB) Your first Kubernetes Pod and ReplicaSet (LABS) Container Lifecycle Hooks Maybe Convert Wasm Extension Config? GetIstio - CLI, training, and community Attach multiple VirtualServices to Istio Gateway Kubernetes Volumes Explained: Keep Data Beyond the Pod Send a Slack message when Docker images are updated Kubernetes Network Policy Ambassador Container Pattern Start Kubernetes Release Sidecar Container Pattern Kubernetes Init Containers Deploying multiple Istio Ingress Gateways Branch by Abstraction Pattern The Strangler Pattern Kubernetes Development Environment with Skaffold Securing Kubernetes Ingress with Ambassador and Let's Encrypt All About the Ingress Resource How to quarantine Kubernetes pods? Getting started with Kubernetes Horizontal partitioning in MongoDB Docker image tagging scheme Six things to keep in mind when working with Dockerfiles Beginners guide to Docker Beginners guide to gateways and proxies Deploy and Operate Multiple Istio Meshes in one Kubernetes Cluster Managing service meshes with Meshery Circuit Breaking in Istio Explained Build and push your Docker images using Github Actions Kubernetes and Istio service mesh workshop materials Build Netlify-like deployment for React app using Kubernetes pods Six exciting enhancements in Istio 1.4.0 Fallacies of Distributed Systems CAP Theorem Explained Minikube Basics and How to Get Started with Kubernetes 5 Tips to Be More Productive with Kubernetes What are sticky sessions and how to configure them with Istio? Debugging Kubernetes applications using Istio Kubernetes Ingress and Istio Gateway Resource Zero Downtime Releases using Kubernetes and Istio Traffic Mirroring with Istio Service Mesh Expose a Kubernetes service on your own custom domain
Master the Kubernetes CLI (kubectl) - Cheatsheet
Peter Jausovec · 2019-10-30 · via Learn Cloud Native

This cheatsheet contains a list of most common commands you will use when working with Kubernetes cluster and its resources.

If you're working with Kubernetes on daily basis or if you're just learning about Kubernetes you will run into a set of commands that are used often than the other commands. The ones used more often are also usually easy to remember (especially if you're typing them out multiple times a day).

The problem becomes when you're either trying to do something more advanced or run a command against a resource you're aren't using very often or not too familiar with it. This is where this cheatsheet comes into play - it will help you quickly find the command you want, so you can copy & paste it, run it and move on.

How to use this kubectl Cheatsheet

This cheatsheet is organized into multiple sections that are based on the actions you are trying to perform against Kubernetes resources. Each section contains a table with the command and the explanation of what that command does.

Introduction

Welcome friends! I am glad you've decided to either learn more about kubectl or just trying to find some useful commands or ideas. First things first - since you're here, I am assuming you have a Kubernetes cluster running and have access to it and you also have kubectl installed.

The basics

The commands in this cheatsheet are all using the full name of the Kubernetes CLI - kubectl. If you'll be working with Kubernetes often, I strongly advise you to create an alias for that command - it will save you a lot of typing in the long run. If you want to take this to another level, check out this set of Kubectl aliases.

To create an alias for kubectl, you can run the following command:

Or just put it directly in your ~/.bash_profile file:

echo "alias k='kubectl'" >> ~/.bash_profile

In most of the example below, I am using a pod resource as an example - you can replace pod with any other Kubernetes resource (unless the commnd is specific to that one reasource only).

I am also using the full resource names such as pod, deployment etc. but you don't have to. Refer to the Resource names section for short resource names such as po, svc or deploy.

Let's get started!

Basic resource information

CommandExplanation
kubectl get pod mypodLists the pod with name mypod in the current namespace
kubectl get podLists all pods in the current namespace
kubectl get pod -n mynamespaceLists all pods in mynamespace namespace
kubectl get pod --all-namespacesLists all pods in all namespaces
kubectl get pod --all-namespaces -o wideLists all pods in all namespaces with IP and Node
kubectl get all --all-namespacesLists all resources in the cluster
kubectl describe pod mypodDescribes the resource in mor details (perfect for diagnosing issues)
kubectl get pod --show-labelsShows the labels next to all pods
kubectl explain podShows documentation for the resource (e.g. pod in our case)
kubectl get pod mypod -o yamlShows the YAML representation of the pod called mypod
kubectl get pod mypod -o jsonShows the JSON representation of the pod called mypod
kubectl cluster-infoShows information about the cluster
kubectl describeLists all resource names
kubectl get pod -wWatches the pods (useful when waiting for e.g. pods to start)

Note

Note 1: replace the pod in above commands with any other resource (e.g. service, deployment, ...)

Note

Note 2: use the short name for resources. For example: po for pods, svc for service, deploy for deployment, etc.

Detailed resource information

CommandExplanation
kubectl get pod --selector="app=myapp"Lists all pods with label app=myapp
kubectl get pod --selector="app=myapp" -o jsonpath='{.items[*].metadata.name}'Get the pod names that have the label app=myapp set
kubectl get pod --selector="app=myapp" -o jsonpath='{.items[*].spec.containers[*].image}'Get the image names of pods that have the label app=myapp set
kubectl get pod mypod -o jsonpath='{.items[*].status.podIP}'Get the pod IPs of the mypod
kubectl get pod mypod -o jsonpath='{.spec.containers[0].ports[0].containerPort}'Get the first container port in the pod
kubectl -v 9 get podGets the pods with maximum (9) verbosity

Sorting and filtering

CommandExplanation
kubectl get pod --sory-by=.metadata.nameLists the pods and sorts them by their names
kubectl get pod --sory-by=.metadata.creationTimestampLists the pods by creation time, oldest first
kubectl get pod -l app=myappShow pods that have the label app=myapp set

Labelling and annotating resources

CommandExplanation
kubectl label pod mypod mylabel=myvalueAdds the label mylabel=myvalue to the pod named mypod
kubectl label pod mypod mylabel-Removes the mylabel from the pod named mypod
kubectl get pod mypod -o jsonpath='{.items[*].metadata.annotations}'Get all annotations for the pod named mypod
kubectl annotate pod mypod name=valueAdd an annotation name=value to the pod named mypod
kubectl annotate pod mypod name-Removes the annotation name from the pod named mypod

Creating, editing and deleting resources

CommandExplanation
kubectl create -f ./file.yamlCreate resources defined in file file.yaml
kubectl delete -f ./file.yamlDelete resources defined in file file.yaml
kubectl delete pod mypodDelete a pod named mypod in the current namespace
kubectl run mypod --image=myimageCreates a pod (and deployment) called mypod with image myimage
kubectl run mypod --image=myimage --port=8080Creates a pod (and deployment) called mypod with image myimage and exposes port 8080

Advanced commands

CommandExplanation
kubectl run curl --image=radial/busyboxplus:curl -i --ttyRuns the radial/busyboxplus:curl image and gives you a terminal into it (useful for accessing pods/services within the cluster)
kubectl port-forward mypod 8080:CONTAINER_PORTForwards the local port 8080 to CONTAINER_PORT (replace this with actual container port number)
kubectl expose deployment mydeployment --type="NodePort" --port 8080Exposes deployment mydeployment to external traffic and makes it available on port 8080
kubectl exec -it mypod -- /bin/bashRuns the /bin/bash (terminal) inside the pod called mypod
kubectl attach mypodWatch the standard output of a container in real time
kubectl cp mypod:/some/path/file.txt .Copies the file /some/path/file.txt from mypod to the current directory

Resource names

Here's the list of all Kubernetes resource names and their shorthand equivalents (if available).

Note

Note: you also run kubectl describe to get a list of these.

Long nameShort name
all
certificatesigningrequestscsr
clusterrolebindings
clusterroles
componentstatusescs
configmapscm
controllerrevisions
cronjobs
customresourcedefinitioncrd
daemonsetsds
deploymentsdeploy
endpointsep
eventsev
horizontalpodautoscalershpa
ingressesing, ingress
jobs
limitrangeslimits
namepsacesns
networkpoliciesnetpol
nodesno
persistentvolumeclaimspvc
persistentvolumespv
poddisruptionbudgetspdb
podpreset
podspo, pod
podsecuritypoliciespsp
podtemplates
replicasetsrs
replicationcontrollersrc
resourcequotasquota
rolebindings
roles
secrets
serviceaccountssa
servicessvc
statefulsetssts
storageclassessc